util~ Enum

An enumerated object base class.

This class is essentially abstract, and must be extended by another class that overrides the module:util~Enum.enumValues method.

Constructor

(abstract) new Enum(name)

Constructor.

Parameters:
NameTypeDescription
namestring

the name

Members

name

Get the enum name.

Methods

equals(value) → {boolean}

Test if a string is equal to this enum's name.

As long as enum values are consistently obtained from the module:util~Enum.enumValues array then enum instances can be compared with ===. If unsure, this method can be used to compare string values instead.

If value is passed as an actual Enum instance, then if that enum is the same class as this enum it's name is compared to this instance's name.

Parameters:
NameTypeDescription
valuestring | Enum

the value to test

Returns:

true if value is the same as this instance's name value

Type: 
boolean

(abstract, static) enumValues() → {Array.<module:util~Enum>}

Get all enum values.

This method must be overridden by subclasses to return something meaningful. This implementation returns an empty array.

Returns:

get all enum values

Type: 
Array.<module:util~Enum>

(static) enumsValue(enums) → {object}

This method takes an array of enums and turns them into a mapped object, using the enum name as object property names.

Parameters:
NameTypeDescription
enumsArray.<module:util~Enum>

the enum list to turn into a value object

Returns:

an object with enum name properties with associated enum values

Type: 
object

(static) namesFor(set) → {Array.<string>}

Get the names of a set of Enum instances.

Parameters:
NameTypeDescription
setArray.<Enum>

the set of Enum instances to get the names of

Returns:

array of Enum name values

Type: 
Array.<string>

(static) valueOf(name) → {module:util~Enum}

Get an enum instance from its name.

This method searches the module:util~Enum#enumVvalues array for a matching value.

Parameters:
NameTypeDescription
namestring

the enum name to get an instnace for

Returns:

the instance, or undefined if no instance exists for the given name

Type: 
module:util~Enum