@cabloy/utils 1.0.32 → 1.0.34

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,6 +1,5 @@
1
1
  import type * as Celjs from '@cabloy/cel-js' with { 'resolution-mode': 'import' };
2
2
  import type { CstNode } from 'chevrotain';
3
- export declare const CeljsPrefix = "#!#";
4
3
  export declare function evaluateExpressions<T = any>(expressions: any, context?: object, functions?: Record<string, CallableFunction>, dry?: boolean): T;
5
4
  export declare function evaluate<T = any>(expression: CstNode | string, context?: object, functions?: Record<string, CallableFunction>): T;
6
5
  export declare function parse(expression: string): Celjs.ParseResult;
package/dist/cel.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as celjs from '@cabloy/cel-js';
2
2
  import { isNil } from "./check.js";
3
3
  import { hashkey } from "./hash.js";
4
+ import { StringPrefixCel, StringPrefixRaw } from "./types.js";
4
5
  import { getProperty } from "./utils.js";
5
- export const CeljsPrefix = '#!#';
6
6
  export function evaluateExpressions(expressions, context, functions, dry) {
7
7
  if (isNil(expressions))
8
8
  return _returnExpressionWithDry(expressions, dry);
@@ -26,9 +26,9 @@ function _evaluateExpressionInner(expression, context, functions, dry) {
26
26
  return evaluateExpressions(expression, context, functions, dry);
27
27
  if (typeof expression !== 'string')
28
28
  return _returnExpressionWithDry(expression, dry);
29
- if (!expression.startsWith(CeljsPrefix))
29
+ if (!expression.startsWith(StringPrefixCel))
30
30
  return _returnExpressionWithDry(expression, dry);
31
- return dry ? true : evaluate(expression.substring(CeljsPrefix.length), context, functions);
31
+ return dry ? true : evaluate(expression.substring(StringPrefixCel.length), context, functions);
32
32
  }
33
33
  function _returnExpressionWithDry(expression, dry) {
34
34
  return dry ? false : expression;
@@ -42,8 +42,8 @@ export function evaluate(expression, context, functions) {
42
42
  }
43
43
  // string
44
44
  if (typeof expression === 'string') {
45
- if (expression.startsWith(CeljsPrefix)) {
46
- return expression.substring(CeljsPrefix.length);
45
+ if (expression.startsWith(StringPrefixRaw)) {
46
+ return expression.substring(StringPrefixRaw.length);
47
47
  }
48
48
  return celjs.evaluate(expression, context, functions);
49
49
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from './cel.ts';
2
2
  export * from './check.ts';
3
3
  export * from './hash.ts';
4
+ export * from './match.ts';
5
+ export * from './types.ts';
4
6
  export * from './utils.ts';
5
7
  export * from './vona.ts';
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./cel.js";
2
2
  export * from "./check.js";
3
3
  export * from "./hash.js";
4
+ export * from "./match.js";
5
+ export * from "./types.js";
4
6
  export * from "./utils.js";
5
7
  export * from "./vona.js";
@@ -0,0 +1,4 @@
1
+ export type TypeMatchSelectorFunction = (this: any, ...args: any[]) => boolean;
2
+ export type TypeMatchSelectorRule<T> = T | RegExp | TypeMatchSelectorFunction;
3
+ export type TypeMatchSelectorRules<T> = (TypeMatchSelectorRule<T>)[] | TypeMatchSelectorRule<T>;
4
+ export declare function matchSelector<T>(match: TypeMatchSelectorRules<T>, selector: string | boolean, matchThis?: any, ...matchArgs: any[]): any;
package/dist/match.js ADDED
@@ -0,0 +1,16 @@
1
+ import { evaluateExpressions } from "./cel.js";
2
+ import { StringPrefixCel, StringPrefixRegexp } from "./types.js";
3
+ import { evaluateSimple } from "./utils.js";
4
+ export function matchSelector(match, selector, matchThis, ...matchArgs) {
5
+ if (!Array.isArray(match)) {
6
+ // prepare
7
+ if (typeof match === 'string' && match.startsWith(StringPrefixRegexp)) {
8
+ match = evaluateSimple(match.substring(StringPrefixRegexp.length));
9
+ }
10
+ return ((typeof match === 'string' && match.startsWith(StringPrefixCel) && !!evaluateExpressions(match, { selector, context: matchArgs[0], args: matchArgs })) ||
11
+ (typeof match === 'string' && !match.startsWith(StringPrefixCel) && typeof selector === 'string' && match === selector) ||
12
+ (match instanceof RegExp && typeof selector === 'string' && match.test(selector)) ||
13
+ (typeof match === 'function' && match.call(matchThis, selector, ...matchArgs)));
14
+ }
15
+ return match.some(item => matchSelector(item, selector));
16
+ }
@@ -0,0 +1,3 @@
1
+ export declare const StringPrefixRegexp = "regexp://";
2
+ export declare const StringPrefixCel = "cel://";
3
+ export declare const StringPrefixRaw = "raw://";
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export const StringPrefixRegexp = 'regexp://';
2
+ export const StringPrefixCel = 'cel://';
3
+ export const StringPrefixRaw = 'raw://';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/utils",
3
3
  "type": "module",
4
- "version": "1.0.32",
4
+ "version": "1.0.34",
5
5
  "description": "cabloy utils",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -25,8 +25,8 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@cabloy/cel-js": "^0.7.2",
29
- "@cabloy/module-info": "^1.3.23",
28
+ "@cabloy/cel-js": "^0.7.3",
29
+ "@cabloy/module-info": "^1.3.24",
30
30
  "@cabloy/word-utils": "^2.0.1",
31
31
  "chevrotain": "^11.0.3",
32
32
  "object-hash": "^3.0.0"