enum-utils v1.0.0
enum-utils
Conversion and extraction utilities for enums with TypeScript type-safety.
Install
$ npm install enum-utilsUsage
Node.js / CommonJS:
const { EnumUtils } = require('enum-utils')ESNext / TypeScript:
import { EnumUtils } from 'enum-utils'API
EnumUtils.entries<T>(e: T): string, T
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
EnumUtils.keys<T>(e: T): string[]
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[]
EnumUtils.keysByValue<T>(e: T): object
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
EnumUtils.values<T>(e: T): T[]
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[]
EnumUtils.valuesByKey<T>(input: T): object
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.
Sponsors
Maintainers
License
7 years ago