exprify 1.0.3 → 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/package.json CHANGED
@@ -1,27 +1,61 @@
1
1
  {
2
2
  "name": "exprify",
3
- "version": "1.0.3",
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
- "main": "dist/exprify.cjs.js",
6
+ "main": "dist/exprify.cjs.cjs",
7
7
  "module": "dist/exprify.esm.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/exprify.esm.js",
11
+ "require": "./dist/exprify.cjs.cjs"
12
+ }
13
+ },
8
14
  "browser": "dist/exprify.js",
9
15
  "unpkg": "dist/exprify.min.js",
10
16
  "publishConfig": {
11
17
  "access": "public"
12
18
  },
19
+ "bin": {
20
+ "exprify": "./bin/cli.mjs"
21
+ },
22
+ "engines": {
23
+ "node": ">=18.0.0"
24
+ },
25
+ "overrides": {
26
+ "test-exclude": "^7.0.1",
27
+ "glob": "^13.0.6"
28
+ },
13
29
  "scripts": {
14
30
  "start": "node src/index.js",
15
- "clean": "rimraf dist",
31
+ "dev": "node --watch src/index.js",
32
+ "clean": "node tools/clean.js",
16
33
  "build": "npm run clean && rollup -c",
17
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
18
- "dev": "nodemon src/index.js"
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"
19
43
  },
20
44
  "jest": {
21
45
  "testMatch": [
22
46
  "**/test/**/*.js"
23
47
  ]
24
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
+ ],
25
59
  "keywords": [
26
60
  "math",
27
61
  "parser",
@@ -34,24 +68,26 @@
34
68
  "license": "GPL-3.0",
35
69
  "repository": {
36
70
  "type": "git",
37
- "url": "git+https://github.com/code-hemu/Exprify.git"
71
+ "url": "git+https://github.com/code-hemu/exprify.git"
38
72
  },
39
73
  "bugs": {
40
- "url": "https://github.com/code-hemu/Exprify/issues"
74
+ "url": "https://github.com/code-hemu/exprify/issues"
41
75
  },
42
- "homepage": "https://github.com/code-hemu/Exprify#readme",
76
+ "homepage": "https://github.com/code-hemu/exprify#readme",
43
77
  "devDependencies": {
44
- "@babel/cli": "^7.24.0",
45
- "@babel/core": "^7.24.0",
46
- "@babel/preset-env": "^7.24.0",
47
- "@rollup/plugin-commonjs": "^23.0.0",
48
- "@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",
49
81
  "@rollup/plugin-terser": "^1.0.0",
50
- "glob": "^13.0.6",
51
- "jest": "^29.0.0",
52
- "nodemon": "^3.0.0",
53
- "rimraf": "^6.1.3",
54
- "rollup": "^2.0.0",
55
- "rollup-plugin-strip-banner": "^3.1.0"
82
+ "@size-limit/file": "^12.1.0",
83
+ "eslint": "^10.4.1",
84
+ "globals": "^17.6.0",
85
+ "husky": "^9.1.7",
86
+ "jest": "^30.4.2",
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"
56
92
  }
57
93
  }
@@ -1,30 +1,38 @@
1
- export function createContext({ variables, functions, units, evaluate}) {
2
- if (!variables) throw new Error("Variable store missing");
3
- if (!functions) throw new Error("Function registry missing");
4
- if (!units) throw new Error("Units list missing");
5
- if (!evaluate) throw new Error("evaluate function missing");
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
- return {
8
- variables: variables,
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
- withScope(scope = {}) {
13
- const tempVars = {
14
- ...variables.all?.(),
15
- ...scope
16
- };
17
- return createContext({
18
- functions: functions,
19
- evaluate,
20
- units,
21
- variables: {
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
+ }