UNPKG

@naturalcycles/js-lib

Version:

Standard library for universal (browser + Node.js) javascript

69 lines (68 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._objectAssign = exports._objectEntries = exports._objectKeys = exports._stringMapEntries = exports._stringMapValues = exports._passNothingPredicate = exports._passthroughPredicate = exports._noop = exports._passUndefinedMapper = exports._passthroughMapper = exports.MISS = exports.SKIP = exports.END = void 0; exports._typeCast = _typeCast; /** * Symbol to indicate END of Sequence. */ exports.END = Symbol('END'); /** * Symbol to indicate SKIP of item (e.g in AbortableMapper) */ exports.SKIP = Symbol('SKIP'); /** * Symbol to indicate cache miss. * To distinguish from cache returning `undefined` or `null`. */ exports.MISS = Symbol('MISS'); const _passthroughMapper = item => item; exports._passthroughMapper = _passthroughMapper; const _passUndefinedMapper = () => undefined; exports._passUndefinedMapper = _passUndefinedMapper; /** * Function that does nothings and returns `undefined`. */ const _noop = (..._args) => undefined; exports._noop = _noop; const _passthroughPredicate = () => true; exports._passthroughPredicate = _passthroughPredicate; const _passNothingPredicate = () => false; exports._passNothingPredicate = _passNothingPredicate; /** * Needed due to https://github.com/microsoft/TypeScript/issues/13778 * Only affects typings, no runtime effect. */ exports._stringMapValues = Object.values; /** * Needed due to https://github.com/microsoft/TypeScript/issues/13778 * Only affects typings, no runtime effect. */ exports._stringMapEntries = Object.entries; /** * Alias of `Object.keys`, but returns keys typed as `keyof T`, not as just `string`. * This is how TypeScript should work, actually. */ exports._objectKeys = Object.keys; /** * Alias of `Object.entries`, but returns better-typed output. * * So e.g you can use _objectEntries(obj).map([k, v] => {}) * and `k` will be `keyof obj` instead of generic `string`. */ exports._objectEntries = Object.entries; /** * Utility function that helps to cast *existing variable* to needed type T. * * @example * try {} catch (err) { * // err is unknown here * _typeCast<AppError>(err) * // now err is of type AppError * err.data = {} // can be done, because it was casted * } */ function _typeCast(v) { } /** * Type-safe Object.assign that checks that part is indeed a Partial<T> */ exports._objectAssign = Object.assign;