UNPKG

@brizy/ui

Version:
44 lines (43 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mEq = exports.isRecord = exports.passT = exports._pass = exports.isTs = exports.isT = void 0; exports.pass = pass; exports.errorOnEmpty = errorOnEmpty; const MVal_1 = require("./MVal"); /** * Check whenever an potential maybe value is empty or not */ const isT = (t) => !(0, MVal_1.isNothing)(t); exports.isT = isT; /** * Check whenever a list of values has undefined values or not */ const isTs = (ts) => ts.every(exports.isT); exports.isTs = isTs; function pass(predicate) { return (t) => (predicate(t) ? t : undefined); } const _pass = (predicate) => (t) => predicate(t) ? t : undefined; exports._pass = _pass; /** * Test a value if is of specific type given type guard predicate, * If the value passes the predicate, return value, * otherwise, return undefined */ const passT = (guard) => (a) => guard(a) ? a : undefined; exports.passT = passT; // eslint-disable-next-line @typescript-eslint/no-explicit-any const isRecord = (v) => { return Object.values(v).every(exports.isT); }; exports.isRecord = isRecord; function errorOnEmpty(m) { return t => { if ((0, exports.isT)(t)) { return t; } throw new Error(m); }; } const mEq = (predicate) => (a, b) => (!(0, MVal_1.isNothing)(a) && !(0, MVal_1.isNothing)(b) && predicate(a, b)) || a === b; exports.mEq = mEq;