Methods
(inner) createEnum(structure) → {Proxy}
A factory function that accepts a plain enum object and returns a proxied enum object.
The enum proxy intercepts the read and write operations on an enum object and:
Throws an error when a non-existent enum value is accessed
Throws an error when an enum object property is changed
Parameters:
Name | Type | Description |
---|---|---|
structure |
object | The enum structure |
- Source:
Throws:
-
Will throws an error if the structure is not an object and the values associated to the structure keys are not 'number', 'string', 'boolean' or 'undefined'.
- Type
- TypeError
Returns:
The enum based on the structure
- Type
- Proxy
Examples
const Sizes = createEnum({
Small: 'small',
Medium: 'medium',
Large: 'large',
})
const Bool = createEnum({
'Yes': true,
'No': false,
'Undefined': undefined,
});