@nice2dev/ui-math 1.2.0 → 1.2.1
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/dist/index.cjs +5 -5
- package/dist/index.d.ts +28 -4
- package/dist/index.mjs +1149 -1071
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,12 @@ export declare class CalculatorService {
|
|
|
43
43
|
private variables;
|
|
44
44
|
private config;
|
|
45
45
|
constructor(config?: CalculatorConfig);
|
|
46
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Evaluate an expression — parsed by {@link ExpressionParser}, never run as code (until 1.2.0 a
|
|
48
|
+
* chain of regex replacements fed `new Function`: `asin` came out as `aMath.sin`, `ceil` lost
|
|
49
|
+
* its `e` to Euler's number, a result in exponent notation summed wrongly, and any text ran).
|
|
50
|
+
* `log` is base 10 like the key, `ln` natural; trig functions follow `angleUnit`.
|
|
51
|
+
*/
|
|
47
52
|
evaluate(expression: string): number;
|
|
48
53
|
/** Add to history */
|
|
49
54
|
addHistory(expression: string, result: string, mode: CalculatorMode): void;
|
|
@@ -119,21 +124,40 @@ export declare interface EquationTemplate {
|
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
127
|
+
* Expression parser for math expressions — no `eval`: the input is parsed into a tree and the
|
|
128
|
+
* tree is evaluated, so only numbers, the listed functions and the given variables exist.
|
|
129
|
+
* Supports: + - * / ^ (right-associative, above unary minus: `-2^2` = -4), parentheses, function
|
|
130
|
+
* calls, variables, numbers with an exponent (`1.5e-7`) and implicit multiplication (`2x`, `2pi`,
|
|
131
|
+
* `2(x+1)`). `×`, `÷`, `−`, `π` and `√` are read as `*`, `/`, `-`, `pi` and `sqrt`.
|
|
124
132
|
*/
|
|
125
133
|
export declare class ExpressionParser {
|
|
126
134
|
private pos;
|
|
127
135
|
private expr;
|
|
136
|
+
private readonly options;
|
|
137
|
+
constructor(options?: ExpressionParserOptions);
|
|
128
138
|
parse(expression: string): MathFunction;
|
|
129
139
|
private parseAddSub;
|
|
130
140
|
private parseMulDiv;
|
|
131
|
-
private parsePower;
|
|
132
141
|
private parseUnary;
|
|
142
|
+
private parsePower;
|
|
133
143
|
private parsePrimary;
|
|
144
|
+
/** A name from a table, honouring `ignoreCase`. */
|
|
145
|
+
private lookup;
|
|
134
146
|
private evaluate;
|
|
135
147
|
}
|
|
136
148
|
|
|
149
|
+
/** Options of {@link ExpressionParser}; every one is optional and off by default. */
|
|
150
|
+
export declare interface ExpressionParserOptions {
|
|
151
|
+
/** Functions by name, over the built-ins (e.g. `{ log: Math.log10 }` for a calculator). */
|
|
152
|
+
functions?: Record<string, (...args: number[]) => number>;
|
|
153
|
+
/** Constants by name, over `pi`, `e`, `phi`, `tau`. */
|
|
154
|
+
constants?: Record<string, number>;
|
|
155
|
+
/** Match function and constant names case-insensitively (`SIN`, `Pi`). */
|
|
156
|
+
ignoreCase?: boolean;
|
|
157
|
+
/** Throw on input left over after a whole expression, instead of ignoring it. */
|
|
158
|
+
strict?: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
137
161
|
export declare const FUNCTION_PRESETS: FunctionPreset[];
|
|
138
162
|
|
|
139
163
|
export declare interface FunctionPreset {
|