@briza/illogical 1.5.6 → 1.5.9
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/changelog.md +13 -0
- package/lib/illogical.esm.js +24 -15
- package/lib/illogical.js +24 -15
- package/package.json +1 -1
- package/readme.md +26 -5
package/changelog.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# illogical changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.9
|
|
4
|
+
|
|
5
|
+
- Modify OVERLAP expression such that the OVERLAP of two empty arrays returns true
|
|
6
|
+
|
|
7
|
+
## 1.5.8
|
|
8
|
+
|
|
9
|
+
- Introduce the backtick syntax for condition referencing keys that contain dot delimiters
|
|
10
|
+
|
|
11
|
+
## 1.5.7
|
|
12
|
+
|
|
13
|
+
- Update documentation to include example of comparison operator with two references
|
|
14
|
+
- Fix linting issues
|
|
15
|
+
|
|
3
16
|
## 1.5.6
|
|
4
17
|
|
|
5
18
|
- Comparison Expressions updated to support string comparison for ISO-8601 formatted dates.
|
package/lib/illogical.esm.js
CHANGED
|
@@ -549,6 +549,9 @@ class Overlap extends Comparison {
|
|
|
549
549
|
}
|
|
550
550
|
const leftArray = left;
|
|
551
551
|
const rightArray = right;
|
|
552
|
+
if (leftArray.length === 0 && rightArray.length === 0) {
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
552
555
|
return leftArray.some(element => rightArray.includes(element));
|
|
553
556
|
}
|
|
554
557
|
|
|
@@ -1232,23 +1235,29 @@ class Collection extends Operand {
|
|
|
1232
1235
|
|
|
1233
1236
|
const keyWithArrayIndexRegex = /^(?<currentKey>[^[\]]+?)(?<indexes>(?:\[\d+])+)?$/;
|
|
1234
1237
|
const arrayIndexRegex = /\[(\d+)]/g;
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
const keys = [];
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
keys
|
|
1241
|
-
const
|
|
1242
|
-
if (
|
|
1243
|
-
|
|
1244
|
-
|
|
1238
|
+
const parseBacktickWrappedKey = key => key.startsWith('`') && key.endsWith('`') ? key.slice(1, -1) : key;
|
|
1239
|
+
const parseKey = key => {
|
|
1240
|
+
const keys = key.match(/(`[^[\]]+`(\[\d+\])*|[^`.]+)/g);
|
|
1241
|
+
return !keys ? [] : keys.flatMap(key => {
|
|
1242
|
+
const unwrappedKey = parseBacktickWrappedKey(key);
|
|
1243
|
+
const keys = [];
|
|
1244
|
+
const parseResult = keyWithArrayIndexRegex.exec(unwrappedKey);
|
|
1245
|
+
if (parseResult) {
|
|
1246
|
+
var _parseResult$groups$c, _parseResult$groups, _parseResult$groups2;
|
|
1247
|
+
const extractedKey = parseBacktickWrappedKey((_parseResult$groups$c = parseResult === null || parseResult === void 0 || (_parseResult$groups = parseResult.groups) === null || _parseResult$groups === void 0 ? void 0 : _parseResult$groups.currentKey) !== null && _parseResult$groups$c !== void 0 ? _parseResult$groups$c : unwrappedKey);
|
|
1248
|
+
keys.push(extractedKey);
|
|
1249
|
+
const rawIndexes = parseResult === null || parseResult === void 0 || (_parseResult$groups2 = parseResult.groups) === null || _parseResult$groups2 === void 0 ? void 0 : _parseResult$groups2.indexes;
|
|
1250
|
+
if (rawIndexes) {
|
|
1251
|
+
for (const indexResult of rawIndexes.matchAll(arrayIndexRegex)) {
|
|
1252
|
+
keys.push(parseInt(indexResult[1]));
|
|
1253
|
+
}
|
|
1245
1254
|
}
|
|
1255
|
+
} else {
|
|
1256
|
+
keys.push(unwrappedKey);
|
|
1246
1257
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
return keys;
|
|
1251
|
-
});
|
|
1258
|
+
return keys;
|
|
1259
|
+
});
|
|
1260
|
+
};
|
|
1252
1261
|
const complexKeyExpression = /{([^{}]+)}/;
|
|
1253
1262
|
function extractComplexKeys(ctx, key) {
|
|
1254
1263
|
// Resolve complex keys
|
package/lib/illogical.js
CHANGED
|
@@ -553,6 +553,9 @@ class Overlap extends Comparison {
|
|
|
553
553
|
}
|
|
554
554
|
const leftArray = left;
|
|
555
555
|
const rightArray = right;
|
|
556
|
+
if (leftArray.length === 0 && rightArray.length === 0) {
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
556
559
|
return leftArray.some(element => rightArray.includes(element));
|
|
557
560
|
}
|
|
558
561
|
|
|
@@ -1236,23 +1239,29 @@ class Collection extends Operand {
|
|
|
1236
1239
|
|
|
1237
1240
|
const keyWithArrayIndexRegex = /^(?<currentKey>[^[\]]+?)(?<indexes>(?:\[\d+])+)?$/;
|
|
1238
1241
|
const arrayIndexRegex = /\[(\d+)]/g;
|
|
1239
|
-
const
|
|
1240
|
-
|
|
1241
|
-
const keys = [];
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
keys
|
|
1245
|
-
const
|
|
1246
|
-
if (
|
|
1247
|
-
|
|
1248
|
-
|
|
1242
|
+
const parseBacktickWrappedKey = key => key.startsWith('`') && key.endsWith('`') ? key.slice(1, -1) : key;
|
|
1243
|
+
const parseKey = key => {
|
|
1244
|
+
const keys = key.match(/(`[^[\]]+`(\[\d+\])*|[^`.]+)/g);
|
|
1245
|
+
return !keys ? [] : keys.flatMap(key => {
|
|
1246
|
+
const unwrappedKey = parseBacktickWrappedKey(key);
|
|
1247
|
+
const keys = [];
|
|
1248
|
+
const parseResult = keyWithArrayIndexRegex.exec(unwrappedKey);
|
|
1249
|
+
if (parseResult) {
|
|
1250
|
+
var _parseResult$groups$c, _parseResult$groups, _parseResult$groups2;
|
|
1251
|
+
const extractedKey = parseBacktickWrappedKey((_parseResult$groups$c = parseResult === null || parseResult === void 0 || (_parseResult$groups = parseResult.groups) === null || _parseResult$groups === void 0 ? void 0 : _parseResult$groups.currentKey) !== null && _parseResult$groups$c !== void 0 ? _parseResult$groups$c : unwrappedKey);
|
|
1252
|
+
keys.push(extractedKey);
|
|
1253
|
+
const rawIndexes = parseResult === null || parseResult === void 0 || (_parseResult$groups2 = parseResult.groups) === null || _parseResult$groups2 === void 0 ? void 0 : _parseResult$groups2.indexes;
|
|
1254
|
+
if (rawIndexes) {
|
|
1255
|
+
for (const indexResult of rawIndexes.matchAll(arrayIndexRegex)) {
|
|
1256
|
+
keys.push(parseInt(indexResult[1]));
|
|
1257
|
+
}
|
|
1249
1258
|
}
|
|
1259
|
+
} else {
|
|
1260
|
+
keys.push(unwrappedKey);
|
|
1250
1261
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
return keys;
|
|
1255
|
-
});
|
|
1262
|
+
return keys;
|
|
1263
|
+
});
|
|
1264
|
+
};
|
|
1256
1265
|
const complexKeyExpression = /{([^{}]+)}/;
|
|
1257
1266
|
function extractComplexKeys(ctx, key) {
|
|
1258
1267
|
// Resolve complex keys
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@briza/illogical",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
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",
|
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'] ` | `{
|
|
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
|
|