@tachybase/evaluators 1.6.11 → 1.6.13-alpha.2

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.
@@ -35,10 +35,12 @@ __export(server_exports, {
35
35
  module.exports = __toCommonJS(server_exports);
36
36
  var import_utils = require("@tachybase/utils");
37
37
  var import_formulajs = __toESM(require("../utils/formulajs"));
38
+ var import_mathjs = __toESM(require("../utils/mathjs"));
38
39
  var import_string = __toESM(require("../utils/string"));
39
40
  var import_utils3 = require("../utils");
40
41
  const evaluators = new import_utils.Registry();
41
42
  evaluators.register("formula.js", import_formulajs.default);
43
+ evaluators.register("math.js", import_mathjs.default);
42
44
  evaluators.register("string", import_string.default);
43
45
  var server_default = evaluators;
44
46
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,49 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var mathjs_exports = {};
20
+ __export(mathjs_exports, {
21
+ default: () => mathjs_default
22
+ });
23
+ module.exports = __toCommonJS(mathjs_exports);
24
+ var import_mathjs = require("mathjs");
25
+ var import__ = require(".");
26
+ function getMathjsIndexValue(target, index) {
27
+ if (index < 1) {
28
+ throw new Error("Index out of range");
29
+ }
30
+ return target == null ? void 0 : target[index - 1];
31
+ }
32
+ __name(getMathjsIndexValue, "getMathjsIndexValue");
33
+ var mathjs_default = import__.evaluate.bind(function(expression, scope = {}) {
34
+ const exp = expression.replace(/(\$\$\d+)\[(\d+)\]/g, (_, name, index) => {
35
+ return `getMathjsIndexValue(${name}, ${index})`;
36
+ });
37
+ const safeScope = { getMathjsIndexValue };
38
+ const varMap = {};
39
+ let counter = 0;
40
+ const safeExp = exp.replace(/\$\$\d+/g, (match) => {
41
+ if (!varMap[match]) {
42
+ const safeKey = `__v${counter++}`;
43
+ varMap[match] = safeKey;
44
+ safeScope[safeKey] = scope[match];
45
+ }
46
+ return varMap[match];
47
+ });
48
+ return (0, import_mathjs.evaluate)(safeExp, safeScope);
49
+ }, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/evaluators",
3
- "version": "1.6.11",
3
+ "version": "1.6.13-alpha.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/tegojs/tego#readme",
6
6
  "bugs": {
@@ -39,7 +39,8 @@
39
39
  "dependencies": {
40
40
  "@formulajs/formulajs": "4.5.3",
41
41
  "lodash": "4.17.21",
42
- "@tachybase/utils": "1.6.11"
42
+ "mathjs": "15.2.0",
43
+ "@tachybase/utils": "1.6.13-alpha.2"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/node": "20.17.10"