map-transform 0.4.0-alpha.9 → 0.4.0-beta.1
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 +192 -40
- package/dist/functions/compare.d.ts +2 -1
- package/dist/functions/compare.js +26 -5
- package/dist/functions/compare.js.map +1 -1
- package/dist/functions/explode.js +4 -3
- package/dist/functions/explode.js.map +1 -1
- package/dist/functions/index.d.ts +4 -0
- package/dist/functions/index.js +4 -0
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/indexFn.d.ts +2 -0
- package/dist/functions/indexFn.js +9 -0
- package/dist/functions/indexFn.js.map +1 -0
- package/dist/functions/joinSplit.d.ts +4 -4
- package/dist/functions/joinSplit.js +12 -4
- package/dist/functions/joinSplit.js.map +1 -1
- 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/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 +4 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/operations/alt.d.ts +1 -1
- package/dist/operations/alt.js +28 -6
- package/dist/operations/alt.js.map +1 -1
- package/dist/operations/apply.js +10 -5
- package/dist/operations/apply.js.map +1 -1
- package/dist/operations/concat.js +9 -5
- package/dist/operations/concat.js.map +1 -1
- package/dist/operations/directionals.js +7 -6
- package/dist/operations/directionals.js.map +1 -1
- package/dist/operations/filter.js +5 -6
- package/dist/operations/filter.js.map +1 -1
- package/dist/operations/fixed.js +2 -4
- package/dist/operations/fixed.js.map +1 -1
- package/dist/operations/getSet.d.ts +3 -3
- package/dist/operations/getSet.js +139 -30
- package/dist/operations/getSet.js.map +1 -1
- package/dist/operations/ifelse.d.ts +1 -1
- package/dist/operations/ifelse.js +21 -10
- package/dist/operations/ifelse.js.map +1 -1
- package/dist/operations/iterate.d.ts +2 -1
- package/dist/operations/iterate.js +14 -10
- 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 +9 -5
- package/dist/operations/lookup.js.map +1 -1
- package/dist/operations/merge.js +9 -7
- package/dist/operations/merge.js.map +1 -1
- package/dist/operations/modify.js +13 -6
- package/dist/operations/modify.js.map +1 -1
- package/dist/operations/pipe.js +14 -16
- 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/props.d.ts +2 -0
- package/dist/operations/props.js +114 -0
- package/dist/operations/props.js.map +1 -0
- package/dist/operations/root.js +3 -5
- package/dist/operations/root.js.map +1 -1
- package/dist/operations/transform.js +4 -2
- package/dist/operations/transform.js.map +1 -1
- package/dist/operations/value.js +2 -4
- package/dist/operations/value.js.map +1 -1
- package/dist/types.d.ts +39 -12
- package/dist/utils/array.d.ts +1 -0
- package/dist/utils/array.js +3 -1
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/definitionHelpers.d.ts +3 -1
- package/dist/utils/definitionHelpers.js +72 -17
- 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/is.d.ts +2 -0
- package/dist/utils/is.js +5 -1
- package/dist/utils/is.js.map +1 -1
- package/dist/utils/pathGetter.js +12 -3
- package/dist/utils/pathGetter.js.map +1 -1
- package/dist/utils/pathSetter.d.ts +1 -0
- package/dist/utils/pathSetter.js +16 -6
- package/dist/utils/pathSetter.js.map +1 -1
- package/dist/utils/stateHelpers.d.ts +30 -6
- package/dist/utils/stateHelpers.js +30 -14
- package/dist/utils/stateHelpers.js.map +1 -1
- package/dist/utils/xor.d.ts +1 -0
- package/dist/utils/xor.js +7 -0
- package/dist/utils/xor.js.map +1 -0
- package/package.json +6 -6
- package/ava-dist.config.cjs +0 -3
- package/ava.config.cjs +0 -5
- package/dist/functions/join.d.ts +0 -7
- package/dist/functions/join.js +0 -12
- package/dist/functions/join.js.map +0 -1
- package/dist/operations/mutate.d.ts +0 -2
- package/dist/operations/mutate.js +0 -80
- package/dist/operations/mutate.js.map +0 -1
package/README.md
CHANGED
|
@@ -148,8 +148,8 @@ npm install map-transform --save
|
|
|
148
148
|
- Map objects won't be mapped over an array by default. You have to specify
|
|
149
149
|
`$iterate: true`
|
|
150
150
|
- The `alt` operation now accepts any type of pipeline, but not a helper
|
|
151
|
-
function
|
|
152
|
-
- The root path prefix is changed from `$` to
|
|
151
|
+
function, and all alternative pipelines must be given as arguments to `alt()`
|
|
152
|
+
- The root path prefix is changed from `$` to `^^`
|
|
153
153
|
|
|
154
154
|
## Usage
|
|
155
155
|
|
|
@@ -305,15 +305,18 @@ below.
|
|
|
305
305
|
|
|
306
306
|
MapTransform will treat `undefined` as a value that is not set, and so a
|
|
307
307
|
transform object will not be applied to it. So if an `undefined` value meets
|
|
308
|
-
a transform object, it will produce `undefined`,
|
|
308
|
+
a transform object, it will produce `undefined`, regardless of the shape of the
|
|
309
309
|
transform object.
|
|
310
310
|
|
|
311
311
|
This is not the case for `null`, though. MapTransform treats `null` as a value,
|
|
312
312
|
an intended nothing, and will apply a transform object to it, even though it
|
|
313
313
|
will most likely produce nothing but default values. To change this behavior,
|
|
314
|
-
set `
|
|
315
|
-
will essentially make MapTransform treat `null` the same way
|
|
316
|
-
it
|
|
314
|
+
set `noneValues: [undefined, null]` on the `options` object passed to
|
|
315
|
+
MapTransform. This will essentially make MapTransform treat `null` the same way
|
|
316
|
+
as `undefined` when it meets to the transform object.
|
|
317
|
+
|
|
318
|
+
The example above sets `undefined` and `null` as none-values, but you could in
|
|
319
|
+
principle set any primitive values here.
|
|
317
320
|
|
|
318
321
|
#### Directional transform objects
|
|
319
322
|
|
|
@@ -563,10 +566,10 @@ See the `transform()` operation for more on how defining as an object works.
|
|
|
563
566
|
|
|
564
567
|
#### `ifelse(conditionFn, truePipeline, falsePipeline)` operation
|
|
565
568
|
|
|
566
|
-
The `ifelse()` operation will run the `truePipeline` if the `conditionFn`
|
|
567
|
-
in
|
|
568
|
-
[the `filter()` operation](#filterconditionFn-operation)
|
|
569
|
-
requirements for the `conditionFn`.
|
|
569
|
+
The `ifelse()` operation will run the `truePipeline` if the `conditionFn`
|
|
570
|
+
results in something truthy, JavaScript tstyle, otherwise it will run the
|
|
571
|
+
`falsePipeline`. See [the `filter()` operation](#filterconditionFn-operation)
|
|
572
|
+
for more on the requirements for the `conditionFn`.
|
|
570
573
|
|
|
571
574
|
Both `truePipeline` and `falsePipeline` are optional, in case you only need to
|
|
572
575
|
apply a pipeline in one of the cases.
|
|
@@ -587,6 +590,29 @@ const def31 = [
|
|
|
587
590
|
]
|
|
588
591
|
```
|
|
589
592
|
|
|
593
|
+
Defining an if operation as an object:
|
|
594
|
+
|
|
595
|
+
```javascript
|
|
596
|
+
import { mapTransform } from 'map-transform'
|
|
597
|
+
|
|
598
|
+
const def31b = [
|
|
599
|
+
'members'
|
|
600
|
+
{
|
|
601
|
+
name: 'name',
|
|
602
|
+
active: 'hasPayed'
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
$if: 'active',
|
|
606
|
+
then: set('active[]'),
|
|
607
|
+
else: set('inactive[]')
|
|
608
|
+
}
|
|
609
|
+
]
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
Note that `$if`, `then`, and `else` in the object notation may be any type of
|
|
613
|
+
pipeline definition. The only gotcha is that if `$if` is a function, it is
|
|
614
|
+
treated as a `conditionFn`, like in `def31`, not as a state mapper.
|
|
615
|
+
|
|
590
616
|
#### `iterate(pipeline)` operation
|
|
591
617
|
|
|
592
618
|
If you want something to be mapped over the items of an array, the `iterate`
|
|
@@ -622,6 +648,9 @@ When an id is passed to the apply operation as `pipelinedId`, the pipeline will
|
|
|
622
648
|
be applied in the place of the apply operation and executed as if it was part of
|
|
623
649
|
the pipeline definition in the first place.
|
|
624
650
|
|
|
651
|
+
When no pipeline is provided, e.g. because the id is unknown, no pipeline will
|
|
652
|
+
be applied and the data will pass through untouched.
|
|
653
|
+
|
|
625
654
|
```javascript
|
|
626
655
|
import { mapTransform, apply, transform } from 'map-transform'
|
|
627
656
|
|
|
@@ -690,25 +719,23 @@ import { value, alt } from 'map-transform'
|
|
|
690
719
|
const def10 = {
|
|
691
720
|
id: 'data.customerNo',
|
|
692
721
|
type: value('customer'),
|
|
693
|
-
name:
|
|
722
|
+
name: alt('data.name', value('Anonymous')),
|
|
694
723
|
}
|
|
695
724
|
```
|
|
696
725
|
|
|
697
726
|
The operation will not set anything when mapping with `.onlyMappedValues()`.
|
|
698
727
|
|
|
699
728
|
If you want to define the `value` operation as an operation object, use
|
|
700
|
-
`$transform` or `$
|
|
729
|
+
`$transform` or the short form `$value`:
|
|
701
730
|
|
|
702
731
|
```javascript
|
|
703
732
|
const def10asObject = {
|
|
704
733
|
id: 'data.customerNo',
|
|
705
734
|
type: { $transform: 'value', value: 'customer' },
|
|
706
|
-
name: ['data.name', { $
|
|
735
|
+
name: { $alt: ['data.name', { $value: 'Anonymous' }] },
|
|
707
736
|
}
|
|
708
737
|
```
|
|
709
738
|
|
|
710
|
-
There is also a shortcut for `{ $transform: 'value', value: 'customer' }`: `{ $value: 'customer' }`, which might be useful when typing definitions by hand.
|
|
711
|
-
|
|
712
739
|
#### `fixed(data)` operation
|
|
713
740
|
|
|
714
741
|
The data given to the fixed operation, will be inserted in the pipeline in place
|
|
@@ -720,14 +747,15 @@ will be included when mapping with `.onlyMappedValues()` as well.
|
|
|
720
747
|
|
|
721
748
|
#### `alt(pipeline)` operation
|
|
722
749
|
|
|
723
|
-
The alt operation will apply the
|
|
724
|
-
the pipeline
|
|
725
|
-
|
|
726
|
-
|
|
750
|
+
The alt operation will apply the pipelines in turn until it gets a value,
|
|
751
|
+
meaning that if the first pipeline returns `undefined`, it will try the next and
|
|
752
|
+
so on. This is how you provide default values in MapTransform. The pipeline may
|
|
753
|
+
be as simple as a `value()` operation, a dot notation path into the source data,
|
|
754
|
+
or a full pipeline of several operations.
|
|
727
755
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
756
|
+
Note that when the return value is an array, it is treated as a value, as it is
|
|
757
|
+
not an `undefined` value. To provide the `alt` operation to every item in the
|
|
758
|
+
array, use the `iterate` operation.
|
|
731
759
|
|
|
732
760
|
```javascript
|
|
733
761
|
import { alt, transform, functions } from 'map-transform'
|
|
@@ -739,11 +767,9 @@ const formatDate = (data) => {
|
|
|
739
767
|
|
|
740
768
|
const def11 = {
|
|
741
769
|
id: 'data.id',
|
|
742
|
-
name:
|
|
770
|
+
name: alt('data.name', value('Anonymous')),
|
|
743
771
|
updatedAt: [
|
|
744
|
-
'data.updateDate',
|
|
745
|
-
alt('data.createDate'),
|
|
746
|
-
alt(transform(currentDate)),
|
|
772
|
+
alt('data.updateDate', 'data.createDate', transform(currentDate)),
|
|
747
773
|
transform(formatDate),
|
|
748
774
|
],
|
|
749
775
|
}
|
|
@@ -757,16 +783,24 @@ we still have `undefined`, the second alt will call the customer function
|
|
|
757
783
|
another transform operation pipes whatever data we get from all of this through
|
|
758
784
|
the `formatDate` function.
|
|
759
785
|
|
|
786
|
+
When `alt` is run in reverse, the alternative pipelines are run in the oposite
|
|
787
|
+
order, with the last being run first. The first pipeline is always run, though,
|
|
788
|
+
as it is common practice to let the first be a `get` that acts like a `set` in
|
|
789
|
+
reverse.
|
|
790
|
+
|
|
791
|
+
With only one pipeline, `alt` will behave a bit differently. A single pipeline
|
|
792
|
+
will be run if the state has an `undefined` value, but skipped otherwise. This
|
|
793
|
+
is different from the multi-pipeline behavor, where the first is always run and
|
|
794
|
+
the rest is only run if the previous returns `undefined`.
|
|
795
|
+
|
|
760
796
|
You may also define an alt operation as an object:
|
|
761
797
|
|
|
762
798
|
```javascript
|
|
763
799
|
const def11asObject = {
|
|
764
800
|
id: 'data.id',
|
|
765
|
-
name: ['data.name', { $
|
|
801
|
+
name: { $alt: ['data.name', { $value: 'Anonymous' }] },
|
|
766
802
|
updatedAt: [
|
|
767
|
-
'data.updateDate',
|
|
768
|
-
{ $alt: 'get', path: 'data.createDate' },
|
|
769
|
-
{ $alt: 'currentDate' },
|
|
803
|
+
{ $alt: ['data.updateDate', 'data.createDate', 'currentDate'] },
|
|
770
804
|
{ $transform: 'formatDate' },
|
|
771
805
|
],
|
|
772
806
|
}
|
|
@@ -787,6 +821,12 @@ This operation will always return an array, even when it is given only one
|
|
|
787
821
|
pipeline that does not return an array. Pipelines that does not result in a
|
|
788
822
|
value (i.e. return `undefined`) will be filtered away.
|
|
789
823
|
|
|
824
|
+
```javascript
|
|
825
|
+
{
|
|
826
|
+
$concat: ['data.users', 'data.admins']
|
|
827
|
+
}
|
|
828
|
+
```
|
|
829
|
+
|
|
790
830
|
#### `merge(pipeline, pipeline, ...)` operation
|
|
791
831
|
|
|
792
832
|
`merge()` will run all given pipelines and deep merge their results. Conflicts
|
|
@@ -830,6 +870,27 @@ const response = {
|
|
|
830
870
|
Had we ran this without the `modify()` operation, the returned object would only
|
|
831
871
|
have the `data` prop.
|
|
832
872
|
|
|
873
|
+
This is equivalent to setting the `$modify` property to `true` on the object
|
|
874
|
+
mutation object:
|
|
875
|
+
|
|
876
|
+
```javascript
|
|
877
|
+
const def34b = {
|
|
878
|
+
$modify: true,
|
|
879
|
+
data: 'data.deeply.placed.items',
|
|
880
|
+
}
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
Note that `$modify` may also be set further down in the object structure. Also,
|
|
884
|
+
in some cases it may make more sense to specify a path in the source data to
|
|
885
|
+
merge with:
|
|
886
|
+
|
|
887
|
+
```javascript
|
|
888
|
+
const def34c = {
|
|
889
|
+
$modify: 'response',
|
|
890
|
+
data: 'response.data.deeply.placed.items',
|
|
891
|
+
}
|
|
892
|
+
```
|
|
893
|
+
|
|
833
894
|
#### `fwd(pipeline)` and `rev(pipeline)` operation
|
|
834
895
|
|
|
835
896
|
All operations in MapTransform will apply in both directions, although some of
|
|
@@ -1010,7 +1071,51 @@ mapper.rev(mappedData)
|
|
|
1010
1071
|
// --> { content: { meta: { authors: ['user1', 'user3'] } } }
|
|
1011
1072
|
```
|
|
1012
1073
|
|
|
1013
|
-
|
|
1074
|
+
You may also define this as a transform object:
|
|
1075
|
+
|
|
1076
|
+
```javascript
|
|
1077
|
+
const def18o = ['content.meta.authors[]', { $lookup: '$users[]', path: 'id' }]
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
#### `and(pipeline, pipeline, ...)` operation
|
|
1081
|
+
|
|
1082
|
+
Will run all provided pipelines, force their return values to boolean, according
|
|
1083
|
+
to JavaScript rules, and return `true` if they are all `true`, otherwise
|
|
1084
|
+
`false`.
|
|
1085
|
+
|
|
1086
|
+
Typically used together with [`ifelse` operation](#ifelseconditionFn-truePipeline-falsePipeline-operation),
|
|
1087
|
+
to support AND logic:
|
|
1088
|
+
|
|
1089
|
+
```javascript
|
|
1090
|
+
const def36 = [
|
|
1091
|
+
{
|
|
1092
|
+
$if: { $and: ['active', 'authorized'] },
|
|
1093
|
+
then: 'content',
|
|
1094
|
+
else: { $value: undefined },
|
|
1095
|
+
},
|
|
1096
|
+
]
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
#### `or(pipeline, pipeline, ...)` operation
|
|
1100
|
+
|
|
1101
|
+
Will run all provided pipelines, force their return values to boolean, according
|
|
1102
|
+
to JavaScript rules, and return `true` if any of the are `true`, otherwise
|
|
1103
|
+
`false`.
|
|
1104
|
+
|
|
1105
|
+
Typically used together with [`ifelse` operation](#ifelseconditionFn-truePipeline-falsePipeline-operation),
|
|
1106
|
+
to support OR logic:
|
|
1107
|
+
|
|
1108
|
+
```javascript
|
|
1109
|
+
const def37 = [
|
|
1110
|
+
{
|
|
1111
|
+
$if: { $or: ['active', 'draft'] },
|
|
1112
|
+
then: 'content',
|
|
1113
|
+
else: { $value: undefined },
|
|
1114
|
+
},
|
|
1115
|
+
]
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
#### `compare({ path, operator, match, matchPath, not })` function
|
|
1014
1119
|
|
|
1015
1120
|
This is a helper function intended for use with the `filter()` operation. You
|
|
1016
1121
|
pass a dot notation `path` and a `match` value (string, number, boolean) to
|
|
@@ -1023,10 +1128,14 @@ data.
|
|
|
1023
1128
|
|
|
1024
1129
|
The default is to compare the values resulting from `path` and `match` or
|
|
1025
1130
|
`matchPath` with equality, but other operations may be set on the `operator`
|
|
1026
|
-
property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='
|
|
1131
|
+
property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='`, `in`, or
|
|
1132
|
+
`exists`. `in` requires equality to at least one of the elements in an array,
|
|
1133
|
+
and `exists` requires any value besides `undefined`.
|
|
1134
|
+
|
|
1135
|
+
If the `path` points to an array, the value is expected to be one of the values
|
|
1136
|
+
in the array.
|
|
1027
1137
|
|
|
1028
|
-
|
|
1029
|
-
the array.
|
|
1138
|
+
Set `not` to `true` to reverse the result of the comparison.
|
|
1030
1139
|
|
|
1031
1140
|
Here's an example where only data where role is set to 'admin' will be kept:
|
|
1032
1141
|
|
|
@@ -1055,6 +1164,9 @@ const def19o = [
|
|
|
1055
1164
|
]
|
|
1056
1165
|
```
|
|
1057
1166
|
|
|
1167
|
+
When you define the `compare` function as a transform object in JSON and need to
|
|
1168
|
+
compare to `undefined`, use `**undefined**` instead.
|
|
1169
|
+
|
|
1058
1170
|
#### `explode()` function
|
|
1059
1171
|
|
|
1060
1172
|
Given an object, the `explode` helper function will return an array with one
|
|
@@ -1093,6 +1205,11 @@ Or as a transform object:
|
|
|
1093
1205
|
const def32o = ['currencies', { $transform: 'explode' }]
|
|
1094
1206
|
```
|
|
1095
1207
|
|
|
1208
|
+
### `index()` function
|
|
1209
|
+
|
|
1210
|
+
When iterating, this will return the index of the current item in the array.
|
|
1211
|
+
When used outside of an iteration, it always returns `0`.
|
|
1212
|
+
|
|
1096
1213
|
#### `implode()` function
|
|
1097
1214
|
|
|
1098
1215
|
This is the exact opposite of the `explode` helper, imploding from a service and
|
|
@@ -1115,7 +1232,8 @@ is returned instead.
|
|
|
1115
1232
|
|
|
1116
1233
|
The `map` function only supports primitive values, so any object will be mapped to
|
|
1117
1234
|
`undefined` or the value given by the wildcard in the dictionary. Arrays will be
|
|
1118
|
-
iterated to map each value in the array.
|
|
1235
|
+
iterated to map each value in the array. To map to or from `undefined` with a
|
|
1236
|
+
dictionary defined in JSON, use the value `**undefined**`.
|
|
1119
1237
|
|
|
1120
1238
|
Example:
|
|
1121
1239
|
|
|
@@ -1134,7 +1252,7 @@ const def28 = {
|
|
|
1134
1252
|
}
|
|
1135
1253
|
```
|
|
1136
1254
|
|
|
1137
|
-
When using `map` in an operation object, you may
|
|
1255
|
+
When using `map` in an operation object, you may provide a dictionary array
|
|
1138
1256
|
or a named dictionary on the `dictionary` property. An example of with a named
|
|
1139
1257
|
dictionary:
|
|
1140
1258
|
|
|
@@ -1157,6 +1275,40 @@ const def29 = {
|
|
|
1157
1275
|
const mapper = mapTransform(def29, { dictionaries: { statusCodes: dictionary } })
|
|
1158
1276
|
```
|
|
1159
1277
|
|
|
1278
|
+
#### `sort({asc, path})` function
|
|
1279
|
+
|
|
1280
|
+
The `sort` helper function will sort the given array of items in ascending or
|
|
1281
|
+
descending (depending on whether `asc` is `true` or `false`). Ascending is the
|
|
1282
|
+
default. When a `path` is given, the sort is performed on the value at that path
|
|
1283
|
+
on each object in the array. With no `path`, the values in the array are sorted
|
|
1284
|
+
directly.
|
|
1285
|
+
|
|
1286
|
+
Example:
|
|
1287
|
+
|
|
1288
|
+
```javascript
|
|
1289
|
+
import { mapTransform, transform, functions } from 'map-transform'
|
|
1290
|
+
const { sort } = functions
|
|
1291
|
+
|
|
1292
|
+
const data = {
|
|
1293
|
+
items: [{ id: 'ent5' }, { id: 'ent1' }, { id: 'ent3' }],
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
const def35 = {
|
|
1297
|
+
data: ['items', transform(sort({ asc: true, path: 'id' }))],
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
const ret = mapTransform(def35)(data)
|
|
1301
|
+
// --> { caption: 'Bergen by night. By John F.' }
|
|
1302
|
+
```
|
|
1303
|
+
|
|
1304
|
+
The `sort` function is also available through a transform object:
|
|
1305
|
+
|
|
1306
|
+
```javascript
|
|
1307
|
+
const def35o = {
|
|
1308
|
+
data: ['items', { $transform: 'sort', asc: true, path: 'id' }],
|
|
1309
|
+
}
|
|
1310
|
+
```
|
|
1311
|
+
|
|
1160
1312
|
#### `template(template)` function
|
|
1161
1313
|
|
|
1162
1314
|
The `template` helper function takes a [handlebars] template and applies the
|
|
@@ -1268,7 +1420,7 @@ const def22 = [
|
|
|
1268
1420
|
'data.customers[]',
|
|
1269
1421
|
{
|
|
1270
1422
|
id: 'customerNo',
|
|
1271
|
-
name: ['fullname',
|
|
1423
|
+
name: [alt('fullname', value('Anonymous'))],
|
|
1272
1424
|
},
|
|
1273
1425
|
]
|
|
1274
1426
|
|
|
@@ -1382,8 +1534,8 @@ same goes for flipped transform objects if you want to forward transform.
|
|
|
1382
1534
|
|
|
1383
1535
|
MapTransform will try its best to map the data it gets to the state you want,
|
|
1384
1536
|
and will always set all properties, even though the mapping you defined result
|
|
1385
|
-
in `undefined`. You may include `alt()` operations to provide default or
|
|
1386
|
-
values for these cases.
|
|
1537
|
+
in `undefined`. You may include `alt()` operations to provide default or
|
|
1538
|
+
fallback values for these cases.
|
|
1387
1539
|
|
|
1388
1540
|
But sometimes, you want just the data that is actually present in the source
|
|
1389
1541
|
data, without defaults or properties set to `undefined`. MapTransform's
|
|
@@ -1399,7 +1551,7 @@ import { mapTransform, alt, value } from 'map-transform'
|
|
|
1399
1551
|
|
|
1400
1552
|
const def24 = {
|
|
1401
1553
|
id: 'customerNo',
|
|
1402
|
-
name:
|
|
1554
|
+
name: alt('fullname', value('Anonymous')),
|
|
1403
1555
|
}
|
|
1404
1556
|
|
|
1405
1557
|
const mapper = mapTransform(def24)
|
|
@@ -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,9 @@
|
|
|
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");
|
|
6
|
+
const stateHelpers_1 = require("../utils/stateHelpers");
|
|
4
7
|
const not = (comparer) => (value, match) => !comparer(value, match);
|
|
5
8
|
const compareArrayOrValue = (comparer) => (value, match) => Array.isArray(value)
|
|
6
9
|
? value.some((value) => comparer(value, match))
|
|
@@ -8,6 +11,10 @@ const compareArrayOrValue = (comparer) => (value, match) => Array.isArray(value)
|
|
|
8
11
|
const isNumeric = (value) => typeof value === 'number';
|
|
9
12
|
const compareArrayOrValueNumeric = (comparer) => compareArrayOrValue((value, match) => isNumeric(value) && isNumeric(match) && comparer(value, match));
|
|
10
13
|
const compareEqual = compareArrayOrValue((value, match) => value === match);
|
|
14
|
+
const compareIn = (value, match) => Array.isArray(match)
|
|
15
|
+
? match.some((item) => compareEqual(value, item))
|
|
16
|
+
: compareEqual(value, match);
|
|
17
|
+
const exists = (value) => value !== undefined;
|
|
11
18
|
function createComparer(operator) {
|
|
12
19
|
switch (operator) {
|
|
13
20
|
case '=':
|
|
@@ -22,18 +29,32 @@ function createComparer(operator) {
|
|
|
22
29
|
return compareArrayOrValueNumeric((value, match) => value < match);
|
|
23
30
|
case '<=':
|
|
24
31
|
return compareArrayOrValueNumeric((value, match) => value <= match);
|
|
32
|
+
case 'in':
|
|
33
|
+
return compareIn;
|
|
34
|
+
case 'exists':
|
|
35
|
+
return exists;
|
|
25
36
|
default:
|
|
26
37
|
return (_value, _match) => false;
|
|
27
38
|
}
|
|
28
39
|
}
|
|
29
|
-
function compare({ path = '.', operator = '=', match, matchPath, }) {
|
|
40
|
+
function compare({ path = '.', operator = '=', match, matchPath, not = false, }) {
|
|
30
41
|
const getValue = (0, pathGetter_1.default)(path);
|
|
31
|
-
const
|
|
42
|
+
const useRoot = typeof matchPath === 'string' &&
|
|
43
|
+
matchPath[0] === '^' &&
|
|
44
|
+
matchPath[1] !== '.';
|
|
45
|
+
const realMatchPath = useRoot
|
|
46
|
+
? matchPath.slice(matchPath[1] === '^' ? 2 : 1)
|
|
47
|
+
: matchPath;
|
|
48
|
+
const realMatchValue = mapAny(escape_1.unescapeValue, match);
|
|
49
|
+
const getMatch = typeof realMatchPath === 'string'
|
|
50
|
+
? (0, pathGetter_1.default)(realMatchPath)
|
|
51
|
+
: () => realMatchValue;
|
|
32
52
|
const comparer = createComparer(operator);
|
|
33
|
-
return (data) => {
|
|
53
|
+
return (data, state) => {
|
|
34
54
|
const value = getValue(data);
|
|
35
|
-
const match = getMatch(data);
|
|
36
|
-
|
|
55
|
+
const match = getMatch(useRoot ? (0, stateHelpers_1.getRootFromState)(state) : data);
|
|
56
|
+
const result = comparer(value, match);
|
|
57
|
+
return not ? !result : result;
|
|
37
58
|
};
|
|
38
59
|
}
|
|
39
60
|
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":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,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,SAAS,CAAA;IACb,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,IAAA,+BAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAChE,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;AA5BD,0BA4BC"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.implode = exports.explode = void 0;
|
|
4
4
|
const is_1 = require("../utils/is");
|
|
5
|
-
const isExplodedArray = (data) => data.
|
|
5
|
+
const isExplodedArray = (data) => data.length > 0 &&
|
|
6
|
+
data.every((item) => (0, is_1.isObject)(item) && typeof item.key === 'number');
|
|
6
7
|
const setValueOnKey = (target, keyValue) => {
|
|
7
8
|
if ((0, is_1.isObject)(keyValue)) {
|
|
8
9
|
const { key, value } = keyValue;
|
|
@@ -42,11 +43,11 @@ function doExplode(data) {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
function explode() {
|
|
45
|
-
return (data,
|
|
46
|
+
return (data, state) => (state.rev ? doImplode(data) : doExplode(data));
|
|
46
47
|
}
|
|
47
48
|
exports.explode = explode;
|
|
48
49
|
function implode() {
|
|
49
|
-
return (data,
|
|
50
|
+
return (data, state) => (state.rev ? doExplode(data) : doImplode(data));
|
|
50
51
|
}
|
|
51
52
|
exports.implode = implode;
|
|
52
53
|
//# sourceMappingURL=explode.js.map
|
|
@@ -1 +1 @@
|
|
|
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,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,KAAK,CAAA;SAC5B;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,SAAS,SAAS,CAAC,IAAa;IAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC,MAAM,CAChB,aAAa,EACb,eAAe,CAAC,IAAI,CAAC;YACnB,CAAC,CAAE,EAAgB;YAC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CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;AACzE,CAAC;AAFD,0BAEC;AAED,SAAgB,OAAO;IACrB,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;AACzE,CAAC;AAFD,0BAEC"}
|
|
@@ -2,9 +2,11 @@ import { value, fixed } from './value';
|
|
|
2
2
|
import compare from './compare';
|
|
3
3
|
import { explode, implode } from './explode';
|
|
4
4
|
import get from './get';
|
|
5
|
+
import index from './indexFn';
|
|
5
6
|
import { join, split } from './joinSplit';
|
|
6
7
|
import logical from './logical';
|
|
7
8
|
import map from './map';
|
|
9
|
+
import sort from './sort';
|
|
8
10
|
import template from './template';
|
|
9
11
|
declare const _default: {
|
|
10
12
|
compare: typeof compare;
|
|
@@ -12,9 +14,11 @@ declare const _default: {
|
|
|
12
14
|
fixed: typeof fixed;
|
|
13
15
|
get: typeof get;
|
|
14
16
|
implode: typeof implode;
|
|
17
|
+
index: typeof index;
|
|
15
18
|
join: typeof join;
|
|
16
19
|
logical: typeof logical;
|
|
17
20
|
map: typeof map;
|
|
21
|
+
sort: typeof sort;
|
|
18
22
|
split: typeof split;
|
|
19
23
|
template: typeof template;
|
|
20
24
|
value: typeof value;
|
package/dist/functions/index.js
CHANGED
|
@@ -4,9 +4,11 @@ const value_1 = require("./value");
|
|
|
4
4
|
const compare_1 = require("./compare");
|
|
5
5
|
const explode_1 = require("./explode");
|
|
6
6
|
const get_1 = require("./get");
|
|
7
|
+
const indexFn_1 = require("./indexFn");
|
|
7
8
|
const joinSplit_1 = require("./joinSplit");
|
|
8
9
|
const logical_1 = require("./logical");
|
|
9
10
|
const map_1 = require("./map");
|
|
11
|
+
const sort_1 = require("./sort");
|
|
10
12
|
const template_1 = require("./template");
|
|
11
13
|
exports.default = {
|
|
12
14
|
compare: compare_1.default,
|
|
@@ -14,9 +16,11 @@ exports.default = {
|
|
|
14
16
|
fixed: value_1.fixed,
|
|
15
17
|
get: get_1.default,
|
|
16
18
|
implode: explode_1.implode,
|
|
19
|
+
index: indexFn_1.default,
|
|
17
20
|
join: joinSplit_1.join,
|
|
18
21
|
logical: logical_1.default,
|
|
19
22
|
map: map_1.default,
|
|
23
|
+
sort: sort_1.default,
|
|
20
24
|
split: joinSplit_1.split,
|
|
21
25
|
template: template_1.default,
|
|
22
26
|
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,uCAA4C;AAC5C,+BAAuB;AACvB,2CAAyC;AACzC,uCAA+B;AAC/B,+BAAuB;AACvB,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,KAAK,EAAL,iBAAK;IACL,QAAQ,EAAR,kBAAQ;IACR,KAAK,EAAL,aAAK;CACN,CAAA"}
|
|
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,uCAA6B;AAC7B,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,KAAK,EAAL,iBAAK;IACL,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexFn.js","sourceRoot":"","sources":["../../src/functions/indexFn.ts"],"names":[],"mappings":";;AAEA,SAAwB,OAAO;IAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACtB,OAAO,KAAK,CAAC,KAAK,IAAI,CAAC,CAAA;IACzB,CAAC,CAAA;AACH,CAAC;AAJD,0BAIC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Operands, DataMapper } from '../types';
|
|
2
|
-
interface
|
|
1
|
+
import { Operands as BaseOperands, DataMapper } from '../types';
|
|
2
|
+
interface Operands extends BaseOperands {
|
|
3
3
|
path?: string | string[];
|
|
4
4
|
sep?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function join(options:
|
|
7
|
-
export declare function split(options:
|
|
6
|
+
export declare function join(options: Operands): DataMapper;
|
|
7
|
+
export declare function split(options: Operands): DataMapper;
|
|
8
8
|
export {};
|
|
@@ -3,15 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.split = exports.join = void 0;
|
|
4
4
|
const pathGetter_1 = require("../utils/pathGetter");
|
|
5
5
|
const pathSetter_1 = require("../utils/pathSetter");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const xor_1 = require("../utils/xor");
|
|
7
|
+
const array_1 = require("../utils/array");
|
|
8
|
+
function joinSplit({ path, sep = ' ' }, split) {
|
|
9
|
+
const pathArr = (0, array_1.ensureArray)(path);
|
|
8
10
|
if (pathArr.length === 0) {
|
|
9
|
-
return (
|
|
11
|
+
return (data, { rev }) => (0, xor_1.default)(split, rev)
|
|
12
|
+
? typeof data === 'string'
|
|
13
|
+
? data.split(sep)
|
|
14
|
+
: undefined
|
|
15
|
+
: Array.isArray(data)
|
|
16
|
+
? data.join(sep)
|
|
17
|
+
: undefined;
|
|
10
18
|
}
|
|
11
19
|
const getFns = pathArr.map(pathGetter_1.default);
|
|
12
20
|
const setFns = pathArr.map(pathSetter_1.default);
|
|
13
21
|
return (data, { rev }) => {
|
|
14
|
-
if (split
|
|
22
|
+
if ((0, xor_1.default)(split, rev)) {
|
|
15
23
|
const values = typeof data === 'string' ? data.split(sep) : [];
|
|
16
24
|
return setFns.reduce((obj, setFn, index) => setFn(values[index], obj), undefined);
|
|
17
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joinSplit.js","sourceRoot":"","sources":["../../src/functions/joinSplit.ts"],"names":[],"mappings":";;;AAEA,oDAAwC;AACxC,oDAAwC;
|
|
1
|
+
{"version":3,"file":"joinSplit.js","sourceRoot":"","sources":["../../src/functions/joinSplit.ts"],"names":[],"mappings":";;;AAEA,oDAAwC;AACxC,oDAAwC;AACxC,sCAA8B;AAC9B,0CAA4C;AAO5C,SAAS,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,EAAY,EAAE,KAAc;IAC9D,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAA;IACjC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CACvB,IAAA,aAAG,EAAC,KAAK,EAAE,GAAG,CAAC;YACb,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ;gBACxB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;gBACjB,CAAC,CAAC,SAAS;YACb,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;gBACrB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;gBAChB,CAAC,CAAC,SAAS,CAAA;KAChB;IA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