space-lift
Version:
TypeScript Array, Object, Map, Set, Union, Enum utils
17 lines (16 loc) • 536 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createEnum = void 0;
/**
* Creates a type safe string enumeration from a list of strings, providing:
* the list of all possible values, an object with all enum keys and the derived type of the enum in a single declaration.
*/
function createEnum(...values) {
const enumeration = {};
values.forEach(v => (enumeration[v] = v));
return {
enum: enumeration,
values: new Set(values)
};
}
exports.createEnum = createEnum;