mathjs 15.1.0 → 15.2.0
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.
- package/HISTORY.md +22 -0
- package/NOTICE +1 -1
- package/README.md +6 -6
- package/bin/cli.js +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/function/import.js +7 -0
- package/lib/cjs/core/function/typed.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesDen.generated.js +19 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesNum.generated.js +19 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +14 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +123 -121
- package/lib/cjs/entry/pureFunctionsAny.generated.js +344 -336
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +4 -0
- package/lib/cjs/expression/embeddedDocs/function/fraction/den.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/fraction/num.js +14 -0
- package/lib/cjs/expression/parse.js +26 -2
- package/lib/cjs/factoriesAny.js +15 -1
- package/lib/cjs/function/algebra/polynomialRoot.js +4 -0
- package/lib/cjs/function/arithmetic/add.js +8 -1
- package/lib/cjs/function/arithmetic/cbrt.js +7 -6
- package/lib/cjs/function/arithmetic/ceil.js +10 -2
- package/lib/cjs/function/arithmetic/exp.js +7 -5
- package/lib/cjs/function/arithmetic/expm1.js +6 -5
- package/lib/cjs/function/arithmetic/fix.js +10 -2
- package/lib/cjs/function/arithmetic/floor.js +10 -2
- package/lib/cjs/function/arithmetic/log.js +13 -0
- package/lib/cjs/function/arithmetic/mod.js +8 -2
- package/lib/cjs/function/arithmetic/nthRoot.js +9 -3
- package/lib/cjs/function/arithmetic/nthRoots.js +7 -10
- package/lib/cjs/function/fraction/den.js +60 -0
- package/lib/cjs/function/fraction/num.js +62 -0
- package/lib/cjs/function/matrix/map.js +6 -0
- package/lib/cjs/function/relational/compare.js +6 -0
- package/lib/cjs/function/relational/compareNatural.js +8 -2
- package/lib/cjs/function/relational/deepEqual.js +8 -3
- package/lib/cjs/function/relational/equal.js +15 -2
- package/lib/cjs/function/relational/unequal.js +14 -2
- package/lib/cjs/function/set/setDistinct.js +2 -1
- package/lib/cjs/function/string/format.js +9 -0
- package/lib/cjs/function/utils/isFinite.js +8 -1
- package/lib/cjs/function/utils/numeric.js +6 -0
- package/lib/cjs/header.js +3 -3
- package/lib/cjs/type/bigint.js +5 -0
- package/lib/cjs/type/boolean.js +6 -0
- package/lib/cjs/type/complex/function/complex.js +6 -0
- package/lib/cjs/type/fraction/function/fraction.js +8 -0
- package/lib/cjs/type/matrix/function/index.js +8 -0
- package/lib/cjs/type/matrix/function/matrix.js +6 -0
- package/lib/cjs/type/matrix/function/sparse.js +4 -0
- package/lib/cjs/type/string.js +4 -0
- package/lib/cjs/type/unit/Unit.js +7 -0
- package/lib/cjs/type/unit/function/unit.js +8 -0
- package/lib/cjs/utils/array.js +3 -0
- package/lib/cjs/utils/customs.js +39 -46
- package/lib/cjs/utils/map.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/function/import.js +7 -0
- package/lib/esm/core/function/typed.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesDen.generated.js +12 -0
- package/lib/esm/entry/dependenciesAny/dependenciesNum.generated.js +12 -0
- package/lib/esm/entry/dependenciesAny.generated.js +2 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +125 -123
- package/lib/esm/entry/pureFunctionsAny.generated.js +341 -333
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -0
- package/lib/esm/expression/embeddedDocs/function/fraction/den.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/fraction/num.js +8 -0
- package/lib/esm/expression/parse.js +26 -2
- package/lib/esm/factoriesAny.js +3 -1
- package/lib/esm/function/algebra/polynomialRoot.js +4 -0
- package/lib/esm/function/arithmetic/add.js +8 -1
- package/lib/esm/function/arithmetic/cbrt.js +7 -6
- package/lib/esm/function/arithmetic/ceil.js +10 -2
- package/lib/esm/function/arithmetic/exp.js +7 -5
- package/lib/esm/function/arithmetic/expm1.js +6 -5
- package/lib/esm/function/arithmetic/fix.js +10 -2
- package/lib/esm/function/arithmetic/floor.js +10 -2
- package/lib/esm/function/arithmetic/log.js +13 -0
- package/lib/esm/function/arithmetic/mod.js +8 -2
- package/lib/esm/function/arithmetic/nthRoot.js +9 -3
- package/lib/esm/function/arithmetic/nthRoots.js +7 -10
- package/lib/esm/function/fraction/den.js +54 -0
- package/lib/esm/function/fraction/num.js +56 -0
- package/lib/esm/function/matrix/map.js +6 -0
- package/lib/esm/function/relational/compare.js +6 -0
- package/lib/esm/function/relational/compareNatural.js +8 -2
- package/lib/esm/function/relational/deepEqual.js +8 -3
- package/lib/esm/function/relational/equal.js +15 -2
- package/lib/esm/function/relational/unequal.js +14 -2
- package/lib/esm/function/set/setDistinct.js +2 -1
- package/lib/esm/function/string/format.js +9 -0
- package/lib/esm/function/utils/isFinite.js +8 -1
- package/lib/esm/function/utils/numeric.js +6 -0
- package/lib/esm/header.js +1 -1
- package/lib/esm/type/bigint.js +5 -0
- package/lib/esm/type/boolean.js +6 -0
- package/lib/esm/type/complex/function/complex.js +6 -0
- package/lib/esm/type/fraction/function/fraction.js +8 -0
- package/lib/esm/type/matrix/function/index.js +8 -0
- package/lib/esm/type/matrix/function/matrix.js +6 -0
- package/lib/esm/type/matrix/function/sparse.js +4 -0
- package/lib/esm/type/string.js +4 -0
- package/lib/esm/type/unit/Unit.js +7 -0
- package/lib/esm/type/unit/function/unit.js +8 -0
- package/lib/esm/utils/array.js +3 -0
- package/lib/esm/utils/customs.js +42 -56
- package/lib/esm/utils/map.js +3 -3
- package/lib/esm/version.js +1 -1
- package/package.json +14 -14
- package/types/index.d.ts +96 -15
|
@@ -14,6 +14,7 @@ export var createSetDistinct = /* #__PURE__ */factory(name, dependencies, _ref =
|
|
|
14
14
|
/**
|
|
15
15
|
* Collect the distinct elements of a multiset.
|
|
16
16
|
* A multi-dimension array will be converted to a single-dimension array before the operation.
|
|
17
|
+
* The items of the returned array will be sorted in natural order.
|
|
17
18
|
*
|
|
18
19
|
* Syntax:
|
|
19
20
|
*
|
|
@@ -28,7 +29,7 @@ export var createSetDistinct = /* #__PURE__ */factory(name, dependencies, _ref =
|
|
|
28
29
|
* setMultiplicity
|
|
29
30
|
*
|
|
30
31
|
* @param {Array | Matrix} a A multiset
|
|
31
|
-
* @return {Array | Matrix} A set containing the
|
|
32
|
+
* @return {Array | Matrix} A set containing the distinct elements of the multiset
|
|
32
33
|
*/
|
|
33
34
|
return typed(name, {
|
|
34
35
|
'Array | Matrix': function Array__Matrix(a) {
|
|
@@ -120,6 +120,15 @@ export var createFormat = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
120
120
|
*
|
|
121
121
|
* print
|
|
122
122
|
*
|
|
123
|
+
* History:
|
|
124
|
+
*
|
|
125
|
+
* v0.4 Created
|
|
126
|
+
* v0.7 Round to a consistent number of digits (rather than decimals)
|
|
127
|
+
* v0.15 Added multiple number notations and configurable precision
|
|
128
|
+
* v3 Added support for JSON objects
|
|
129
|
+
* v9 Added binary, hexadecimal, and octal notations
|
|
130
|
+
* v10.4.2 Add `truncate` option
|
|
131
|
+
*
|
|
123
132
|
* @param {*} value Value to be stringified
|
|
124
133
|
* @param {Object | Function | number} [options] Formatting options
|
|
125
134
|
* @return {string} The formatted value
|
|
@@ -34,8 +34,15 @@ export var createIsFinite = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
34
34
|
*
|
|
35
35
|
* isBounded isNumeric, isPositive, isNegative, isNaN
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* History:
|
|
38
|
+
*
|
|
39
|
+
* v15.1 Created
|
|
40
|
+
*
|
|
41
|
+
* @param {number | BigNumber | bigint | Complex | Fraction | Unit | Array | Matrix} x
|
|
42
|
+
* Value to be tested
|
|
38
43
|
* @return {boolean | Array | Matrix}
|
|
44
|
+
* Whether the value, or its entries, are finite, as appropriate
|
|
45
|
+
* to its type
|
|
39
46
|
*/
|
|
40
47
|
return typed(name, {
|
|
41
48
|
'Array | Matrix': A => map(A, isBounded),
|
|
@@ -46,6 +46,12 @@ export var createNumeric = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
46
46
|
*
|
|
47
47
|
* number, fraction, bignumber, bigint, string, format
|
|
48
48
|
*
|
|
49
|
+
* History:
|
|
50
|
+
*
|
|
51
|
+
* v6 Created
|
|
52
|
+
* v13 Added `bigint` support
|
|
53
|
+
* v14.2.1 Prefer mathjs `bigint()` to built-in `BigInt()`
|
|
54
|
+
*
|
|
49
55
|
* @param {string | number | BigNumber | bigint | Fraction } value
|
|
50
56
|
* A numeric value or a string containing a numeric value
|
|
51
57
|
* @param {string} outputType
|
package/lib/esm/header.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @date @@date
|
|
11
11
|
*
|
|
12
12
|
* @license
|
|
13
|
-
* Copyright (C) 2013-
|
|
13
|
+
* Copyright (C) 2013-2026 Jos de Jong <wjosdejong@gmail.com>
|
|
14
14
|
*
|
|
15
15
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
16
16
|
* use this file except in compliance with the License. You may obtain a copy
|
package/lib/esm/type/bigint.js
CHANGED
|
@@ -25,6 +25,11 @@ export var createBigint = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
25
25
|
*
|
|
26
26
|
* number, bignumber, boolean, complex, index, matrix, string, unit
|
|
27
27
|
*
|
|
28
|
+
* History:
|
|
29
|
+
*
|
|
30
|
+
* v13 Created
|
|
31
|
+
* v14.2.1 Added conversion options
|
|
32
|
+
*
|
|
28
33
|
* @param {string | number | BigNumber | bigint | Fraction | boolean | Array | Matrix | null} [value] Value to be converted
|
|
29
34
|
* @return {bigint | Array | Matrix} The created bigint
|
|
30
35
|
*/
|
package/lib/esm/type/boolean.js
CHANGED
|
@@ -30,6 +30,12 @@ export var createBoolean = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
30
30
|
*
|
|
31
31
|
* bignumber, complex, index, matrix, string, unit
|
|
32
32
|
*
|
|
33
|
+
* History:
|
|
34
|
+
*
|
|
35
|
+
* v0.11 Created
|
|
36
|
+
* v0.16 Added conversion from BigNumber
|
|
37
|
+
* v14.2.1 Added conversion from bigint
|
|
38
|
+
*
|
|
33
39
|
* @param {string | number | boolean | Array | Matrix | null} value A value of any type
|
|
34
40
|
* @return {boolean | Array | Matrix} The boolean value
|
|
35
41
|
*/
|
|
@@ -41,6 +41,12 @@ export var createComplex = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
41
41
|
*
|
|
42
42
|
* bignumber, boolean, index, matrix, number, string, unit
|
|
43
43
|
*
|
|
44
|
+
* History:
|
|
45
|
+
*
|
|
46
|
+
* v0.5 Created
|
|
47
|
+
* v0.16 Added conversion from BigNumber
|
|
48
|
+
* v6 Added conversion from Fraction
|
|
49
|
+
*
|
|
44
50
|
* @param {* | Array | Matrix} [args]
|
|
45
51
|
* Arguments specifying the real and imaginary part of the complex number
|
|
46
52
|
* @return {Complex | Array | Matrix} Returns a complex value
|
|
@@ -39,6 +39,14 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
39
39
|
*
|
|
40
40
|
* bignumber, number, string, unit
|
|
41
41
|
*
|
|
42
|
+
* History:
|
|
43
|
+
*
|
|
44
|
+
* v2 Created
|
|
45
|
+
* v3 Added conversion from BigNumber
|
|
46
|
+
* v11.8 Added conversion from Unit
|
|
47
|
+
* v13 Added conversion from bigint
|
|
48
|
+
* v14 Move to bigint-based fraction.js@5; construct from two bigints
|
|
49
|
+
*
|
|
42
50
|
* @param {number | string | Fraction | BigNumber | bigint | Unit | Array | Matrix} [args]
|
|
43
51
|
* Arguments specifying the value, or numerator and denominator of
|
|
44
52
|
* the fraction
|
|
@@ -39,6 +39,14 @@ export var createIndex = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
39
39
|
*
|
|
40
40
|
* bignumber, boolean, complex, matrix, number, string, unit
|
|
41
41
|
*
|
|
42
|
+
* History:
|
|
43
|
+
*
|
|
44
|
+
* v? Created
|
|
45
|
+
* v2 Dropped support for `[start, end, step]` arguments in favor
|
|
46
|
+
* of lists of arbitrary values; added support for Range
|
|
47
|
+
* objects.
|
|
48
|
+
* v11.10 Added support for arrays of booleans as indices.
|
|
49
|
+
*
|
|
42
50
|
* @param {...*} ranges Zero or more ranges or numbers.
|
|
43
51
|
* @return {Index} Returns the created index
|
|
44
52
|
*/
|
|
@@ -35,6 +35,12 @@ export var createMatrix = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
35
35
|
*
|
|
36
36
|
* bignumber, boolean, complex, index, number, string, unit, sparse
|
|
37
37
|
*
|
|
38
|
+
* History:
|
|
39
|
+
*
|
|
40
|
+
* v0.5 Created
|
|
41
|
+
* v1.5 Support dense or sparse Matrix types; allow construction
|
|
42
|
+
* from string, Array, or another Matrix.
|
|
43
|
+
*
|
|
38
44
|
* @param {Array | Matrix} [data] A multi dimensional array
|
|
39
45
|
* @param {string} [format] The Matrix storage format, either `'dense'` or `'sparse'`
|
|
40
46
|
* @param {string} [datatype] Type of the values
|
|
@@ -35,6 +35,10 @@ export var createSparse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
35
35
|
*
|
|
36
36
|
* bignumber, boolean, complex, index, number, string, unit, matrix
|
|
37
37
|
*
|
|
38
|
+
* History:
|
|
39
|
+
*
|
|
40
|
+
* v1.5 Created
|
|
41
|
+
*
|
|
38
42
|
* @param {Array | Matrix} [data] A two dimensional array
|
|
39
43
|
*
|
|
40
44
|
* @return {Matrix} The created matrix
|
package/lib/esm/type/string.js
CHANGED
|
@@ -29,6 +29,10 @@ export var createString = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
29
29
|
*
|
|
30
30
|
* bignumber, boolean, complex, index, matrix, number, unit
|
|
31
31
|
*
|
|
32
|
+
* History:
|
|
33
|
+
*
|
|
34
|
+
* v0.9 Created
|
|
35
|
+
*
|
|
32
36
|
* @param {* | Array | Matrix | null} [value] A value to convert to a string
|
|
33
37
|
* @return {string | Array | Matrix} The created string
|
|
34
38
|
*/
|
|
@@ -3159,6 +3159,13 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
3159
3159
|
value: 1,
|
|
3160
3160
|
offset: 0
|
|
3161
3161
|
},
|
|
3162
|
+
Ah: {
|
|
3163
|
+
name: 'Ah',
|
|
3164
|
+
base: BASE_UNITS.ELECTRIC_CHARGE,
|
|
3165
|
+
prefixes: PREFIXES.SHORT,
|
|
3166
|
+
value: 3600,
|
|
3167
|
+
offset: 0
|
|
3168
|
+
},
|
|
3162
3169
|
// Electric capacitance
|
|
3163
3170
|
farad: {
|
|
3164
3171
|
name: 'farad',
|
|
@@ -32,6 +32,14 @@ export var createUnitFunction = /* #__PURE__ */factory(name, dependencies, _ref
|
|
|
32
32
|
*
|
|
33
33
|
* bignumber, boolean, complex, index, matrix, number, string, createUnit
|
|
34
34
|
*
|
|
35
|
+
* History:
|
|
36
|
+
*
|
|
37
|
+
* v0.5 Created
|
|
38
|
+
* v0.16 Support conversion from BigNumber
|
|
39
|
+
* v2.5 Support BigNumber and Fraction values in units
|
|
40
|
+
* v2.6 Support Complex values in units
|
|
41
|
+
* v11.1 Allow the type of unit to be specifed by a unit (not just string)
|
|
42
|
+
*
|
|
35
43
|
* @param {* | Array | Matrix} args A number and unit.
|
|
36
44
|
* @return {Unit | Array | Matrix} The created unit
|
|
37
45
|
*/
|
package/lib/esm/utils/array.js
CHANGED
|
@@ -820,6 +820,9 @@ export function get(array, index) {
|
|
|
820
820
|
if (!Array.isArray(array)) {
|
|
821
821
|
throw new Error('Array expected');
|
|
822
822
|
}
|
|
823
|
+
if (!Array.isArray(index)) {
|
|
824
|
+
throw new Error('Array expected for index');
|
|
825
|
+
}
|
|
823
826
|
var size = arraySize(array);
|
|
824
827
|
if (index.length !== size.length) {
|
|
825
828
|
throw new DimensionError(index.length, size.length);
|
package/lib/esm/utils/customs.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { hasOwnProperty } from './object.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Get a property of a plain object
|
|
4
|
+
* Get a property of a plain object or array
|
|
5
5
|
* Throws an error in case the object is not a plain object or the
|
|
6
6
|
* property is not defined on the object itself
|
|
7
7
|
* @param {Object} object
|
|
8
8
|
* @param {string} prop
|
|
9
9
|
* @return {*} Returns the property value when safe
|
|
10
10
|
*/
|
|
11
|
-
function getSafeProperty(object, prop) {
|
|
12
|
-
|
|
13
|
-
if (isSafeProperty(object, prop)) {
|
|
11
|
+
export function getSafeProperty(object, prop) {
|
|
12
|
+
if (isSafeObjectProperty(object, prop) || isSafeArrayProperty(object, prop)) {
|
|
14
13
|
return object[prop];
|
|
15
14
|
}
|
|
16
|
-
if (
|
|
17
|
-
throw new Error(
|
|
15
|
+
if (isSafeMethod(object, prop)) {
|
|
16
|
+
throw new Error("Cannot access method \"".concat(prop, "\" as a property"));
|
|
17
|
+
}
|
|
18
|
+
if (object === null || object === undefined) {
|
|
19
|
+
throw new TypeError("Cannot access property \"".concat(prop, "\": object is ").concat(object));
|
|
18
20
|
}
|
|
19
21
|
throw new Error('No access to property "' + prop + '"');
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
|
-
* Set a property on a plain object.
|
|
25
|
+
* Set a property on a plain object or array.
|
|
24
26
|
* Throws an error in case the object is not a plain object or the
|
|
25
27
|
* property would override an inherited property like .constructor or .toString
|
|
26
28
|
* @param {Object} object
|
|
@@ -28,49 +30,43 @@ function getSafeProperty(object, prop) {
|
|
|
28
30
|
* @param {*} value
|
|
29
31
|
* @return {*} Returns the value
|
|
30
32
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// only allow setting safe properties of a plain object
|
|
34
|
-
if (isSafeProperty(object, prop)) {
|
|
33
|
+
export function setSafeProperty(object, prop, value) {
|
|
34
|
+
if (isSafeObjectProperty(object, prop) || isSafeArrayProperty(object, prop)) {
|
|
35
35
|
object[prop] = value;
|
|
36
36
|
return value;
|
|
37
37
|
}
|
|
38
|
-
throw new Error(
|
|
38
|
+
throw new Error("No access to property \"".concat(prop, "\""));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* Test whether a property is safe
|
|
43
|
-
* For example .
|
|
44
|
-
* @param {Object
|
|
42
|
+
* Test whether a property is safe for reading and writing on an object
|
|
43
|
+
* For example .constructor and .__proto__ are not safe
|
|
44
|
+
* @param {Object} object
|
|
45
45
|
* @param {string} prop
|
|
46
46
|
* @return {boolean} Returns true when safe
|
|
47
47
|
*/
|
|
48
|
-
function
|
|
49
|
-
if (!isPlainObject(object)
|
|
48
|
+
export function isSafeObjectProperty(object, prop) {
|
|
49
|
+
if (!isPlainObject(object)) {
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
// UNSAFE: inherited from Function prototype
|
|
66
|
-
// e.g call, apply
|
|
67
|
-
if (prop in Function.prototype) {
|
|
68
|
-
// 'in' is used instead of hasOwnProperty for nodejs v0.10
|
|
69
|
-
// which is inconsistent on root prototypes. It is safe
|
|
70
|
-
// here because Function.prototype is a root object
|
|
52
|
+
return !(prop in Object.prototype);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Test whether a property is safe for reading and writing on an Array
|
|
57
|
+
* For example .__proto__ and .constructor are not safe
|
|
58
|
+
* @param {unknown} array
|
|
59
|
+
* @param {string | number} prop
|
|
60
|
+
* @return {boolean} Returns true when safe
|
|
61
|
+
*/
|
|
62
|
+
export function isSafeArrayProperty(array, prop) {
|
|
63
|
+
if (!Array.isArray(array)) {
|
|
71
64
|
return false;
|
|
72
65
|
}
|
|
73
|
-
return
|
|
66
|
+
return typeof prop === 'number' || typeof prop === 'string' && isInteger(prop) || prop === 'length';
|
|
67
|
+
}
|
|
68
|
+
function isInteger(prop) {
|
|
69
|
+
return /^\d+$/.test(prop);
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
/**
|
|
@@ -80,7 +76,7 @@ function isSafeProperty(object, prop) {
|
|
|
80
76
|
* @param {string} method
|
|
81
77
|
* @return {function} Returns the method when valid
|
|
82
78
|
*/
|
|
83
|
-
function getSafeMethod(object, method) {
|
|
79
|
+
export function getSafeMethod(object, method) {
|
|
84
80
|
if (!isSafeMethod(object, method)) {
|
|
85
81
|
throw new Error('No access to method "' + method + '"');
|
|
86
82
|
}
|
|
@@ -94,21 +90,24 @@ function getSafeMethod(object, method) {
|
|
|
94
90
|
* @param {string} method
|
|
95
91
|
* @return {boolean} Returns true when safe, false otherwise
|
|
96
92
|
*/
|
|
97
|
-
function isSafeMethod(object, method) {
|
|
93
|
+
export function isSafeMethod(object, method) {
|
|
98
94
|
if (object === null || object === undefined || typeof object[method] !== 'function') {
|
|
99
95
|
return false;
|
|
100
96
|
}
|
|
97
|
+
|
|
101
98
|
// UNSAFE: ghosted
|
|
102
99
|
// e.g overridden toString
|
|
103
100
|
// Note that IE10 doesn't support __proto__ and we can't do this check there.
|
|
104
101
|
if (hasOwnProperty(object, method) && Object.getPrototypeOf && method in Object.getPrototypeOf(object)) {
|
|
105
102
|
return false;
|
|
106
103
|
}
|
|
104
|
+
|
|
107
105
|
// SAFE: whitelisted
|
|
108
106
|
// e.g toString
|
|
109
|
-
if (
|
|
107
|
+
if (safeNativeMethods.has(method)) {
|
|
110
108
|
return true;
|
|
111
109
|
}
|
|
110
|
+
|
|
112
111
|
// UNSAFE: inherited from Object prototype
|
|
113
112
|
// e.g constructor
|
|
114
113
|
if (method in Object.prototype) {
|
|
@@ -117,6 +116,7 @@ function isSafeMethod(object, method) {
|
|
|
117
116
|
// here because Object.prototype is a root object
|
|
118
117
|
return false;
|
|
119
118
|
}
|
|
119
|
+
|
|
120
120
|
// UNSAFE: inherited from Function prototype
|
|
121
121
|
// e.g call, apply
|
|
122
122
|
if (method in Function.prototype) {
|
|
@@ -127,21 +127,7 @@ function isSafeMethod(object, method) {
|
|
|
127
127
|
}
|
|
128
128
|
return true;
|
|
129
129
|
}
|
|
130
|
-
function isPlainObject(object) {
|
|
130
|
+
export function isPlainObject(object) {
|
|
131
131
|
return typeof object === 'object' && object && object.constructor === Object;
|
|
132
132
|
}
|
|
133
|
-
var
|
|
134
|
-
length: true,
|
|
135
|
-
name: true
|
|
136
|
-
};
|
|
137
|
-
var safeNativeMethods = {
|
|
138
|
-
toString: true,
|
|
139
|
-
valueOf: true,
|
|
140
|
-
toLocaleString: true
|
|
141
|
-
};
|
|
142
|
-
export { getSafeProperty };
|
|
143
|
-
export { setSafeProperty };
|
|
144
|
-
export { isSafeProperty };
|
|
145
|
-
export { getSafeMethod };
|
|
146
|
-
export { isSafeMethod };
|
|
147
|
-
export { isPlainObject };
|
|
133
|
+
var safeNativeMethods = new Set(['toString', 'valueOf', 'toLocaleString']);
|
package/lib/esm/utils/map.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSafeProperty,
|
|
1
|
+
import { getSafeProperty, isSafeObjectProperty, setSafeProperty } from './customs.js';
|
|
2
2
|
import { isMap, isObject } from './is.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -25,7 +25,7 @@ export class ObjectWrappingMap {
|
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
27
|
has(key) {
|
|
28
|
-
return
|
|
28
|
+
return isSafeObjectProperty(this.wrappedObject, key) && key in this.wrappedObject;
|
|
29
29
|
}
|
|
30
30
|
entries() {
|
|
31
31
|
return mapIterator(this.keys(), key => [key, this.get(key)]);
|
|
@@ -36,7 +36,7 @@ export class ObjectWrappingMap {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
delete(key) {
|
|
39
|
-
if (
|
|
39
|
+
if (isSafeObjectProperty(this.wrappedObject, key)) {
|
|
40
40
|
delete this.wrappedObject[key];
|
|
41
41
|
}
|
|
42
42
|
}
|
package/lib/esm/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mathjs",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.2.0",
|
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
|
6
6
|
"homepage": "https://mathjs.org",
|
|
@@ -36,23 +36,23 @@
|
|
|
36
36
|
"typed-function": "^4.2.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@babel/core": "7.
|
|
39
|
+
"@babel/core": "7.29.0",
|
|
40
40
|
"@babel/plugin-transform-object-assign": "7.27.1",
|
|
41
|
-
"@babel/plugin-transform-optional-catch-binding": "7.
|
|
42
|
-
"@babel/plugin-transform-runtime": "7.
|
|
43
|
-
"@babel/preset-env": "7.
|
|
44
|
-
"@babel/register": "7.28.
|
|
41
|
+
"@babel/plugin-transform-optional-catch-binding": "7.28.6",
|
|
42
|
+
"@babel/plugin-transform-runtime": "7.29.0",
|
|
43
|
+
"@babel/preset-env": "7.29.0",
|
|
44
|
+
"@babel/register": "7.28.6",
|
|
45
45
|
"@types/assert": "1.5.11",
|
|
46
46
|
"@types/mocha": "10.0.10",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
48
|
-
"@typescript-eslint/parser": "8.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "8.55.0",
|
|
48
|
+
"@typescript-eslint/parser": "8.55.0",
|
|
49
49
|
"assert": "2.1.0",
|
|
50
50
|
"babel-loader": "10.0.0",
|
|
51
51
|
"c8": "10.1.3",
|
|
52
52
|
"codecov": "3.8.3",
|
|
53
53
|
"del": "8.0.1",
|
|
54
54
|
"eigen": "0.2.2",
|
|
55
|
-
"es-check": "9.
|
|
55
|
+
"es-check": "9.5.4",
|
|
56
56
|
"eslint": "8.57.1",
|
|
57
57
|
"eslint-config-prettier": "9.1.0",
|
|
58
58
|
"eslint-config-standard": "17.1.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"eslint-plugin-n": "16.6.2",
|
|
62
62
|
"eslint-plugin-prettier": "5.5.4",
|
|
63
63
|
"eslint-plugin-promise": "6.6.0",
|
|
64
|
-
"expect-type": "1.
|
|
64
|
+
"expect-type": "1.3.0",
|
|
65
65
|
"expr-eval": "2.0.2",
|
|
66
66
|
"fancy-log": "2.0.0",
|
|
67
67
|
"glob": "11.0.3",
|
|
@@ -85,14 +85,14 @@
|
|
|
85
85
|
"ndarray-ops": "1.2.2",
|
|
86
86
|
"ndarray-pack": "1.2.1",
|
|
87
87
|
"numericjs": "1.2.6",
|
|
88
|
-
"prettier": "3.
|
|
88
|
+
"prettier": "3.8.1",
|
|
89
89
|
"process": "0.11.10",
|
|
90
|
-
"sinon": "21.0.
|
|
90
|
+
"sinon": "21.0.1",
|
|
91
91
|
"sylvester": "0.0.21",
|
|
92
|
-
"tinybench": "
|
|
92
|
+
"tinybench": "6.0.0",
|
|
93
93
|
"ts-node": "10.9.2",
|
|
94
94
|
"typescript": "5.9.3",
|
|
95
|
-
"webpack": "5.
|
|
95
|
+
"webpack": "5.105.0",
|
|
96
96
|
"zeros": "1.0.0"
|
|
97
97
|
},
|
|
98
98
|
"type": "module",
|