@brizy/ui
Version:
React elements in Brizy style
33 lines (32 loc) • 1.03 kB
JavaScript
import { isNothing } from "./MVal";
/**
* Check whenever an potential maybe value is empty or not
*/
export const isT = (t) => !isNothing(t);
/**
* Check whenever a list of values has undefined values or not
*/
export const isTs = (ts) => ts.every(isT);
export function pass(predicate) {
return (t) => (predicate(t) ? t : undefined);
}
export const _pass = (predicate) => (t) => predicate(t) ? t : undefined;
/**
* Test a value if is of specific type given type guard predicate,
* If the value passes the predicate, return value,
* otherwise, return undefined
*/
export const passT = (guard) => (a) => guard(a) ? a : undefined;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const isRecord = (v) => {
return Object.values(v).every(isT);
};
export function errorOnEmpty(m) {
return t => {
if (isT(t)) {
return t;
}
throw new Error(m);
};
}
export const mEq = (predicate) => (a, b) => (!isNothing(a) && !isNothing(b) && predicate(a, b)) || a === b;