Object type (defining types of keys and correspoding values).
Object mapping keys to values (mutations prevented with Object.freeze
).
Can be used for accessing values by keys using dot syntax.
const LOCALES = Enum({ English: 'en', Czech: 'cs', Slovak: 'sk' });
const Locale = LOCALES.accessor;
const locale = Locale.Czech; // locale is 'cs'
Lists all values.
Array of values (safe to mutate).
Checks if value is contained in enum's set of values.
Value with unknown type.
Boolean (true
if valid enum value, otherwise false
).
Checks if value is contained in enum's set of values.
Value with unknown type.
Nothing if valid enum value, throws error if invalid.
RangeError
Lists all keys.
Array of keys (similar to Object.keys
).
Checks if key is contained in enum's keys.
Value with unknown type.
Boolean (true
if valid enum key, otherwise false
).
Checks if key is contained in enum's keys.
Value with unknown type.
Nothing if valid enum key, throws error if invalid.
RangeError
Lists all key-value pairs.
Array of tuples (similar to Object.entries
).
Checks if key-value pair is contained in enum.
Value with unknown type.
Nothing if tuple with matching key and value, throws error if invalid.
Checks if key-value pair is contained in enum.
Value with unknown type.
Boolean (true
if tuple with matching key and value, otherwise false
).
RangeError
Access key for given value.
Enum value.
Enum key matching given value.
Generated using TypeDoc
Enum object created from a map of key-value pairs.
A labeled enum is more similar to a built-in
enum
, because it distinguishes between keys and values.A labeled enum supports the same methods as a SimpleEnum, as well as additional methods for handling keys and key-value pairs.