Creates a simple enum from an array of values.
Type of values (union of strings or numbers).
Array of all values.
Simple enum object.
const ROLES = Enum(['viewer', 'editor', 'owner']);
Creates a labeled enum from an object.
Object type (defining types of keys and correspoding values).
Object mapping keys to values.
Labeled enum object.
const LANGUAGES = Enum({
English: 'English',
Czech: 'Čeština',
Slovak: 'Slovenčina',
});
Creates a simple enum by adding values to another enum.
Type of simple enum or labeled enum.
Type of added values (union of strings or numbers).
Source enum object (simple or labeled).
Values to be added.
Simple enum object.
const STATUSES = Enum(['alive', 'dead']);
const INFECTED_STATUSES = Enum.extend(STATUSES, ['zombie']);
Creates a labeled enum by adding keys and values to another enum.
Type of labeled enum.
Object type (defining types of added keys and correspoding values).
Source labeled enum object.
Object with key-value pairs to be added.
Labeled enum object.
const LOCALES = Enum({ English: 'en', Czech: 'cs', Slovak: 'sk' });
const EXTENDED_LOCALES = Enum.extend(LOCALES, { Spanish: 'es' });
Creates a labeled enum by removing keys from another enum.
Type of labeled enum.
Type of keys to be removed.
Source labeled enum object.
Array of keys to remove.
Labeled enum object.
const LEVELS = Enum({ off: 0, warn: 1, error: 2 });
const ERROR_LEVELS = Enum.exclude(LEVELS, ['off']);
Creates a labeled enum by removing values from another enum.
Type of labeled enum.
Type of values to be removed.
Source labeled enum object.
Array of values to remove.
Labeled enum object.
const LEVELS = Enum({ off: 0, warn: 1, error: 2 });
const ERROR_LEVELS = Enum.exclude(LEVELS, [0]);
Creates a simple enum by removing values from another enum.
Type of simple enum.
Type of values to be removed.
Source simple enum object.
Array of values to remove.
Simple enum object.
const STATUSES = Enum(['pending', 'fulfilled', 'rejected']);
const SETTLED_STATUSES = Enum.exclude(STATUSES, ['pending']);
Generated using TypeDoc
Core
Enum
object.Enum(...)
) creates an enum.Enum.extend(...)
),Enum.exclude(...)
).Each function has different overloads to support creating both simple and labeled enums.