UNPKG

project-libs

Version:

project-libs 是一个常用函数集锦的工具库,包括浏览器、函数式、常用验证、cookie、数组处理等函数。

51 lines (50 loc) 1.53 kB
"use strict"; var __read = (this && this.__read) || function (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; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = pipe; /** * 管道函数,从左向右依次执行 * @returns {any} any * @example * ``` * function a(name) { return 'test:' + name } function b(statement) { return statement.toUpperCase() + '!' } function c(str) { return str.replace(/[cC]/, 'CCCCC') } pipe(a, b, c)('com') // TEST:CCCCCOM! * ``` */ function pipe() { var fns = __spreadArray([], __read(arguments), false); return function (arg) { var res = arg; for (var i = 0; i < fns.length; i++) { res = fns[i](res); } return res; }; }