@briza/illogical 1.5.5 → 1.5.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@briza/illogical",
3
- "version": "1.5.5",
3
+ "version": "1.5.8",
4
4
  "description": "A micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.",
5
5
  "main": "lib/illogical.js",
6
6
  "module": "lib/illogical.esm.js",
@@ -42,31 +42,31 @@
42
42
  "rules"
43
43
  ],
44
44
  "devDependencies": {
45
- "@babel/core": "^7.17.9",
46
- "@babel/plugin-proposal-class-properties": "^7.16.7",
47
- "@babel/preset-env": "^7.16.11",
48
- "@babel/preset-typescript": "^7.16.7",
49
- "@rollup/plugin-babel": "^5.3.1",
50
- "@rollup/plugin-commonjs": "^21.0.3",
51
- "@rollup/plugin-node-resolve": "^13.2.0",
52
- "@types/jest": "^27.4.1",
53
- "@typescript-eslint/eslint-plugin": "^5.19.0",
54
- "@typescript-eslint/parser": "^5.19.0",
55
- "eslint": "^8.13.0",
56
- "eslint-config-prettier": "^8.5.0",
57
- "eslint-import-resolver-typescript": "^2.7.1",
58
- "eslint-plugin-import": "^2.26.0",
45
+ "@babel/core": "^7.23.6",
46
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
47
+ "@babel/preset-env": "^7.23.6",
48
+ "@babel/preset-typescript": "^7.23.3",
49
+ "@rollup/plugin-babel": "^6.0.4",
50
+ "@rollup/plugin-commonjs": "^25.0.7",
51
+ "@rollup/plugin-eslint": "^9.0.5",
52
+ "@rollup/plugin-node-resolve": "^15.2.3",
53
+ "@types/jest": "^28.1.8",
54
+ "@typescript-eslint/eslint-plugin": "^6.14.0",
55
+ "@typescript-eslint/parser": "^6.14.0",
56
+ "eslint": "^8.55.0",
57
+ "eslint-config-prettier": "^9.1.0",
58
+ "eslint-import-resolver-typescript": "^3.6.1",
59
+ "eslint-plugin-import": "^2.29.0",
59
60
  "eslint-plugin-node": "^11.1.0",
60
- "eslint-plugin-prettier": "^3.4.1",
61
- "eslint-plugin-promise": "^6.0.0",
62
- "eslint-plugin-simple-import-sort": "^7.0.0",
63
- "jest": "^27.5.1",
61
+ "eslint-plugin-prettier": "^5.0.1",
62
+ "eslint-plugin-promise": "^6.1.1",
63
+ "eslint-plugin-simple-import-sort": "^10.0.0",
64
+ "jest": "^29.7.0",
64
65
  "license-checker": "^25.0.1",
65
- "prettier": "^2.6.2",
66
- "rollup": "^2.70.1",
67
- "rollup-plugin-eslint": "^7.0.0",
68
- "ts-jest": "^27.1.4",
69
- "typedoc": "^0.22.15",
70
- "typescript": "4.6.3"
66
+ "prettier": "^3.1.1",
67
+ "rollup": "^4.8.0",
68
+ "ts-jest": "^29.1.1",
69
+ "typedoc": "^0.25.4",
70
+ "typescript": "^5.3.3"
71
71
  }
72
72
  }
package/readme.md CHANGED
@@ -230,6 +230,26 @@ The evaluation data context is used to provide the expression with variable refe
230
230
  To reference the nested reference, please use "." delimiter, e.g.:
231
231
  `$address.city`
232
232
 
233
+ If the key of the nested reference includes the "." delimiter, please wrap the whole key with backticks `` ` ``, e.g.:
234
+ `` $address.`city.code` `` can reference the object
235
+ ```javascript
236
+ {
237
+ address: {
238
+ 'city.code': 'TOR'
239
+ }
240
+ }
241
+ ```
242
+
243
+ `` $address.`city.code`[0] `` can reference the object
244
+ ```javascript
245
+ {
246
+ address: {
247
+ 'city.code': ['TOR']
248
+ }
249
+ }
250
+ ```
251
+ when the value of the nested reference is an array.
252
+
233
253
  #### Accessing Array Element:
234
254
 
235
255
  `$options[1]`
@@ -331,11 +351,12 @@ The reference operand must be prefixed with `$` symbol, e.g.: `$name`. This migh
331
351
 
332
352
  **Example**
333
353
 
334
- | Expression | Data Context |
335
- | ----------------------------- | ----------------- |
336
- | `['==', '$age', 21]` | `{age: 21}` |
337
- | `['==', 'circle', '$shape'] ` | `{age: 'circle'}` |
338
- | `['==', '$visible', true]` | `{visible: true}` |
354
+ | Expression | Data Context |
355
+ | ----------------------------- | ------------------------------------- |
356
+ | `['==', '$age', 21]` | `{age: 21}` |
357
+ | `['==', 'circle', '$shape'] ` | `{shape: 'circle'}` |
358
+ | `['==', '$visible', true]` | `{visible: true}` |
359
+ | `['==', '$circle', '$shape']` | `{circle: 'circle', shape: 'circle'}` |
339
360
 
340
361
  #### Collection
341
362
 
@@ -383,56 +404,72 @@ engine.evaluate(['!=', 'circle', 'square']) // true
383
404
 
384
405
  Expression format: `[">", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.
385
406
 
386
- > Valid operand types: number.
407
+ > Valid operand types: number, string.
408
+
409
+ - String comparison only supports ISO-8601 formatted dates.
387
410
 
388
411
  ```json
389
412
  [">", 10, 5]
413
+ [">", "2023-01-01", "2022-12-31"]
390
414
  ```
391
415
 
392
416
  ```js
393
417
  engine.evaluate(['>', 10, 5]) // true
418
+ engine.evaluate(['>', '2023-01-01', '2022-12-31']) // true
394
419
  ```
395
420
 
396
421
  #### Greater Than or Equal
397
422
 
398
423
  Expression format: `[">=", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.
399
424
 
400
- > Valid operand types: number.
425
+ > Valid operand types: number, string.
426
+
427
+ - String comparison only supports ISO-8601 formatted dates.
401
428
 
402
429
  ```json
403
430
  [">=", 5, 5]
431
+ [">=", "2023-01-01", "2023-01-01"]
404
432
  ```
405
433
 
406
434
  ```js
407
435
  engine.evaluate(['>=', 5, 5]) // true
436
+ engine.evaluate(['>=', '2023-01-01', '2023-01-01']) // true
408
437
  ```
409
438
 
410
439
  #### Less Than
411
440
 
412
441
  Expression format: `["<", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.
413
442
 
414
- > Valid operand types: number.
443
+ > Valid operand types: number, string.
444
+
445
+ - String comparison only supports ISO-8601 formatted dates.
415
446
 
416
447
  ```json
417
448
  ["<", 5, 10]
449
+ ["<", "2022-12-31", "2023-01-01"]
418
450
  ```
419
451
 
420
452
  ```js
421
453
  engine.evaluate(['<', 5, 10]) // true
454
+ engine.evaluate(['<', '2022-12-31', '2023-01-01']) // true
422
455
  ```
423
456
 
424
457
  #### Less Than or Equal
425
458
 
426
459
  Expression format: `["<=", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.
427
460
 
428
- > Valid operand types: number.
461
+ > Valid operand types: number, string.
462
+
463
+ - String comparison only supports ISO-8601 formatted dates.
429
464
 
430
465
  ```json
431
466
  ["<=", 5, 5]
467
+ ["<=", "2023-01-01", "2023-01-01"]
432
468
  ```
433
469
 
434
470
  ```js
435
471
  engine.evaluate(['<=', 5, 5]) // true
472
+ engine.evaluate(['<=', '2023-01-01', '2023-01-01']) // true
436
473
  ```
437
474
 
438
475
  #### In
@@ -3,7 +3,7 @@ import { Options } from '../parser/options';
3
3
  /**
4
4
  * Valid types for context members
5
5
  */
6
- declare type ContextValue = Record<string, unknown> | string | number | boolean | null | undefined | ContextValue[];
6
+ type ContextValue = Record<string, unknown> | string | number | boolean | null | undefined | ContextValue[];
7
7
  /**
8
8
  * Evaluation Context
9
9
  * Holds references used during the evaluation process.
@@ -15,7 +15,7 @@ export interface Context {
15
15
  /**
16
16
  * Evaluation result
17
17
  */
18
- export declare type Result = undefined | null | string | number | boolean | Array<Result> | Record<string, unknown>;
18
+ export type Result = undefined | null | string | number | boolean | Array<Result> | Record<string, unknown>;
19
19
  export declare enum EvaluableType {
20
20
  Operand = "Operand",
21
21
  Expression = "Expression"
@@ -53,5 +53,5 @@ export interface Evaluable {
53
53
  */
54
54
  toString(): string;
55
55
  }
56
- export declare type SimplifyArgs = Parameters<Evaluable['simplify']>;
56
+ export type SimplifyArgs = Parameters<Evaluable['simplify']>;
57
57
  export {};
@@ -9,3 +9,8 @@ export declare const toNumber: (value: Result) => number | undefined;
9
9
  * @param value value to be converted to string
10
10
  */
11
11
  export declare const toString: (value: Result) => string | undefined;
12
+ /**
13
+ * Convert a value to number if it's type is string, otherwise return NaN
14
+ * @param value value to be converted to number
15
+ */
16
+ export declare const toDateNumber: (value: Result) => number;
@@ -1,8 +1,8 @@
1
1
  import { Evaluable } from '../common/evaluable';
2
2
  import { Options } from './options';
3
- export declare type Input = string | number | boolean | null | Input[] | [string, ...Input[]];
4
- export declare type ArrayInput = Input[];
5
- export declare type ExpressionInput = [string, ...Input[]];
3
+ export type Input = string | number | boolean | null | Input[] | [string, ...Input[]];
4
+ export type ArrayInput = Input[];
5
+ export type ExpressionInput = [string, ...Input[]];
6
6
  /**
7
7
  * Parser of raw expressions into Evaluable expression
8
8
  */
@@ -1,4 +1,4 @@
1
- export declare type optionValue = ((operand: string) => string | boolean) | Map<symbol, string>;
1
+ export type optionValue = ((operand: string) => string | boolean) | Map<symbol, string>;
2
2
  export interface Options {
3
3
  /**
4
4
  * A function used to determine if the operand is a reference type,