Enum
Install
npm i --save @dwcore/enum
Usage
// CJS
const Enum = require('@dwcore/enum');
const SafeEnum = require('@dwcore/enum/SafeEnum');
// ESM
import Enum from '@dwcore/enum';
import SafeEnum from '@dwcore/enum/SafeEnum';
const Color = new Enum({
RED: 'Red',
GREEN: 'Green',
BLUE: 'Blue'
});
Color.RED === 'Red'; // => true
Color.GREEN === 'Green'; // => true
Color.BLUE === 'Blue'; // => true
const Cardsuit = new Enum([
'CLUBS',
'DIAMONDS',
'HEARTS',
'SPADES'
]);
typeof Cardsuit.CLUBS === 'symbol'; // => true
typeof Cardsuit.DIAMONDS === 'symbol'; // => true
typeof Cardsuit.HEARTS === 'symbol'; // => true
typeof Cardsuit.SPADES === 'symbol'; // => true
const Type = new Enum([
['UNDEFINED', 'Undefined'],
['NULL', 'Null'],
['OBJECT', 'Object'],
['NUMBER', 'Number'],
['STRING', 'String'],
['BOOLEAN', 'Boolean'],
['SYMBOL', 'Symbol'],
['BIGINT', 'BigInt']
]);
Type.UNDEFINED === 'Undefined'; // => true
Type.NULL === 'Null'; // => true
Type.OBJECT === 'Object'; // => true
Type.NUMBER === 'Number'; // => true
Type.STRING === 'String'; // => true
Type.BOOLEAN === 'Boolean'; // => true
Type.SYMBOL === 'Symbol'; // => true
Type.BIGINT === 'BigInt'; // => true