Skip to content
Conversion and extraction utilities for enums with TypeScript type-safety.
Branch: master
Clone or download
Pull request Compare This branch is 38 commits behind typeslick:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
__meta__
src
.babelrc.js
.gitignore
.prettierrc.json
CODE_OF_CONDUCT.md
LICENSE
README.md
api-extractor.json
cSpell.json
jest.config.js
package.json
tsconfig.json
tslint.json
typedoc.json

README.md

enum-utils

Conversion and extraction utilities for enums with TypeScript type-safety.

tslint: Slick code style: Prettier npm semantic-release License

Install

$ npm install enum-utils

Usage

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

MIT

You can’t perform that action at this time.