easy-enum-js
v0.1.1
Published
Simple module creating an enum class.
Downloads
1
Readme
easy-enum-js
A javascript enumeration class for nodejs.
Usage
The module exports a class Enum. Instantiation is easy:
let Enum = require('easy-enum-js');
const SampleEnum = new Enum('red', 'green', 'blue');
Values can be accessed by standard dot notation.
console.log(SampleEnum.green);
// output: 1
Or by the included function getVal(key).
A number of functions are included:
toString()
const SampleEnum = new Enum('red', 'green', 'blue');
SampleEnum.toString();
// output: "{ "blue": 0; "green": 1; "red": 2 }"
toObject()
const SampleEnum = new Enum('red', 'green', 'blue');
SampleEnum.toObject();
// output: { "blue": 0, "green": 1, "red": 2 }
getVal(key)
const SampleEnum = new Enum('red', 'green', 'blue');
SampleEnum.getVal('red');
// output: 2