mathjs 12.4.2 → 12.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/HISTORY.md +8 -0
  2. package/README.md +4 -0
  3. package/bin/cli.js +1 -1
  4. package/lib/browser/math.js +1 -1
  5. package/lib/browser/math.js.LICENSE.txt +2 -2
  6. package/lib/browser/math.js.map +1 -1
  7. package/lib/cjs/core/function/config.js +1 -11
  8. package/lib/cjs/core/function/import.js +3 -4
  9. package/lib/cjs/expression/parse.js +7 -7
  10. package/lib/cjs/function/algebra/derivative.js +1 -1
  11. package/lib/cjs/function/algebra/rationalize.js +2 -2
  12. package/lib/cjs/function/algebra/simplifyConstant.js +1 -1
  13. package/lib/cjs/function/statistics/mad.js +1 -1
  14. package/lib/cjs/function/statistics/std.js +1 -1
  15. package/lib/cjs/function/statistics/utils/improveErrorMessage.js +2 -2
  16. package/lib/cjs/header.js +2 -2
  17. package/lib/cjs/type/unit/Unit.js +3 -2
  18. package/lib/cjs/utils/array.js +0 -11
  19. package/lib/cjs/utils/bignumber/formatter.js +1 -1
  20. package/lib/cjs/utils/factory.js +1 -2
  21. package/lib/cjs/utils/object.js +1 -1
  22. package/lib/cjs/utils/snapshot.js +4 -4
  23. package/lib/cjs/version.js +1 -1
  24. package/lib/esm/core/function/config.js +1 -11
  25. package/lib/esm/core/function/import.js +3 -4
  26. package/lib/esm/expression/parse.js +7 -7
  27. package/lib/esm/function/algebra/derivative.js +1 -1
  28. package/lib/esm/function/algebra/rationalize.js +2 -2
  29. package/lib/esm/function/algebra/simplifyConstant.js +1 -1
  30. package/lib/esm/function/statistics/mad.js +1 -1
  31. package/lib/esm/function/statistics/std.js +1 -1
  32. package/lib/esm/function/statistics/utils/improveErrorMessage.js +2 -2
  33. package/lib/esm/type/unit/Unit.js +3 -2
  34. package/lib/esm/utils/array.js +0 -10
  35. package/lib/esm/utils/bignumber/formatter.js +1 -1
  36. package/lib/esm/utils/factory.js +1 -2
  37. package/lib/esm/utils/object.js +1 -1
  38. package/lib/esm/utils/snapshot.js +4 -4
  39. package/lib/esm/version.js +1 -1
  40. package/package.json +1 -1
  41. package/types/EXPLANATION.md +13 -1
  42. package/types/index.d.ts +14 -1
@@ -91,16 +91,6 @@ function configFactory(config, emit) {
91
91
  return _config;
92
92
  }
93
93
 
94
- /**
95
- * Test whether an Array contains a specific item.
96
- * @param {Array.<string>} array
97
- * @param {string} item
98
- * @return {boolean}
99
- */
100
- function contains(array, item) {
101
- return array.indexOf(item) !== -1;
102
- }
103
-
104
94
  /**
105
95
  * Validate an option
106
96
  * @param {Object} options Object with options
@@ -108,7 +98,7 @@ function contains(array, item) {
108
98
  * @param {Array.<string>} values Array with valid values for this option
109
99
  */
110
100
  function validateOption(options, name, values) {
111
- if (options[name] !== undefined && !contains(values, options[name])) {
101
+ if (options[name] !== undefined && !values.includes(options[name])) {
112
102
  // unknown value
113
103
  console.warn('Warning: Unknown value "' + options[name] + '" for configuration option "' + name + '". ' + 'Available options: ' + values.map(function (value) {
114
104
  return JSON.stringify(value);
@@ -10,7 +10,6 @@ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
10
  var _is = require("../../utils/is.js");
11
11
  var _factory = require("../../utils/factory.js");
12
12
  var _object = require("../../utils/object.js");
13
- var _array = require("../../utils/array.js");
14
13
  var _ArgumentsError = require("../../error/ArgumentsError.js");
15
14
  function importFactory(typed, load, math, importedFactories) {
16
15
  /**
@@ -225,7 +224,7 @@ function importFactory(typed, load, math, importedFactories) {
225
224
  */
226
225
  function _importFactory(factory, options) {
227
226
  var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : factory.fn;
228
- if ((0, _array.contains)(name, '.')) {
227
+ if (name.includes('.')) {
229
228
  throw new Error('Factory name should not contain a nested path. ' + 'Name: ' + JSON.stringify(name));
230
229
  }
231
230
  var namespace = isTransformFunctionFactory(factory) ? math.expression.transform : math;
@@ -235,7 +234,7 @@ function importFactory(typed, load, math, importedFactories) {
235
234
  // collect all dependencies, handle finding both functions and classes and other special cases
236
235
  var dependencies = {};
237
236
  factory.dependencies.map(_factory.stripOptionalNotation).forEach(function (dependency) {
238
- if ((0, _array.contains)(dependency, '.')) {
237
+ if (dependency.includes('.')) {
239
238
  throw new Error('Factory dependency should not contain a nested path. ' + 'Name: ' + JSON.stringify(dependency));
240
239
  }
241
240
  if (dependency === 'math') {
@@ -318,7 +317,7 @@ function importFactory(typed, load, math, importedFactories) {
318
317
  return !(0, _object.hasOwnProperty)(unsafe, name);
319
318
  }
320
319
  function factoryAllowedInExpressions(factory) {
321
- return factory.fn.indexOf('.') === -1 &&
320
+ return !factory.fn.includes('.') &&
322
321
  // FIXME: make checking on path redundant, check on meta data instead
323
322
  !(0, _object.hasOwnProperty)(unsafe, factory.fn) && (!factory.meta || !factory.meta.isClass);
324
323
  }
@@ -959,7 +959,7 @@ var createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(nam
959
959
  }
960
960
 
961
961
  /**
962
- * multiply, divide, modulus
962
+ * multiply, divide
963
963
  * @return {Node} node
964
964
  * @private
965
965
  */
@@ -1023,7 +1023,7 @@ var createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(nam
1023
1023
  * @private
1024
1024
  */
1025
1025
  function parseRule2(state) {
1026
- var node = parsePercentage(state);
1026
+ var node = parseModulusPercentage(state);
1027
1027
  var last = node;
1028
1028
  var tokenStates = [];
1029
1029
  while (true) {
@@ -1045,7 +1045,7 @@ var createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(nam
1045
1045
  // Rewind once and build the "number / number" node; the symbol will be consumed later
1046
1046
  (0, _extends2["default"])(state, tokenStates.pop());
1047
1047
  tokenStates.pop();
1048
- last = parsePercentage(state);
1048
+ last = parseModulusPercentage(state);
1049
1049
  node = new OperatorNode('/', 'divide', [node, last]);
1050
1050
  } else {
1051
1051
  // Not a match, so rewind
@@ -1066,11 +1066,11 @@ var createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(nam
1066
1066
  }
1067
1067
 
1068
1068
  /**
1069
- * percentage or mod
1069
+ * modulus and percentage
1070
1070
  * @return {Node} node
1071
1071
  * @private
1072
1072
  */
1073
- function parsePercentage(state) {
1073
+ function parseModulusPercentage(state) {
1074
1074
  var node, name, fn, params;
1075
1075
  node = parseUnary(state);
1076
1076
  var operators = {
@@ -1233,7 +1233,7 @@ var createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(nam
1233
1233
  if ((0, _object.hasOwnProperty)(CONSTANTS, name)) {
1234
1234
  // true, false, null, ...
1235
1235
  node = new ConstantNode(CONSTANTS[name]);
1236
- } else if (NUMERIC_CONSTANTS.indexOf(name) !== -1) {
1236
+ } else if (NUMERIC_CONSTANTS.includes(name)) {
1237
1237
  // NaN, Infinity
1238
1238
  node = new ConstantNode(numeric(name, 'number'));
1239
1239
  } else {
@@ -1263,7 +1263,7 @@ var createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(nam
1263
1263
  */
1264
1264
  function parseAccessors(state, node, types) {
1265
1265
  var params;
1266
- while ((state.token === '(' || state.token === '[' || state.token === '.') && (!types || types.indexOf(state.token) !== -1)) {
1266
+ while ((state.token === '(' || state.token === '[' || state.token === '.') && (!types || types.includes(state.token))) {
1267
1267
  // eslint-disable-line no-unmodified-loop-condition
1268
1268
  params = [];
1269
1269
  if (state.token === '(') {
@@ -163,7 +163,7 @@ var createDerivative = exports.createDerivative = /* #__PURE__ */(0, _factory.fa
163
163
  return constTag(constNodes, node.content, varName);
164
164
  },
165
165
  'Object, FunctionAssignmentNode, string': function ObjectFunctionAssignmentNodeString(constNodes, node, varName) {
166
- if (node.params.indexOf(varName) === -1) {
166
+ if (!node.params.includes(varName)) {
167
167
  constNodes[node] = true;
168
168
  return true;
169
169
  }
@@ -235,7 +235,7 @@ var createRationalize = exports.createRationalize = /* #__PURE__ */(0, _factory.
235
235
  recPoly(node.args[0]);
236
236
  }
237
237
  } else {
238
- if (oper.indexOf(node.op) === -1) {
238
+ if (!oper.includes(node.op)) {
239
239
  throw new Error('Operator ' + node.op + ' invalid in polynomial expression');
240
240
  }
241
241
  for (var i = 0; i < node.args.length; i++) {
@@ -733,7 +733,7 @@ var createRationalize = exports.createRationalize = /* #__PURE__ */(0, _factory.
733
733
  throw new Error('There is an unsolved function call');
734
734
  } else if (tp === 'OperatorNode') {
735
735
  // ***** OperatorName *****
736
- if ('+-*^'.indexOf(node.op) === -1) throw new Error('Operator ' + node.op + ' invalid');
736
+ if (!'+-*^'.includes(node.op)) throw new Error('Operator ' + node.op + ' invalid');
737
737
  if (noPai !== null) {
738
738
  // -(unary),^ : children of *,+,-
739
739
  if ((node.fn === 'unaryMinus' || node.fn === 'pow') && noPai.fn !== 'add' && noPai.fn !== 'subtract' && noPai.fn !== 'multiply') {
@@ -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.indexOf(node.name) === -1) {
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.indexOf('median') !== -1) {
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.indexOf(' variance') !== -1) {
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).indexOf('Unexpected type') !== -1) {
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).indexOf('complex numbers') !== -1) {
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
  }
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.2
10
- * @date 2024-04-24
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 = new Unit(json.value, json.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
  };
@@ -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.indexOf('e') !== -1) {
210
+ if (valueStr.includes('e')) {
211
211
  var BigNumber = value.constructor;
212
212
  valueStr = new BigNumber(valueStr).toFixed();
213
213
  }
@@ -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 ((0, _array.contains)(factory.dependencies, dependency.fn || dependency.name)) {
70
+ if (factory.dependencies.includes(dependency.fn || dependency.name)) {
72
71
  return true;
73
72
  }
74
73
  if (factory.dependencies.some(function (d) {
@@ -389,5 +389,5 @@ function pickShallow(object, properties) {
389
389
 
390
390
  // helper function to test whether a string contains a path like 'user.name'
391
391
  function isPath(str) {
392
- return str.indexOf('.') !== -1;
392
+ return str.includes('.');
393
393
  }
@@ -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(' ').indexOf('is moved to') !== -1 && args.join(' ').indexOf('Please use the new location instead') !== -1) {
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('.').indexOf('docs.') !== -1) {
65
+ if (path.join('.').includes('docs.')) {
66
66
  // ignore the contents of docs
67
67
  return;
68
68
  }
69
- if (path.join('.').indexOf('all.') !== -1) {
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].indexOf('Dependencies') !== -1) {
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') {
@@ -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.2';
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.
@@ -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 && !contains(values, options[name])) {
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 (contains(name, '.')) {
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 (contains(dependency, '.')) {
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.indexOf('.') === -1 &&
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
  }
@@ -952,7 +952,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
952
952
  }
953
953
 
954
954
  /**
955
- * multiply, divide, modulus
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 = parsePercentage(state);
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 = parsePercentage(state);
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
- * percentage or mod
1062
+ * modulus and percentage
1063
1063
  * @return {Node} node
1064
1064
  * @private
1065
1065
  */
1066
- function parsePercentage(state) {
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.indexOf(name) !== -1) {
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.indexOf(state.token) !== -1)) {
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.indexOf(varName) === -1) {
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.indexOf(node.op) === -1) {
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 ('+-*^'.indexOf(node.op) === -1) throw new Error('Operator ' + node.op + ' invalid');
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.indexOf(node.name) === -1) {
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.indexOf('median') !== -1) {
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.indexOf(' variance') !== -1) {
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).indexOf('Unexpected type') !== -1) {
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).indexOf('complex numbers') !== -1) {
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
  }
@@ -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 = new Unit(json.value, json.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
  };
@@ -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.indexOf('e') !== -1) {
203
+ if (valueStr.includes('e')) {
204
204
  var BigNumber = value.constructor;
205
205
  valueStr = new BigNumber(valueStr).toFixed();
206
206
  }
@@ -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 (contains(factory.dependencies, dependency.fn || dependency.name)) {
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))) {
@@ -368,5 +368,5 @@ export function pickShallow(object, properties) {
368
368
 
369
369
  // helper function to test whether a string contains a path like 'user.name'
370
370
  function isPath(str) {
371
- return str.indexOf('.') !== -1;
371
+ return str.includes('.');
372
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(' ').indexOf('is moved to') !== -1 && args.join(' ').indexOf('Please use the new location instead') !== -1) {
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('.').indexOf('docs.') !== -1) {
54
+ if (path.join('.').includes('docs.')) {
55
55
  // ignore the contents of docs
56
56
  return;
57
57
  }
58
- if (path.join('.').indexOf('all.') !== -1) {
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].indexOf('Dependencies') !== -1) {
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') {
@@ -1,3 +1,3 @@
1
- export var version = '12.4.2';
1
+ export var version = '12.4.3';
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.