enum-utils
Conversion and extraction utilities for enums with TypeScript type-safety.
Install
$ npm install enum-utils
Usage
Node.js / CommonJS:
ESNext / TypeScript:
API
T
>(e: T
): [string
, T
][]
EnumUtils.entries<Returns an array of key/values of the enumerable properties of an enum.
Type parameters:
T
Parameters:
Name | Type | Description |
---|---|---|
e | T |
Enum value. |
Returns: [string
, T
][]
T
>(e: T
): string
[]
EnumUtils.keys<Returns the names of the enumerable properties and methods of an enum.
Type parameters:
T
Parameters:
Name | Type | Description |
---|---|---|
e | T |
Enum value. |
Returns: string
[]
T
>(e: T
): object
EnumUtils.keysByValue<Returns a value to key mapping object for the input enum.
Note: Reverse mapping keys are omitted.
Type parameters:
T
Parameters:
Name | Type | Description |
---|---|---|
e | T |
Enum value. |
Returns: object
T
>(e: T
): T
[]
EnumUtils.values<Returns an array of values of the enumerable properties of an enum.
Type parameters:
T
Parameters:
Name | Type | Description |
---|---|---|
e | T |
Enum value. |
Returns: T
[]
T
>(input: T
): object
EnumUtils.valuesByKey<Returns a key -> value mapping object for the input enum.
Note: Reverse mapping keys are omitted.
Type parameters:
T
Parameters:
Name | Type |
---|---|
input | T |
Returns: object
Related
News and Updates
Follow @typeslick on Twitter for the latest updates and new project announcements.