mathjs 11.0.1 → 11.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CONTRIBUTING.md +1 -4
- package/HISTORY.md +26 -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/core/create.js +1 -0
- package/lib/cjs/core/function/typed.js +3 -0
- package/lib/cjs/entry/typeChecks.js +6 -0
- 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/utils/is.js +5 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/create.js +2 -1
- package/lib/esm/core/function/typed.js +4 -1
- package/lib/esm/entry/typeChecks.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/utils/is.js +3 -0
- package/lib/esm/version.js +1 -1
- package/package.json +17 -18
- package/types/index.d.ts +26 -16
- package/types/index.ts +21 -0
- package/types/tsconfig.json +4 -1
package/lib/cjs/core/create.js
CHANGED
@@ -122,6 +122,7 @@ function create(factories, config) {
|
|
122
122
|
isOperatorNode: _is.isOperatorNode,
|
123
123
|
isParenthesisNode: _is.isParenthesisNode,
|
124
124
|
isRangeNode: _is.isRangeNode,
|
125
|
+
isRelationalNode: _is.isRelationalNode,
|
125
126
|
isSymbolNode: _is.isSymbolNode,
|
126
127
|
isChain: _is.isChain
|
127
128
|
}); // load config function and apply provided config
|
@@ -197,6 +197,9 @@ var createTyped = /* #__PURE__ */(0, _factory.factory)('typed', dependencies, fu
|
|
197
197
|
}, {
|
198
198
|
name: 'RangeNode',
|
199
199
|
test: _is.isRangeNode
|
200
|
+
}, {
|
201
|
+
name: 'RelationalNode',
|
202
|
+
test: _is.isRelationalNode
|
200
203
|
}, {
|
201
204
|
name: 'SymbolNode',
|
202
205
|
test: _is.isSymbolNode
|
@@ -195,6 +195,12 @@ Object.defineProperty(exports, "isRegExp", {
|
|
195
195
|
return _is.isRegExp;
|
196
196
|
}
|
197
197
|
});
|
198
|
+
Object.defineProperty(exports, "isRelationalNode", {
|
199
|
+
enumerable: true,
|
200
|
+
get: function get() {
|
201
|
+
return _is.isRelationalNode;
|
202
|
+
}
|
203
|
+
});
|
198
204
|
Object.defineProperty(exports, "isResultSet", {
|
199
205
|
enumerable: true,
|
200
206
|
get: function get() {
|
@@ -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.
|
10
|
-
* @date 2022-
|
9
|
+
* @version 11.2.1
|
10
|
+
* @date 2022-09-13
|
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/utils/is.js
CHANGED
@@ -37,6 +37,7 @@ exports.isParenthesisNode = isParenthesisNode;
|
|
37
37
|
exports.isRange = isRange;
|
38
38
|
exports.isRangeNode = isRangeNode;
|
39
39
|
exports.isRegExp = isRegExp;
|
40
|
+
exports.isRelationalNode = isRelationalNode;
|
40
41
|
exports.isResultSet = isResultSet;
|
41
42
|
exports.isSparseMatrix = isSparseMatrix;
|
42
43
|
exports.isString = isString;
|
@@ -237,6 +238,10 @@ function isRangeNode(x) {
|
|
237
238
|
return x && x.isRangeNode === true && x.constructor.prototype.isNode === true || false;
|
238
239
|
}
|
239
240
|
|
241
|
+
function isRelationalNode(x) {
|
242
|
+
return x && x.isRelationalNode === true && x.constructor.prototype.isNode === true || false;
|
243
|
+
}
|
244
|
+
|
240
245
|
function isSymbolNode(x) {
|
241
246
|
return x && x.isSymbolNode === true && x.constructor.prototype.isNode === true || false;
|
242
247
|
}
|
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.
|
7
|
+
var version = '11.2.1'; // 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;
|
package/lib/esm/core/create.js
CHANGED
@@ -5,7 +5,7 @@ import * as emitter from './../utils/emitter.js';
|
|
5
5
|
import { importFactory } from './function/import.js';
|
6
6
|
import { configFactory } from './function/config.js';
|
7
7
|
import { factory, isFactory } from '../utils/factory.js';
|
8
|
-
import { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRegExp, isResultSet, isSparseMatrix, isString, isSymbolNode, isUndefined, isUnit } from '../utils/is.js';
|
8
|
+
import { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRelationalNode, isRegExp, isResultSet, isSparseMatrix, isString, isSymbolNode, isUndefined, isUnit } from '../utils/is.js';
|
9
9
|
import { ArgumentsError } from '../error/ArgumentsError.js';
|
10
10
|
import { DimensionError } from '../error/DimensionError.js';
|
11
11
|
import { IndexError } from '../error/IndexError.js';
|
@@ -97,6 +97,7 @@ export function create(factories, config) {
|
|
97
97
|
isOperatorNode,
|
98
98
|
isParenthesisNode,
|
99
99
|
isRangeNode,
|
100
|
+
isRelationalNode,
|
100
101
|
isSymbolNode,
|
101
102
|
isChain
|
102
103
|
}); // load config function and apply provided config
|
@@ -35,7 +35,7 @@
|
|
35
35
|
* @param {Object<string, function>} signatures Object with one or multiple function signatures
|
36
36
|
* @returns {function} The created typed-function.
|
37
37
|
*/
|
38
|
-
import { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRegExp, isResultSet, isSparseMatrix, isString, isSymbolNode, isUndefined, isUnit } from '../../utils/is.js';
|
38
|
+
import { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRelationalNode, isRegExp, isResultSet, isSparseMatrix, isString, isSymbolNode, isUndefined, isUnit } from '../../utils/is.js';
|
39
39
|
import typedFunction from 'typed-function';
|
40
40
|
import { digits } from '../../utils/number.js';
|
41
41
|
import { factory } from '../../utils/factory.js';
|
@@ -183,6 +183,9 @@ export var createTyped = /* #__PURE__ */factory('typed', dependencies, function
|
|
183
183
|
}, {
|
184
184
|
name: 'RangeNode',
|
185
185
|
test: isRangeNode
|
186
|
+
}, {
|
187
|
+
name: 'RelationalNode',
|
188
|
+
test: isRelationalNode
|
186
189
|
}, {
|
187
190
|
name: 'SymbolNode',
|
188
191
|
test: isSymbolNode
|
@@ -1,2 +1,2 @@
|
|
1
1
|
// util functions
|
2
|
-
export { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isString, isUndefined, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRegExp, isResultSet, isSparseMatrix, isSymbolNode, isUnit } from '../utils/is.js';
|
2
|
+
export { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isString, isUndefined, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRelationalNode, isRegExp, isResultSet, isSparseMatrix, isSymbolNode, isUnit } from '../utils/is.js';
|
@@ -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/utils/is.js
CHANGED
@@ -149,6 +149,9 @@ export function isParenthesisNode(x) {
|
|
149
149
|
export function isRangeNode(x) {
|
150
150
|
return x && x.isRangeNode === true && x.constructor.prototype.isNode === true || false;
|
151
151
|
}
|
152
|
+
export function isRelationalNode(x) {
|
153
|
+
return x && x.isRelationalNode === true && x.constructor.prototype.isNode === true || false;
|
154
|
+
}
|
152
155
|
export function isSymbolNode(x) {
|
153
156
|
return x && x.isSymbolNode === true && x.constructor.prototype.isNode === true || false;
|
154
157
|
}
|
package/lib/esm/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export var version = '11.
|
1
|
+
export var version = '11.2.1'; // 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.
|
3
|
+
"version": "11.2.1",
|
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",
|
@@ -25,42 +25,42 @@
|
|
25
25
|
"unit"
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
|
-
"@babel/runtime": "^7.
|
28
|
+
"@babel/runtime": "^7.19.0",
|
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.
|
39
|
+
"@babel/core": "7.19.0",
|
40
40
|
"@babel/plugin-transform-object-assign": "7.18.6",
|
41
|
-
"@babel/plugin-transform-runtime": "7.18.
|
42
|
-
"@babel/preset-env": "7.
|
41
|
+
"@babel/plugin-transform-runtime": "7.18.10",
|
42
|
+
"@babel/preset-env": "7.19.0",
|
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.37.0",
|
47
|
+
"@typescript-eslint/parser": "5.37.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.25.1",
|
53
53
|
"del": "6.1.1",
|
54
54
|
"dtslint": "4.2.1",
|
55
|
-
"eslint": "8.
|
55
|
+
"eslint": "8.23.1",
|
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
|
-
"eslint-plugin-promise": "6.0.
|
63
|
-
"expect-type": "0.
|
62
|
+
"eslint-plugin-promise": "6.0.1",
|
63
|
+
"expect-type": "0.14.2",
|
64
64
|
"expr-eval": "2.0.2",
|
65
65
|
"fancy-log": "2.0.0",
|
66
66
|
"glob": "8.0.3",
|
@@ -90,8 +90,8 @@
|
|
90
90
|
"process": "0.11.10",
|
91
91
|
"sylvester": "0.0.21",
|
92
92
|
"ts-node": "10.9.1",
|
93
|
-
"typescript": "4.
|
94
|
-
"webpack": "5.
|
93
|
+
"typescript": "4.8.3",
|
94
|
+
"webpack": "5.74.0",
|
95
95
|
"zeros": "1.0.0"
|
96
96
|
},
|
97
97
|
"type": "module",
|
@@ -161,10 +161,9 @@
|
|
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
|
-
"prepare": "npm run build",
|
168
167
|
"update-authors": "node ./tools/update-authors.js"
|
169
168
|
},
|
170
169
|
"bin": {
|
package/types/index.d.ts
CHANGED
@@ -283,6 +283,7 @@ declare namespace math {
|
|
283
283
|
type OperatorNodeMap = {
|
284
284
|
xor: 'xor'
|
285
285
|
and: 'and'
|
286
|
+
or: 'or'
|
286
287
|
bitOr: '|'
|
287
288
|
bitXor: '^|'
|
288
289
|
bitAnd: '&'
|
@@ -291,6 +292,7 @@ declare namespace math {
|
|
291
292
|
smaller: '<'
|
292
293
|
larger: '>'
|
293
294
|
smallerEq: '<='
|
295
|
+
largerEq: '>='
|
294
296
|
leftShift: '<<'
|
295
297
|
rightArithShift: '>>'
|
296
298
|
rightLogShift: '>>>'
|
@@ -478,6 +480,12 @@ declare namespace math {
|
|
478
480
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
479
481
|
reviver(): (key: any, value: any) => any
|
480
482
|
|
483
|
+
/**
|
484
|
+
* Returns replacer function that can be used as replacer in JSON.stringify function.
|
485
|
+
*/
|
486
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
487
|
+
replacer(): (key: any, value: any) => any
|
488
|
+
|
481
489
|
/*************************************************************************
|
482
490
|
* Core functions
|
483
491
|
************************************************************************/
|
@@ -2195,11 +2203,9 @@ declare namespace math {
|
|
2195
2203
|
* undefined. Returns an array with the configured number of elements
|
2196
2204
|
* when number is > 1.
|
2197
2205
|
*/
|
2198
|
-
pickRandom(
|
2199
|
-
|
2200
|
-
|
2201
|
-
weights?: number[]
|
2202
|
-
): number | number[]
|
2206
|
+
pickRandom<T>(array: T[]): T
|
2207
|
+
pickRandom<T>(array: T[], number: number): T[]
|
2208
|
+
pickRandom<T>(array: T[], number: number, weights: number[]): T[]
|
2203
2209
|
|
2204
2210
|
/**
|
2205
2211
|
* Return a random number larger or equal to min and smaller than max
|
@@ -2570,9 +2576,9 @@ declare namespace math {
|
|
2570
2576
|
median(...args: MathType[]): any
|
2571
2577
|
|
2572
2578
|
/**
|
2573
|
-
* Compute the
|
2574
|
-
* a multi dimensional array, the
|
2575
|
-
* calculated. When dim is provided, the
|
2579
|
+
* Compute the minimum value of a matrix or a list of values. In case of
|
2580
|
+
* a multi dimensional array, the minimun of the flattened array will be
|
2581
|
+
* calculated. When dim is provided, the minimun over the selected
|
2576
2582
|
* dimension will be calculated. Parameter dim is zero-based.
|
2577
2583
|
* @param args A single matrix or or multiple scalar values
|
2578
2584
|
* @returns The minimum value
|
@@ -3152,6 +3158,8 @@ declare namespace math {
|
|
3152
3158
|
|
3153
3159
|
isRangeNode(x: unknown): x is RangeNode
|
3154
3160
|
|
3161
|
+
isRelationalNode(x: unknown): x is RelationalNode
|
3162
|
+
|
3155
3163
|
isSymbolNode(x: unknown): x is SymbolNode
|
3156
3164
|
|
3157
3165
|
isChain(x: unknown): x is MathJsChain<unknown>
|
@@ -5515,11 +5523,13 @@ declare namespace math {
|
|
5515
5523
|
* @param number An int or float
|
5516
5524
|
* @param weights An array of ints or floats
|
5517
5525
|
*/
|
5518
|
-
pickRandom(
|
5519
|
-
|
5520
|
-
|
5521
|
-
|
5522
|
-
|
5526
|
+
pickRandom<T>(this: MathJsChain<T[]>): MathJsChain<T>
|
5527
|
+
pickRandom<T>(this: MathJsChain<T[]>, number: number): MathJsChain<T[]>
|
5528
|
+
pickRandom<T>(
|
5529
|
+
this: MathJsChain<T[]>,
|
5530
|
+
number: number,
|
5531
|
+
weights: number[]
|
5532
|
+
): MathJsChain<T[]>
|
5523
5533
|
|
5524
5534
|
/**
|
5525
5535
|
* Return a random number larger or equal to min and smaller than max
|
@@ -5867,9 +5877,9 @@ declare namespace math {
|
|
5867
5877
|
median(this: MathJsChain<MathCollection>, dim?: number): MathJsChain<any>
|
5868
5878
|
|
5869
5879
|
/**
|
5870
|
-
* Compute the
|
5871
|
-
* a multi dimensional array, the
|
5872
|
-
* calculated. When dim is provided, the
|
5880
|
+
* Compute the minimum value of a matrix or a list of values. In case of
|
5881
|
+
* a multi dimensional array, the minimum of the flattened array will be
|
5882
|
+
* calculated. When dim is provided, the minimum over the selected
|
5873
5883
|
* dimension will be calculated. Parameter dim is zero-based.
|
5874
5884
|
* @param dim The minimum over the selected dimension
|
5875
5885
|
*/
|
package/types/index.ts
CHANGED
@@ -2076,6 +2076,7 @@ Factory Test
|
|
2076
2076
|
math.isOperatorNode,
|
2077
2077
|
math.isParenthesisNode,
|
2078
2078
|
math.isRangeNode,
|
2079
|
+
math.isRelationalNode,
|
2079
2080
|
math.isSymbolNode,
|
2080
2081
|
math.isChain,
|
2081
2082
|
]
|
@@ -2189,6 +2190,9 @@ Factory Test
|
|
2189
2190
|
if (math.isRangeNode(x)) {
|
2190
2191
|
expectTypeOf(x).toMatchTypeOf<RangeNode>()
|
2191
2192
|
}
|
2193
|
+
if (math.isRelationalNode(x)) {
|
2194
|
+
expectTypeOf(x).toMatchTypeOf<math.RelationalNode>()
|
2195
|
+
}
|
2192
2196
|
if (math.isSymbolNode(x)) {
|
2193
2197
|
expectTypeOf(x).toMatchTypeOf<SymbolNode>()
|
2194
2198
|
}
|
@@ -2242,3 +2246,20 @@ Resolve examples
|
|
2242
2246
|
).toMatchTypeOf<MathNode[]>()
|
2243
2247
|
expectTypeOf(math.resolve(math.matrix(['x', 'y']))).toMatchTypeOf<Matrix>()
|
2244
2248
|
}
|
2249
|
+
|
2250
|
+
/*
|
2251
|
+
Random examples
|
2252
|
+
*/
|
2253
|
+
{
|
2254
|
+
const math = create(all, {})
|
2255
|
+
expectTypeOf(math.pickRandom([1, 2, 3])).toMatchTypeOf<number>()
|
2256
|
+
expectTypeOf(math.pickRandom(['a', { b: 10 }, 42])).toMatchTypeOf<
|
2257
|
+
string | number | { b: number }
|
2258
|
+
>()
|
2259
|
+
expectTypeOf(math.pickRandom([1, 2, 3])).toMatchTypeOf<number>()
|
2260
|
+
expectTypeOf(math.pickRandom([1, 2, 3], 2)).toMatchTypeOf<number[]>()
|
2261
|
+
|
2262
|
+
expectTypeOf(math.chain([1, 2, 3]).pickRandom(2)).toMatchTypeOf<
|
2263
|
+
MathJsChain<number[]>
|
2264
|
+
>()
|
2265
|
+
}
|