UNPKG

@valuer/fn

Version:

Collection of function utils for Valuer

54 lines (53 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** @private */ var applyTo = function (value) { return function (thunk) { return thunk(value); }; }; var fn; (function (fn) { /** * Get negated thunk * @param thunk Thunk to negate */ fn.not = function (thunk) { return function (value) { return !thunk(value); }; }; /** * Whether any of the thunks over the input returns `true` * @param thunks Thunks to pipe together */ fn.any = function () { var thunks = []; for (var _i = 0; _i < arguments.length; _i++) { thunks[_i] = arguments[_i]; } return function (value) { return thunks.some(applyTo(value)); }; }; /** * Whether exactly one of the thunks over the input returns `true` * @param thunks Thunks to pipe together */ fn.one = function () { var thunks = []; for (var _i = 0; _i < arguments.length; _i++) { thunks[_i] = arguments[_i]; } return function (value) { return thunks.map(applyTo(value)).filter(Boolean).length === 1; }; }; /** * Whether all of the thunks over the input return `true` * @param thunks Thunks to pipe together */ fn.all = function () { var thunks = []; for (var _i = 0; _i < arguments.length; _i++) { thunks[_i] = arguments[_i]; } return fn.not(fn.any.apply(void 0, thunks.map(fn.not))); }; })(fn = exports.fn || (exports.fn = {}));