nullish-utils
Version:
A package to offer nullish, common, operator, functions
28 lines (27 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.firstNonNil = exports.coalescing = exports.areAllNonNil = exports.areAllNil = exports.isAnyNonNil = exports.isAnyNil = exports.isNotNil = exports.isNil = exports.isUndefined = exports.isNull = exports.NIL_VALUES = void 0;
exports.NIL_VALUES = Object.freeze([null, undefined]);
const isNull = (object) => object === exports.NIL_VALUES[0];
exports.isNull = isNull;
const isUndefined = (object) => object === exports.NIL_VALUES[1];
exports.isUndefined = isUndefined;
const isNil = (object) => exports.NIL_VALUES.includes(object);
exports.isNil = isNil;
const isNotNil = (object) => !(0, exports.isNil)(object);
exports.isNotNil = isNotNil;
const isAnyNil = (...args) => { var _a; return (args === null || args === void 0 ? void 0 : args.length) ? (_a = args === null || args === void 0 ? void 0 : args.some) === null || _a === void 0 ? void 0 : _a.call(args, (e) => (0, exports.isNil)(e)) : true; };
exports.isAnyNil = isAnyNil;
const isAnyNonNil = (...args) => { var _a, _b; return (_b = (_a = args === null || args === void 0 ? void 0 : args.some) === null || _a === void 0 ? void 0 : _a.call(args, (e) => (0, exports.isNotNil)(e))) !== null && _b !== void 0 ? _b : false; };
exports.isAnyNonNil = isAnyNonNil;
const areAllNil = (...args) => { var _a, _b; return (_b = (_a = args === null || args === void 0 ? void 0 : args.every) === null || _a === void 0 ? void 0 : _a.call(args, (e) => (0, exports.isNil)(e))) !== null && _b !== void 0 ? _b : true; };
exports.areAllNil = areAllNil;
const areAllNonNil = (...args) => { var _a; return (args === null || args === void 0 ? void 0 : args.length) ? (_a = args === null || args === void 0 ? void 0 : args.every) === null || _a === void 0 ? void 0 : _a.call(args, (e) => (0, exports.isNotNil)(e)) : false; };
exports.areAllNonNil = areAllNonNil;
const coalescing = (...args) => {
var _a;
return (_a = (args !== null && args !== void 0 ? args : []).find((e) => (0, exports.isNotNil)(e))) !== null && _a !== void 0 ? _a : (args.length ? args[args.length - 1] : exports.NIL_VALUES[0]);
};
exports.coalescing = coalescing;
const firstNonNil = (...args) => (args !== null && args !== void 0 ? args : []).find((e) => (0, exports.isNotNil)(e));
exports.firstNonNil = firstNonNil;