@gamepark/rules-api
Version:
API to implement the rules of a board game
44 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEnumValue = exports.getEnumEntries = exports.getEnumValues = exports.getEnumKeys = void 0;
/**
* Get the keys of an enum at run time.
* Credits to https://github.com/tranvansang/enum-for
*
* @param enumType The enumeration
* @returns returns the list of the keys of the enum
*/
function getEnumKeys(enumType) {
return Object.keys(enumType).filter(function (key) { return isNaN(Number(key)); });
}
exports.getEnumKeys = getEnumKeys;
/**
* Get the values of an enum at run time.
* Credits to https://github.com/tranvansang/enum-for
*
* @param enumType The enumeration
* @returns returns the list of the values of the enum
*/
function getEnumValues(enumType) {
return getEnumKeys(enumType).map(function (key) { return enumType[key]; });
}
exports.getEnumValues = getEnumValues;
/**
* Get the entries of an enum at run time.
* Credits to https://github.com/tranvansang/enum-for
*
* @param enumType The enumeration
* @returns returns the list of the entries of the enum
*/
function getEnumEntries(enumType) {
return getEnumKeys(enumType).map(function (key) { return [key, enumType[key]]; });
}
exports.getEnumEntries = getEnumEntries;
/**
* @deprecated Use getEnumValues instead
*/
function isEnumValue(value) {
return typeof value !== 'string';
}
exports.isEnumValue = isEnumValue;
//# sourceMappingURL=enum.util.js.map