A type enforcement library for javascript
Freezes an enumerable object and adds a few helper methods
- Enum
- new Enum(object)
- .has(value) ⇒
boolean
- .key(value) ⇒
string
|undefined
- .each(callback)
import { Enum } from 'type-enforcer';
Param | Type |
---|---|
object | Object.<string, unknown> |
Check if a provided value is in this enum.
Param | Type | Description |
---|---|---|
value | unknown |
A value to check against the values in this Enum. |
Get the key of a provided value.
Param | Type | Description |
---|---|---|
value | unknown |
A value in this enum. |
Calls a callback with each of the enum values.
const items = new Enum({ THING: 'thing' }); items.each((value) => { console.log(value); }); // => 'thing'
Param | Type | Description |
---|---|---|
callback | eachCallback |
Callback is provided one arg, the value. |