@arolariu/website / sites/arolariu.ro/src/lib/utils.generic / formatEnum
Function: formatEnum()
Call Signature
formatEnum<
T>(enumObj,value):string
Defined in: lib/utils.generic.ts:342
Converts a numeric enum value back to its string key.
Type Parameters
T
T extends Record<string, string | number>
Parameters
enumObj
T
The enum object definition.
value
number
The numeric value to look up.
Returns
string
The string key corresponding to the value, or empty string.
Remarks
Usage Context: Useful for displaying human-readable labels for numeric enums.
Limitations:
- Only works for numeric enums where values are unique.
- Returns empty string if value is not found.
Example
enum Status { Active = 1, Inactive = 0 }
// Direct usage
formatEnum(Status, 1); // "Active"
// Curried usage (factory pattern)
const formatStatus = formatEnum(Status);
formatStatus(1); // "Active"
Call Signature
formatEnum<
T>(enumObj): (value) =>string
Defined in: lib/utils.generic.ts:344
Converts a numeric enum value back to its string key.
Type Parameters
T
T extends Record<string, string | number>
Parameters
enumObj
T
The enum object definition.
Returns
The string key corresponding to the value, or empty string.
(
value):string
Parameters
value
number
Returns
string
Remarks
Usage Context: Useful for displaying human-readable labels for numeric enums.
Limitations:
- Only works for numeric enums where values are unique.
- Returns empty string if value is not found.
Example
enum Status { Active = 1, Inactive = 0 }
// Direct usage
formatEnum(Status, 1); // "Active"
// Curried usage (factory pattern)
const formatStatus = formatEnum(Status);
formatStatus(1); // "Active"