mathjs 11.0.1 → 11.1.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 +10 -0
- 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/expression/embeddedDocs/construction/index.js +1 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/unit/Unit.js +30 -25
- package/lib/cjs/type/unit/function/unit.js +5 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/expression/embeddedDocs/construction/index.js +1 -1
- package/lib/esm/type/unit/Unit.js +25 -24
- package/lib/esm/type/unit/function/unit.js +5 -2
- package/lib/esm/version.js +1 -1
- package/package.json +13 -13
- package/types/index.d.ts +6 -0
- package/types/tsconfig.json +4 -1
@@ -9,7 +9,7 @@ var indexDocs = {
|
|
9
9
|
category: 'Construction',
|
10
10
|
syntax: ['[start]', '[start:end]', '[start:step:end]', '[start1, start 2, ...]', '[start1:end1, start2:end2, ...]', '[start1:step1:end1, start2:step2:end2, ...]'],
|
11
11
|
description: 'Create an index to get or replace a subset of a matrix',
|
12
|
-
examples: ['[
|
12
|
+
examples: ['[1, 2, 3]', 'A = [1, 2, 3; 4, 5, 6]', 'A[1, :]', 'A[1, 2] = 50', 'A[1:2, 1:2] = ones(2, 2)'],
|
13
13
|
seealso: ['bignumber', 'boolean', 'complex', 'matrix,', 'number', 'range', 'string', 'unit']
|
14
14
|
};
|
15
15
|
exports.indexDocs = indexDocs;
|
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 11.0
|
10
|
-
* @date 2022-
|
9
|
+
* @version 11.1.0
|
10
|
+
* @date 2022-08-23
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
|
@@ -9,10 +9,10 @@ exports.createUnitClass = void 0;
|
|
9
9
|
|
10
10
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
11
11
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13
|
-
|
14
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
13
|
|
14
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15
|
+
|
16
16
|
var _is = require("../../utils/is.js");
|
17
17
|
|
18
18
|
var _factory = require("../../utils/factory.js");
|
@@ -53,8 +53,8 @@ var createUnitClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
|
|
53
53
|
/**
|
54
54
|
* A unit can be constructed in the following ways:
|
55
55
|
*
|
56
|
-
* const a = new Unit(value,
|
57
|
-
* const b = new Unit(null,
|
56
|
+
* const a = new Unit(value, valuelessUnit)
|
57
|
+
* const b = new Unit(null, valuelessUnit)
|
58
58
|
* const c = Unit.parse(str)
|
59
59
|
*
|
60
60
|
* Example usage:
|
@@ -67,10 +67,10 @@ var createUnitClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
|
|
67
67
|
* @class Unit
|
68
68
|
* @constructor Unit
|
69
69
|
* @param {number | BigNumber | Fraction | Complex | boolean} [value] A value like 5.2
|
70
|
-
* @param {string}
|
70
|
+
* @param {string | Unit} valuelessUnit A unit without value. Can have prefix, like "cm"
|
71
71
|
*/
|
72
72
|
|
73
|
-
function Unit(value,
|
73
|
+
function Unit(value, valuelessUnit) {
|
74
74
|
if (!(this instanceof Unit)) {
|
75
75
|
throw new Error('Constructor must be called with the new operator');
|
76
76
|
}
|
@@ -79,31 +79,36 @@ var createUnitClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
|
|
79
79
|
throw new TypeError('First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined');
|
80
80
|
}
|
81
81
|
|
82
|
-
if (name !== undefined && (typeof name !== 'string' || name === '')) {
|
83
|
-
throw new TypeError('Second parameter in Unit constructor must be a string');
|
84
|
-
}
|
85
|
-
|
86
|
-
if (name !== undefined) {
|
87
|
-
var u = Unit.parse(name);
|
88
|
-
this.units = u.units;
|
89
|
-
this.dimensions = u.dimensions;
|
90
|
-
} else {
|
91
|
-
this.units = [];
|
92
|
-
this.dimensions = [];
|
93
|
-
|
94
|
-
for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
95
|
-
this.dimensions[i] = 0;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
this.value = value !== undefined && value !== null ? this._normalize(value) : null;
|
100
82
|
this.fixPrefix = false; // if true, function format will not search for the
|
101
83
|
// best prefix but leave it as initially provided.
|
102
84
|
// fixPrefix is set true by the method Unit.to
|
103
85
|
// The justification behind this is that if the constructor is explicitly called,
|
104
|
-
// the caller wishes the units to be returned exactly as
|
86
|
+
// the caller wishes the units to be returned exactly as supplied.
|
105
87
|
|
106
88
|
this.skipAutomaticSimplification = true;
|
89
|
+
|
90
|
+
if (valuelessUnit === undefined) {
|
91
|
+
this.units = [];
|
92
|
+
this.dimensions = BASE_DIMENSIONS.map(function (x) {
|
93
|
+
return 0;
|
94
|
+
});
|
95
|
+
} else if (typeof valuelessUnit === 'string') {
|
96
|
+
var u = Unit.parse(valuelessUnit);
|
97
|
+
this.units = u.units;
|
98
|
+
this.dimensions = u.dimensions;
|
99
|
+
} else if ((0, _is.isUnit)(valuelessUnit) && valuelessUnit.value === null) {
|
100
|
+
// clone from valuelessUnit
|
101
|
+
this.fixPrefix = valuelessUnit.fixPrefix;
|
102
|
+
this.skipAutomaticSimplification = valuelessUnit.skipAutomaticSimplification;
|
103
|
+
this.dimensions = valuelessUnit.dimensions.slice(0);
|
104
|
+
this.units = valuelessUnit.units.map(function (u) {
|
105
|
+
return (0, _extends2["default"])({}, u);
|
106
|
+
});
|
107
|
+
} else {
|
108
|
+
throw new TypeError('Second parameter in Unit constructor must be a string or valueless Unit');
|
109
|
+
}
|
110
|
+
|
111
|
+
this.value = this._normalize(value);
|
107
112
|
}
|
108
113
|
/**
|
109
114
|
* Attach type information
|
@@ -24,10 +24,13 @@ var createUnitFunction = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
24
24
|
* Syntax:
|
25
25
|
*
|
26
26
|
* math.unit(unit : string)
|
27
|
-
* math.unit(value : number,
|
27
|
+
* math.unit(value : number, valuelessUnit : Unit)
|
28
|
+
* math.unit(value : number, valuelessUnit : string)
|
28
29
|
*
|
29
30
|
* Examples:
|
30
31
|
*
|
32
|
+
* const kph = math.unit('km/h') // returns Unit km/h (valueless)
|
33
|
+
* const v = math.unit(25, kph) // returns Unit 25 km/h
|
31
34
|
* const a = math.unit(5, 'cm') // returns Unit 50 mm
|
32
35
|
* const b = math.unit('23 kg') // returns Unit 23 kg
|
33
36
|
* a.to('m') // returns Unit 0.05 m
|
@@ -52,7 +55,7 @@ var createUnitFunction = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
52
55
|
allowNoUnits: true
|
53
56
|
}); // a unit with value, like '5cm'
|
54
57
|
},
|
55
|
-
'number | BigNumber | Fraction | Complex, string': function
|
58
|
+
'number | BigNumber | Fraction | Complex, string | Unit': function numberBigNumberFractionComplexStringUnit(value, unit) {
|
56
59
|
return new Unit(value, unit);
|
57
60
|
},
|
58
61
|
'number | BigNumber | Fraction': function numberBigNumberFraction(value) {
|
package/lib/cjs/version.js
CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = '11.0
|
7
|
+
var version = '11.1.0'; // Note: This file is automatically generated when building math.js.
|
8
8
|
// Changes made in this file will be overwritten.
|
9
9
|
|
10
10
|
exports.version = version;
|
@@ -3,6 +3,6 @@ export var indexDocs = {
|
|
3
3
|
category: 'Construction',
|
4
4
|
syntax: ['[start]', '[start:end]', '[start:step:end]', '[start1, start 2, ...]', '[start1:end1, start2:end2, ...]', '[start1:step1:end1, start2:step2:end2, ...]'],
|
5
5
|
description: 'Create an index to get or replace a subset of a matrix',
|
6
|
-
examples: ['[
|
6
|
+
examples: ['[1, 2, 3]', 'A = [1, 2, 3; 4, 5, 6]', 'A[1, :]', 'A[1, 2] = 50', 'A[1:2, 1:2] = ones(2, 2)'],
|
7
7
|
seealso: ['bignumber', 'boolean', 'complex', 'matrix,', 'number', 'range', 'string', 'unit']
|
8
8
|
};
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
3
3
|
|
4
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
5
5
|
|
@@ -37,8 +37,8 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
37
37
|
/**
|
38
38
|
* A unit can be constructed in the following ways:
|
39
39
|
*
|
40
|
-
* const a = new Unit(value,
|
41
|
-
* const b = new Unit(null,
|
40
|
+
* const a = new Unit(value, valuelessUnit)
|
41
|
+
* const b = new Unit(null, valuelessUnit)
|
42
42
|
* const c = Unit.parse(str)
|
43
43
|
*
|
44
44
|
* Example usage:
|
@@ -51,10 +51,10 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
51
51
|
* @class Unit
|
52
52
|
* @constructor Unit
|
53
53
|
* @param {number | BigNumber | Fraction | Complex | boolean} [value] A value like 5.2
|
54
|
-
* @param {string}
|
54
|
+
* @param {string | Unit} valuelessUnit A unit without value. Can have prefix, like "cm"
|
55
55
|
*/
|
56
56
|
|
57
|
-
function Unit(value,
|
57
|
+
function Unit(value, valuelessUnit) {
|
58
58
|
if (!(this instanceof Unit)) {
|
59
59
|
throw new Error('Constructor must be called with the new operator');
|
60
60
|
}
|
@@ -63,31 +63,32 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
63
63
|
throw new TypeError('First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined');
|
64
64
|
}
|
65
65
|
|
66
|
-
if (name !== undefined && (typeof name !== 'string' || name === '')) {
|
67
|
-
throw new TypeError('Second parameter in Unit constructor must be a string');
|
68
|
-
}
|
69
|
-
|
70
|
-
if (name !== undefined) {
|
71
|
-
var u = Unit.parse(name);
|
72
|
-
this.units = u.units;
|
73
|
-
this.dimensions = u.dimensions;
|
74
|
-
} else {
|
75
|
-
this.units = [];
|
76
|
-
this.dimensions = [];
|
77
|
-
|
78
|
-
for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
79
|
-
this.dimensions[i] = 0;
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
|
-
this.value = value !== undefined && value !== null ? this._normalize(value) : null;
|
84
66
|
this.fixPrefix = false; // if true, function format will not search for the
|
85
67
|
// best prefix but leave it as initially provided.
|
86
68
|
// fixPrefix is set true by the method Unit.to
|
87
69
|
// The justification behind this is that if the constructor is explicitly called,
|
88
|
-
// the caller wishes the units to be returned exactly as
|
70
|
+
// the caller wishes the units to be returned exactly as supplied.
|
89
71
|
|
90
72
|
this.skipAutomaticSimplification = true;
|
73
|
+
|
74
|
+
if (valuelessUnit === undefined) {
|
75
|
+
this.units = [];
|
76
|
+
this.dimensions = BASE_DIMENSIONS.map(x => 0);
|
77
|
+
} else if (typeof valuelessUnit === 'string') {
|
78
|
+
var u = Unit.parse(valuelessUnit);
|
79
|
+
this.units = u.units;
|
80
|
+
this.dimensions = u.dimensions;
|
81
|
+
} else if (isUnit(valuelessUnit) && valuelessUnit.value === null) {
|
82
|
+
// clone from valuelessUnit
|
83
|
+
this.fixPrefix = valuelessUnit.fixPrefix;
|
84
|
+
this.skipAutomaticSimplification = valuelessUnit.skipAutomaticSimplification;
|
85
|
+
this.dimensions = valuelessUnit.dimensions.slice(0);
|
86
|
+
this.units = valuelessUnit.units.map(u => _extends({}, u));
|
87
|
+
} else {
|
88
|
+
throw new TypeError('Second parameter in Unit constructor must be a string or valueless Unit');
|
89
|
+
}
|
90
|
+
|
91
|
+
this.value = this._normalize(value);
|
91
92
|
}
|
92
93
|
/**
|
93
94
|
* Attach type information
|
@@ -17,10 +17,13 @@ export var createUnitFunction = /* #__PURE__ */factory(name, dependencies, _ref
|
|
17
17
|
* Syntax:
|
18
18
|
*
|
19
19
|
* math.unit(unit : string)
|
20
|
-
* math.unit(value : number,
|
20
|
+
* math.unit(value : number, valuelessUnit : Unit)
|
21
|
+
* math.unit(value : number, valuelessUnit : string)
|
21
22
|
*
|
22
23
|
* Examples:
|
23
24
|
*
|
25
|
+
* const kph = math.unit('km/h') // returns Unit km/h (valueless)
|
26
|
+
* const v = math.unit(25, kph) // returns Unit 25 km/h
|
24
27
|
* const a = math.unit(5, 'cm') // returns Unit 50 mm
|
25
28
|
* const b = math.unit('23 kg') // returns Unit 23 kg
|
26
29
|
* a.to('m') // returns Unit 0.05 m
|
@@ -45,7 +48,7 @@ export var createUnitFunction = /* #__PURE__ */factory(name, dependencies, _ref
|
|
45
48
|
allowNoUnits: true
|
46
49
|
}); // a unit with value, like '5cm'
|
47
50
|
},
|
48
|
-
'number | BigNumber | Fraction | Complex, string': function
|
51
|
+
'number | BigNumber | Fraction | Complex, string | Unit': function numberBigNumberFractionComplexStringUnit(value, unit) {
|
49
52
|
return new Unit(value, unit);
|
50
53
|
},
|
51
54
|
'number | BigNumber | Fraction': function numberBigNumberFraction(value) {
|
package/lib/esm/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export var version = '11.0
|
1
|
+
export var version = '11.1.0'; // Note: This file is automatically generated when building math.js.
|
2
2
|
// Changes made in this file will be overwritten.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "11.0
|
3
|
+
"version": "11.1.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",
|
@@ -27,37 +27,37 @@
|
|
27
27
|
"dependencies": {
|
28
28
|
"@babel/runtime": "^7.18.9",
|
29
29
|
"complex.js": "^2.1.1",
|
30
|
-
"decimal.js": "^10.
|
30
|
+
"decimal.js": "^10.4.0",
|
31
31
|
"escape-latex": "^1.2.0",
|
32
32
|
"fraction.js": "^4.2.0",
|
33
33
|
"javascript-natural-sort": "^0.7.1",
|
34
34
|
"seedrandom": "^3.0.5",
|
35
35
|
"tiny-emitter": "^2.1.0",
|
36
|
-
"typed-function": "^
|
36
|
+
"typed-function": "^4.1.0"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@babel/core": "7.18.
|
39
|
+
"@babel/core": "7.18.13",
|
40
40
|
"@babel/plugin-transform-object-assign": "7.18.6",
|
41
|
-
"@babel/plugin-transform-runtime": "7.18.
|
42
|
-
"@babel/preset-env": "7.18.
|
41
|
+
"@babel/plugin-transform-runtime": "7.18.10",
|
42
|
+
"@babel/preset-env": "7.18.10",
|
43
43
|
"@babel/register": "7.18.9",
|
44
44
|
"@types/assert": "1.5.6",
|
45
45
|
"@types/mocha": "9.1.1",
|
46
|
-
"@typescript-eslint/eslint-plugin": "5.
|
47
|
-
"@typescript-eslint/parser": "5.
|
46
|
+
"@typescript-eslint/eslint-plugin": "5.33.0",
|
47
|
+
"@typescript-eslint/parser": "5.34.0",
|
48
48
|
"assert": "2.0.0",
|
49
49
|
"babel-loader": "8.2.5",
|
50
50
|
"benchmark": "2.1.4",
|
51
51
|
"codecov": "3.8.3",
|
52
|
-
"core-js": "3.
|
52
|
+
"core-js": "3.24.1",
|
53
53
|
"del": "6.1.1",
|
54
54
|
"dtslint": "4.2.1",
|
55
|
-
"eslint": "8.
|
55
|
+
"eslint": "8.22.0",
|
56
56
|
"eslint-config-prettier": "8.5.0",
|
57
57
|
"eslint-config-standard": "17.0.0",
|
58
58
|
"eslint-plugin-import": "2.26.0",
|
59
59
|
"eslint-plugin-mocha": "10.1.0",
|
60
|
-
"eslint-plugin-n": "15.2.
|
60
|
+
"eslint-plugin-n": "15.2.5",
|
61
61
|
"eslint-plugin-prettier": "4.2.1",
|
62
62
|
"eslint-plugin-promise": "6.0.0",
|
63
63
|
"expect-type": "0.13.0",
|
@@ -91,7 +91,7 @@
|
|
91
91
|
"sylvester": "0.0.21",
|
92
92
|
"ts-node": "10.9.1",
|
93
93
|
"typescript": "4.7.4",
|
94
|
-
"webpack": "5.
|
94
|
+
"webpack": "5.74.0",
|
95
95
|
"zeros": "1.0.0"
|
96
96
|
},
|
97
97
|
"type": "module",
|
@@ -161,7 +161,7 @@
|
|
161
161
|
"test:all": "npm run test:src && npm run test:generated && npm run test:node && npm run test:types",
|
162
162
|
"test:browser": "karma start test/browser-test-config/local-karma.js",
|
163
163
|
"test:browserstack": "karma start test/browser-test-config/browserstack-karma.js",
|
164
|
-
"test:types": "cd types && node --loader ts-node/esm ./index.ts",
|
164
|
+
"test:types": "cd types && tsc -p ./tsconfig.json && node --loader ts-node/esm ./index.ts",
|
165
165
|
"coverage": "nyc --reporter=lcov --reporter=text-summary mocha test/unit-tests && echo \"\nDetailed coverage report is available at ./coverage/lcov-report/index.html\"",
|
166
166
|
"prepublishOnly": "npm run test:all && npm run lint",
|
167
167
|
"prepare": "npm run build",
|
package/types/index.d.ts
CHANGED
@@ -478,6 +478,12 @@ declare namespace math {
|
|
478
478
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
479
479
|
reviver(): (key: any, value: any) => any
|
480
480
|
|
481
|
+
/**
|
482
|
+
* Returns replacer function that can be used as replacer in JSON.stringify function.
|
483
|
+
*/
|
484
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
485
|
+
replacer(): (key: any, value: any) => any
|
486
|
+
|
481
487
|
/*************************************************************************
|
482
488
|
* Core functions
|
483
489
|
************************************************************************/
|