0.0.4 • Published 6 years ago

@rxluz/js-enum v0.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@rxluz/js-enum

An ENUM implementation in JS

Build Status codecov Commitizen friendly npm.io npm.io npm.io

Usage

Example (es module)

import jsENUM from '@rxluz/js-enum';

const direction = jsENUM('UP', 'DOWN', 'LEFT', 'RIGHT');

const myDirection = direction.DOWN;

Example (commonjs)

var jsENUM = require('@rxluz/js-enum').default;

const direction = jsENUM('UP', 'DOWN', 'LEFT', 'RIGHT');

const myDirection = direction.DOWN;

Using custom values

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)

Install

With npm installed, run

$ npm i @rxluz/js-enum --save

Acknowledgments

  • This project was inspired by a chat in NodeJS Brasil Telegram Group.
  • rxluz

See Also

License

MIT