An ENUM implementation in JS
import jsENUM from '@rxluz/js-enum';
const direction = jsENUM('UP', 'DOWN', 'LEFT', 'RIGHT');
const myDirection = direction.DOWN;
var jsENUM = require('@rxluz/js-enum').default;
const direction = jsENUM('UP', 'DOWN', 'LEFT', 'RIGHT');
const myDirection = direction.DOWN;
The default value to each element of your enum will be a sequential number (eg. UP: 0, DOWN: 1, LEFT: 2, RIGHT, 3), but you could change this putting a custom value to each element
const direction = jsENUM(['UP', 'UP'], 'DOWN', 'LEFT', 'RIGHT');
const myDirection = direction.DOWN;
In the example above the values will be (eg. UP: UP, DOWN: 1, LEFT: 2, RIGHT, 3)
With npm installed, run
$ npm i @rxluz/js-enum --save
- This project was inspired by a chat in NodeJS Brasil Telegram Group.
- rxluz
MIT