UNPKG

@jplorg/jpl

Version:
42 lines (41 loc) 1.22 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') { if (b === 0) { throw new _library.JPLZeroDivisionError('%s (%*<100v) cannot be divided by zero', ta, a); } return a / b; } break; case 'string': if (tb === 'string') { if (b === '') return [...a]; return a.split(b); } break; default: } throw new _library.JPLTypeError('%s (%*<100v) cannot be divided by %s (%*<100v)', ta, a, tb, b); }))); }, /** { by: function } */ map(runtime, params) { return { by: (0, _utils.call)(params.by) }; } };