map-transform 0.4.0-alpha.2 → 0.4.0-alpha.20
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/README.md +164 -18
- package/dist/functions/compare.d.ts +2 -1
- package/dist/functions/compare.js +21 -5
- package/dist/functions/compare.js.map +1 -1
- package/dist/functions/explode.d.ts +2 -1
- package/dist/functions/explode.js +12 -4
- package/dist/functions/explode.js.map +1 -1
- package/dist/functions/index.d.ts +6 -1
- package/dist/functions/index.js +6 -1
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/joinSplit.js +4 -5
- package/dist/functions/joinSplit.js.map +1 -1
- package/dist/functions/logical.d.ts +7 -0
- package/dist/functions/logical.js +24 -0
- package/dist/functions/logical.js.map +1 -0
- package/dist/functions/map.js +5 -4
- package/dist/functions/map.js.map +1 -1
- package/dist/functions/not.js +1 -1
- package/dist/functions/not.js.map +1 -1
- package/dist/functions/sort.d.ts +7 -0
- package/dist/functions/sort.js +33 -0
- package/dist/functions/sort.js.map +1 -0
- package/dist/functions/template.js +7 -5
- package/dist/functions/template.js.map +1 -1
- package/dist/functions/validate.js +2 -2
- package/dist/functions/validate.js.map +1 -1
- package/dist/functions/value.js +2 -2
- package/dist/functions/value.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/operations/alt.d.ts +1 -1
- package/dist/operations/alt.js +4 -2
- package/dist/operations/alt.js.map +1 -1
- package/dist/operations/apply.js +1 -4
- package/dist/operations/apply.js.map +1 -1
- package/dist/operations/concat.js +1 -1
- package/dist/operations/concat.js.map +1 -1
- package/dist/operations/filter.js +10 -8
- package/dist/operations/filter.js.map +1 -1
- package/dist/operations/getSet.d.ts +2 -1
- package/dist/operations/getSet.js +14 -8
- package/dist/operations/getSet.js.map +1 -1
- package/dist/operations/ifelse.d.ts +1 -1
- package/dist/operations/ifelse.js +12 -5
- package/dist/operations/ifelse.js.map +1 -1
- package/dist/operations/iterate.js +6 -8
- package/dist/operations/iterate.js.map +1 -1
- package/dist/operations/logical.d.ts +3 -0
- package/dist/operations/logical.js +17 -0
- package/dist/operations/logical.js.map +1 -0
- package/dist/operations/lookup.js.map +1 -1
- package/dist/operations/merge.d.ts +1 -0
- package/dist/operations/merge.js +25 -2
- package/dist/operations/merge.js.map +1 -1
- package/dist/operations/modify.d.ts +1 -1
- package/dist/operations/modify.js +2 -2
- package/dist/operations/modify.js.map +1 -1
- package/dist/operations/mutate.js +85 -29
- package/dist/operations/mutate.js.map +1 -1
- package/dist/operations/pipe.js +13 -3
- package/dist/operations/pipe.js.map +1 -1
- package/dist/operations/plug.js +1 -1
- package/dist/operations/plug.js.map +1 -1
- package/dist/operations/root.js +2 -1
- package/dist/operations/root.js.map +1 -1
- package/dist/operations/transform.js +3 -3
- package/dist/operations/transform.js.map +1 -1
- package/dist/types.d.ts +32 -8
- package/dist/utils/array.d.ts +2 -0
- package/dist/utils/array.js +12 -0
- package/dist/utils/array.js.map +1 -0
- package/dist/utils/definitionHelpers.js +64 -15
- package/dist/utils/definitionHelpers.js.map +1 -1
- package/dist/utils/escape.d.ts +2 -0
- package/dist/utils/escape.js +8 -0
- package/dist/utils/escape.js.map +1 -0
- package/dist/utils/functional.d.ts +1 -0
- package/dist/utils/functional.js +3 -1
- package/dist/utils/functional.js.map +1 -1
- package/dist/utils/is.d.ts +2 -0
- package/dist/utils/is.js +5 -1
- package/dist/utils/is.js.map +1 -1
- package/dist/utils/pathGetter.d.ts +4 -2
- package/dist/utils/pathGetter.js +24 -19
- package/dist/utils/pathGetter.js.map +1 -1
- package/dist/utils/pathSetter.d.ts +5 -3
- package/dist/utils/pathSetter.js +48 -43
- package/dist/utils/pathSetter.js.map +1 -1
- package/dist/utils/stateHelpers.d.ts +3 -3
- package/dist/utils/stateHelpers.js +6 -6
- package/dist/utils/stateHelpers.js.map +1 -1
- package/package.json +8 -10
package/README.md
CHANGED
|
@@ -188,11 +188,14 @@ const def2 = {
|
|
|
188
188
|
// }
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
When you transform an array of data with a mapping object,
|
|
192
|
-
data array
|
|
191
|
+
When you transform an array of data with a mapping object, you'll have to set
|
|
192
|
+
`$iterate: true` to have each item in the data array be transformed with the
|
|
193
|
+
mapping object. If you don't the entire array will be passed to the mapping
|
|
194
|
+
object.
|
|
193
195
|
|
|
194
196
|
```javascript
|
|
195
197
|
const def3 = {
|
|
198
|
+
$iterate: true,
|
|
196
199
|
title: 'heading',
|
|
197
200
|
}
|
|
198
201
|
|
|
@@ -203,12 +206,8 @@ const def3 = {
|
|
|
203
206
|
// ]
|
|
204
207
|
```
|
|
205
208
|
|
|
206
|
-
|
|
207
|
-
the
|
|
208
|
-
transform pipeline.
|
|
209
|
-
|
|
210
|
-
**Note:** When a mapping object is part of a transform pipeline, the default is
|
|
211
|
-
to not iterate. See [**transform pipeline**](#transform-pipeline) for more.
|
|
209
|
+
**Note:** Iterating used to be the default behavior, but it has been changed due
|
|
210
|
+
to the contradiction with how the mapping object behaves everywhere else.
|
|
212
211
|
|
|
213
212
|
A key will set whatever is returned by the pipeline (see
|
|
214
213
|
[next section](#values-on-the-transform-object)), whether it is a string, a
|
|
@@ -326,6 +325,17 @@ When running a forward transformation, transform objects marked with
|
|
|
326
325
|
`$direction: 'rev'` will be skipped. The same goes for `$direction: 'fwd'` in
|
|
327
326
|
reverse.
|
|
328
327
|
|
|
328
|
+
You may specify aliases for `fwd` and `rev` in the `mapTransform` options:
|
|
329
|
+
|
|
330
|
+
```javascript
|
|
331
|
+
const options = { fwdAlias: 'from', revAlias: 'to' }
|
|
332
|
+
const mapper = mapTransform(def, options)
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
In this case, `from` and `to` may be used to specify forward and reverse
|
|
336
|
+
direction respectively. `fwd` and `rev` will still work in addition to the
|
|
337
|
+
aliases.
|
|
338
|
+
|
|
329
339
|
### Transform pipeline
|
|
330
340
|
|
|
331
341
|
The idea of the transform pipeline, is that you describe a set of
|
|
@@ -553,10 +563,10 @@ See the `transform()` operation for more on how defining as an object works.
|
|
|
553
563
|
|
|
554
564
|
#### `ifelse(conditionFn, truePipeline, falsePipeline)` operation
|
|
555
565
|
|
|
556
|
-
The `ifelse()` operation will run the `truePipeline` if the `conditionFn`
|
|
557
|
-
in
|
|
558
|
-
[the `filter()` operation](#filterconditionFn-operation)
|
|
559
|
-
requirements for the `conditionFn`.
|
|
566
|
+
The `ifelse()` operation will run the `truePipeline` if the `conditionFn`
|
|
567
|
+
results in something truthy, JavaScript tstyle, otherwise it will run the
|
|
568
|
+
`falsePipeline`. See [the `filter()` operation](#filterconditionFn-operation)
|
|
569
|
+
for more on the requirements for the `conditionFn`.
|
|
560
570
|
|
|
561
571
|
Both `truePipeline` and `falsePipeline` are optional, in case you only need to
|
|
562
572
|
apply a pipeline in one of the cases.
|
|
@@ -577,6 +587,29 @@ const def31 = [
|
|
|
577
587
|
]
|
|
578
588
|
```
|
|
579
589
|
|
|
590
|
+
Defining an if operation as an object:
|
|
591
|
+
|
|
592
|
+
```javascript
|
|
593
|
+
import { mapTransform } from 'map-transform'
|
|
594
|
+
|
|
595
|
+
const def31b = [
|
|
596
|
+
'members'
|
|
597
|
+
{
|
|
598
|
+
name: 'name',
|
|
599
|
+
active: 'hasPayed'
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
$if: 'active',
|
|
603
|
+
then: set('active[]'),
|
|
604
|
+
else: set('inactive[]')
|
|
605
|
+
}
|
|
606
|
+
]
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
Note that `$if`, `then`, and `else` in the object notation may be any type of
|
|
610
|
+
pipeline definition. The only gotcha is that if `$if` is a function, it is
|
|
611
|
+
treated as a `conditionFn`, like in `def31`, not as a state mapper.
|
|
612
|
+
|
|
580
613
|
#### `iterate(pipeline)` operation
|
|
581
614
|
|
|
582
615
|
If you want something to be mapped over the items of an array, the `iterate`
|
|
@@ -612,6 +645,9 @@ When an id is passed to the apply operation as `pipelinedId`, the pipeline will
|
|
|
612
645
|
be applied in the place of the apply operation and executed as if it was part of
|
|
613
646
|
the pipeline definition in the first place.
|
|
614
647
|
|
|
648
|
+
When no pipeline is provided, e.g. because the id is unknown, no pipeline will
|
|
649
|
+
be applied and the data will pass through untouched.
|
|
650
|
+
|
|
615
651
|
```javascript
|
|
616
652
|
import { mapTransform, apply, transform } from 'map-transform'
|
|
617
653
|
|
|
@@ -697,6 +733,8 @@ const def10asObject = {
|
|
|
697
733
|
}
|
|
698
734
|
```
|
|
699
735
|
|
|
736
|
+
There is also a shortcut for `{ $transform: 'value', value: 'customer' }`: `{ $value: 'customer' }`, which might be useful when typing definitions by hand.
|
|
737
|
+
|
|
700
738
|
#### `fixed(data)` operation
|
|
701
739
|
|
|
702
740
|
The data given to the fixed operation, will be inserted in the pipeline in place
|
|
@@ -818,6 +856,27 @@ const response = {
|
|
|
818
856
|
Had we ran this without the `modify()` operation, the returned object would only
|
|
819
857
|
have the `data` prop.
|
|
820
858
|
|
|
859
|
+
This is equivalent to setting the `$modify` property to `true` on the object
|
|
860
|
+
mutation object:
|
|
861
|
+
|
|
862
|
+
```javascript
|
|
863
|
+
const def34b = {
|
|
864
|
+
$modify: true,
|
|
865
|
+
data: 'data.deeply.placed.items',
|
|
866
|
+
}
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
Note that `$modify` may also be set further down in the object structure. Also,
|
|
870
|
+
in some cases it may make more sense to specify a path in the source data to
|
|
871
|
+
merge with:
|
|
872
|
+
|
|
873
|
+
```javascript
|
|
874
|
+
const def34c = {
|
|
875
|
+
$modify: 'response',
|
|
876
|
+
data: 'response.data.deeply.placed.items',
|
|
877
|
+
}
|
|
878
|
+
```
|
|
879
|
+
|
|
821
880
|
#### `fwd(pipeline)` and `rev(pipeline)` operation
|
|
822
881
|
|
|
823
882
|
All operations in MapTransform will apply in both directions, although some of
|
|
@@ -998,7 +1057,45 @@ mapper.rev(mappedData)
|
|
|
998
1057
|
// --> { content: { meta: { authors: ['user1', 'user3'] } } }
|
|
999
1058
|
```
|
|
1000
1059
|
|
|
1001
|
-
#### `
|
|
1060
|
+
#### `and(pipeline, pipeline, ...)` operation
|
|
1061
|
+
|
|
1062
|
+
Will run all provided pipelines, force their return values to boolean, according
|
|
1063
|
+
to JavaScript rules, and return `true` if they are all `true`, otherwise
|
|
1064
|
+
`false`.
|
|
1065
|
+
|
|
1066
|
+
Typically used together with [`ifelse` operation](#ifelseconditionFn-truePipeline-falsePipeline-operation),
|
|
1067
|
+
to support AND logic:
|
|
1068
|
+
|
|
1069
|
+
```javascript
|
|
1070
|
+
const def36 = [
|
|
1071
|
+
{
|
|
1072
|
+
$if: { $and: ['active', 'authorized'] },
|
|
1073
|
+
then: 'content',
|
|
1074
|
+
else: { $value: undefined },
|
|
1075
|
+
},
|
|
1076
|
+
]
|
|
1077
|
+
```
|
|
1078
|
+
|
|
1079
|
+
#### `or(pipeline, pipeline, ...)` operation
|
|
1080
|
+
|
|
1081
|
+
Will run all provided pipelines, force their return values to boolean, according
|
|
1082
|
+
to JavaScript rules, and return `true` if any of the are `true`, otherwise
|
|
1083
|
+
`false`.
|
|
1084
|
+
|
|
1085
|
+
Typically used together with [`ifelse` operation](#ifelseconditionFn-truePipeline-falsePipeline-operation),
|
|
1086
|
+
to support OR logic:
|
|
1087
|
+
|
|
1088
|
+
```javascript
|
|
1089
|
+
const def37 = [
|
|
1090
|
+
{
|
|
1091
|
+
$if: { $or: ['active', 'draft'] },
|
|
1092
|
+
then: 'content',
|
|
1093
|
+
else: { $value: undefined },
|
|
1094
|
+
},
|
|
1095
|
+
]
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
#### `compare({ path, operator, match, matchPath, not })` function
|
|
1002
1099
|
|
|
1003
1100
|
This is a helper function intended for use with the `filter()` operation. You
|
|
1004
1101
|
pass a dot notation `path` and a `match` value (string, number, boolean) to
|
|
@@ -1011,10 +1108,14 @@ data.
|
|
|
1011
1108
|
|
|
1012
1109
|
The default is to compare the values resulting from `path` and `match` or
|
|
1013
1110
|
`matchPath` with equality, but other operations may be set on the `operator`
|
|
1014
|
-
property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='
|
|
1111
|
+
property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='`, `in`, or
|
|
1112
|
+
`exists`. `in` requires equality to at least one of the elements in an array,
|
|
1113
|
+
and `exists` requires any value besides `undefined`.
|
|
1114
|
+
|
|
1115
|
+
If the `path` points to an array, the value is expected to be one of the values
|
|
1116
|
+
in the array.
|
|
1015
1117
|
|
|
1016
|
-
|
|
1017
|
-
the array.
|
|
1118
|
+
Set `not` to `true` to reverse the result of the comparison.
|
|
1018
1119
|
|
|
1019
1120
|
Here's an example where only data where role is set to 'admin' will be kept:
|
|
1020
1121
|
|
|
@@ -1043,6 +1144,9 @@ const def19o = [
|
|
|
1043
1144
|
]
|
|
1044
1145
|
```
|
|
1045
1146
|
|
|
1147
|
+
When you define the `compare` function as a transform object in JSON and need to
|
|
1148
|
+
compare to `undefined`, use `**undefined**` instead.
|
|
1149
|
+
|
|
1046
1150
|
#### `explode()` function
|
|
1047
1151
|
|
|
1048
1152
|
Given an object, the `explode` helper function will return an array with one
|
|
@@ -1081,6 +1185,13 @@ Or as a transform object:
|
|
|
1081
1185
|
const def32o = ['currencies', { $transform: 'explode' }]
|
|
1082
1186
|
```
|
|
1083
1187
|
|
|
1188
|
+
#### `implode()` function
|
|
1189
|
+
|
|
1190
|
+
This is the exact opposite of the `explode` helper, imploding from a service and
|
|
1191
|
+
explode in reverse (to a service). See
|
|
1192
|
+
[the documentation for `explode()`](#explode-function), but remember that the
|
|
1193
|
+
directions will be reversed for `implode()`.
|
|
1194
|
+
|
|
1084
1195
|
#### `map(dictionary)` function
|
|
1085
1196
|
|
|
1086
1197
|
This helper function accepts a dictionary described as an array of tuples, where
|
|
@@ -1096,7 +1207,8 @@ is returned instead.
|
|
|
1096
1207
|
|
|
1097
1208
|
The `map` function only supports primitive values, so any object will be mapped to
|
|
1098
1209
|
`undefined` or the value given by the wildcard in the dictionary. Arrays will be
|
|
1099
|
-
iterated to map each value in the array.
|
|
1210
|
+
iterated to map each value in the array. To map to or from `undefined` with a
|
|
1211
|
+
dictionary defined in JSON, use the value `**undefined**`.
|
|
1100
1212
|
|
|
1101
1213
|
Example:
|
|
1102
1214
|
|
|
@@ -1115,7 +1227,7 @@ const def28 = {
|
|
|
1115
1227
|
}
|
|
1116
1228
|
```
|
|
1117
1229
|
|
|
1118
|
-
When using `map` in an operation object, you may
|
|
1230
|
+
When using `map` in an operation object, you may provide a dictionary array
|
|
1119
1231
|
or a named dictionary on the `dictionary` property. An example of with a named
|
|
1120
1232
|
dictionary:
|
|
1121
1233
|
|
|
@@ -1138,6 +1250,40 @@ const def29 = {
|
|
|
1138
1250
|
const mapper = mapTransform(def29, { dictionaries: { statusCodes: dictionary } })
|
|
1139
1251
|
```
|
|
1140
1252
|
|
|
1253
|
+
#### `sort({asc, path})` function
|
|
1254
|
+
|
|
1255
|
+
The `sort` helper function will sort the given array of items in ascending or
|
|
1256
|
+
descending (depending on whether `asc` is `true` or `false`). Ascending is the
|
|
1257
|
+
default. When a `path` is given, the sort is performed on the value at that path
|
|
1258
|
+
on each object in the array. With no `path`, the values in the array are sorted
|
|
1259
|
+
directly.
|
|
1260
|
+
|
|
1261
|
+
Example:
|
|
1262
|
+
|
|
1263
|
+
```javascript
|
|
1264
|
+
import { mapTransform, transform, functions } from 'map-transform'
|
|
1265
|
+
const { sort } = functions
|
|
1266
|
+
|
|
1267
|
+
const data = {
|
|
1268
|
+
items: [{ id: 'ent5' }, { id: 'ent1' }, { id: 'ent3' }],
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
const def35 = {
|
|
1272
|
+
data: ['items', transform(sort({ asc: true, path: 'id' }))],
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
const ret = mapTransform(def35)(data)
|
|
1276
|
+
// --> { caption: 'Bergen by night. By John F.' }
|
|
1277
|
+
```
|
|
1278
|
+
|
|
1279
|
+
The `sort` function is also available through a transform object:
|
|
1280
|
+
|
|
1281
|
+
```javascript
|
|
1282
|
+
const def35o = {
|
|
1283
|
+
data: ['items', { $transform: 'sort', asc: true, path: 'id' }],
|
|
1284
|
+
}
|
|
1285
|
+
```
|
|
1286
|
+
|
|
1141
1287
|
#### `template(template)` function
|
|
1142
1288
|
|
|
1143
1289
|
The `template` helper function takes a [handlebars] template and applies the
|
|
@@ -4,6 +4,7 @@ interface CompareOperands extends Operands {
|
|
|
4
4
|
operator?: string;
|
|
5
5
|
match?: unknown;
|
|
6
6
|
matchPath?: Path;
|
|
7
|
+
not?: boolean;
|
|
7
8
|
}
|
|
8
|
-
export default function compare({ path, operator, match, matchPath, }: CompareOperands): DataMapper;
|
|
9
|
+
export default function compare({ path, operator, match, matchPath, not, }: CompareOperands): DataMapper;
|
|
9
10
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mapAny = require("map-any");
|
|
3
4
|
const pathGetter_1 = require("../utils/pathGetter");
|
|
5
|
+
const escape_1 = require("../utils/escape");
|
|
4
6
|
const not = (comparer) => (value, match) => !comparer(value, match);
|
|
5
7
|
const compareArrayOrValue = (comparer) => (value, match) => Array.isArray(value)
|
|
6
8
|
? value.some((value) => comparer(value, match))
|
|
@@ -8,6 +10,10 @@ const compareArrayOrValue = (comparer) => (value, match) => Array.isArray(value)
|
|
|
8
10
|
const isNumeric = (value) => typeof value === 'number';
|
|
9
11
|
const compareArrayOrValueNumeric = (comparer) => compareArrayOrValue((value, match) => isNumeric(value) && isNumeric(match) && comparer(value, match));
|
|
10
12
|
const compareEqual = compareArrayOrValue((value, match) => value === match);
|
|
13
|
+
const compareIn = (value, match) => Array.isArray(match)
|
|
14
|
+
? match.some((item) => compareEqual(value, item))
|
|
15
|
+
: compareEqual(value, match);
|
|
16
|
+
const exists = (value) => value !== undefined;
|
|
11
17
|
function createComparer(operator) {
|
|
12
18
|
switch (operator) {
|
|
13
19
|
case '=':
|
|
@@ -22,18 +28,28 @@ function createComparer(operator) {
|
|
|
22
28
|
return compareArrayOrValueNumeric((value, match) => value < match);
|
|
23
29
|
case '<=':
|
|
24
30
|
return compareArrayOrValueNumeric((value, match) => value <= match);
|
|
31
|
+
case 'in':
|
|
32
|
+
return compareIn;
|
|
33
|
+
case 'exists':
|
|
34
|
+
return exists;
|
|
25
35
|
default:
|
|
26
36
|
return (_value, _match) => false;
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
|
-
function compare({ path = '.', operator = '=', match, matchPath, }) {
|
|
39
|
+
function compare({ path = '.', operator = '=', match, matchPath, not = false, }) {
|
|
30
40
|
const getValue = (0, pathGetter_1.default)(path);
|
|
31
|
-
const
|
|
41
|
+
const useRoot = typeof matchPath === 'string' && matchPath[0] === '^';
|
|
42
|
+
const realMatchPath = useRoot ? matchPath.slice(1) : matchPath;
|
|
43
|
+
const realMatchValue = mapAny(escape_1.unescapeValue, match);
|
|
44
|
+
const getMatch = typeof realMatchPath === 'string'
|
|
45
|
+
? (0, pathGetter_1.default)(realMatchPath)
|
|
46
|
+
: () => realMatchValue;
|
|
32
47
|
const comparer = createComparer(operator);
|
|
33
|
-
return (data) => {
|
|
48
|
+
return (data, state) => {
|
|
34
49
|
const value = getValue(data);
|
|
35
|
-
const match = getMatch(data);
|
|
36
|
-
|
|
50
|
+
const match = getMatch(useRoot ? state.root : data);
|
|
51
|
+
const result = comparer(value, match);
|
|
52
|
+
return not ? !result : result;
|
|
37
53
|
};
|
|
38
54
|
}
|
|
39
55
|
exports.default = compare;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/functions/compare.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/functions/compare.ts"],"names":[],"mappings":";;AA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AS,CAAA;IAC9D,MAAM,cAAc,GAAG,MAAM,CAAC,sBAAa,EAAE,KAAK,CAAC,CAAA;IACnD,MAAM,QAAQ,GACZ,OAAO,aAAa,KAAK,QAAQ;QAC/B,CAAC,CAAC,IAAA,oBAAM,EAAC,aAAa,CAAC;QACvB,CAAC,CAAC,GAAG,EAAE,CAAC,cAAc,CAAA;IAC1B,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;IAEzC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACrB,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC5B,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACnD,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACrC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAA;IAC/B,CAAC,CAAA;AACH,CAAC;AAvBD,0BAuBC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.implode = exports.explode = void 0;
|
|
3
4
|
const is_1 = require("../utils/is");
|
|
4
|
-
const isExplodedArray = (data) => data.
|
|
5
|
+
const isExplodedArray = (data) => data.length > 0 &&
|
|
6
|
+
data.every((item) => (0, is_1.isObject)(item) && typeof item.key === 'number');
|
|
5
7
|
const setValueOnKey = (target, keyValue) => {
|
|
6
8
|
if ((0, is_1.isObject)(keyValue)) {
|
|
7
9
|
const { key, value } = keyValue;
|
|
@@ -26,7 +28,9 @@ function doImplode(data) {
|
|
|
26
28
|
}
|
|
27
29
|
function doExplode(data) {
|
|
28
30
|
if ((0, is_1.isObject)(data)) {
|
|
29
|
-
return Object.entries(data)
|
|
31
|
+
return Object.entries(data)
|
|
32
|
+
.filter(([, value]) => value !== undefined)
|
|
33
|
+
.map(([key, value]) => ({
|
|
30
34
|
key,
|
|
31
35
|
value,
|
|
32
36
|
}));
|
|
@@ -39,7 +43,11 @@ function doExplode(data) {
|
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
function explode() {
|
|
42
|
-
return (data,
|
|
46
|
+
return (data, state) => (state.rev ? doImplode(data) : doExplode(data));
|
|
43
47
|
}
|
|
44
|
-
exports.
|
|
48
|
+
exports.explode = explode;
|
|
49
|
+
function implode() {
|
|
50
|
+
return (data, state) => (state.rev ? doExplode(data) : doImplode(data));
|
|
51
|
+
}
|
|
52
|
+
exports.implode = implode;
|
|
45
53
|
//# sourceMappingURL=explode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explode.js","sourceRoot":"","sources":["../../src/functions/explode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explode.js","sourceRoot":"","sources":["../../src/functions/explode.ts"],"names":[],"mappings":";;;AAEA,oCAAsC;AAOtC,MAAM,eAAe,GAAG,CAAC,IAAe,EAAE,EAAE,CAC1C,IAAI,CAAC,MAAM,GAAG,CAAC;IACf,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,aAAQ,EAAC,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAA;AAEtE,MAAM,aAAa,GAAG,CACpB,MAA2C,EAC3C,QAAiB,EACjB,EAAE;IACF,IAAI,IAAA,aAAQ,EAAC,QAAQ,CAAC,EAAE;QACtB,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAA;QAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzB,MAAM,CAAC,GAAa,CAAC,GAAG,KAAK,CAAA;SAC9B;aAAM;YACL,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,KAA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AAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;AACzE,CAAC;AAFD,0BAEC"}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { value, fixed } from './value';
|
|
2
2
|
import compare from './compare';
|
|
3
|
-
import explode from './explode';
|
|
3
|
+
import { explode, implode } from './explode';
|
|
4
4
|
import get from './get';
|
|
5
5
|
import { join, split } from './joinSplit';
|
|
6
|
+
import logical from './logical';
|
|
6
7
|
import map from './map';
|
|
8
|
+
import sort from './sort';
|
|
7
9
|
import template from './template';
|
|
8
10
|
declare const _default: {
|
|
9
11
|
compare: typeof compare;
|
|
10
12
|
explode: typeof explode;
|
|
11
13
|
fixed: typeof fixed;
|
|
12
14
|
get: typeof get;
|
|
15
|
+
implode: typeof implode;
|
|
13
16
|
join: typeof join;
|
|
17
|
+
logical: typeof logical;
|
|
14
18
|
map: typeof map;
|
|
19
|
+
sort: typeof sort;
|
|
15
20
|
split: typeof split;
|
|
16
21
|
template: typeof template;
|
|
17
22
|
value: typeof value;
|
package/dist/functions/index.js
CHANGED
|
@@ -5,15 +5,20 @@ const compare_1 = require("./compare");
|
|
|
5
5
|
const explode_1 = require("./explode");
|
|
6
6
|
const get_1 = require("./get");
|
|
7
7
|
const joinSplit_1 = require("./joinSplit");
|
|
8
|
+
const logical_1 = require("./logical");
|
|
8
9
|
const map_1 = require("./map");
|
|
10
|
+
const sort_1 = require("./sort");
|
|
9
11
|
const template_1 = require("./template");
|
|
10
12
|
exports.default = {
|
|
11
13
|
compare: compare_1.default,
|
|
12
|
-
explode: explode_1.
|
|
14
|
+
explode: explode_1.explode,
|
|
13
15
|
fixed: value_1.fixed,
|
|
14
16
|
get: get_1.default,
|
|
17
|
+
implode: explode_1.implode,
|
|
15
18
|
join: joinSplit_1.join,
|
|
19
|
+
logical: logical_1.default,
|
|
16
20
|
map: map_1.default,
|
|
21
|
+
sort: sort_1.default,
|
|
17
22
|
split: joinSplit_1.split,
|
|
18
23
|
template: template_1.default,
|
|
19
24
|
value: value_1.value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;AAAA,mCAAsC;AACtC,uCAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;AAAA,mCAAsC;AACtC,uCAA+B;AAC/B,uCAA4C;AAC5C,+BAAuB;AACvB,2CAAyC;AACzC,uCAA+B;AAC/B,+BAAuB;AACvB,iCAAyB;AACzB,yCAAiC;AAEjC,kBAAe;IACb,OAAO,EAAP,iBAAO;IACP,OAAO,EAAP,iBAAO;IACP,KAAK,EAAL,aAAK;IACL,GAAG,EAAH,aAAG;IACH,OAAO,EAAP,iBAAO;IACP,IAAI,EAAJ,gBAAI;IACJ,OAAO,EAAP,iBAAO;IACP,GAAG,EAAH,aAAG;IACH,IAAI,EAAJ,cAAI;IACJ,KAAK,EAAL,iBAAK;IACL,QAAQ,EAAR,kBAAQ;IACR,KAAK,EAAL,aAAK;CACN,CAAA"}
|
|
@@ -5,16 +5,15 @@ const pathGetter_1 = require("../utils/pathGetter");
|
|
|
5
5
|
const pathSetter_1 = require("../utils/pathSetter");
|
|
6
6
|
function joinSplit({ path = [], sep = ' ' }, split) {
|
|
7
7
|
const pathArr = [].concat(path);
|
|
8
|
+
if (pathArr.length === 0) {
|
|
9
|
+
return (_data, _context) => undefined;
|
|
10
|
+
}
|
|
8
11
|
const getFns = pathArr.map(pathGetter_1.default);
|
|
9
12
|
const setFns = pathArr.map(pathSetter_1.default);
|
|
10
13
|
return (data, { rev }) => {
|
|
11
14
|
if (split ? !rev : rev) {
|
|
12
15
|
const values = typeof data === 'string' ? data.split(sep) : [];
|
|
13
|
-
|
|
14
|
-
setFns.forEach((setFn, index) => {
|
|
15
|
-
ret = setFn(values[index], ret);
|
|
16
|
-
});
|
|
17
|
-
return ret;
|
|
16
|
+
return setFns.reduce((obj, setFn, index) => setFn(values[index], obj), undefined);
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
20
19
|
const values = getFns.map((fn) => fn(data));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joinSplit.js","sourceRoot":"","sources":["../../src/functions/joinSplit.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"joinSplit.js","sourceRoot":"","sources":["../../src/functions/joinSplit.ts"],"names":[],"mappings":";;;AAEA,oDAAwC;AACxC,oDAAwC;AAOxC,SAAS,SAAS,CAChB,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,GAAG,GAAG,EAAW,EACjC,KAAc;IAEd,MAAM,OAAO,GAAI,EAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAA;KACtC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,CAAA;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,CAAA;IAElC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QACvB,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE;YACtB,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;YAC9D,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,GAAY,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,EACzD,SAAS,CACV,CAAA;SACF;aAAM;YACL,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;YAC3C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;SAC/D;IACH,CAAC,CAAA;AACH,CAAC;AAED,SAAgB,IAAI,CAAC,OAAgB;IACnC,OAAO,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AAClC,CAAC;AAFD,oBAEC;AAED,SAAgB,KAAK,CAAC,OAAgB;IACpC,OAAO,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACjC,CAAC;AAFD,sBAEC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pathGetter_1 = require("../utils/pathGetter");
|
|
4
|
+
const pathSetter_1 = require("../utils/pathSetter");
|
|
5
|
+
function compare({ path = '.', operator = 'AND', }) {
|
|
6
|
+
const pathArr = [].concat(path);
|
|
7
|
+
const getFns = pathArr.map(pathGetter_1.default);
|
|
8
|
+
const setFns = pathArr.map(pathSetter_1.default);
|
|
9
|
+
const logicalOp = operator === 'OR'
|
|
10
|
+
? (a, b) => Boolean(a) || Boolean(b)
|
|
11
|
+
: (a, b) => Boolean(a) && Boolean(b);
|
|
12
|
+
return (data, { rev }) => {
|
|
13
|
+
if (rev) {
|
|
14
|
+
const value = Boolean(data);
|
|
15
|
+
return setFns.reduce((obj, setFn) => setFn(value, obj), undefined);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const values = getFns.map((fn) => fn(data));
|
|
19
|
+
return values.reduce(logicalOp);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.default = compare;
|
|
24
|
+
//# sourceMappingURL=logical.js.map
|
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,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const mapAny = require("map-any");
|
|
4
|
+
const escape_1 = require("../utils/escape");
|
|
4
5
|
const isSupportedValue = (data) => ['string', 'number', 'boolean'].includes(typeof data) ||
|
|
5
6
|
data === null ||
|
|
6
7
|
data === undefined;
|
|
@@ -33,10 +34,10 @@ function map(operands, options) {
|
|
|
33
34
|
if (!dictionary) {
|
|
34
35
|
return () => undefined;
|
|
35
36
|
}
|
|
36
|
-
return (data,
|
|
37
|
-
const { rev } =
|
|
38
|
-
const match = translate(data, dictionary, rev);
|
|
39
|
-
return match === '*' ? data : match;
|
|
37
|
+
return (data, state) => {
|
|
38
|
+
const { rev = false } = state;
|
|
39
|
+
const match = translate((0, escape_1.escapeValue)(data), dictionary, rev);
|
|
40
|
+
return match === '*' ? data : (0, escape_1.unescapeValue)(match);
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
exports.default = map;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/functions/map.ts"],"names":[],"mappings":";;AAAA,kCAAkC;
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/functions/map.ts"],"names":[],"mappings":";;AAAA,kCAAkC;AAClC,4CAA4D;AAO5D,MAAM,gBAAgB,GAAG,CAAC,IAAa,EAA2B,EAAE,CAClE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC;IACrD,IAAI,KAAK,IAAI;IACb,IAAI,KAAK,SAAS,CAAA;AAEpB,SAAS,cAAc,CACrB,KAAsB,EACtB,UAAsB,EACtB,SAAgB;IAGhB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,KAAK,CAAC,CAAA;IAClE,OAAO,KAA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,GAAG,KAAK,EAAE,GAAG,KAAK,CAAA;QAC7B,MAAM,KAAK,GAAG,SAAS,CAAC,IAAA,oBAAW,EAAC,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;QAC3D,OAAO,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,sBAAa,EAAC,KAAK,CAAC,CAAA;IACpD,CAAC,CAAA;AACH,CAAC;AAhBD,sBAgBC"}
|
package/dist/functions/not.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not.js","sourceRoot":"","sources":["../../src/functions/not.ts"],"names":[],"mappings":";;AAEA,SAAwB,GAAG,CAAC,EAAc;IACxC,OAAO,CAAC,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"not.js","sourceRoot":"","sources":["../../src/functions/not.ts"],"names":[],"mappings":";;AAEA,SAAwB,GAAG,CAAC,EAAc;IACxC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC5C,CAAC;AAFD,sBAEC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pathGetter_1 = require("../utils/pathGetter");
|
|
4
|
+
const functional_1 = require("../utils/functional");
|
|
5
|
+
const compare = (direction, getFn) => function compare(valueA, valueB) {
|
|
6
|
+
const a = getFn(valueA);
|
|
7
|
+
const b = getFn(valueB);
|
|
8
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
9
|
+
return (a - b) * direction;
|
|
10
|
+
}
|
|
11
|
+
else if (a instanceof Date && b instanceof Date) {
|
|
12
|
+
return (a.getTime() - b.getTime()) * direction;
|
|
13
|
+
}
|
|
14
|
+
else if (a === undefined || a === null || b === undefined || b === null) {
|
|
15
|
+
return a === undefined || a === null ? 1 : -1;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const strA = String(a);
|
|
19
|
+
const strB = String(b);
|
|
20
|
+
return strA === strB ? 0 : strA > strB ? 1 * direction : -1 * direction;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function template(operands) {
|
|
24
|
+
const direction = operands?.asc === false ? -1 : 1;
|
|
25
|
+
const getFn = operands?.path ? (0, pathGetter_1.default)(operands.path) : functional_1.identity;
|
|
26
|
+
return (data) => {
|
|
27
|
+
return Array.isArray(data)
|
|
28
|
+
? data.slice().sort(compare(direction, getFn))
|
|
29
|
+
: data;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.default = template;
|
|
33
|
+
//# sourceMappingURL=sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.js","sourceRoot":"","sources":["../../src/functions/sort.ts"],"names":[],"mappings":";;AACA,oDAAwC;AACxC,oDAA8C;AAO9C,MAAM,OAAO,GAAG,CAAC,SAAiB,EAAE,KAAiC,EAAE,EAAE,CACvE,SAAS,OAAO,CAAC,MAAe,EAAE,MAAe;IAC/C,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IACvB,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IACvB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;QAClD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAA;KAC3B;SAAM,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,IAAI,EAAE;QACjD,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,SAAS,CAAA;KAC/C;SAAM,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,EAAE;QACzE,OAAO,CAAC,KAAK,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