UNPKG

@jplorg/jpl

Version:
40 lines (39 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _library = require("../../../library"); var _utils = require("../utils"); var _default = exports.default = { /** { by: [op] } */ op(runtime, input, target, params, scope, next) { return runtime.executeInstructions(params.by ?? [], [input], scope, async by => next(await runtime.alterValue(target, a => { const b = runtime.unwrapValue(by); const ta = runtime.type(a); const tb = runtime.type(b); switch (ta) { case 'number': if (tb === 'number') return a * b; break; case 'string': if (tb === 'number') { if (b < 1) return null; return a.repeat(b); } break; case 'object': if (tb === 'object') return runtime.merge(a, b); break; default: } throw new _library.JPLTypeError('%s (%*<100v) and %s (%*<100v) cannot be multiplied together', ta, a, tb, b); }))); }, /** { by: function } */ map(runtime, params) { return { by: (0, _utils.call)(params.by) }; } };