Enum with symbols
npm install symbol-enumEnum with symbols.






``javascript`
const SymbolEnum = require('symbol-enum')
Creates a new Enum with the specified keys.
``javascript``
const MyEnum = new SymbolEnum('a', 'b', 'c')
Retrieves the symbol corresponding to the key.
``javascript``
const val = MyEnum.a
val // Symbol(a)
Retrieves the key corresponding to the symbol.
``javascript``
MyEnum[val] // "a"
Returns an iterator that can be used to iterate through the keys.
`javascript`
Array.from(MyEnum[SymbolEnum.keys]) // "[ a, b, c ]"
Returns an iterator that can be used to iterate through the values.
`javascript`
Array.from(MyEnum[SymbolEnum.values]) // "[ Symbol(a), Symbol(b), Symbol(c) ]"
Returns whether the enum contains the specified key.
`javascript`
MyEnumSymbolEnum.has // true
Returns whether the enum contains the specified value.
`javascript`
MyEnumSymbol.hasValue // true
Returns the number of keys passed to the constructor.
For your convenience, the following properties are also available directly on the object itself, but only if you don't specify keys and values as a member of the enum itself.
* #[SymbolEnum.keys] as keys#[SymbolEnum.values]
* as values#[SymbolEnum.has]
* as has#[SymbolEnum.hasValue]
* as hasValue
If you do, underscores will be prepended to the property name until it becomes available. For example, if you added both keys and _keys in the Enum, #[SymbolEnum.keys] will also be available at #__keys.
SymbolEnum extends from null and does not have any string prototype methods so we have a clean slate. This means we don't inherit from Object and have any of its properties.
#### Exception: #constructor
Since we're using classes here, that means [constructor][Object.prototype.constructor] will still be defined by default. No worries, if you specify constructor` as a key, it will be overridden.
MIT
[Object.prototype.constructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor