Easily create Enum-like objects.
npm install enumish --save
Import the library and invoke it with a list of strings (for mirrored values):
import enums from 'enumish';
// basic usage
const Directions = enums('TOP', 'LEFT', 'RIGHT', 'BOTTOM', 'CENTER');
// result
Directions.TOP === 'TOP'; // true
Some of the arguments can be objects, for custom values:
// custom values
const SideBarComponents = enums('ICON_PICKER', {
LAYOUT_SELECTOR: 'LayoutSelector',
COLOR_PICKER: 'ColorPickerSection'
});
// result
SideBarComponents.ICON_PICKER === 'ICON_PICKER'; // true
SideBarComponents.LAYOUT_SELECTOR === 'LayoutSelector'; // true
You can supply the keys as an array, and a converter function for the second argument:
// custom converter function as the second argument
const Icons = enums(['BOLD', 'ITALIC'], val => val.toLowerCase());
// result
Icons.BOLD === 'bold'; // true
Further usage can be found in the tests.
npm run test
Built using Library Starter Light.
MIT