@barchart/common-js
Version:
Library of common JavaScript utilities
94 lines (93 loc) • 2.75 kB
TypeScript
/**
* An enumeration. Must be inherited. Do not instantiate directly.
* Also, this class uses the ES6 Map, therefore a polyfill must
* be supplied.
*
* @public
* @interface
*/
export default class Enum {
/**
* Looks up an enumeration item; given the enumeration type and the enumeration
* item's value. If no matching item can be found, a null value is returned.
*
* @public
* @static
* @param {Function} type - The enumeration type.
* @param {string} code - The enumeration item's code.
* @returns {Enum|null}
*/
public static fromCode(type: Function, code: string): Enum | null;
/**
* Looks up an enumeration item; given the enumeration type and the enumeration
* item's value. If no matching item can be found, a null value is returned.
*
* @public
* @static
* @param {Function} type - The enumeration type.
* @param {number} mapping - The enumeration item's mapping value.
* @returns {Enum|null}
*/
public static fromMapping(type: Function, mapping: number): Enum | null;
/**
* Returns the enumeration's items (given an enumeration type).
*
* @public
* @static
* @param {Function} type - The enumeration to list.
* @returns {Array}
*/
public static getItems(type: Function): any[];
/**
* @param {string} code - The unique code of the enumeration item.
* @param {string} description - A description of the enumeration item.
* @param {number=} mapping - An alternate key value (used when external systems identify enumeration items using integer values).
*/
constructor(code: string, description: string, mapping?: number | undefined);
/**
* The unique code.
*
* @public
* @returns {string}
*/
public get code(): string;
/**
* The description.
*
* @public
* @returns {string}
*/
public get description(): string;
/**
* An alternate key value (used when external systems identify enumeration items
* using numeric values). This value will not be present for all enumerations.
*
* @public
* @returns {number|null}
*/
public get mapping(): number | null;
/**
* Returns true if the provided {@link Enum} argument is equal
* to the instance.
*
* @public
* @param {Enum} other
* @returns {boolean}
*/
public equals(other: Enum): boolean;
/**
* Returns the JSON representation.
*
* @public
* @returns {string}
*/
public toJSON(): string;
/**
* Returns a string representation.
*
* @public
* @returns {string}
*/
public toString(): string;
#private;
}