Skip to content

Repository files navigation

enum-values

Library for getting the names and values of typescript enum

Installation

npm install enum-values --save

Example in TypeScript

import{EnumValues}from'enum-values';// Suppose we have an numeric and a string valued enumenumNumericEnum{VALUE1,VALUE2,VALUE3}enumStringEnum{VALUE4='V4',VALUE5='V5'}// names will be equal to: ['VALUE1', 'VALUE2', 'VALUE3']varnames1=EnumValues.getNames(NumericEnum);// names will be equal to: ['VALUE4', 'VALUE5']varnames2=EnumValues.getNames(StringEnum);// values will be equal to: [0, 1, 2]varvalues1=EnumValues.getValues(NumericEnum);// values will be equal to: ['V4', 'V5']varvalues2=EnumValues.getValues(StringEnum);// namesAndValues will be equal to:// [// { name: 'VALUE1', value: 0 },// { name: 'VALUE2', value: 1 },// { name: 'VALUE3', value: 2 }// ]varnamesAndValues1=EnumValues.getNamesAndValues(NumericEnum);// namesAndValues will be equal to:// [// { name: 'VALUE4', value: 'V4' },// { name: 'VALUE5', value: 'V5' }// ]varnamesAndValues2=EnumValues.getNamesAndValues(StringEnum);

Known issues

Currently the library does not support mixing string and numeric enums.

// This enum will not work:enumMixedEnum{A='A',1=2,3='B',C=4}

About

Library for getting the names and values of typescript enum

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages