@cabloy/utils 1.0.29 → 1.0.30

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/cel.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type * as CelJS from 'cel-js' with { 'resolution-mode': 'import' };
1
+ import type * as Celjs from 'cel-js' with { 'resolution-mode': 'import' };
2
2
  import type { CstNode } from 'chevrotain';
3
- export declare function evaluateExpressions(expressions: any, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>): unknown;
3
+ export declare const CeljsPrefix = "#!#";
4
+ export declare function evaluateExpressions(expressions: any, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>, dry?: boolean): unknown;
4
5
  export declare function evaluate(expression: CstNode | string, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>): unknown;
5
- export declare function parse(expression: string): CelJS.ParseResult;
6
+ export declare function parse(expression: string): Celjs.ParseResult;
package/dist/cel.js CHANGED
@@ -1,20 +1,35 @@
1
1
  import * as celjs from 'cel-js';
2
2
  import { isNil } from "./check.js";
3
- export function evaluateExpressions(expressions, context, functions) {
3
+ export const CeljsPrefix = '#!#';
4
+ export function evaluateExpressions(expressions, context, functions, dry) {
4
5
  if (isNil(expressions))
5
- return expressions;
6
+ return _returnExpressionWithDry(expressions, dry);
6
7
  if (Array.isArray(expressions)) {
7
- return expressions.map(item => evaluate(item, context, functions));
8
+ return expressions.map(item => _evaluateExpressionInner(item, context, functions, dry));
8
9
  }
9
10
  else if (typeof expressions === 'object') {
10
11
  const res = {};
11
12
  for (const key in expressions) {
12
- res[key] = evaluate(expressions[key], context, functions);
13
+ res[key] = _evaluateExpressionInner(expressions[key], context, functions, dry);
13
14
  }
14
15
  return res;
15
16
  }
16
17
  // others
17
- return evaluate(expressions, context, functions);
18
+ return _evaluateExpressionInner(expressions, context, functions, dry);
19
+ }
20
+ function _evaluateExpressionInner(expression, context, functions, dry) {
21
+ if (isNil(expression))
22
+ return _returnExpressionWithDry(expression, dry);
23
+ if (typeof expression === 'object')
24
+ return evaluateExpressions(expression, context, functions, dry);
25
+ if (typeof expression !== 'string')
26
+ return _returnExpressionWithDry(expression, dry);
27
+ if (!expression.startsWith(CeljsPrefix))
28
+ return _returnExpressionWithDry(expression, dry);
29
+ return dry ? true : evaluate(expression.substring(CeljsPrefix.length), context, functions);
30
+ }
31
+ function _returnExpressionWithDry(expression, dry) {
32
+ return dry ? false : expression;
18
33
  }
19
34
  export function evaluate(expression, context, functions) {
20
35
  // CstNode
@@ -23,8 +38,8 @@ export function evaluate(expression, context, functions) {
23
38
  }
24
39
  // string
25
40
  if (typeof expression === 'string') {
26
- if (expression.startsWith('##')) {
27
- return expression.substring('##'.length);
41
+ if (expression.startsWith(CeljsPrefix)) {
42
+ return expression.substring(CeljsPrefix.length);
28
43
  }
29
44
  return celjs.evaluate(expression, context, functions);
30
45
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/utils",
3
3
  "type": "module",
4
- "version": "1.0.29",
4
+ "version": "1.0.30",
5
5
  "description": "cabloy utils",
6
6
  "publishConfig": {
7
7
  "access": "public"