@cortex-js/compute-engine 0.25.0 → 0.26.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/dist/compute-engine.esm.js +27153 -25341
- package/dist/compute-engine.js +27124 -25300
- package/dist/compute-engine.min.esm.js +88 -23
- package/dist/compute-engine.min.js +88 -23
- package/dist/math-json.esm.js +42 -196
- package/dist/math-json.js +42 -196
- package/dist/math-json.min.esm.js +42 -196
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/ansi-codes.d.ts +30 -4
- package/dist/types/common/buffer.d.ts +9 -0
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +9 -0
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/styled-text.d.ts +28 -0
- package/dist/types/common/suggest.d.ts +1 -0
- package/dist/types/common/syntax-highlighter.d.ts +40 -0
- package/dist/types/common/terminal.d.ts +19 -0
- package/dist/types/common/type/parse.d.ts +4 -0
- package/dist/types/common/type/primitive.d.ts +8 -0
- package/dist/types/common/type/serialize.d.ts +2 -0
- package/dist/types/common/type/subtype.d.ts +6 -0
- package/dist/types/common/type/types.d.ts +249 -0
- package/dist/types/common/type/utils.d.ts +39 -0
- package/dist/types/common/utils.d.ts +2 -1
- package/dist/types/compute-engine/assume.d.ts +13 -13
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +71 -47
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +12 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +16 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +20 -0
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
- package/dist/types/compute-engine/boxed-expression/box.d.ts +13 -71
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +31 -13
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +66 -45
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +41 -37
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +13 -9
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +34 -66
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +63 -41
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +44 -27
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +6 -0
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -6
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +9 -0
- package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -4
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +5 -39
- package/dist/types/compute-engine/boxed-expression/order.d.ts +26 -14
- package/dist/types/compute-engine/{symbolic → boxed-expression}/polynomials.d.ts +11 -15
- package/dist/types/compute-engine/{symbolic → boxed-expression}/product.d.ts +18 -24
- package/dist/types/compute-engine/boxed-expression/public.d.ts +947 -656
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +6 -0
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
- package/dist/types/compute-engine/{solve.d.ts → boxed-expression/solve.d.ts} +5 -5
- package/dist/types/compute-engine/{symbolic → boxed-expression}/tensor-fields.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +22 -16
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -7
- package/dist/types/compute-engine/collection-utils.d.ts +24 -2
- package/dist/types/compute-engine/compile.d.ts +3 -3
- package/dist/types/compute-engine/compute-engine.d.ts +133 -165
- package/dist/types/compute-engine/cost-function.d.ts +11 -1
- package/dist/types/compute-engine/function-utils.d.ts +5 -5
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -30
- package/dist/types/compute-engine/latex-syntax/public.d.ts +22 -18
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -8
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +4 -2
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +24 -1
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -3
- package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
- package/dist/types/compute-engine/library/library.d.ts +2 -4
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +5 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +46 -40
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +59 -0
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +77 -0
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +58 -0
- package/dist/types/compute-engine/numeric-value/public.d.ts +110 -0
- package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
- package/dist/types/compute-engine/numerics/bignum.d.ts +12 -0
- package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
- package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +19 -0
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +4 -14
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +6 -9
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +9 -59
- package/dist/types/compute-engine/numerics/primes.d.ts +3 -3
- package/dist/types/compute-engine/numerics/rationals.d.ts +29 -13
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
- package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
- package/dist/types/compute-engine/public.d.ts +8 -4
- package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -2
- package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
- package/dist/types/compute-engine/{simplify-rules.d.ts → symbolic/simplify-rules.d.ts} +1 -1
- package/dist/types/compute-engine/{symbolic → tensor}/tensors.d.ts +3 -3
- package/dist/types/compute-engine.d.ts +4 -2
- package/dist/types/math-json/identifiers.d.ts +11 -0
- package/dist/types/math-json/{math-json-format.d.ts → types.d.ts} +4 -9
- package/dist/types/math-json/utils.d.ts +15 -23
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +11 -11
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -48
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +0 -40
- package/dist/types/compute-engine/domain-utils.d.ts +0 -19
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -17
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
- package/dist/types/compute-engine/library/domains.d.ts +0 -16
- package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
- package/dist/types/compute-engine/rules.d.ts +0 -20
- package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
- package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
- package/dist/types/compute-engine/symbolic/negate.d.ts +0 -11
- package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
package/dist/math-json.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 0.
|
|
1
|
+
/** Compute Engine 0.26.0 */
|
|
2
2
|
|
|
3
3
|
// src/math-json/utils.ts
|
|
4
4
|
function isSymbolObject(expr) {
|
|
@@ -10,229 +10,79 @@ function isStringObject(expr) {
|
|
|
10
10
|
function isFunctionObject(expr) {
|
|
11
11
|
return expr !== null && typeof expr === "object" && "fn" in expr;
|
|
12
12
|
}
|
|
13
|
-
function isDictionaryObject(expr) {
|
|
14
|
-
return expr !== null && typeof expr === "object" && "dict" in expr;
|
|
15
|
-
}
|
|
16
|
-
var recommendedScriptsRegex;
|
|
17
|
-
function isRecommendedScripts(text) {
|
|
18
|
-
if (!recommendedScriptsRegex) {
|
|
19
|
-
const recommendedScripts = [
|
|
20
|
-
"Zyyy",
|
|
21
|
-
"Zinh",
|
|
22
|
-
"Arab",
|
|
23
|
-
"Armn",
|
|
24
|
-
"Beng",
|
|
25
|
-
"Bopo",
|
|
26
|
-
"Cyrl",
|
|
27
|
-
"Deva",
|
|
28
|
-
"Ethi",
|
|
29
|
-
"Geor",
|
|
30
|
-
"Grek",
|
|
31
|
-
"Gujr",
|
|
32
|
-
"Guru",
|
|
33
|
-
"Hang",
|
|
34
|
-
"Hani",
|
|
35
|
-
"Hebr",
|
|
36
|
-
"Hira",
|
|
37
|
-
"Kana",
|
|
38
|
-
"Knda",
|
|
39
|
-
"Khmr",
|
|
40
|
-
"Laoo",
|
|
41
|
-
"Latn",
|
|
42
|
-
"Mlym",
|
|
43
|
-
"Mymr",
|
|
44
|
-
"Orya",
|
|
45
|
-
"Sinh",
|
|
46
|
-
"Taml",
|
|
47
|
-
"Telu",
|
|
48
|
-
"Thaa",
|
|
49
|
-
"Thai",
|
|
50
|
-
"Tibt"
|
|
51
|
-
];
|
|
52
|
-
const regexPattern = `^[${recommendedScripts.map((x) => `\\p{Script=${x}}`).join("")}]*$`;
|
|
53
|
-
recommendedScriptsRegex = new RegExp(regexPattern, "u");
|
|
54
|
-
}
|
|
55
|
-
return recommendedScriptsRegex.test(text);
|
|
56
|
-
}
|
|
57
|
-
function isValidIdentifier(s) {
|
|
58
|
-
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))
|
|
59
|
-
return true;
|
|
60
|
-
if (ONLY_EMOJIS.test(s))
|
|
61
|
-
return true;
|
|
62
|
-
if (!isRecommendedScripts(s))
|
|
63
|
-
return false;
|
|
64
|
-
return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
|
|
65
|
-
}
|
|
66
|
-
var VS16 = "\\u{FE0F}";
|
|
67
|
-
var KEYCAP = "\\u{20E3}";
|
|
68
|
-
var ZWJ = "\\u{200D}";
|
|
69
|
-
var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
|
|
70
|
-
var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
|
|
71
|
-
var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
|
|
72
|
-
var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
|
|
73
|
-
var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
|
|
74
|
-
var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
|
|
75
|
-
var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
|
|
76
|
-
var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
|
|
77
|
-
function validateIdentifier(s) {
|
|
78
|
-
if (typeof s !== "string")
|
|
79
|
-
return "not-a-string";
|
|
80
|
-
if (s === "")
|
|
81
|
-
return "empty-string";
|
|
82
|
-
if (s.normalize() !== s)
|
|
83
|
-
return "expected-nfc";
|
|
84
|
-
if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
|
|
85
|
-
return "unexpected-bidi-marker";
|
|
86
|
-
if (ONLY_EMOJIS.test(s))
|
|
87
|
-
return "valid";
|
|
88
|
-
if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
|
|
89
|
-
return "unexpected-mixed-emoji";
|
|
90
|
-
if (!isRecommendedScripts(s))
|
|
91
|
-
return "unexpected-script";
|
|
92
|
-
if (!isValidIdentifier(s)) {
|
|
93
|
-
if (!isValidIdentifier(s[0]))
|
|
94
|
-
return "invalid-first-char";
|
|
95
|
-
return "invalid-char";
|
|
96
|
-
}
|
|
97
|
-
return "valid";
|
|
98
|
-
}
|
|
99
13
|
function stringValue(expr) {
|
|
100
|
-
if (expr === null || expr === void 0)
|
|
101
|
-
|
|
102
|
-
if (typeof expr
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
return null;
|
|
106
|
-
if (expr.length < 2)
|
|
107
|
-
return null;
|
|
108
|
-
if (expr[0] !== "'" || expr[expr.length - 1] !== "'")
|
|
109
|
-
return null;
|
|
14
|
+
if (expr === null || expr === void 0) return null;
|
|
15
|
+
if (typeof expr === "object" && "str" in expr) return expr.str;
|
|
16
|
+
if (typeof expr !== "string") return null;
|
|
17
|
+
if (expr.length < 2) return null;
|
|
18
|
+
if (expr.at(0) !== "'" || expr.at(-1) !== "'") return null;
|
|
110
19
|
return expr.substring(1, expr.length - 1);
|
|
111
20
|
}
|
|
112
|
-
function
|
|
113
|
-
if (Array.isArray(expr))
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
return expr[0];
|
|
121
|
-
}
|
|
122
|
-
if (expr === null || expr === void 0)
|
|
123
|
-
return null;
|
|
124
|
-
if (isFunctionObject(expr))
|
|
125
|
-
return expr.fn[0];
|
|
126
|
-
return null;
|
|
21
|
+
function operator(expr) {
|
|
22
|
+
if (Array.isArray(expr)) return expr[0];
|
|
23
|
+
if (expr === null || expr === void 0) return "";
|
|
24
|
+
if (isFunctionObject(expr)) return expr.fn[0];
|
|
25
|
+
return "";
|
|
127
26
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
|
|
27
|
+
function operands(expr) {
|
|
28
|
+
if (Array.isArray(expr)) return expr.slice(1);
|
|
29
|
+
if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
|
|
30
|
+
return [];
|
|
131
31
|
}
|
|
132
|
-
function
|
|
133
|
-
if (Array.isArray(expr))
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return null;
|
|
137
|
-
if (isFunctionObject(expr))
|
|
138
|
-
return expr.fn.slice(1);
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
function op(expr, n) {
|
|
142
|
-
if (Array.isArray(expr))
|
|
143
|
-
return expr[n] ?? null;
|
|
144
|
-
if (expr === null || expr === void 0)
|
|
145
|
-
return null;
|
|
146
|
-
if (isFunctionObject(expr))
|
|
147
|
-
return expr.fn[n] ?? null;
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
function op1(expr) {
|
|
151
|
-
return op(expr, 1);
|
|
152
|
-
}
|
|
153
|
-
function op2(expr) {
|
|
154
|
-
return op(expr, 2);
|
|
32
|
+
function operand(expr, n) {
|
|
33
|
+
if (Array.isArray(expr)) return expr[n] ?? null;
|
|
34
|
+
if (expr === null || !isFunctionObject(expr)) return null;
|
|
35
|
+
return expr.fn[n] ?? null;
|
|
155
36
|
}
|
|
156
37
|
function nops(expr) {
|
|
157
|
-
if (expr === null || expr === void 0)
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
return Math.max(0, expr.length - 1);
|
|
161
|
-
if (isFunctionObject(expr))
|
|
162
|
-
return Math.max(0, expr.fn.length - 1);
|
|
38
|
+
if (expr === null || expr === void 0) return 0;
|
|
39
|
+
if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
|
|
40
|
+
if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
|
|
163
41
|
return 0;
|
|
164
42
|
}
|
|
165
43
|
function symbol(expr) {
|
|
166
44
|
if (typeof expr === "string") {
|
|
167
|
-
if (/^[+-]?[0-9\.]/.test(expr))
|
|
168
|
-
return null;
|
|
45
|
+
if (/^[+-]?[0-9\.]/.test(expr)) return null;
|
|
169
46
|
if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
|
|
170
47
|
return null;
|
|
171
48
|
return expr;
|
|
172
49
|
}
|
|
173
|
-
if (expr === null || expr === void 0)
|
|
174
|
-
return null;
|
|
50
|
+
if (expr === null || expr === void 0) return null;
|
|
175
51
|
const s = isSymbolObject(expr) ? expr.sym : expr;
|
|
176
|
-
if (typeof s !== "string")
|
|
177
|
-
return null;
|
|
52
|
+
if (typeof s !== "string") return null;
|
|
178
53
|
return s;
|
|
179
54
|
}
|
|
180
55
|
function keyValuePair(expr) {
|
|
181
|
-
const h =
|
|
56
|
+
const h = operator(expr);
|
|
182
57
|
if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return [key,
|
|
58
|
+
const [k, v] = operands(expr);
|
|
59
|
+
const key = stringValue(k);
|
|
60
|
+
if (!key) return null;
|
|
61
|
+
return [key, v ?? "Nothing"];
|
|
187
62
|
}
|
|
188
63
|
return null;
|
|
189
64
|
}
|
|
190
65
|
function dictionary(expr) {
|
|
191
|
-
if (expr === null)
|
|
192
|
-
return null;
|
|
193
|
-
if (typeof expr === "object" && "dict" in expr)
|
|
194
|
-
return expr.dict;
|
|
66
|
+
if (expr === null) return null;
|
|
195
67
|
const kv = keyValuePair(expr);
|
|
196
|
-
if (kv)
|
|
197
|
-
|
|
198
|
-
const h = head(expr);
|
|
68
|
+
if (kv) return { [kv[0]]: kv[1] };
|
|
69
|
+
const h = operator(expr);
|
|
199
70
|
if (h === "Dictionary") {
|
|
200
71
|
const result = {};
|
|
72
|
+
const ops = operands(expr);
|
|
201
73
|
for (let i = 1; i < nops(expr); i++) {
|
|
202
|
-
const kv2 = keyValuePair(
|
|
203
|
-
if (kv2)
|
|
204
|
-
result[kv2[0]] = kv2[1];
|
|
74
|
+
const kv2 = keyValuePair(ops[i]);
|
|
75
|
+
if (kv2) result[kv2[0]] = kv2[1];
|
|
205
76
|
}
|
|
206
77
|
return result;
|
|
207
78
|
}
|
|
208
79
|
return null;
|
|
209
80
|
}
|
|
210
|
-
function applyRecursively(expr, fn) {
|
|
211
|
-
const h = head(expr);
|
|
212
|
-
if (h !== null) {
|
|
213
|
-
return [
|
|
214
|
-
fn(h),
|
|
215
|
-
...(ops(expr) ?? []).map(fn)
|
|
216
|
-
];
|
|
217
|
-
}
|
|
218
|
-
const dict = dictionary(expr);
|
|
219
|
-
if (dict !== null) {
|
|
220
|
-
const keys = Object.keys(dict);
|
|
221
|
-
const result = {};
|
|
222
|
-
for (const key of keys)
|
|
223
|
-
result[key] = fn(dict[key]);
|
|
224
|
-
return { dict: result };
|
|
225
|
-
}
|
|
226
|
-
return fn(expr);
|
|
227
|
-
}
|
|
228
81
|
function mapArgs(expr, fn) {
|
|
229
82
|
let args = null;
|
|
230
|
-
if (Array.isArray(expr))
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
args = expr.fn;
|
|
234
|
-
if (args === null)
|
|
235
|
-
return [];
|
|
83
|
+
if (Array.isArray(expr)) args = expr;
|
|
84
|
+
if (isFunctionObject(expr)) args = expr.fn;
|
|
85
|
+
if (args === null) return [];
|
|
236
86
|
let i = 1;
|
|
237
87
|
const result = [];
|
|
238
88
|
while (i < args.length) {
|
|
@@ -243,20 +93,16 @@ function mapArgs(expr, fn) {
|
|
|
243
93
|
}
|
|
244
94
|
|
|
245
95
|
// src/math-json.ts
|
|
246
|
-
var version = "0.
|
|
96
|
+
var version = "0.26.0";
|
|
247
97
|
export {
|
|
248
|
-
applyRecursively,
|
|
249
98
|
dictionary as getDictionary,
|
|
250
99
|
stringValue as getStringValue,
|
|
251
|
-
head,
|
|
252
|
-
headName,
|
|
253
|
-
isDictionaryObject,
|
|
254
100
|
isFunctionObject,
|
|
255
101
|
isStringObject,
|
|
256
102
|
isSymbolObject,
|
|
257
103
|
mapArgs,
|
|
258
|
-
|
|
259
|
-
|
|
104
|
+
operand,
|
|
105
|
+
operator,
|
|
260
106
|
symbol,
|
|
261
107
|
version
|
|
262
108
|
};
|
package/dist/math-json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** MathJSON 0.
|
|
1
|
+
/** MathJSON 0.26.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
|
|
3
3
|
var MathJson = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -22,18 +22,14 @@ var MathJson = (() => {
|
|
|
22
22
|
// src/math-json.ts
|
|
23
23
|
var math_json_exports = {};
|
|
24
24
|
__export(math_json_exports, {
|
|
25
|
-
applyRecursively: () => applyRecursively,
|
|
26
25
|
getDictionary: () => dictionary,
|
|
27
26
|
getStringValue: () => stringValue,
|
|
28
|
-
head: () => head,
|
|
29
|
-
headName: () => headName,
|
|
30
|
-
isDictionaryObject: () => isDictionaryObject,
|
|
31
27
|
isFunctionObject: () => isFunctionObject,
|
|
32
28
|
isStringObject: () => isStringObject,
|
|
33
29
|
isSymbolObject: () => isSymbolObject,
|
|
34
30
|
mapArgs: () => mapArgs,
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
operand: () => operand,
|
|
32
|
+
operator: () => operator,
|
|
37
33
|
symbol: () => symbol,
|
|
38
34
|
version: () => version
|
|
39
35
|
});
|
|
@@ -48,229 +44,79 @@ var MathJson = (() => {
|
|
|
48
44
|
function isFunctionObject(expr) {
|
|
49
45
|
return expr !== null && typeof expr === "object" && "fn" in expr;
|
|
50
46
|
}
|
|
51
|
-
function isDictionaryObject(expr) {
|
|
52
|
-
return expr !== null && typeof expr === "object" && "dict" in expr;
|
|
53
|
-
}
|
|
54
|
-
var recommendedScriptsRegex;
|
|
55
|
-
function isRecommendedScripts(text) {
|
|
56
|
-
if (!recommendedScriptsRegex) {
|
|
57
|
-
const recommendedScripts = [
|
|
58
|
-
"Zyyy",
|
|
59
|
-
"Zinh",
|
|
60
|
-
"Arab",
|
|
61
|
-
"Armn",
|
|
62
|
-
"Beng",
|
|
63
|
-
"Bopo",
|
|
64
|
-
"Cyrl",
|
|
65
|
-
"Deva",
|
|
66
|
-
"Ethi",
|
|
67
|
-
"Geor",
|
|
68
|
-
"Grek",
|
|
69
|
-
"Gujr",
|
|
70
|
-
"Guru",
|
|
71
|
-
"Hang",
|
|
72
|
-
"Hani",
|
|
73
|
-
"Hebr",
|
|
74
|
-
"Hira",
|
|
75
|
-
"Kana",
|
|
76
|
-
"Knda",
|
|
77
|
-
"Khmr",
|
|
78
|
-
"Laoo",
|
|
79
|
-
"Latn",
|
|
80
|
-
"Mlym",
|
|
81
|
-
"Mymr",
|
|
82
|
-
"Orya",
|
|
83
|
-
"Sinh",
|
|
84
|
-
"Taml",
|
|
85
|
-
"Telu",
|
|
86
|
-
"Thaa",
|
|
87
|
-
"Thai",
|
|
88
|
-
"Tibt"
|
|
89
|
-
];
|
|
90
|
-
const regexPattern = `^[${recommendedScripts.map((x) => `\\p{Script=${x}}`).join("")}]*$`;
|
|
91
|
-
recommendedScriptsRegex = new RegExp(regexPattern, "u");
|
|
92
|
-
}
|
|
93
|
-
return recommendedScriptsRegex.test(text);
|
|
94
|
-
}
|
|
95
|
-
function isValidIdentifier(s) {
|
|
96
|
-
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))
|
|
97
|
-
return true;
|
|
98
|
-
if (ONLY_EMOJIS.test(s))
|
|
99
|
-
return true;
|
|
100
|
-
if (!isRecommendedScripts(s))
|
|
101
|
-
return false;
|
|
102
|
-
return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
|
|
103
|
-
}
|
|
104
|
-
var VS16 = "\\u{FE0F}";
|
|
105
|
-
var KEYCAP = "\\u{20E3}";
|
|
106
|
-
var ZWJ = "\\u{200D}";
|
|
107
|
-
var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
|
|
108
|
-
var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
|
|
109
|
-
var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
|
|
110
|
-
var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
|
|
111
|
-
var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
|
|
112
|
-
var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
|
|
113
|
-
var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
|
|
114
|
-
var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
|
|
115
|
-
function validateIdentifier(s) {
|
|
116
|
-
if (typeof s !== "string")
|
|
117
|
-
return "not-a-string";
|
|
118
|
-
if (s === "")
|
|
119
|
-
return "empty-string";
|
|
120
|
-
if (s.normalize() !== s)
|
|
121
|
-
return "expected-nfc";
|
|
122
|
-
if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
|
|
123
|
-
return "unexpected-bidi-marker";
|
|
124
|
-
if (ONLY_EMOJIS.test(s))
|
|
125
|
-
return "valid";
|
|
126
|
-
if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
|
|
127
|
-
return "unexpected-mixed-emoji";
|
|
128
|
-
if (!isRecommendedScripts(s))
|
|
129
|
-
return "unexpected-script";
|
|
130
|
-
if (!isValidIdentifier(s)) {
|
|
131
|
-
if (!isValidIdentifier(s[0]))
|
|
132
|
-
return "invalid-first-char";
|
|
133
|
-
return "invalid-char";
|
|
134
|
-
}
|
|
135
|
-
return "valid";
|
|
136
|
-
}
|
|
137
47
|
function stringValue(expr) {
|
|
138
|
-
if (expr === null || expr === void 0)
|
|
139
|
-
|
|
140
|
-
if (typeof expr
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
return null;
|
|
144
|
-
if (expr.length < 2)
|
|
145
|
-
return null;
|
|
146
|
-
if (expr[0] !== "'" || expr[expr.length - 1] !== "'")
|
|
147
|
-
return null;
|
|
48
|
+
if (expr === null || expr === void 0) return null;
|
|
49
|
+
if (typeof expr === "object" && "str" in expr) return expr.str;
|
|
50
|
+
if (typeof expr !== "string") return null;
|
|
51
|
+
if (expr.length < 2) return null;
|
|
52
|
+
if (expr.at(0) !== "'" || expr.at(-1) !== "'") return null;
|
|
148
53
|
return expr.substring(1, expr.length - 1);
|
|
149
54
|
}
|
|
150
|
-
function
|
|
151
|
-
if (Array.isArray(expr))
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
return expr[0];
|
|
159
|
-
}
|
|
160
|
-
if (expr === null || expr === void 0)
|
|
161
|
-
return null;
|
|
162
|
-
if (isFunctionObject(expr))
|
|
163
|
-
return expr.fn[0];
|
|
164
|
-
return null;
|
|
55
|
+
function operator(expr) {
|
|
56
|
+
if (Array.isArray(expr)) return expr[0];
|
|
57
|
+
if (expr === null || expr === void 0) return "";
|
|
58
|
+
if (isFunctionObject(expr)) return expr.fn[0];
|
|
59
|
+
return "";
|
|
165
60
|
}
|
|
166
|
-
function
|
|
167
|
-
|
|
168
|
-
|
|
61
|
+
function operands(expr) {
|
|
62
|
+
if (Array.isArray(expr)) return expr.slice(1);
|
|
63
|
+
if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
|
|
64
|
+
return [];
|
|
169
65
|
}
|
|
170
|
-
function
|
|
171
|
-
if (Array.isArray(expr))
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return null;
|
|
175
|
-
if (isFunctionObject(expr))
|
|
176
|
-
return expr.fn.slice(1);
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
function op(expr, n) {
|
|
180
|
-
if (Array.isArray(expr))
|
|
181
|
-
return expr[n] ?? null;
|
|
182
|
-
if (expr === null || expr === void 0)
|
|
183
|
-
return null;
|
|
184
|
-
if (isFunctionObject(expr))
|
|
185
|
-
return expr.fn[n] ?? null;
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
function op1(expr) {
|
|
189
|
-
return op(expr, 1);
|
|
190
|
-
}
|
|
191
|
-
function op2(expr) {
|
|
192
|
-
return op(expr, 2);
|
|
66
|
+
function operand(expr, n) {
|
|
67
|
+
if (Array.isArray(expr)) return expr[n] ?? null;
|
|
68
|
+
if (expr === null || !isFunctionObject(expr)) return null;
|
|
69
|
+
return expr.fn[n] ?? null;
|
|
193
70
|
}
|
|
194
71
|
function nops(expr) {
|
|
195
|
-
if (expr === null || expr === void 0)
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
return Math.max(0, expr.length - 1);
|
|
199
|
-
if (isFunctionObject(expr))
|
|
200
|
-
return Math.max(0, expr.fn.length - 1);
|
|
72
|
+
if (expr === null || expr === void 0) return 0;
|
|
73
|
+
if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
|
|
74
|
+
if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
|
|
201
75
|
return 0;
|
|
202
76
|
}
|
|
203
77
|
function symbol(expr) {
|
|
204
78
|
if (typeof expr === "string") {
|
|
205
|
-
if (/^[+-]?[0-9\.]/.test(expr))
|
|
206
|
-
return null;
|
|
79
|
+
if (/^[+-]?[0-9\.]/.test(expr)) return null;
|
|
207
80
|
if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
|
|
208
81
|
return null;
|
|
209
82
|
return expr;
|
|
210
83
|
}
|
|
211
|
-
if (expr === null || expr === void 0)
|
|
212
|
-
return null;
|
|
84
|
+
if (expr === null || expr === void 0) return null;
|
|
213
85
|
const s = isSymbolObject(expr) ? expr.sym : expr;
|
|
214
|
-
if (typeof s !== "string")
|
|
215
|
-
return null;
|
|
86
|
+
if (typeof s !== "string") return null;
|
|
216
87
|
return s;
|
|
217
88
|
}
|
|
218
89
|
function keyValuePair(expr) {
|
|
219
|
-
const h =
|
|
90
|
+
const h = operator(expr);
|
|
220
91
|
if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return [key,
|
|
92
|
+
const [k, v] = operands(expr);
|
|
93
|
+
const key = stringValue(k);
|
|
94
|
+
if (!key) return null;
|
|
95
|
+
return [key, v ?? "Nothing"];
|
|
225
96
|
}
|
|
226
97
|
return null;
|
|
227
98
|
}
|
|
228
99
|
function dictionary(expr) {
|
|
229
|
-
if (expr === null)
|
|
230
|
-
return null;
|
|
231
|
-
if (typeof expr === "object" && "dict" in expr)
|
|
232
|
-
return expr.dict;
|
|
100
|
+
if (expr === null) return null;
|
|
233
101
|
const kv = keyValuePair(expr);
|
|
234
|
-
if (kv)
|
|
235
|
-
|
|
236
|
-
const h = head(expr);
|
|
102
|
+
if (kv) return { [kv[0]]: kv[1] };
|
|
103
|
+
const h = operator(expr);
|
|
237
104
|
if (h === "Dictionary") {
|
|
238
105
|
const result = {};
|
|
106
|
+
const ops = operands(expr);
|
|
239
107
|
for (let i = 1; i < nops(expr); i++) {
|
|
240
|
-
const kv2 = keyValuePair(
|
|
241
|
-
if (kv2)
|
|
242
|
-
result[kv2[0]] = kv2[1];
|
|
108
|
+
const kv2 = keyValuePair(ops[i]);
|
|
109
|
+
if (kv2) result[kv2[0]] = kv2[1];
|
|
243
110
|
}
|
|
244
111
|
return result;
|
|
245
112
|
}
|
|
246
113
|
return null;
|
|
247
114
|
}
|
|
248
|
-
function applyRecursively(expr, fn) {
|
|
249
|
-
const h = head(expr);
|
|
250
|
-
if (h !== null) {
|
|
251
|
-
return [
|
|
252
|
-
fn(h),
|
|
253
|
-
...(ops(expr) ?? []).map(fn)
|
|
254
|
-
];
|
|
255
|
-
}
|
|
256
|
-
const dict = dictionary(expr);
|
|
257
|
-
if (dict !== null) {
|
|
258
|
-
const keys = Object.keys(dict);
|
|
259
|
-
const result = {};
|
|
260
|
-
for (const key of keys)
|
|
261
|
-
result[key] = fn(dict[key]);
|
|
262
|
-
return { dict: result };
|
|
263
|
-
}
|
|
264
|
-
return fn(expr);
|
|
265
|
-
}
|
|
266
115
|
function mapArgs(expr, fn) {
|
|
267
116
|
let args = null;
|
|
268
|
-
if (Array.isArray(expr))
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
args = expr.fn;
|
|
272
|
-
if (args === null)
|
|
273
|
-
return [];
|
|
117
|
+
if (Array.isArray(expr)) args = expr;
|
|
118
|
+
if (isFunctionObject(expr)) args = expr.fn;
|
|
119
|
+
if (args === null) return [];
|
|
274
120
|
let i = 1;
|
|
275
121
|
const result = [];
|
|
276
122
|
while (i < args.length) {
|
|
@@ -281,7 +127,7 @@ var MathJson = (() => {
|
|
|
281
127
|
}
|
|
282
128
|
|
|
283
129
|
// src/math-json.ts
|
|
284
|
-
var version = "0.
|
|
130
|
+
var version = "0.26.0";
|
|
285
131
|
return __toCommonJS(math_json_exports);
|
|
286
132
|
})();
|
|
287
133
|
Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
|