exprify 1.0.4 → 1.0.6
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/HISTORY.md +49 -0
- package/README.md +100 -180
- package/SECURITY.md +18 -0
- package/bin/cli.mjs +234 -0
- package/dist/exprify.cjs.cjs +3558 -1220
- package/dist/exprify.cjs.cjs.map +1 -1
- package/dist/exprify.esm.js +3558 -1220
- package/dist/exprify.esm.js.map +1 -1
- package/dist/exprify.js +3560 -1222
- package/dist/exprify.js.map +1 -1
- package/dist/exprify.min.js +2 -2
- package/dist/exprify.min.js.map +1 -1
- package/package.json +44 -17
- package/src/core/context.js +35 -27
- package/src/core/exprify.js +880 -0
- package/src/function/executor.js +29 -20
- package/src/function/internal.js +1150 -153
- package/src/function/registry.js +23 -16
- package/src/index.js +1 -1
- package/src/math/bignumber.js +31 -0
- package/src/math/fraction.js +112 -0
- package/src/math/operations.js +38 -24
- package/src/parser/astBuild.js +276 -214
- package/src/parser/evaluator.js +431 -171
- package/src/parser/tokenizer.js +179 -146
- package/src/utils/decimal.js +264 -0
- package/src/utils/globalUnits.js +43 -35
- package/src/utils/matrix.js +14 -14
- package/src/utils/store.js +69 -47
- package/src/variables/store.js +18 -15
- package/src/core/Exprify.js +0 -369
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exprify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A powerful math expression parser and evaluator with runtime data-type checking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/exprify.cjs.cjs",
|
|
@@ -16,21 +16,46 @@
|
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"exprify": "./bin/cli.mjs"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.0.0"
|
|
24
|
+
},
|
|
19
25
|
"overrides": {
|
|
26
|
+
"test-exclude": "^7.0.1",
|
|
20
27
|
"glob": "^13.0.6"
|
|
21
28
|
},
|
|
22
29
|
"scripts": {
|
|
23
30
|
"start": "node src/index.js",
|
|
24
|
-
"
|
|
31
|
+
"dev": "node --watch src/index.js",
|
|
32
|
+
"clean": "node tools/clean.js",
|
|
25
33
|
"build": "npm run clean && rollup -c",
|
|
26
|
-
"test": "node
|
|
27
|
-
"
|
|
34
|
+
"test": "node tools/test.js",
|
|
35
|
+
"test:coverage": "node tools/test.js --coverage",
|
|
36
|
+
"size": "size-limit",
|
|
37
|
+
"lint": "eslint src/ test/",
|
|
38
|
+
"lint:fix": "eslint --fix src/ test/",
|
|
39
|
+
"format": "prettier --write .",
|
|
40
|
+
"format:check": "prettier --check .",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"prepare": "husky"
|
|
28
43
|
},
|
|
29
44
|
"jest": {
|
|
30
45
|
"testMatch": [
|
|
31
46
|
"**/test/**/*.js"
|
|
32
47
|
]
|
|
33
48
|
},
|
|
49
|
+
"size-limit": [
|
|
50
|
+
{
|
|
51
|
+
"path": "dist/exprify.min.js",
|
|
52
|
+
"limit": "30 KB"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"path": "dist/exprify.esm.js",
|
|
56
|
+
"limit": "60 KB"
|
|
57
|
+
}
|
|
58
|
+
],
|
|
34
59
|
"keywords": [
|
|
35
60
|
"math",
|
|
36
61
|
"parser",
|
|
@@ -43,24 +68,26 @@
|
|
|
43
68
|
"license": "GPL-3.0",
|
|
44
69
|
"repository": {
|
|
45
70
|
"type": "git",
|
|
46
|
-
"url": "git+https://github.com/code-hemu/
|
|
71
|
+
"url": "git+https://github.com/code-hemu/exprify.git"
|
|
47
72
|
},
|
|
48
73
|
"bugs": {
|
|
49
|
-
"url": "https://github.com/code-hemu/
|
|
74
|
+
"url": "https://github.com/code-hemu/exprify/issues"
|
|
50
75
|
},
|
|
51
|
-
"homepage": "https://github.com/code-hemu/
|
|
76
|
+
"homepage": "https://github.com/code-hemu/exprify#readme",
|
|
52
77
|
"devDependencies": {
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@rollup/plugin-commonjs": "^23.0.0",
|
|
57
|
-
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
78
|
+
"@eslint/js": "^10.0.1",
|
|
79
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
80
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
58
81
|
"@rollup/plugin-terser": "^1.0.0",
|
|
59
|
-
"
|
|
82
|
+
"@size-limit/file": "^12.1.0",
|
|
83
|
+
"eslint": "^10.4.1",
|
|
84
|
+
"globals": "^17.6.0",
|
|
85
|
+
"husky": "^9.1.7",
|
|
60
86
|
"jest": "^30.4.2",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"rollup": "^
|
|
64
|
-
"
|
|
87
|
+
"lint-staged": "^17.0.7",
|
|
88
|
+
"prettier": "^3.8.4",
|
|
89
|
+
"rollup": "^4.0.0",
|
|
90
|
+
"size-limit": "^12.1.0",
|
|
91
|
+
"typescript": "^6.0.3"
|
|
65
92
|
}
|
|
66
93
|
}
|
package/src/core/context.js
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
export function createContext({ variables, functions, units, evaluate}) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export function createContext({ variables, functions, units, evaluate }) {
|
|
2
|
+
if (!variables) {
|
|
3
|
+
throw new Error('Variable store missing');
|
|
4
|
+
}
|
|
5
|
+
if (!functions) {
|
|
6
|
+
throw new Error('Function registry missing');
|
|
7
|
+
}
|
|
8
|
+
if (!units) {
|
|
9
|
+
throw new Error('Units list missing');
|
|
10
|
+
}
|
|
11
|
+
if (!evaluate) {
|
|
12
|
+
throw new Error('evaluate function missing');
|
|
13
|
+
}
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
return {
|
|
16
|
+
variables: variables,
|
|
17
|
+
functions: functions,
|
|
18
|
+
units: units,
|
|
19
|
+
evaluate,
|
|
20
|
+
|
|
21
|
+
withScope(scope = {}) {
|
|
22
|
+
const tempVars = {
|
|
23
|
+
...variables.all?.(),
|
|
24
|
+
...scope,
|
|
25
|
+
};
|
|
26
|
+
return createContext({
|
|
9
27
|
functions: functions,
|
|
10
|
-
units: units,
|
|
11
28
|
evaluate,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
get: (k) => tempVars[k],
|
|
23
|
-
set: (k, v) => (tempVars[k] = v),
|
|
24
|
-
all: () => tempVars
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
29
|
+
units,
|
|
30
|
+
variables: {
|
|
31
|
+
get: (/** @type {string | number} */ k) => tempVars[k],
|
|
32
|
+
set: (/** @type {string | number} */ k, /** @type {any} */ v) => (tempVars[k] = v),
|
|
33
|
+
all: () => tempVars,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|