mathjs 12.4.1 → 12.4.3
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +17 -0
- package/README.md +4 -0
- package/bin/cli.js +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/create.js +3 -3
- package/lib/cjs/core/function/config.js +1 -11
- package/lib/cjs/core/function/import.js +3 -4
- package/lib/cjs/defaultInstance.js +1 -1
- package/lib/cjs/entry/allFactoriesAny.js +1 -1
- package/lib/cjs/entry/allFactoriesNumber.js +1 -1
- package/lib/cjs/expression/node/AccessorNode.js +2 -3
- package/lib/cjs/expression/node/ArrayNode.js +2 -3
- package/lib/cjs/expression/node/AssignmentNode.js +2 -3
- package/lib/cjs/expression/node/BlockNode.js +2 -3
- package/lib/cjs/expression/node/ConditionalNode.js +2 -3
- package/lib/cjs/expression/node/ConstantNode.js +2 -3
- package/lib/cjs/expression/node/FunctionAssignmentNode.js +2 -3
- package/lib/cjs/expression/node/FunctionNode.js +5 -6
- package/lib/cjs/expression/node/IndexNode.js +2 -3
- package/lib/cjs/expression/node/Node.js +1 -2
- package/lib/cjs/expression/node/ObjectNode.js +2 -3
- package/lib/cjs/expression/node/OperatorNode.js +2 -3
- package/lib/cjs/expression/node/ParenthesisNode.js +2 -3
- package/lib/cjs/expression/node/RangeNode.js +2 -3
- package/lib/cjs/expression/node/RelationalNode.js +2 -3
- package/lib/cjs/expression/node/SymbolNode.js +2 -3
- package/lib/cjs/expression/parse.js +7 -7
- package/lib/cjs/function/algebra/derivative.js +1 -1
- package/lib/cjs/function/algebra/rationalize.js +2 -2
- package/lib/cjs/function/algebra/simplifyConstant.js +1 -1
- package/lib/cjs/function/statistics/mad.js +1 -1
- package/lib/cjs/function/statistics/std.js +1 -1
- package/lib/cjs/function/statistics/utils/improveErrorMessage.js +2 -2
- package/lib/cjs/function/utils/isNaN.js +5 -3
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/unit/Unit.js +3 -2
- package/lib/cjs/utils/array.js +0 -11
- package/lib/cjs/utils/bignumber/formatter.js +1 -1
- package/lib/cjs/utils/factory.js +1 -2
- package/lib/cjs/utils/map.js +2 -4
- package/lib/cjs/utils/object.js +1 -7
- package/lib/cjs/utils/snapshot.js +5 -5
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/create.js +3 -3
- package/lib/esm/core/function/config.js +1 -11
- package/lib/esm/core/function/import.js +3 -4
- package/lib/esm/expression/node/FunctionNode.js +3 -3
- package/lib/esm/expression/parse.js +7 -7
- package/lib/esm/function/algebra/derivative.js +1 -1
- package/lib/esm/function/algebra/rationalize.js +2 -2
- package/lib/esm/function/algebra/simplifyConstant.js +1 -1
- package/lib/esm/function/statistics/mad.js +1 -1
- package/lib/esm/function/statistics/std.js +1 -1
- package/lib/esm/function/statistics/utils/improveErrorMessage.js +2 -2
- package/lib/esm/function/utils/isNaN.js +1 -3
- package/lib/esm/type/unit/Unit.js +3 -2
- package/lib/esm/utils/array.js +0 -10
- package/lib/esm/utils/bignumber/formatter.js +1 -1
- package/lib/esm/utils/factory.js +1 -2
- package/lib/esm/utils/object.js +1 -4
- package/lib/esm/utils/snapshot.js +4 -4
- package/lib/esm/version.js +1 -1
- package/package.json +15 -15
- package/types/EXPLANATION.md +13 -1
- package/types/index.d.ts +18 -1
@@ -360,7 +360,7 @@ var createSimplifyConstant = exports.createSimplifyConstant = /* #__PURE__ */(0,
|
|
360
360
|
{
|
361
361
|
// Process operators as OperatorNode
|
362
362
|
var operatorFunctions = ['add', 'multiply'];
|
363
|
-
if (operatorFunctions.
|
363
|
+
if (!operatorFunctions.includes(node.name)) {
|
364
364
|
var args = node.args.map(function (arg) {
|
365
365
|
return foldFraction(arg, options);
|
366
366
|
});
|
@@ -58,7 +58,7 @@ var createMad = exports.createMad = /* #__PURE__ */(0, _factory.factory)(name, d
|
|
58
58
|
return abs(subtract(value, med));
|
59
59
|
}));
|
60
60
|
} catch (err) {
|
61
|
-
if (err instanceof TypeError && err.message.
|
61
|
+
if (err instanceof TypeError && err.message.includes('median')) {
|
62
62
|
throw new TypeError(err.message.replace('median', 'mad'));
|
63
63
|
} else {
|
64
64
|
throw (0, _improveErrorMessage.improveErrorMessage)(err, 'mad');
|
@@ -91,7 +91,7 @@ var createStd = exports.createStd = /* #__PURE__ */(0, _factory.factory)(name, d
|
|
91
91
|
return sqrt(v);
|
92
92
|
}
|
93
93
|
} catch (err) {
|
94
|
-
if (err instanceof TypeError && err.message.
|
94
|
+
if (err instanceof TypeError && err.message.includes(' variance')) {
|
95
95
|
throw new TypeError(err.message.replace(' variance', ' std'));
|
96
96
|
} else {
|
97
97
|
throw err;
|
@@ -18,11 +18,11 @@ var _is = require("../../../utils/is.js");
|
|
18
18
|
function improveErrorMessage(err, fnName, value) {
|
19
19
|
// TODO: add information with the index (also needs transform in expression parser)
|
20
20
|
var details;
|
21
|
-
if (String(err).
|
21
|
+
if (String(err).includes('Unexpected type')) {
|
22
22
|
details = arguments.length > 2 ? ' (type: ' + (0, _is.typeOf)(value) + ', value: ' + JSON.stringify(value) + ')' : ' (type: ' + err.data.actual + ')';
|
23
23
|
return new TypeError('Cannot calculate ' + fnName + ', unexpected type of argument' + details);
|
24
24
|
}
|
25
|
-
if (String(err).
|
25
|
+
if (String(err).includes('complex numbers')) {
|
26
26
|
details = arguments.length > 2 ? ' (type: ' + (0, _is.typeOf)(value) + ', value: ' + JSON.stringify(value) + ')' : '';
|
27
27
|
return new TypeError('Cannot calculate ' + fnName + ', no ordering relation is defined for complex numbers' + details);
|
28
28
|
}
|
@@ -54,8 +54,10 @@ var createIsNaN = exports.createIsNaN = /* #__PURE__ */(0, _factory.factory)(nam
|
|
54
54
|
Unit: function Unit(x) {
|
55
55
|
return Number.isNaN(x.value);
|
56
56
|
},
|
57
|
-
'Array | Matrix': function
|
58
|
-
return
|
59
|
-
|
57
|
+
'Array | Matrix': typed.referToSelf(function (self) {
|
58
|
+
return function (x) {
|
59
|
+
return (0, _collection.deepMap)(x, self);
|
60
|
+
};
|
61
|
+
})
|
60
62
|
});
|
61
63
|
});
|
package/lib/cjs/header.js
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
* It features real and complex numbers, units, matrices, a large set of
|
7
7
|
* mathematical functions, and a flexible expression parser.
|
8
8
|
*
|
9
|
-
* @version 12.4.
|
10
|
-
* @date 2024-
|
9
|
+
* @version 12.4.3
|
10
|
+
* @date 2024-05-31
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2024 Jos de Jong <wjosdejong@gmail.com>
|
@@ -856,7 +856,7 @@ var createUnitClass = exports.createUnitClass = /* #__PURE__ */(0, _factory.fact
|
|
856
856
|
return {
|
857
857
|
mathjs: 'Unit',
|
858
858
|
value: this._denormalize(this.value),
|
859
|
-
unit: this.formatUnits(),
|
859
|
+
unit: this.units.length > 0 ? this.formatUnits() : null,
|
860
860
|
fixPrefix: this.fixPrefix
|
861
861
|
};
|
862
862
|
};
|
@@ -869,7 +869,8 @@ var createUnitClass = exports.createUnitClass = /* #__PURE__ */(0, _factory.fact
|
|
869
869
|
* @return {Unit}
|
870
870
|
*/
|
871
871
|
Unit.fromJSON = function (json) {
|
872
|
-
var unit
|
872
|
+
var _json$unit;
|
873
|
+
var unit = new Unit(json.value, (_json$unit = json.unit) !== null && _json$unit !== void 0 ? _json$unit : undefined);
|
873
874
|
unit.fixPrefix = json.fixPrefix || false;
|
874
875
|
return unit;
|
875
876
|
};
|
package/lib/cjs/utils/array.js
CHANGED
@@ -11,7 +11,6 @@ exports.broadcastTo = broadcastTo;
|
|
11
11
|
exports.checkBroadcastingRules = checkBroadcastingRules;
|
12
12
|
exports.clone = clone;
|
13
13
|
exports.concat = concat;
|
14
|
-
exports.contains = contains;
|
15
14
|
exports.filter = filter;
|
16
15
|
exports.filterRegExp = filterRegExp;
|
17
16
|
exports.flatten = flatten;
|
@@ -657,16 +656,6 @@ function initial(array) {
|
|
657
656
|
return array.slice(0, array.length - 1);
|
658
657
|
}
|
659
658
|
|
660
|
-
/**
|
661
|
-
* Test whether an array or string contains an item
|
662
|
-
* @param {Array | string} array
|
663
|
-
* @param {*} item
|
664
|
-
* @return {boolean}
|
665
|
-
*/
|
666
|
-
function contains(array, item) {
|
667
|
-
return array.indexOf(item) !== -1;
|
668
|
-
}
|
669
|
-
|
670
659
|
/**
|
671
660
|
* Recursively concatenate two matrices.
|
672
661
|
* The contents of the matrices is not cloned.
|
@@ -207,7 +207,7 @@ function toEngineering(value, precision) {
|
|
207
207
|
// find difference in exponents, and calculate the value without exponent
|
208
208
|
var valueWithoutExp = value.mul(Math.pow(10, -newExp));
|
209
209
|
var valueStr = valueWithoutExp.toPrecision(precision);
|
210
|
-
if (valueStr.
|
210
|
+
if (valueStr.includes('e')) {
|
211
211
|
var BigNumber = value.constructor;
|
212
212
|
valueStr = new BigNumber(valueStr).toFixed();
|
213
213
|
}
|
package/lib/cjs/utils/factory.js
CHANGED
@@ -10,7 +10,6 @@ exports.isFactory = isFactory;
|
|
10
10
|
exports.isOptionalDependency = isOptionalDependency;
|
11
11
|
exports.sortFactories = sortFactories;
|
12
12
|
exports.stripOptionalNotation = stripOptionalNotation;
|
13
|
-
var _array = require("./array.js");
|
14
13
|
var _object = require("./object.js");
|
15
14
|
/**
|
16
15
|
* Create a factory function, which can be used to inject dependencies.
|
@@ -68,7 +67,7 @@ function sortFactories(factories) {
|
|
68
67
|
function containsDependency(factory, dependency) {
|
69
68
|
// TODO: detect circular references
|
70
69
|
if (isFactory(factory)) {
|
71
|
-
if (
|
70
|
+
if (factory.dependencies.includes(dependency.fn || dependency.name)) {
|
72
71
|
return true;
|
73
72
|
}
|
74
73
|
if (factory.dependencies.some(function (d) {
|
package/lib/cjs/utils/map.js
CHANGED
@@ -32,7 +32,7 @@ var ObjectWrappingMap = exports.ObjectWrappingMap = /*#__PURE__*/function () {
|
|
32
32
|
this.wrappedObject = object;
|
33
33
|
this[Symbol.iterator] = this.entries;
|
34
34
|
}
|
35
|
-
(0, _createClass2["default"])(ObjectWrappingMap, [{
|
35
|
+
return (0, _createClass2["default"])(ObjectWrappingMap, [{
|
36
36
|
key: "keys",
|
37
37
|
value: function keys() {
|
38
38
|
return Object.keys(this.wrappedObject).values();
|
@@ -104,7 +104,6 @@ var ObjectWrappingMap = exports.ObjectWrappingMap = /*#__PURE__*/function () {
|
|
104
104
|
return Object.keys(this.wrappedObject).length;
|
105
105
|
}
|
106
106
|
}]);
|
107
|
-
return ObjectWrappingMap;
|
108
107
|
}();
|
109
108
|
/**
|
110
109
|
* Create a map with two partitions: a and b.
|
@@ -133,7 +132,7 @@ var PartitionedMap = exports.PartitionedMap = /*#__PURE__*/function () {
|
|
133
132
|
this.bKeys = bKeys;
|
134
133
|
this[Symbol.iterator] = this.entries;
|
135
134
|
}
|
136
|
-
(0, _createClass2["default"])(PartitionedMap, [{
|
135
|
+
return (0, _createClass2["default"])(PartitionedMap, [{
|
137
136
|
key: "get",
|
138
137
|
value: function get(key) {
|
139
138
|
return this.bKeys.has(key) ? this.b.get(key) : this.a.get(key);
|
@@ -199,7 +198,6 @@ var PartitionedMap = exports.PartitionedMap = /*#__PURE__*/function () {
|
|
199
198
|
return (0, _toConsumableArray2["default"])(this.keys()).length;
|
200
199
|
}
|
201
200
|
}]);
|
202
|
-
return PartitionedMap;
|
203
201
|
}();
|
204
202
|
/**
|
205
203
|
* Create a new iterator that maps over the provided iterator, applying a mapping function to each item
|
package/lib/cjs/utils/object.js
CHANGED
@@ -19,7 +19,6 @@ exports.pick = pick;
|
|
19
19
|
exports.pickShallow = pickShallow;
|
20
20
|
exports.set = set;
|
21
21
|
exports.traverse = traverse;
|
22
|
-
exports.values = values;
|
23
22
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
24
23
|
var _is = require("./is.js");
|
25
24
|
/**
|
@@ -387,13 +386,8 @@ function pickShallow(object, properties) {
|
|
387
386
|
}
|
388
387
|
return copy;
|
389
388
|
}
|
390
|
-
function values(object) {
|
391
|
-
return Object.keys(object).map(function (key) {
|
392
|
-
return object[key];
|
393
|
-
});
|
394
|
-
}
|
395
389
|
|
396
390
|
// helper function to test whether a string contains a path like 'user.name'
|
397
391
|
function isPath(str) {
|
398
|
-
return str.
|
392
|
+
return str.includes('.');
|
399
393
|
}
|
@@ -15,7 +15,7 @@ var allIsFunctions = _interopRequireWildcard(require("./is.js"));
|
|
15
15
|
var _create = require("../core/create.js");
|
16
16
|
var _string = require("./string.js");
|
17
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
18
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
19
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
20
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
|
21
21
|
* This file contains helper methods to create expected snapshot structures
|
@@ -31,7 +31,7 @@ function validateBundle(expectedBundleStructure, bundle) {
|
|
31
31
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
32
32
|
args[_key] = arguments[_key];
|
33
33
|
}
|
34
|
-
if (args.join(' ').
|
34
|
+
if (args.join(' ').includes('is moved to') && args.join(' ').includes('Please use the new location instead')) {
|
35
35
|
// Ignore warnings like:
|
36
36
|
// Warning: math.type.isNumber is moved to math.isNumber in v6.0.0. Please use the new location instead.
|
37
37
|
return;
|
@@ -62,11 +62,11 @@ function validateBundle(expectedBundleStructure, bundle) {
|
|
62
62
|
var expectedType = get(expectedBundleStructure, path) || 'undefined';
|
63
63
|
|
64
64
|
// FIXME: ugly to have these special cases
|
65
|
-
if (path.join('.').
|
65
|
+
if (path.join('.').includes('docs.')) {
|
66
66
|
// ignore the contents of docs
|
67
67
|
return;
|
68
68
|
}
|
69
|
-
if (path.join('.').
|
69
|
+
if (path.join('.').includes('all.')) {
|
70
70
|
// ignore the contents of all dependencies
|
71
71
|
return;
|
72
72
|
}
|
@@ -191,7 +191,7 @@ function traverse(obj) {
|
|
191
191
|
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (value, path) {};
|
192
192
|
var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
193
193
|
// FIXME: ugly to have these special cases
|
194
|
-
if (path.length > 0 && path[0].
|
194
|
+
if (path.length > 0 && path[0].includes('Dependencies')) {
|
195
195
|
// special case for objects holding a collection of dependencies
|
196
196
|
callback(obj, path);
|
197
197
|
} else if (validateTypeOf(obj) === 'Array') {
|
package/lib/cjs/version.js
CHANGED
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = exports.version = '12.4.
|
7
|
+
var version = exports.version = '12.4.3';
|
8
8
|
// Note: This file is automatically generated when building math.js.
|
9
9
|
// Changes made in this file will be overwritten.
|
package/lib/esm/core/create.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import typedFunction from 'typed-function';
|
3
|
-
import { deepFlatten, isLegacyFactory
|
3
|
+
import { deepFlatten, isLegacyFactory } from '../utils/object.js';
|
4
4
|
import * as emitter from './../utils/emitter.js';
|
5
5
|
import { importFactory } from './function/import.js';
|
6
6
|
import { configFactory } from './function/config.js';
|
@@ -170,7 +170,7 @@ export function create(factories, config) {
|
|
170
170
|
// listen for changes in config, import all functions again when changed
|
171
171
|
// TODO: move this listener into the import function?
|
172
172
|
math.on('config', () => {
|
173
|
-
values(importedFactories).forEach(factory => {
|
173
|
+
Object.values(importedFactories).forEach(factory => {
|
174
174
|
if (factory && factory.meta && factory.meta.recreateOnConfigChange) {
|
175
175
|
// FIXME: only re-create when the current instance is the same as was initially created
|
176
176
|
// FIXME: delete the functions/constants before importing them again?
|
@@ -190,7 +190,7 @@ export function create(factories, config) {
|
|
190
190
|
|
191
191
|
// import the factory functions like createAdd as an array instead of object,
|
192
192
|
// else they will get a different naming (`createAdd` instead of `add`).
|
193
|
-
math.import(values(deepFlatten(factories)));
|
193
|
+
math.import(Object.values(deepFlatten(factories)));
|
194
194
|
math.ArgumentsError = ArgumentsError;
|
195
195
|
math.DimensionError = DimensionError;
|
196
196
|
math.IndexError = IndexError;
|
@@ -82,16 +82,6 @@ export function configFactory(config, emit) {
|
|
82
82
|
return _config;
|
83
83
|
}
|
84
84
|
|
85
|
-
/**
|
86
|
-
* Test whether an Array contains a specific item.
|
87
|
-
* @param {Array.<string>} array
|
88
|
-
* @param {string} item
|
89
|
-
* @return {boolean}
|
90
|
-
*/
|
91
|
-
function contains(array, item) {
|
92
|
-
return array.indexOf(item) !== -1;
|
93
|
-
}
|
94
|
-
|
95
85
|
/**
|
96
86
|
* Validate an option
|
97
87
|
* @param {Object} options Object with options
|
@@ -99,7 +89,7 @@ function contains(array, item) {
|
|
99
89
|
* @param {Array.<string>} values Array with valid values for this option
|
100
90
|
*/
|
101
91
|
function validateOption(options, name, values) {
|
102
|
-
if (options[name] !== undefined && !
|
92
|
+
if (options[name] !== undefined && !values.includes(options[name])) {
|
103
93
|
// unknown value
|
104
94
|
console.warn('Warning: Unknown value "' + options[name] + '" for configuration option "' + name + '". ' + 'Available options: ' + values.map(value => JSON.stringify(value)).join(', ') + '.');
|
105
95
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { isBigNumber, isComplex, isFraction, isMatrix, isUnit } from '../../utils/is.js';
|
2
2
|
import { isFactory, stripOptionalNotation } from '../../utils/factory.js';
|
3
3
|
import { hasOwnProperty, lazy } from '../../utils/object.js';
|
4
|
-
import { contains } from '../../utils/array.js';
|
5
4
|
import { ArgumentsError } from '../../error/ArgumentsError.js';
|
6
5
|
export function importFactory(typed, load, math, importedFactories) {
|
7
6
|
/**
|
@@ -216,7 +215,7 @@ export function importFactory(typed, load, math, importedFactories) {
|
|
216
215
|
*/
|
217
216
|
function _importFactory(factory, options) {
|
218
217
|
var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : factory.fn;
|
219
|
-
if (
|
218
|
+
if (name.includes('.')) {
|
220
219
|
throw new Error('Factory name should not contain a nested path. ' + 'Name: ' + JSON.stringify(name));
|
221
220
|
}
|
222
221
|
var namespace = isTransformFunctionFactory(factory) ? math.expression.transform : math;
|
@@ -226,7 +225,7 @@ export function importFactory(typed, load, math, importedFactories) {
|
|
226
225
|
// collect all dependencies, handle finding both functions and classes and other special cases
|
227
226
|
var dependencies = {};
|
228
227
|
factory.dependencies.map(stripOptionalNotation).forEach(dependency => {
|
229
|
-
if (
|
228
|
+
if (dependency.includes('.')) {
|
230
229
|
throw new Error('Factory dependency should not contain a nested path. ' + 'Name: ' + JSON.stringify(dependency));
|
231
230
|
}
|
232
231
|
if (dependency === 'math') {
|
@@ -305,7 +304,7 @@ export function importFactory(typed, load, math, importedFactories) {
|
|
305
304
|
return !hasOwnProperty(unsafe, name);
|
306
305
|
}
|
307
306
|
function factoryAllowedInExpressions(factory) {
|
308
|
-
return factory.fn.
|
307
|
+
return !factory.fn.includes('.') &&
|
309
308
|
// FIXME: make checking on path redundant, check on meta data instead
|
310
309
|
!hasOwnProperty(unsafe, factory.fn) && (!factory.meta || !factory.meta.isClass);
|
311
310
|
}
|
@@ -9,7 +9,7 @@ import { defaultTemplate, latexFunctions } from '../../utils/latex.js';
|
|
9
9
|
var name = 'FunctionNode';
|
10
10
|
var dependencies = ['math', 'Node', 'SymbolNode'];
|
11
11
|
export var createFunctionNode = /* #__PURE__ */factory(name, dependencies, _ref => {
|
12
|
-
var
|
12
|
+
var _FunctionNode;
|
13
13
|
var {
|
14
14
|
math,
|
15
15
|
Node,
|
@@ -456,13 +456,13 @@ export var createFunctionNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
456
456
|
return this.type + ':' + this.name;
|
457
457
|
}
|
458
458
|
}
|
459
|
-
|
459
|
+
_FunctionNode = FunctionNode;
|
460
460
|
_defineProperty(FunctionNode, "name", name);
|
461
461
|
_defineProperty(FunctionNode, "onUndefinedFunction", function (name) {
|
462
462
|
throw new Error('Undefined function ' + name);
|
463
463
|
});
|
464
464
|
_defineProperty(FunctionNode, "fromJSON", function (json) {
|
465
|
-
return new
|
465
|
+
return new _FunctionNode(json.fn, json.args);
|
466
466
|
});
|
467
467
|
return FunctionNode;
|
468
468
|
}, {
|
@@ -952,7 +952,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
952
952
|
}
|
953
953
|
|
954
954
|
/**
|
955
|
-
* multiply, divide
|
955
|
+
* multiply, divide
|
956
956
|
* @return {Node} node
|
957
957
|
* @private
|
958
958
|
*/
|
@@ -1016,7 +1016,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1016
1016
|
* @private
|
1017
1017
|
*/
|
1018
1018
|
function parseRule2(state) {
|
1019
|
-
var node =
|
1019
|
+
var node = parseModulusPercentage(state);
|
1020
1020
|
var last = node;
|
1021
1021
|
var tokenStates = [];
|
1022
1022
|
while (true) {
|
@@ -1038,7 +1038,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1038
1038
|
// Rewind once and build the "number / number" node; the symbol will be consumed later
|
1039
1039
|
_extends(state, tokenStates.pop());
|
1040
1040
|
tokenStates.pop();
|
1041
|
-
last =
|
1041
|
+
last = parseModulusPercentage(state);
|
1042
1042
|
node = new OperatorNode('/', 'divide', [node, last]);
|
1043
1043
|
} else {
|
1044
1044
|
// Not a match, so rewind
|
@@ -1059,11 +1059,11 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1059
1059
|
}
|
1060
1060
|
|
1061
1061
|
/**
|
1062
|
-
*
|
1062
|
+
* modulus and percentage
|
1063
1063
|
* @return {Node} node
|
1064
1064
|
* @private
|
1065
1065
|
*/
|
1066
|
-
function
|
1066
|
+
function parseModulusPercentage(state) {
|
1067
1067
|
var node, name, fn, params;
|
1068
1068
|
node = parseUnary(state);
|
1069
1069
|
var operators = {
|
@@ -1226,7 +1226,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1226
1226
|
if (hasOwnProperty(CONSTANTS, name)) {
|
1227
1227
|
// true, false, null, ...
|
1228
1228
|
node = new ConstantNode(CONSTANTS[name]);
|
1229
|
-
} else if (NUMERIC_CONSTANTS.
|
1229
|
+
} else if (NUMERIC_CONSTANTS.includes(name)) {
|
1230
1230
|
// NaN, Infinity
|
1231
1231
|
node = new ConstantNode(numeric(name, 'number'));
|
1232
1232
|
} else {
|
@@ -1256,7 +1256,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1256
1256
|
*/
|
1257
1257
|
function parseAccessors(state, node, types) {
|
1258
1258
|
var params;
|
1259
|
-
while ((state.token === '(' || state.token === '[' || state.token === '.') && (!types || types.
|
1259
|
+
while ((state.token === '(' || state.token === '[' || state.token === '.') && (!types || types.includes(state.token))) {
|
1260
1260
|
// eslint-disable-line no-unmodified-loop-condition
|
1261
1261
|
params = [];
|
1262
1262
|
if (state.token === '(') {
|
@@ -159,7 +159,7 @@ export var createDerivative = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
159
159
|
return constTag(constNodes, node.content, varName);
|
160
160
|
},
|
161
161
|
'Object, FunctionAssignmentNode, string': function ObjectFunctionAssignmentNodeString(constNodes, node, varName) {
|
162
|
-
if (node.params.
|
162
|
+
if (!node.params.includes(varName)) {
|
163
163
|
constNodes[node] = true;
|
164
164
|
return true;
|
165
165
|
}
|
@@ -229,7 +229,7 @@ export var createRationalize = /* #__PURE__ */factory(name, dependencies, _ref =
|
|
229
229
|
recPoly(node.args[0]);
|
230
230
|
}
|
231
231
|
} else {
|
232
|
-
if (oper.
|
232
|
+
if (!oper.includes(node.op)) {
|
233
233
|
throw new Error('Operator ' + node.op + ' invalid in polynomial expression');
|
234
234
|
}
|
235
235
|
for (var i = 0; i < node.args.length; i++) {
|
@@ -727,7 +727,7 @@ export var createRationalize = /* #__PURE__ */factory(name, dependencies, _ref =
|
|
727
727
|
throw new Error('There is an unsolved function call');
|
728
728
|
} else if (tp === 'OperatorNode') {
|
729
729
|
// ***** OperatorName *****
|
730
|
-
if ('+-*^'.
|
730
|
+
if (!'+-*^'.includes(node.op)) throw new Error('Operator ' + node.op + ' invalid');
|
731
731
|
if (noPai !== null) {
|
732
732
|
// -(unary),^ : children of *,+,-
|
733
733
|
if ((node.fn === 'unaryMinus' || node.fn === 'pow') && noPai.fn !== 'add' && noPai.fn !== 'subtract' && noPai.fn !== 'multiply') {
|
@@ -339,7 +339,7 @@ export var createSimplifyConstant = /* #__PURE__ */factory(name, dependencies, _
|
|
339
339
|
{
|
340
340
|
// Process operators as OperatorNode
|
341
341
|
var operatorFunctions = ['add', 'multiply'];
|
342
|
-
if (operatorFunctions.
|
342
|
+
if (!operatorFunctions.includes(node.name)) {
|
343
343
|
var args = node.args.map(arg => foldFraction(arg, options));
|
344
344
|
|
345
345
|
// If all args are numbers
|
@@ -54,7 +54,7 @@ export var createMad = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
54
54
|
return abs(subtract(value, med));
|
55
55
|
}));
|
56
56
|
} catch (err) {
|
57
|
-
if (err instanceof TypeError && err.message.
|
57
|
+
if (err instanceof TypeError && err.message.includes('median')) {
|
58
58
|
throw new TypeError(err.message.replace('median', 'mad'));
|
59
59
|
} else {
|
60
60
|
throw improveErrorMessage(err, 'mad');
|
@@ -87,7 +87,7 @@ export var createStd = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
87
87
|
return sqrt(v);
|
88
88
|
}
|
89
89
|
} catch (err) {
|
90
|
-
if (err instanceof TypeError && err.message.
|
90
|
+
if (err instanceof TypeError && err.message.includes(' variance')) {
|
91
91
|
throw new TypeError(err.message.replace(' variance', ' std'));
|
92
92
|
} else {
|
93
93
|
throw err;
|
@@ -13,11 +13,11 @@ import { typeOf } from '../../../utils/is.js';
|
|
13
13
|
export function improveErrorMessage(err, fnName, value) {
|
14
14
|
// TODO: add information with the index (also needs transform in expression parser)
|
15
15
|
var details;
|
16
|
-
if (String(err).
|
16
|
+
if (String(err).includes('Unexpected type')) {
|
17
17
|
details = arguments.length > 2 ? ' (type: ' + typeOf(value) + ', value: ' + JSON.stringify(value) + ')' : ' (type: ' + err.data.actual + ')';
|
18
18
|
return new TypeError('Cannot calculate ' + fnName + ', unexpected type of argument' + details);
|
19
19
|
}
|
20
|
-
if (String(err).
|
20
|
+
if (String(err).includes('complex numbers')) {
|
21
21
|
details = arguments.length > 2 ? ' (type: ' + typeOf(value) + ', value: ' + JSON.stringify(value) + ')' : '';
|
22
22
|
return new TypeError('Cannot calculate ' + fnName + ', no ordering relation is defined for complex numbers' + details);
|
23
23
|
}
|
@@ -50,8 +50,6 @@ export var createIsNaN = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
50
50
|
Unit: function Unit(x) {
|
51
51
|
return Number.isNaN(x.value);
|
52
52
|
},
|
53
|
-
'Array | Matrix':
|
54
|
-
return deepMap(x, Number.isNaN);
|
55
|
-
}
|
53
|
+
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
56
54
|
});
|
57
55
|
});
|
@@ -844,7 +844,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
844
844
|
return {
|
845
845
|
mathjs: 'Unit',
|
846
846
|
value: this._denormalize(this.value),
|
847
|
-
unit: this.formatUnits(),
|
847
|
+
unit: this.units.length > 0 ? this.formatUnits() : null,
|
848
848
|
fixPrefix: this.fixPrefix
|
849
849
|
};
|
850
850
|
};
|
@@ -857,7 +857,8 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
857
857
|
* @return {Unit}
|
858
858
|
*/
|
859
859
|
Unit.fromJSON = function (json) {
|
860
|
-
var unit
|
860
|
+
var _json$unit;
|
861
|
+
var unit = new Unit(json.value, (_json$unit = json.unit) !== null && _json$unit !== void 0 ? _json$unit : undefined);
|
861
862
|
unit.fixPrefix = json.fixPrefix || false;
|
862
863
|
return unit;
|
863
864
|
};
|
package/lib/esm/utils/array.js
CHANGED
@@ -618,16 +618,6 @@ export function initial(array) {
|
|
618
618
|
return array.slice(0, array.length - 1);
|
619
619
|
}
|
620
620
|
|
621
|
-
/**
|
622
|
-
* Test whether an array or string contains an item
|
623
|
-
* @param {Array | string} array
|
624
|
-
* @param {*} item
|
625
|
-
* @return {boolean}
|
626
|
-
*/
|
627
|
-
export function contains(array, item) {
|
628
|
-
return array.indexOf(item) !== -1;
|
629
|
-
}
|
630
|
-
|
631
621
|
/**
|
632
622
|
* Recursively concatenate two matrices.
|
633
623
|
* The contents of the matrices is not cloned.
|
@@ -200,7 +200,7 @@ export function toEngineering(value, precision) {
|
|
200
200
|
// find difference in exponents, and calculate the value without exponent
|
201
201
|
var valueWithoutExp = value.mul(Math.pow(10, -newExp));
|
202
202
|
var valueStr = valueWithoutExp.toPrecision(precision);
|
203
|
-
if (valueStr.
|
203
|
+
if (valueStr.includes('e')) {
|
204
204
|
var BigNumber = value.constructor;
|
205
205
|
valueStr = new BigNumber(valueStr).toFixed();
|
206
206
|
}
|
package/lib/esm/utils/factory.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { contains } from './array.js';
|
2
1
|
import { pickShallow } from './object.js';
|
3
2
|
|
4
3
|
/**
|
@@ -57,7 +56,7 @@ export function sortFactories(factories) {
|
|
57
56
|
function containsDependency(factory, dependency) {
|
58
57
|
// TODO: detect circular references
|
59
58
|
if (isFactory(factory)) {
|
60
|
-
if (
|
59
|
+
if (factory.dependencies.includes(dependency.fn || dependency.name)) {
|
61
60
|
return true;
|
62
61
|
}
|
63
62
|
if (factory.dependencies.some(d => containsDependency(factoriesByName[d], dependency))) {
|
package/lib/esm/utils/object.js
CHANGED
@@ -365,11 +365,8 @@ export function pickShallow(object, properties) {
|
|
365
365
|
}
|
366
366
|
return copy;
|
367
367
|
}
|
368
|
-
export function values(object) {
|
369
|
-
return Object.keys(object).map(key => object[key]);
|
370
|
-
}
|
371
368
|
|
372
369
|
// helper function to test whether a string contains a path like 'user.name'
|
373
370
|
function isPath(str) {
|
374
|
-
return str.
|
371
|
+
return str.includes('.');
|
375
372
|
}
|
@@ -20,7 +20,7 @@ export function validateBundle(expectedBundleStructure, bundle) {
|
|
20
20
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
21
21
|
args[_key] = arguments[_key];
|
22
22
|
}
|
23
|
-
if (args.join(' ').
|
23
|
+
if (args.join(' ').includes('is moved to') && args.join(' ').includes('Please use the new location instead')) {
|
24
24
|
// Ignore warnings like:
|
25
25
|
// Warning: math.type.isNumber is moved to math.isNumber in v6.0.0. Please use the new location instead.
|
26
26
|
return;
|
@@ -51,11 +51,11 @@ export function validateBundle(expectedBundleStructure, bundle) {
|
|
51
51
|
var expectedType = get(expectedBundleStructure, path) || 'undefined';
|
52
52
|
|
53
53
|
// FIXME: ugly to have these special cases
|
54
|
-
if (path.join('.').
|
54
|
+
if (path.join('.').includes('docs.')) {
|
55
55
|
// ignore the contents of docs
|
56
56
|
return;
|
57
57
|
}
|
58
|
-
if (path.join('.').
|
58
|
+
if (path.join('.').includes('all.')) {
|
59
59
|
// ignore the contents of all dependencies
|
60
60
|
return;
|
61
61
|
}
|
@@ -181,7 +181,7 @@ function traverse(obj) {
|
|
181
181
|
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (value, path) => {};
|
182
182
|
var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
183
183
|
// FIXME: ugly to have these special cases
|
184
|
-
if (path.length > 0 && path[0].
|
184
|
+
if (path.length > 0 && path[0].includes('Dependencies')) {
|
185
185
|
// special case for objects holding a collection of dependencies
|
186
186
|
callback(obj, path);
|
187
187
|
} else if (validateTypeOf(obj) === 'Array') {
|
package/lib/esm/version.js
CHANGED