UNPKG

@buurman/commons

Version:

The buurman commons package is a utility belt

167 lines (151 loc) 5.45 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var identity = function (v) { return v; }; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } var createMutatorApi = function (returnValue, reducer) { var mutations = []; var addMutation = function (mutation) { mutations.push(mutation); return returnValue(); }; return { createMutator: function (type, mapArgsToPayload) { if (mapArgsToPayload === void 0) { mapArgsToPayload = identity; } return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return addMutation({ type: type, payload: mapArgsToPayload.apply(void 0, __spread(args)) }); }; }, applyMutations: function (initialValue) { return mutations.reduce(reducer, initialValue); }, }; }; var not = function (fn) { return (function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return !fn.apply(void 0, __spread(args)); }); }; var and = function () { var fns = []; for (var _i = 0; _i < arguments.length; _i++) { fns[_i] = arguments[_i]; } return (function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return fns.every(function (fn) { return fn.apply(void 0, __spread(args)); }); }); }; var or = function () { var fns = []; for (var _i = 0; _i < arguments.length; _i++) { fns[_i] = arguments[_i]; } return (function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return fns.some(function (fn) { return fn.apply(void 0, __spread(args)); }); }); }; var isIncludedIn = function (arr) { return function (v) { return arr.includes(v); }; }; var isNotIncludedIn = function (arr) { return not(isIncludedIn(arr)); }; // aliases var inArray = isIncludedIn; var notInArray = isNotIncludedIn; var isType = function (type) { return function (value) { return typeof value === type; }; }; var isString = isType("string"); var isNumber = isType("number"); var isBoolean = isType("boolean"); var isObject = isType("object"); var isSymbol = isType("symbol"); var isBigInt = isType("bigint"); var isFunction = isType("function"); var isUndefined = isType("undefined"); var isNotString = not(isString); var ensureArray = function (value) { return value == null ? [] : Array.isArray(value) ? value : [value]; }; var keys = Object.keys.bind(Object); var values = Object.values.bind(Object); var entries = Object.entries.bind(Object); var joinLines = function (lines) { return lines.join("\n"); }; var getLines = function (text) { return text.split("\n"); }; var createLineMapper = function (transformer) { return function (text) { return text .split("\n") .map(transformer) .join("\n"); }; }; exports.and = and; exports.createLineMapper = createLineMapper; exports.createMutatorApi = createMutatorApi; exports.ensureArray = ensureArray; exports.entries = entries; exports.getLines = getLines; exports.identity = identity; exports.inArray = inArray; exports.isBigInt = isBigInt; exports.isBoolean = isBoolean; exports.isFunction = isFunction; exports.isIncludedIn = isIncludedIn; exports.isNotIncludedIn = isNotIncludedIn; exports.isNotString = isNotString; exports.isNumber = isNumber; exports.isObject = isObject; exports.isString = isString; exports.isSymbol = isSymbol; exports.isType = isType; exports.isUndefined = isUndefined; exports.joinLines = joinLines; exports.keys = keys; exports.not = not; exports.notInArray = notInArray; exports.or = or; exports.values = values; //# sourceMappingURL=index.js.map