UNPKG

1.18 kBJavaScriptView Raw
1import { errorTransform } from './utils/errorTransform.js';
2import { factory } from '../../utils/factory.js';
3import { createApply } from '../../function/matrix/apply.js';
4import { isBigNumber, isNumber } from '../../utils/is.js';
5var name = 'apply';
6var dependencies = ['typed', 'isInteger'];
7/**
8 * Attach a transform function to math.apply
9 * Adds a property transform containing the transform function.
10 *
11 * This transform changed the last `dim` parameter of function apply
12 * from one-based to zero based
13 */
14
15export var createApplyTransform = /* #__PURE__ */factory(name, dependencies, (_ref) => {
16 var {
17 typed,
18 isInteger
19 } = _ref;
20 var apply = createApply({
21 typed,
22 isInteger
23 }); // @see: comment of concat itself
24
25 return typed('apply', {
26 '...any': function any(args) {
27 // change dim from one-based to zero-based
28 var dim = args[1];
29
30 if (isNumber(dim)) {
31 args[1] = dim - 1;
32 } else if (isBigNumber(dim)) {
33 args[1] = dim.minus(1);
34 }
35
36 try {
37 return apply.apply(null, args);
38 } catch (err) {
39 throw errorTransform(err);
40 }
41 }
42 });
43}, {
44 isTransformFunction: true
45});
\No newline at end of file