Skip to content

Latest commit

 

History

History
96 lines (68 loc) · 2.84 KB

Enum.md

File metadata and controls

96 lines (68 loc) · 2.84 KB

Type Enforcer

A type enforcement library for javascript

npm build coverage deps size vulnerabilities license


Enum

Freezes an enumerable object and adds a few helper methods


new Enum(object)

import { Enum } from 'type-enforcer';
Param Type
object Object.<string, unknown>


enum.has(value) ⇒ boolean

Check if a provided value is in this enum.

Param Type Description
value unknown A value to check against the values in this Enum.


enum.key(value) ⇒ string | undefined

Get the key of a provided value.

Param Type Description
value unknown A value in this enum.


enum.each(callback)

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.