@danielsimonjr/mathts-expression 0.5.3 → 0.6.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.d.ts +1364 -0
- package/dist/index.js +49 -0
- package/package.json +59 -59
package/dist/index.js
CHANGED
|
@@ -7948,6 +7948,18 @@ var createNode = /* @__PURE__ */ factory(
|
|
|
7948
7948
|
}
|
|
7949
7949
|
}
|
|
7950
7950
|
}
|
|
7951
|
+
function dotEscape(s) {
|
|
7952
|
+
return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
|
|
7953
|
+
}
|
|
7954
|
+
function dotNodeLabel(node) {
|
|
7955
|
+
const t = node.type;
|
|
7956
|
+
if (isConstantNode(node))
|
|
7957
|
+
return `${t}: ${String(node.value)}`;
|
|
7958
|
+
if (isSymbolNode(node)) return `${t}: ${node.name}`;
|
|
7959
|
+
if (isOperatorNode(node)) return `${t}: ${node.op}`;
|
|
7960
|
+
if (isFunctionNode(node)) return `${t}: ${node.name}`;
|
|
7961
|
+
return t;
|
|
7962
|
+
}
|
|
7951
7963
|
class Node {
|
|
7952
7964
|
get type() {
|
|
7953
7965
|
return "Node";
|
|
@@ -8218,6 +8230,43 @@ var createNode = /* @__PURE__ */ factory(
|
|
|
8218
8230
|
}
|
|
8219
8231
|
return this._toTex(options);
|
|
8220
8232
|
}
|
|
8233
|
+
/**
|
|
8234
|
+
* Render this node as Markdown-embeddable math. Display (block) math by
|
|
8235
|
+
* default (`$$…$$`), inline (`$…$`) when `options.inline` is true. Thin
|
|
8236
|
+
* wrapper over toTex(); adds no failure mode beyond toTex's own.
|
|
8237
|
+
* @param {Object} [options]
|
|
8238
|
+
* @return {string}
|
|
8239
|
+
*/
|
|
8240
|
+
toMarkdown(options) {
|
|
8241
|
+
const tex = this.toTex(options);
|
|
8242
|
+
return options?.inline ? "$" + tex + "$" : "$$\n" + tex + "\n$$";
|
|
8243
|
+
}
|
|
8244
|
+
/**
|
|
8245
|
+
* Render the AST subtree rooted at this node as a Graphviz digraph: one
|
|
8246
|
+
* DOT node per AST node (label = node type + a value for leaves), with
|
|
8247
|
+
* parent→child edges. Never throws.
|
|
8248
|
+
* @param {Object} [options]
|
|
8249
|
+
* @return {string}
|
|
8250
|
+
*/
|
|
8251
|
+
toDOT(options) {
|
|
8252
|
+
const ids = /* @__PURE__ */ new Map();
|
|
8253
|
+
const nodes = [];
|
|
8254
|
+
const edges = [];
|
|
8255
|
+
let counter = 0;
|
|
8256
|
+
this.traverse((node, _path, parent) => {
|
|
8257
|
+
const id = "n" + counter++;
|
|
8258
|
+
ids.set(node, id);
|
|
8259
|
+
nodes.push(` ${id} [label="${dotEscape(dotNodeLabel(node))}"];`);
|
|
8260
|
+
if (parent) {
|
|
8261
|
+
const pid = ids.get(parent);
|
|
8262
|
+
if (pid) edges.push(` ${pid} -> ${id};`);
|
|
8263
|
+
}
|
|
8264
|
+
});
|
|
8265
|
+
const name47 = options?.name ?? "AST";
|
|
8266
|
+
return `digraph ${name47} {
|
|
8267
|
+
${nodes.concat(edges).join("\n")}
|
|
8268
|
+
}`;
|
|
8269
|
+
}
|
|
8221
8270
|
/**
|
|
8222
8271
|
* Render this node to a MathML fragment (the MathML analog of `toTex`).
|
|
8223
8272
|
* Like `toTex`, this returns the body — wrap it in a `<math>` element with
|
package/package.json
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@danielsimonjr/mathts-expression",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Expression parser and evaluator for MathTS",
|
|
5
|
-
"author": "Daniel Simon Jr.",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
|
-
"module": "./dist/index.js",
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist",
|
|
19
|
-
"README.md"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
23
|
-
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
24
|
-
"test": "vitest run",
|
|
25
|
-
"test:watch": "vitest",
|
|
26
|
-
"test:coverage": "vitest run --coverage",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"lint": "eslint src --ext .ts",
|
|
29
|
-
"lint:fix": "eslint src --ext .ts --fix",
|
|
30
|
-
"clean": "rm -rf dist",
|
|
31
|
-
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
32
|
-
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"@danielsimonjr/mathts-core": "^0.
|
|
35
|
-
"typed-function": "^4.0.0"
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@types/node": "^25.5.2",
|
|
39
|
-
"tsup": "^8.0.0",
|
|
40
|
-
"typescript": "^5.3.0",
|
|
41
|
-
"vitest": "^4.1.5"
|
|
42
|
-
},
|
|
43
|
-
"publishConfig": {
|
|
44
|
-
"access": "public"
|
|
45
|
-
},
|
|
46
|
-
"repository": {
|
|
47
|
-
"type": "git",
|
|
48
|
-
"url": "git+https://github.com/danielsimonjr/mathts.git",
|
|
49
|
-
"directory": "expression"
|
|
50
|
-
},
|
|
51
|
-
"keywords": [
|
|
52
|
-
"math",
|
|
53
|
-
"typescript",
|
|
54
|
-
"expression",
|
|
55
|
-
"parser",
|
|
56
|
-
"evaluator",
|
|
57
|
-
"compiler"
|
|
58
|
-
]
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@danielsimonjr/mathts-expression",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "Expression parser and evaluator for MathTS",
|
|
5
|
+
"author": "Daniel Simon Jr.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
23
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint src --ext .ts",
|
|
29
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@danielsimonjr/mathts-core": "^0.7.0",
|
|
35
|
+
"typed-function": "^4.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^25.5.2",
|
|
39
|
+
"tsup": "^8.0.0",
|
|
40
|
+
"typescript": "^5.3.0",
|
|
41
|
+
"vitest": "^4.1.5"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/danielsimonjr/mathts.git",
|
|
49
|
+
"directory": "expression"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"math",
|
|
53
|
+
"typescript",
|
|
54
|
+
"expression",
|
|
55
|
+
"parser",
|
|
56
|
+
"evaluator",
|
|
57
|
+
"compiler"
|
|
58
|
+
]
|
|
59
|
+
}
|