@serenity-is/corelib / Enum
Variable: Enum
constEnum:object
Defined in: src/base/system.ts:381
Enum utilities
Type Declaration
getIconClass()
getIconClass: (
enumType,value) =>string
Get the icon class for a specific enum value.
Parameters
enumType
any
Enum type
value
Enum value, numeric or string
string | number
Returns
string
Icon class name or undefined if not found
getText()
getText: (
enumType,value) =>string
Returns the text that a member of an enum shows as it is, e.g. the one of a member that has no local text key, and which the generator sends with the enum. A member with a key gets its text from the local texts instead.
Parameters
enumType
any
Enum object.
value
The value of the member.
string | number
Returns
string
The literal text of the member, or undefined when it has a key.
getTextKey()
getTextKey: (
enumType,value) =>string
Returns the local text key that a member of an enum declares, which is not the one that its enum implies, i.e.
Enums.<enumKey>.<Member>, e.g. one that a text attribute of the member gives. An empty string means the member
has no key, and its text is shown as it is, see getText.
Parameters
enumType
any
Enum object.
value
The value of the member.
string | number
Returns
string
The local text key of the member, or undefined when it uses the one its enum implies.
getValues()
getValues: <
T>(enumType) =>T[]
Returns all values of an enum as an array, in their declaration order. A numeric enum returns its numeric values, a string enum returns the string values of its members.
Type Parameters
T
T = any
Parameters
enumType
any
Enum object to enumerate.
Returns
T[]
Array of enum values. It is typed as any[] by default, and can be narrowed with a type
argument, e.g. Enum.getValues<WidgetCategory>(WidgetCategory).
isStringEnum()
isStringEnum: (
enumType) =>boolean
Checks whether an enum has string members, i.e. whether it is generated from a StringEnum. The kind is recorded when the enum is registered; before that, the members are inspected.
Parameters
enumType
any
Enum type
Returns
boolean
True when the members of the enum are strings
toString()
toString: (
enumType,value) =>string
Convert an enum value to a string containing enum names.
Parameters
enumType
any
Enum type
value
Enum value
string | number
Returns
string