UNPKG

@datr.tech/marble-transformer-core

Version:
66 lines 2.53 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformer = void 0; /** * @name Transformer * * @description The transformer accepts an array of 'handlers', * each of which, ultimately, would be called from the * inner 'transform' function. * * @param {ITransformerInput} params * @param {IHandler[]} params.handlers REQUIRED An array of 'handler' functions. * @returns {ITransformerOutput} An object containing a 'transform' function. * * @see {@link module:interfaces/core/transformers/ITransformer} * @see {@link module:test/unit/core/transformers} * * @author Datr.Tech Admin <admin@datr.tech> * @version 0.3.1 * * @example const transform = transformer({ handlers }); * const destination = transform({ source }); */ var transformer = function (_a) { var handlers = _a.handlers; /** * @name transform * * @description Transform the received 'source' param by passing it, * along with any 'options', and along with the reducer's * 'accumulator' to each of the 'handler' functions. * * @param {ITransformInput} params * @param {ISource} params.source REQUIRED The object to be transformer. * @param {IOptions} params.options OPTIONAL An optional 'options' object. * @returns {ITransformOutput} The transformed 'source'. * * @see {@link module:interfaces/core/transforms/ITransform} * * @author Datr.Tech Admin <admin@datr.tech> * @version 0.3.1 */ return function (_a) { var source = _a.source, options = _a.options; return handlers.reduce(function (accumulator, handler) { return handler({ source: source, accumulator: __assign({}, accumulator), options: options || {}, }); }, {}); }; }; exports.transformer = transformer; //# sourceMappingURL=transformer.js.map