@nocobase/evaluators 0.9.2-alpha.4 → 0.9.4-alpha.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.
@@ -56,6 +56,9 @@ function evaluate(expression, scope = {}) {
56
56
  } else {
57
57
  result = replaceNumberIndex(v, context);
58
58
  }
59
+ if (result instanceof Date) {
60
+ result = `'${result.toISOString()}'`;
61
+ }
59
62
  return ` ${result} `;
60
63
  });
61
64
  return this(exp, context);
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/evaluators",
3
- "version": "0.9.2-alpha.4",
3
+ "version": "0.9.4-alpha.1",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "Apache-2.0",
8
8
  "dependencies": {
9
9
  "@formulajs/formulajs": "4.2.0",
10
- "@nocobase/utils": "0.9.2-alpha.4",
10
+ "@nocobase/utils": "0.9.4-alpha.1",
11
11
  "mathjs": "^10.6.0"
12
12
  },
13
13
  "repository": {
@@ -15,5 +15,5 @@
15
15
  "url": "git+https://github.com/nocobase/nocobase.git",
16
16
  "directory": "packages/evaluators"
17
17
  },
18
- "gitHead": "96cb023f353a4fb099dea074c575be65ebab813f"
18
+ "gitHead": "0b4936be557be918dbdf8196dadcbc7eb395906d"
19
19
  }
@@ -27,6 +27,15 @@ describe('evaluate', () => {
27
27
  expect(result).toBe(1);
28
28
  });
29
29
 
30
+ it('function result Date', () => {
31
+ const result = formulaEval('{{a}}', {
32
+ a() {
33
+ return new Date();
34
+ },
35
+ });
36
+ expect(result).toMatch(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z/);
37
+ });
38
+
30
39
  it('number path to array item 0 (math.js)', () => {
31
40
  expect(() => mathEval('{{a.0}}', { a: [1, 2, 3] })).toThrow();
32
41
  });
@@ -55,6 +55,10 @@ export function evaluate(this: Evaluator, expression: string, scope: Scope = {})
55
55
  result = replaceNumberIndex(v, context);
56
56
  }
57
57
 
58
+ if (result instanceof Date) {
59
+ result = `'${result.toISOString()}'`;
60
+ }
61
+
58
62
  return ` ${result} `;
59
63
  });
60
64
  return this(exp, context);