@cabloy/utils 1.0.13 → 1.0.15
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 +2 -1
- package/dist/cel.js +12 -5
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +3 -2
- package/package.json +4 -3
package/dist/cel.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as CelJS from 'cel-js' with { 'resolution-mode': 'import' };
|
|
2
|
+
import type { CstNode } from 'chevrotain';
|
|
2
3
|
export declare function evaluateExpressions(expressions: any, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>): unknown;
|
|
3
|
-
export declare function evaluate(expression: string, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>): unknown;
|
|
4
|
+
export declare function evaluate(expression: CstNode | string, context?: Record<string, unknown>, functions?: Record<string, CallableFunction>): unknown;
|
|
4
5
|
export declare function parse(expression: string): CelJS.ParseResult;
|
package/dist/cel.js
CHANGED
|
@@ -17,12 +17,19 @@ export function evaluateExpressions(expressions, context, functions) {
|
|
|
17
17
|
return evaluate(expressions, context, functions);
|
|
18
18
|
}
|
|
19
19
|
export function evaluate(expression, context, functions) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return expression.substring('##'.length);
|
|
20
|
+
// CstNode
|
|
21
|
+
if (typeof expression === 'object' && expression.children) {
|
|
22
|
+
return celjs.evaluate(expression, context, functions);
|
|
24
23
|
}
|
|
25
|
-
|
|
24
|
+
// string
|
|
25
|
+
if (typeof expression === 'string') {
|
|
26
|
+
if (expression.startsWith('##')) {
|
|
27
|
+
return expression.substring('##'.length);
|
|
28
|
+
}
|
|
29
|
+
return celjs.evaluate(expression, context, functions);
|
|
30
|
+
}
|
|
31
|
+
// others
|
|
32
|
+
return expression;
|
|
26
33
|
}
|
|
27
34
|
export function parse(expression) {
|
|
28
35
|
return celjs.parse(expression);
|
package/dist/utils.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export declare function catchError<T>(fnMethod: (...args: any[]) => Promise<T>):
|
|
|
3
3
|
export declare function sleep(ms: any): Promise<unknown>;
|
|
4
4
|
export declare function replaceTemplate(content: string, scope: object): string;
|
|
5
5
|
export declare function setProperty<T>(obj: object, name: string, value: T): void;
|
|
6
|
-
export declare function getProperty<T>(obj: object, name: string, sep?: string): T | undefined;
|
|
7
|
-
export declare function getPropertyObject<T>(obj: object, name: string, sep?: string): T | undefined;
|
|
6
|
+
export declare function getProperty<T>(obj: object | undefined, name: string, sep?: string): T | undefined;
|
|
7
|
+
export declare function getPropertyObject<T>(obj: object | undefined, name: string, sep?: string): T | undefined;
|
|
8
8
|
export declare function createFunction(expression: string, scopeKeys?: string[]): Function;
|
|
9
9
|
export declare function evaluateSimple(expression: string, scope?: object): any;
|
|
10
10
|
export declare function getRandomInt(size: number, start?: number): number;
|
package/dist/utils.js
CHANGED
|
@@ -53,9 +53,10 @@ export function getProperty(obj, name, sep) {
|
|
|
53
53
|
export function getPropertyObject(obj, name, sep) {
|
|
54
54
|
return _getProperty(obj, name, sep, true);
|
|
55
55
|
}
|
|
56
|
-
function _getProperty(
|
|
57
|
-
if (!
|
|
56
|
+
function _getProperty(_obj, name, sep, forceObject) {
|
|
57
|
+
if (!_obj)
|
|
58
58
|
return undefined;
|
|
59
|
+
let obj = _obj;
|
|
59
60
|
const names = name.split(sep || '.');
|
|
60
61
|
// loop
|
|
61
62
|
for (const name of names) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cabloy/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.15",
|
|
5
5
|
"description": "cabloy utils",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@cabloy/word-utils": "^2.0.
|
|
28
|
+
"@cabloy/word-utils": "^2.0.1",
|
|
29
29
|
"cel-js": "^0.3.1",
|
|
30
|
-
"
|
|
30
|
+
"chevrotain": "^11.0.3",
|
|
31
|
+
"@cabloy/module-info": "^1.3.7"
|
|
31
32
|
}
|
|
32
33
|
}
|