mathjs 10.6.0 → 10.6.3
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +21 -0
- package/lib/browser/math.js +6 -5
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +16 -16
- package/types/index.d.ts +67 -35
- package/types/index.ts +72 -4
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 10.6.
|
10
|
-
* @date 2022-
|
9
|
+
* @version 10.6.3
|
10
|
+
* @date 2022-06-24
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
|
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 = '10.6.
|
7
|
+
var version = '10.6.3'; // 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/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export var version = '10.6.
|
1
|
+
export var version = '10.6.3'; // 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": "10.6.
|
3
|
+
"version": "10.6.3",
|
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,7 +25,7 @@
|
|
25
25
|
"unit"
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
|
-
"@babel/runtime": "^7.
|
28
|
+
"@babel/runtime": "^7.18.3",
|
29
29
|
"complex.js": "^2.1.1",
|
30
30
|
"decimal.js": "^10.3.1",
|
31
31
|
"escape-latex": "^1.2.0",
|
@@ -36,28 +36,28 @@
|
|
36
36
|
"typed-function": "^2.1.0"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@babel/core": "7.
|
39
|
+
"@babel/core": "7.18.5",
|
40
40
|
"@babel/plugin-transform-object-assign": "7.16.7",
|
41
|
-
"@babel/plugin-transform-runtime": "7.
|
42
|
-
"@babel/preset-env": "7.
|
41
|
+
"@babel/plugin-transform-runtime": "7.18.5",
|
42
|
+
"@babel/preset-env": "7.18.2",
|
43
43
|
"@babel/register": "7.17.7",
|
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.29.0",
|
47
|
+
"@typescript-eslint/parser": "5.29.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.
|
53
|
-
"del": "6.
|
52
|
+
"core-js": "3.23.2",
|
53
|
+
"del": "6.1.1",
|
54
54
|
"dtslint": "4.2.1",
|
55
|
-
"eslint": "8.
|
55
|
+
"eslint": "8.18.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
|
-
"eslint-plugin-mocha": "10.0.
|
60
|
-
"eslint-plugin-n": "15.2.
|
59
|
+
"eslint-plugin-mocha": "10.0.5",
|
60
|
+
"eslint-plugin-n": "15.2.3",
|
61
61
|
"eslint-plugin-prettier": "4.0.0",
|
62
62
|
"eslint-plugin-promise": "6.0.0",
|
63
63
|
"expect-type": "0.13.0",
|
@@ -69,7 +69,7 @@
|
|
69
69
|
"handlebars": "4.7.7",
|
70
70
|
"istanbul": "0.4.5",
|
71
71
|
"jsep": "1.3.6",
|
72
|
-
"karma": "6.
|
72
|
+
"karma": "6.4.0",
|
73
73
|
"karma-browserstack-launcher": "1.6.0",
|
74
74
|
"karma-firefox-launcher": "2.1.2",
|
75
75
|
"karma-mocha": "2.0.1",
|
@@ -86,11 +86,11 @@
|
|
86
86
|
"numericjs": "1.2.6",
|
87
87
|
"nyc": "15.1.0",
|
88
88
|
"pad-right": "0.2.2",
|
89
|
-
"prettier": "2.
|
89
|
+
"prettier": "2.7.1",
|
90
90
|
"process": "0.11.10",
|
91
91
|
"sylvester": "0.0.21",
|
92
|
-
"ts-node": "10.
|
93
|
-
"typescript": "4.
|
92
|
+
"ts-node": "10.8.1",
|
93
|
+
"typescript": "4.7.4",
|
94
94
|
"webpack": "4.46.0",
|
95
95
|
"zeros": "1.0.0"
|
96
96
|
},
|
package/types/index.d.ts
CHANGED
@@ -276,32 +276,77 @@ declare namespace math {
|
|
276
276
|
new (properties: Record<string, MathNode>): ObjectNode
|
277
277
|
}
|
278
278
|
|
279
|
-
|
279
|
+
type OperatorNodeMap = {
|
280
|
+
xor: 'xor'
|
281
|
+
and: 'and'
|
282
|
+
bitOr: '|'
|
283
|
+
bitXor: '^|'
|
284
|
+
bitAnd: '&'
|
285
|
+
equal: '=='
|
286
|
+
unequal: '!='
|
287
|
+
smaller: '<'
|
288
|
+
larger: '>'
|
289
|
+
smallerEq: '<='
|
290
|
+
leftShift: '<<'
|
291
|
+
rightArithShift: '>>'
|
292
|
+
rightLogShift: '>>>'
|
293
|
+
to: 'to'
|
294
|
+
add: '+'
|
295
|
+
subtract: '-'
|
296
|
+
multiply: '*'
|
297
|
+
divide: '/'
|
298
|
+
dotMultiply: '.*'
|
299
|
+
dotDivide: './'
|
300
|
+
mod: 'mod'
|
301
|
+
unaryPlus: '+'
|
302
|
+
unaryMinus: '-'
|
303
|
+
bitNot: '~'
|
304
|
+
not: 'not'
|
305
|
+
pow: '^'
|
306
|
+
dotPow: '.^'
|
307
|
+
factorial: '!'
|
308
|
+
}
|
309
|
+
|
310
|
+
type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap]
|
311
|
+
type OperatorNodeFn = keyof OperatorNodeMap
|
312
|
+
|
313
|
+
interface OperatorNode<
|
314
|
+
TOp extends OperatorNodeMap[TFn] = never,
|
315
|
+
TFn extends OperatorNodeFn = never,
|
316
|
+
TArgs extends MathNode[] = MathNode[]
|
317
|
+
> extends MathNodeCommon {
|
280
318
|
type: 'OperatorNode'
|
281
319
|
isOperatorNode: true
|
282
|
-
op:
|
283
|
-
fn:
|
284
|
-
args:
|
320
|
+
op: TOp
|
321
|
+
fn: TFn
|
322
|
+
args: TArgs
|
285
323
|
implicit: boolean
|
286
324
|
isUnary(): boolean
|
287
325
|
isBinary(): boolean
|
288
326
|
}
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
327
|
+
|
328
|
+
interface OperatorNodeCtor extends MathNodeCommon {
|
329
|
+
new <
|
330
|
+
TOp extends OperatorNodeMap[TFn],
|
331
|
+
TFn extends OperatorNodeFn,
|
332
|
+
TArgs extends MathNode[]
|
333
|
+
>(
|
334
|
+
op: TOp,
|
335
|
+
fn: TFn,
|
336
|
+
args: TArgs,
|
294
337
|
implicit?: boolean
|
295
|
-
): OperatorNode
|
338
|
+
): OperatorNode<TOp, TFn, TArgs>
|
296
339
|
}
|
297
|
-
|
298
|
-
|
340
|
+
interface ParenthesisNode<TContent extends MathNode = MathNode>
|
341
|
+
extends MathNodeCommon {
|
299
342
|
type: 'ParenthesisNode'
|
300
343
|
isParenthesisNode: true
|
301
|
-
content:
|
344
|
+
content: TContent
|
302
345
|
}
|
303
346
|
interface ParenthesisNodeCtor {
|
304
|
-
new
|
347
|
+
new <TContent extends MathNode>(
|
348
|
+
content: TContent
|
349
|
+
): ParenthesisNode<TContent>
|
305
350
|
}
|
306
351
|
|
307
352
|
interface RangeNode extends MathNodeCommon {
|
@@ -345,7 +390,7 @@ declare namespace math {
|
|
345
390
|
| FunctionNode
|
346
391
|
| IndexNode
|
347
392
|
| ObjectNode
|
348
|
-
| OperatorNode
|
393
|
+
| OperatorNode<OperatorNodeOp, OperatorNodeFn>
|
349
394
|
| ParenthesisNode
|
350
395
|
| RangeNode
|
351
396
|
| RelationalNode
|
@@ -3095,7 +3140,9 @@ declare namespace math {
|
|
3095
3140
|
|
3096
3141
|
isObjectNode(x: unknown): x is ObjectNode
|
3097
3142
|
|
3098
|
-
isOperatorNode(
|
3143
|
+
isOperatorNode(
|
3144
|
+
x: unknown
|
3145
|
+
): x is OperatorNode<OperatorNodeOp, OperatorNodeFn>
|
3099
3146
|
|
3100
3147
|
isParenthesisNode(x: unknown): x is ParenthesisNode
|
3101
3148
|
|
@@ -3762,22 +3809,7 @@ declare namespace math {
|
|
3762
3809
|
interface MathNodeCommon {
|
3763
3810
|
isNode: true
|
3764
3811
|
comment: string
|
3765
|
-
type:
|
3766
|
-
| 'AccessorNode'
|
3767
|
-
| 'ArrayNode'
|
3768
|
-
| 'AssignmentNode'
|
3769
|
-
| 'BlockNode'
|
3770
|
-
| 'ConditionalNode'
|
3771
|
-
| 'ConstantNode'
|
3772
|
-
| 'FunctionAssignmentNode'
|
3773
|
-
| 'FunctionNode'
|
3774
|
-
| 'IndexNode'
|
3775
|
-
| 'ObjectNode'
|
3776
|
-
| 'OperatorNode'
|
3777
|
-
| 'ParenthesisNode'
|
3778
|
-
| 'RangeNode'
|
3779
|
-
| 'RelationalNode'
|
3780
|
-
| 'SymbolNode'
|
3812
|
+
type: string
|
3781
3813
|
|
3782
3814
|
isUpdateNode?: boolean
|
3783
3815
|
|
@@ -3901,9 +3933,9 @@ declare namespace math {
|
|
3901
3933
|
* transformed.toString(); // returns '(3 ^ 2) + (5 * 3)'
|
3902
3934
|
* ```
|
3903
3935
|
*/
|
3904
|
-
transform(
|
3905
|
-
callback: (node:
|
3906
|
-
):
|
3936
|
+
transform<TResult>(
|
3937
|
+
callback: (node: this, path: string, parent: MathNode) => TResult
|
3938
|
+
): TResult
|
3907
3939
|
|
3908
3940
|
/**
|
3909
3941
|
* `traverse(callback)`
|
package/types/index.ts
CHANGED
@@ -25,6 +25,10 @@ import {
|
|
25
25
|
MathNumericType,
|
26
26
|
ConstantNode,
|
27
27
|
OperatorNode,
|
28
|
+
OperatorNodeFn,
|
29
|
+
OperatorNodeOp,
|
30
|
+
SymbolNode,
|
31
|
+
ParenthesisNode,
|
28
32
|
} from 'mathjs'
|
29
33
|
import * as assert from 'assert'
|
30
34
|
import { expectTypeOf } from 'expect-type'
|
@@ -822,6 +826,17 @@ Complex numbers examples
|
|
822
826
|
}
|
823
827
|
}
|
824
828
|
|
829
|
+
/*
|
830
|
+
Parenthesis examples
|
831
|
+
*/
|
832
|
+
{
|
833
|
+
const math = create(all, {})
|
834
|
+
|
835
|
+
expectTypeOf(
|
836
|
+
new math.ParenthesisNode(new math.ConstantNode(3))
|
837
|
+
).toMatchTypeOf<ParenthesisNode<ConstantNode>>()
|
838
|
+
}
|
839
|
+
|
825
840
|
/*
|
826
841
|
Expressions examples
|
827
842
|
*/
|
@@ -921,6 +936,46 @@ Fractions examples
|
|
921
936
|
const _a = math.fraction('2/3')
|
922
937
|
}
|
923
938
|
|
939
|
+
/*
|
940
|
+
Transform examples
|
941
|
+
*/
|
942
|
+
{
|
943
|
+
const math = create(all, {})
|
944
|
+
{
|
945
|
+
const myTransform1 = (node: MathNode): OperatorNode<'+', 'add'> =>
|
946
|
+
new OperatorNode('+', 'add', [node, new ConstantNode(1)])
|
947
|
+
const myTransform2 = (
|
948
|
+
node: OperatorNode<'+', 'add'>
|
949
|
+
): OperatorNode<'-', 'subtract'> =>
|
950
|
+
new OperatorNode('-', 'subtract', [node, new ConstantNode(5)])
|
951
|
+
|
952
|
+
expectTypeOf(
|
953
|
+
math.parse('sqrt(3^2 + 4^2)').transform(myTransform1)
|
954
|
+
).toMatchTypeOf<OperatorNode<'+', 'add', MathNode[]>>()
|
955
|
+
|
956
|
+
assert.deepStrictEqual(
|
957
|
+
math.parse('sqrt(3^2 + 4^2)').transform(myTransform1).toString(),
|
958
|
+
'sqrt(3 ^ 2 + 4 ^ 2) + 1'
|
959
|
+
)
|
960
|
+
|
961
|
+
expectTypeOf(
|
962
|
+
math
|
963
|
+
.parse('sqrt(3^2 + 4^2)')
|
964
|
+
.transform(myTransform1)
|
965
|
+
.transform(myTransform2)
|
966
|
+
).toMatchTypeOf<OperatorNode<'-', 'subtract', MathNode[]>>()
|
967
|
+
|
968
|
+
assert.deepStrictEqual(
|
969
|
+
math
|
970
|
+
.parse('sqrt(3^2 + 4^2)')
|
971
|
+
.transform(myTransform1)
|
972
|
+
.transform(myTransform2)
|
973
|
+
.toString(),
|
974
|
+
'sqrt(3 ^ 2 + 4 ^ 2) + 1 - 5'
|
975
|
+
)
|
976
|
+
}
|
977
|
+
}
|
978
|
+
|
924
979
|
/*
|
925
980
|
Matrices examples
|
926
981
|
*/
|
@@ -1527,23 +1582,34 @@ Function round examples
|
|
1527
1582
|
*/
|
1528
1583
|
{
|
1529
1584
|
const math = create(all, {})
|
1585
|
+
expectTypeOf(
|
1586
|
+
new math.OperatorNode('/', 'divide', [
|
1587
|
+
new math.ConstantNode(3),
|
1588
|
+
new math.SymbolNode('x'),
|
1589
|
+
])
|
1590
|
+
).toMatchTypeOf<OperatorNode<'/', 'divide', (ConstantNode | SymbolNode)[]>>()
|
1591
|
+
|
1530
1592
|
expectTypeOf(new math.ConstantNode(1).clone()).toMatchTypeOf<ConstantNode>()
|
1531
1593
|
expectTypeOf(
|
1532
1594
|
new math.OperatorNode('*', 'multiply', [
|
1533
1595
|
new math.ConstantNode(3),
|
1534
1596
|
new math.SymbolNode('x'),
|
1535
1597
|
]).clone()
|
1536
|
-
).toMatchTypeOf<
|
1598
|
+
).toMatchTypeOf<
|
1599
|
+
OperatorNode<'*', 'multiply', (ConstantNode | SymbolNode)[]>
|
1600
|
+
>()
|
1537
1601
|
|
1538
1602
|
expectTypeOf(
|
1539
1603
|
new math.ConstantNode(1).cloneDeep()
|
1540
1604
|
).toMatchTypeOf<ConstantNode>()
|
1541
1605
|
expectTypeOf(
|
1542
|
-
new math.OperatorNode('
|
1606
|
+
new math.OperatorNode('+', 'unaryPlus', [
|
1543
1607
|
new math.ConstantNode(3),
|
1544
1608
|
new math.SymbolNode('x'),
|
1545
1609
|
]).cloneDeep()
|
1546
|
-
).toMatchTypeOf<
|
1610
|
+
).toMatchTypeOf<
|
1611
|
+
OperatorNode<'+', 'unaryPlus', (ConstantNode | SymbolNode)[]>
|
1612
|
+
>()
|
1547
1613
|
|
1548
1614
|
expectTypeOf(
|
1549
1615
|
math.clone(new math.ConstantNode(1))
|
@@ -1900,7 +1966,9 @@ Factory Test
|
|
1900
1966
|
expectTypeOf(x).toMatchTypeOf<math.ObjectNode>()
|
1901
1967
|
}
|
1902
1968
|
if (math.isOperatorNode(x)) {
|
1903
|
-
expectTypeOf(x).toMatchTypeOf<
|
1969
|
+
expectTypeOf(x).toMatchTypeOf<
|
1970
|
+
OperatorNode<OperatorNodeOp, OperatorNodeFn, MathNode[]>
|
1971
|
+
>()
|
1904
1972
|
}
|
1905
1973
|
if (math.isParenthesisNode(x)) {
|
1906
1974
|
expectTypeOf(x).toMatchTypeOf<math.ParenthesisNode>()
|