1 | import { Decimal } from 'decimal.js'
|
2 |
|
3 | declare const math: math.MathJsStatic
|
4 | export as namespace math
|
5 | export = math
|
6 |
|
7 | type NoLiteralType<T> = T extends number
|
8 | ? number
|
9 | : T extends string
|
10 | ? string
|
11 | : T extends boolean
|
12 | ? boolean
|
13 | : T
|
14 |
|
15 | declare namespace math {
|
16 |
|
17 | type MathNumericType = number | BigNumber | Fraction | Complex
|
18 | type MathScalarType = MathNumericType | Unit
|
19 | type MathArray = MathNumericType[] | MathNumericType[][]
|
20 | type MathCollection = MathArray | Matrix
|
21 | type MathType = MathScalarType | MathCollection
|
22 | type MathExpression = string | string[] | MathCollection
|
23 |
|
24 |
|
25 | type FactoryFunction<T> = (scope: any) => T
|
26 |
|
27 |
|
28 | interface FactoryFunctionMap {
|
29 |
|
30 | [key: string]: FactoryFunction<any> | FactoryFunctionMap
|
31 | }
|
32 |
|
33 |
|
34 | interface ParseOptions {
|
35 |
|
36 | nodes?: Record<string, MathNode>
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | interface ParseFunction {
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | (expr: MathExpression, options?: ParseOptions): MathNode
|
81 |
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | (exprs: MathExpression[], options?: ParseOptions): MathNode[]
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | isAlpha(c: string, cPrev: string, cNext: string): boolean
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 | isValidLatinOrGreek(c: string): boolean
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | isValidMathSymbol(high: string, low: string): boolean
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | isWhitespace(c: string, nestingLevel: number): boolean
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | isDecimalMark(c: string, cNext: string): boolean
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 | isDigitDot(c: string): boolean
|
152 | |
153 |
|
154 |
|
155 |
|
156 |
|
157 | isDigit(c: string): boolean
|
158 | |
159 |
|
160 |
|
161 |
|
162 |
|
163 | isHexDigit(c: string): boolean
|
164 | }
|
165 |
|
166 | interface NodeCtor {
|
167 | new (): MathNode
|
168 | }
|
169 |
|
170 | interface AccessorNode<TObject extends MathNode = MathNode> extends MathNode {
|
171 | type: 'AccessorNode'
|
172 | isAccessorNode: true
|
173 | object: TObject
|
174 | index: IndexNode
|
175 | name: string
|
176 | }
|
177 | interface AccessorNodeCtor {
|
178 | new <TObject extends MathNode = MathNode>(
|
179 | object: TObject,
|
180 | index: IndexNode
|
181 | ): AccessorNode<TObject>
|
182 | }
|
183 |
|
184 | interface ArrayNode<TItems extends MathNode[] = MathNode[]> extends MathNode {
|
185 | type: 'ArrayNode'
|
186 | isArrayNode: true
|
187 | items: TItems
|
188 | }
|
189 | interface ArrayNodeCtor {
|
190 | new <TItems extends MathNode[] = MathNode[]>(
|
191 | items: MathNode[]
|
192 | ): ArrayNode<TItems>
|
193 | }
|
194 |
|
195 | interface AssignmentNode<TValue extends MathNode = MathNode>
|
196 | extends MathNode {
|
197 | type: 'AssignmentNode'
|
198 | isAssignmentNode: true
|
199 | object: SymbolNode | AccessorNode
|
200 | index: IndexNode | null
|
201 | value: TValue
|
202 | name: string
|
203 | }
|
204 | interface AssignmentNodeCtor {
|
205 | new <TValue extends MathNode = MathNode>(
|
206 | object: SymbolNode,
|
207 | value: TValue
|
208 | ): AssignmentNode<TValue>
|
209 | new <TValue extends MathNode = MathNode>(
|
210 | object: SymbolNode | AccessorNode,
|
211 | index: IndexNode,
|
212 | value: TValue
|
213 | ): AssignmentNode<TValue>
|
214 | }
|
215 |
|
216 | interface BlockNode<TNode extends MathNode = MathNode> extends MathNode {
|
217 | type: 'BlockNode'
|
218 | isBlockNode: true
|
219 | blocks: Array<{ node: TNode; visible: boolean }>
|
220 | }
|
221 | interface BlockNodeCtor {
|
222 | new <TNode extends MathNode = MathNode>(
|
223 | arr: Array<{ node: TNode } | { node: TNode; visible: boolean }>
|
224 | ): BlockNode
|
225 | }
|
226 |
|
227 | interface ConditionalNode<
|
228 | TCond extends MathNode = MathNode,
|
229 | TTrueNode extends MathNode = MathNode,
|
230 | TFalseNode extends MathNode = MathNode
|
231 | > extends MathNode {
|
232 | type: 'ConditionalNode'
|
233 | isConditionalNode: boolean
|
234 | condition: TCond
|
235 | trueExpr: TTrueNode
|
236 | falseExpr: TFalseNode
|
237 | }
|
238 | interface ConditionalNodeCtor {
|
239 | new <
|
240 | TCond extends MathNode = MathNode,
|
241 | TTrueNode extends MathNode = MathNode,
|
242 | TFalseNode extends MathNode = MathNode
|
243 | >(
|
244 | condition: TCond,
|
245 | trueExpr: TTrueNode,
|
246 | falseExpr: TFalseNode
|
247 | ): ConditionalNode
|
248 | }
|
249 |
|
250 | interface ConstantNode<TValue extends string | number = number>
|
251 | extends MathNode {
|
252 | type: 'ConstantNode'
|
253 | isConstantNode: true
|
254 |
|
255 | value: TValue
|
256 | }
|
257 |
|
258 | interface ConstantNodeCtor {
|
259 | new <TValue extends string | number = string>(
|
260 | value: TValue
|
261 | ): ConstantNode<TValue>
|
262 | }
|
263 |
|
264 | interface FunctionAssignmentNode<TExpr extends MathNode = MathNode>
|
265 | extends MathNode {
|
266 | type: 'FunctionAssignmentNode'
|
267 | isFunctionAssignmentNode: true
|
268 | name: string
|
269 | params: string[]
|
270 | expr: TExpr
|
271 | }
|
272 | interface FunctionAssignmentNodeCtor {
|
273 | new <TExpr extends MathNode = MathNode>(
|
274 | name: string,
|
275 | params: string[],
|
276 | expr: TExpr
|
277 | ): FunctionAssignmentNode<TExpr>
|
278 | }
|
279 |
|
280 | interface FunctionNode<
|
281 | TFn = SymbolNode,
|
282 | TArgs extends MathNode[] = MathNode[]
|
283 | > extends MathNode {
|
284 | type: 'FunctionNode'
|
285 | isFunctionNode: true
|
286 | fn: TFn
|
287 | args: TArgs
|
288 | }
|
289 | interface FunctionNodeCtor {
|
290 | new <TFn = SymbolNode, TArgs extends MathNode[] = MathNode[]>(
|
291 | fn: TFn,
|
292 | args: TArgs
|
293 | ): FunctionNode<TFn, TArgs>
|
294 |
|
295 | onUndefinedFunction: (name: string) => any
|
296 | }
|
297 |
|
298 | interface IndexNode<TDims extends MathNode[] = MathNode[]> extends MathNode {
|
299 | type: 'IndexNode'
|
300 | isIndexNode: true
|
301 | dimensions: TDims
|
302 | dotNotation: boolean
|
303 | }
|
304 | interface IndexNodeCtor {
|
305 | new <TDims extends MathNode[] = MathNode[]>(dimensions: TDims): IndexNode
|
306 | new <TDims extends MathNode[] = MathNode[]>(
|
307 | dimensions: TDims,
|
308 | dotNotation: boolean
|
309 | ): IndexNode<TDims>
|
310 | }
|
311 |
|
312 | interface ObjectNode<
|
313 | TProps extends Record<string, MathNode> = Record<string, MathNode>
|
314 | > extends MathNode {
|
315 | type: 'ObjectNode'
|
316 | isObjectNode: true
|
317 | properties: TProps
|
318 | }
|
319 | interface ObjectNodeCtor {
|
320 | new <TProps extends Record<string, MathNode> = Record<string, MathNode>>(
|
321 | properties: TProps
|
322 | ): ObjectNode<TProps>
|
323 | }
|
324 |
|
325 | type OperatorNodeMap = {
|
326 | xor: 'xor'
|
327 | and: 'and'
|
328 | or: 'or'
|
329 | bitOr: '|'
|
330 | bitXor: '^|'
|
331 | bitAnd: '&'
|
332 | equal: '=='
|
333 | unequal: '!='
|
334 | smaller: '<'
|
335 | larger: '>'
|
336 | smallerEq: '<='
|
337 | largerEq: '>='
|
338 | leftShift: '<<'
|
339 | rightArithShift: '>>'
|
340 | rightLogShift: '>>>'
|
341 | to: 'to'
|
342 | add: '+'
|
343 | subtract: '-'
|
344 | multiply: '*'
|
345 | divide: '/'
|
346 | dotMultiply: '.*'
|
347 | dotDivide: './'
|
348 | mod: 'mod'
|
349 | unaryPlus: '+'
|
350 | unaryMinus: '-'
|
351 | bitNot: '~'
|
352 | not: 'not'
|
353 | pow: '^'
|
354 | dotPow: '.^'
|
355 | factorial: '!'
|
356 | }
|
357 |
|
358 | type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap]
|
359 | type OperatorNodeFn = keyof OperatorNodeMap
|
360 |
|
361 | interface OperatorNode<
|
362 | TOp extends OperatorNodeMap[TFn] = never,
|
363 | TFn extends OperatorNodeFn = never,
|
364 | TArgs extends MathNode[] = MathNode[]
|
365 | > extends MathNode {
|
366 | type: 'OperatorNode'
|
367 | isOperatorNode: true
|
368 | op: TOp
|
369 | fn: TFn
|
370 | args: TArgs
|
371 | implicit: boolean
|
372 | isUnary(): boolean
|
373 | isBinary(): boolean
|
374 | }
|
375 |
|
376 | interface OperatorNodeCtor extends MathNode {
|
377 | new <
|
378 | TOp extends OperatorNodeMap[TFn],
|
379 | TFn extends OperatorNodeFn,
|
380 | TArgs extends MathNode[]
|
381 | >(
|
382 | op: TOp,
|
383 | fn: TFn,
|
384 | args: TArgs,
|
385 | implicit?: boolean
|
386 | ): OperatorNode<TOp, TFn, TArgs>
|
387 | }
|
388 | interface ParenthesisNode<TContent extends MathNode = MathNode>
|
389 | extends MathNode {
|
390 | type: 'ParenthesisNode'
|
391 | isParenthesisNode: true
|
392 | content: TContent
|
393 | }
|
394 | interface ParenthesisNodeCtor {
|
395 | new <TContent extends MathNode>(
|
396 | content: TContent
|
397 | ): ParenthesisNode<TContent>
|
398 | }
|
399 |
|
400 | interface RangeNode<
|
401 | TStart extends MathNode = MathNode,
|
402 | TEnd extends MathNode = MathNode,
|
403 | TStep extends MathNode = MathNode
|
404 | > extends MathNode {
|
405 | type: 'RangeNode'
|
406 | isRangeNode: true
|
407 | start: TStart
|
408 | end: TEnd
|
409 | step: TStep | null
|
410 | }
|
411 | interface RangeNodeCtor {
|
412 | new <
|
413 | TStart extends MathNode = MathNode,
|
414 | TEnd extends MathNode = MathNode,
|
415 | TStep extends MathNode = MathNode
|
416 | >(
|
417 | start: TStart,
|
418 | end: TEnd,
|
419 | step?: TStep
|
420 | ): RangeNode<TStart, TEnd, TStep>
|
421 | }
|
422 |
|
423 | interface RelationalNode<TParams extends MathNode[] = MathNode[]>
|
424 | extends MathNode {
|
425 | type: 'RelationalNode'
|
426 | isRelationalNode: true
|
427 | conditionals: string[]
|
428 | params: TParams
|
429 | }
|
430 | interface RelationalNodeCtor {
|
431 | new <TParams extends MathNode[] = MathNode[]>(
|
432 | conditionals: string[],
|
433 | params: TParams
|
434 | ): RelationalNode<TParams>
|
435 | }
|
436 |
|
437 | interface SymbolNode extends MathNode {
|
438 | type: 'SymbolNode'
|
439 | isSymbolNode: true
|
440 | name: string
|
441 | }
|
442 | interface SymbolNodeCtor {
|
443 | new (name: string): SymbolNode
|
444 |
|
445 | onUndefinedSymbol: (name: string) => any
|
446 | }
|
447 |
|
448 | |
449 |
|
450 |
|
451 | type MathNodeCommon = MathNode
|
452 |
|
453 | type MathJsFunctionName = keyof MathJsStatic
|
454 |
|
455 | interface LUDecomposition {
|
456 | L: MathCollection
|
457 | U: MathCollection
|
458 | p: number[]
|
459 | }
|
460 |
|
461 | interface SLUDecomposition extends LUDecomposition {
|
462 | q: number[]
|
463 | }
|
464 |
|
465 | interface QRDecomposition {
|
466 | Q: MathCollection
|
467 | R: MathCollection
|
468 | }
|
469 |
|
470 | interface SchurDecomposition {
|
471 | U: MathCollection
|
472 | T: MathCollection
|
473 | }
|
474 |
|
475 | interface FractionDefinition {
|
476 | a: number
|
477 | b: number
|
478 | }
|
479 |
|
480 | interface MathJsStatic extends FactoryDependencies {
|
481 | e: number
|
482 | pi: number
|
483 | i: number
|
484 | Infinity: number
|
485 | LN2: number
|
486 | LN10: number
|
487 | LOG2E: number
|
488 | LOG10E: number
|
489 | NaN: number
|
490 | phi: number
|
491 | SQRT1_2: number
|
492 | SQRT2: number
|
493 | tau: number
|
494 |
|
495 |
|
496 | Node: NodeCtor
|
497 | AccessorNode: AccessorNodeCtor
|
498 | ArrayNode: ArrayNodeCtor
|
499 | AssignmentNode: AssignmentNodeCtor
|
500 | BlockNode: BlockNodeCtor
|
501 | ConditionalNode: ConditionalNodeCtor
|
502 | ConstantNode: ConstantNodeCtor
|
503 | FunctionAssignmentNode: FunctionAssignmentNodeCtor
|
504 | FunctionNode: FunctionNodeCtor
|
505 | IndexNode: IndexNodeCtor
|
506 | ObjectNode: ObjectNodeCtor
|
507 | OperatorNode: OperatorNodeCtor
|
508 | ParenthesisNode: ParenthesisNodeCtor
|
509 | RangeNode: RangeNodeCtor
|
510 | RelationalNode: RelationalNodeCtor
|
511 | SymbolNode: SymbolNodeCtor
|
512 |
|
513 | Matrix: MatrixCtor
|
514 |
|
515 | |
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 | uninitialized: any
|
526 | version: string
|
527 |
|
528 | expression: MathNode
|
529 |
|
530 | |
531 |
|
532 |
|
533 |
|
534 | reviver(): (key: any, value: any) => any
|
535 |
|
536 | |
537 |
|
538 |
|
539 |
|
540 | replacer(): (key: any, value: any) => any
|
541 |
|
542 | |
543 |
|
544 |
|
545 |
|
546 | |
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
55 |