js-enumify
js-enumify introduces Enum Type to JavaScript. Works well on node and browser environments.
Installing
npm install js-enumify
Usage
- Creating enum
; // or const Enum = require('js-enumify'); static {return 'foo';} static {return 320;} static {return false;} static {return 'a' 2 undefined;} static {return a + 1;} static {return a:1 b:3;}
- Getting enum value
SomeEnumFOO; // 'foo'SomeEnum; // Foo { key: 'FOO', value: 'foo' }
- Getting all enums
SomeEnumall // [Foo { key: 'FOO', value: 'foo' }, Foo { key: 'BAR', value: 320 }, Foo { key: 'BAZ', value: false }]
- Getting all enum keys
SomeEnum // ['FOO', 'BAR', 'BAZ']
- Getting all enum values
SomeEnum // ['foo', 320, false]
- Checking if current enum is equal to given one
const foo = SomeEnum;foo // truefoo // truefoo // false
- Checking if current enum value is equal to one of given ones
const foo = SomeEnum;foo; // truefoo; // false
- Parsing enum value to string
const foo = SomeEnum;foo; // '320'Stringfoo; // '320'foo + ''; // '320'
Testing
npm test
Changelog
See Changelog
License
This project is licensed under the MIT License - see the LICENSE.md file for details