Property

new Enumeration()

Creates a new enumeration. The enumeration instances should be frozen.

Property

read-only
$name  string

The name of the enumeration. The default value is the name of the constructor.

Methods

check(value[, message][, ...messageParams])

Checks whether the enumeration has an item with the given value. If not, throws an error.

Parameters

Name Type Optional Description

value

number

 

The value to check.

message

string

Yes

Human-readable description of the error.

messageParams

any type

Yes

Optional interpolation parameters of the message.

Value can be repeated.

Throws

Enumeration error: The passed value is not an enumeration item.

count() → number

Returns the count of the items in enumeration.

Returns

number The count of the enumeration items.

getName(value) → string

Returns the name of an enumeration item.

Parameter

Name Type Optional Description

value

number

 

The enumeration item that name to be returned of.

Throws

Argument error: The value must be a number.

Enumeration error: The passed value is not an enumeration item.

Returns

string The name of the enumeration item.

getValue(name) → number

Returns the value of an enumeration item based on its name.

Parameter

Name Type Optional Description

name

string

 

The enumeration item that value to be returned of.

Throws

Argument error: The name must be a non-empty string.

Enumeration error: The passed name is not an enumeration item.

Returns

number The value of the enumeration item.

hasMember(value) → boolean

Determines if the enumeration has an item with the given value.

Parameter

Name Type Optional Description

value

number

 

The value to check.

Returns

boolean True if the value is an enumeration item, otherwise false.

hasValue(name) → boolean

Determines if the enumeration has an item with the given name.

Parameter

Name Type Optional Description

name

string

 

The name of the enumeration item.

Returns

boolean True if the name is an enumeration item, otherwise false.