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