Introduction
Have you ever had an enum
and wanted to enumerate all the names of an enum
? Or all the values of the enum
? Or even both?!
Well, I had the same problem and I found the solution and now I'm going to share it with you.
Using the Code
Install the npm package enum-values
:
npm install --save enum-values
Using the library is pretty easy (the example is in TypeScript):
import { EnumValues } from 'enum-values';
enum SomeEnum {
VALUE1,
VALUE2,
VALUE3
}
var names = EnumValues.getNames(SomeEnum);
var values = EnumValues.getValues(SomeEnum);
var namesAndValues = EnumValues.getNamesAndValues(SomeEnum);
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.