@cabloy/utils 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/dist/cel.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type * as CelJS from 'cel-js' with { 'resolution-mode': 'import' };
2
+ export declare function evaluateExpressions(expressions: any, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>): unknown;
2
3
  export declare function evaluate(expression: string, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>): unknown;
3
4
  export declare function parse(expression: string): CelJS.ParseResult;
package/dist/cel.js CHANGED
@@ -1,4 +1,21 @@
1
1
  import * as celjs from 'cel-js';
2
+ import { isNil } from "./check.js";
3
+ export function evaluateExpressions(expressions, context, functions) {
4
+ if (isNil(expressions))
5
+ return expressions;
6
+ if (Array.isArray(expressions)) {
7
+ return expressions.map(item => evaluate(item, context, functions));
8
+ }
9
+ else if (typeof expressions === 'object') {
10
+ const res = {};
11
+ for (const key in expressions) {
12
+ res[key] = evaluate(expressions[key], context, functions);
13
+ }
14
+ return res;
15
+ }
16
+ // others
17
+ return evaluate(expressions, context, functions);
18
+ }
2
19
  export function evaluate(expression, context, functions) {
3
20
  if (typeof expression !== 'string')
4
21
  return expression;
package/dist/utils.d.ts CHANGED
@@ -6,3 +6,4 @@ export declare function setProperty<T>(obj: object, name: string, value: T): voi
6
6
  export declare function getProperty<T>(obj: object, name: string, sep?: string): T | undefined;
7
7
  export declare function getPropertyObject<T>(obj: object, name: string, sep?: string): T | undefined;
8
8
  export declare function createFunction(expression: string, scopeKeys?: string[]): Function;
9
+ export declare function evaluateSimple(expression: string): any;
package/dist/utils.js CHANGED
@@ -83,18 +83,7 @@ export function createFunction(expression, scopeKeys) {
83
83
  }
84
84
  return fn;
85
85
  }
86
- // export function evaluate(expression: string, scope?: object) {
87
- // if (!scope) return _evaluateSimple(expression);
88
- // const scopeKeys = Object.keys(scope);
89
- // const scopeParams: any[] = [];
90
- // for (let i = 0; i < scopeKeys.length; i++) {
91
- // const key = scopeKeys[i];
92
- // scopeParams.push(scope[key]);
93
- // }
94
- // const fn = createFunction(expression, scopeKeys);
95
- // return fn(...scopeParams);
96
- // }
97
- // function _evaluateSimple(expression: string) {
98
- // const fn = createFunction(expression);
99
- // return fn();
100
- // }
86
+ export function evaluateSimple(expression) {
87
+ const fn = createFunction(expression);
88
+ return fn();
89
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/utils",
3
3
  "type": "module",
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "description": "cabloy utils",
6
6
  "publishConfig": {
7
7
  "access": "public"