@rxluz/js-enum
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

@rxluz/js-enum

An ENUM implementation in JS

Build Status codecov Commitizen friendly

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

Readme

Keywords

Package Sidebar

Install

npm i @rxluz/js-enum

Weekly Downloads

2

Version

0.0.4

License

MIT

Unpacked Size

21.1 kB

Total Files

12

Last publish

Collaborators

  • rxluz