UNPKG

true-myth

Version:

A library for safe functional programming in JavaScript, with first-class support for TypeScript

38 lines 1.1 kB
"use strict"; /** @module @internal */ Object.defineProperty(exports, "__esModule", { value: true }); exports.safeToString = exports.curry1 = exports.isVoid = void 0; /** * Check if the value here is an all-consuming monstrosity which will consume * everything in its transdimensional rage. A.k.a. `null` or `undefined`. * * @internal */ const isVoid = (value) => typeof value === 'undefined' || value === null; exports.isVoid = isVoid; /** @internal */ function curry1(op, item) { return item !== undefined ? op(item) : op; } exports.curry1 = curry1; /** * Check whether a given key is in an object * @internal */ function has(value, key) { return typeof value === 'object' && value !== null && key in value; } function safeToString(value) { if (has(value, 'toString') && typeof value['toString'] === 'function') { const fnResult = value.toString(); return typeof fnResult === 'string' ? fnResult : JSON.stringify(value); } else { return JSON.stringify(value); } } exports.safeToString = safeToString; //# sourceMappingURL=utils.cjs.map