UNPKG

variant

Version:

Variant types (a.k.a. Discriminated Unions) in TypeScript

26 lines 835 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isPromise = exports.strEnum = exports.identityFunc = void 0; const identityFunc = (x = {}) => x; exports.identityFunc = identityFunc; /** * Utility function to create a K:V from a list of strings * * Taken from: https://basarat.gitbook.io/typescript/type-system/literal-types#string-based-enums * */ function strEnum(o) { return o.reduce((res, key) => { res[key] = key; return res; }, Object.create(null)); } exports.strEnum = strEnum; /** * Determine whether or not a variable is a promise. * @param x */ function isPromise(x) { return x != undefined && typeof x === 'object' && 'then' in x && typeof x.then === 'function'; } exports.isPromise = isPromise; //# sourceMappingURL=util.js.map