map-transform 0.4.0-alpha.3 → 0.4.0-alpha.32

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.
Files changed (114) hide show
  1. package/README.md +211 -46
  2. package/dist/functions/compare.d.ts +2 -1
  3. package/dist/functions/compare.js +26 -5
  4. package/dist/functions/compare.js.map +1 -1
  5. package/dist/functions/explode.d.ts +2 -1
  6. package/dist/functions/explode.js +12 -4
  7. package/dist/functions/explode.js.map +1 -1
  8. package/dist/functions/index.d.ts +6 -1
  9. package/dist/functions/index.js +6 -1
  10. package/dist/functions/index.js.map +1 -1
  11. package/dist/functions/indexFn.d.ts +2 -0
  12. package/dist/functions/indexFn.js +9 -0
  13. package/dist/functions/indexFn.js.map +1 -0
  14. package/dist/functions/joinSplit.js +4 -5
  15. package/dist/functions/joinSplit.js.map +1 -1
  16. package/dist/functions/logical.js +1 -5
  17. package/dist/functions/logical.js.map +1 -1
  18. package/dist/functions/map.js +5 -4
  19. package/dist/functions/map.js.map +1 -1
  20. package/dist/functions/not.js +1 -1
  21. package/dist/functions/not.js.map +1 -1
  22. package/dist/functions/sort.d.ts +7 -0
  23. package/dist/functions/sort.js +33 -0
  24. package/dist/functions/sort.js.map +1 -0
  25. package/dist/functions/template.js +7 -5
  26. package/dist/functions/template.js.map +1 -1
  27. package/dist/functions/validate.js +2 -2
  28. package/dist/functions/validate.js.map +1 -1
  29. package/dist/functions/value.js +2 -2
  30. package/dist/functions/value.js.map +1 -1
  31. package/dist/index.d.ts +3 -1
  32. package/dist/index.js +9 -6
  33. package/dist/index.js.map +1 -1
  34. package/dist/operations/alt.d.ts +1 -1
  35. package/dist/operations/alt.js +28 -6
  36. package/dist/operations/alt.js.map +1 -1
  37. package/dist/operations/apply.js +10 -5
  38. package/dist/operations/apply.js.map +1 -1
  39. package/dist/operations/concat.js +9 -5
  40. package/dist/operations/concat.js.map +1 -1
  41. package/dist/operations/directionals.js +7 -6
  42. package/dist/operations/directionals.js.map +1 -1
  43. package/dist/operations/filter.js +10 -9
  44. package/dist/operations/filter.js.map +1 -1
  45. package/dist/operations/fixed.js +2 -4
  46. package/dist/operations/fixed.js.map +1 -1
  47. package/dist/operations/getSet.d.ts +3 -3
  48. package/dist/operations/getSet.js +137 -25
  49. package/dist/operations/getSet.js.map +1 -1
  50. package/dist/operations/ifelse.d.ts +1 -1
  51. package/dist/operations/ifelse.js +21 -8
  52. package/dist/operations/ifelse.js.map +1 -1
  53. package/dist/operations/iterate.d.ts +2 -1
  54. package/dist/operations/iterate.js +14 -12
  55. package/dist/operations/iterate.js.map +1 -1
  56. package/dist/operations/logical.d.ts +3 -0
  57. package/dist/operations/logical.js +17 -0
  58. package/dist/operations/logical.js.map +1 -0
  59. package/dist/operations/lookup.js +9 -5
  60. package/dist/operations/lookup.js.map +1 -1
  61. package/dist/operations/merge.d.ts +1 -0
  62. package/dist/operations/merge.js +34 -9
  63. package/dist/operations/merge.js.map +1 -1
  64. package/dist/operations/modify.d.ts +1 -1
  65. package/dist/operations/modify.js +15 -8
  66. package/dist/operations/modify.js.map +1 -1
  67. package/dist/operations/pipe.js +18 -10
  68. package/dist/operations/pipe.js.map +1 -1
  69. package/dist/operations/plug.js +1 -1
  70. package/dist/operations/plug.js.map +1 -1
  71. package/dist/operations/props.d.ts +2 -0
  72. package/dist/operations/props.js +114 -0
  73. package/dist/operations/props.js.map +1 -0
  74. package/dist/operations/root.js +3 -4
  75. package/dist/operations/root.js.map +1 -1
  76. package/dist/operations/transform.js +6 -4
  77. package/dist/operations/transform.js.map +1 -1
  78. package/dist/operations/value.js +2 -4
  79. package/dist/operations/value.js.map +1 -1
  80. package/dist/types.d.ts +43 -13
  81. package/dist/utils/array.d.ts +3 -0
  82. package/dist/utils/array.js +14 -0
  83. package/dist/utils/array.js.map +1 -0
  84. package/dist/utils/definitionHelpers.d.ts +3 -1
  85. package/dist/utils/definitionHelpers.js +95 -24
  86. package/dist/utils/definitionHelpers.js.map +1 -1
  87. package/dist/utils/escape.d.ts +2 -0
  88. package/dist/utils/escape.js +8 -0
  89. package/dist/utils/escape.js.map +1 -0
  90. package/dist/utils/functional.d.ts +1 -0
  91. package/dist/utils/functional.js +3 -1
  92. package/dist/utils/functional.js.map +1 -1
  93. package/dist/utils/is.d.ts +2 -0
  94. package/dist/utils/is.js +5 -1
  95. package/dist/utils/is.js.map +1 -1
  96. package/dist/utils/pathGetter.d.ts +4 -2
  97. package/dist/utils/pathGetter.js +24 -19
  98. package/dist/utils/pathGetter.js.map +1 -1
  99. package/dist/utils/pathSetter.d.ts +5 -3
  100. package/dist/utils/pathSetter.js +48 -43
  101. package/dist/utils/pathSetter.js.map +1 -1
  102. package/dist/utils/stateHelpers.d.ts +31 -6
  103. package/dist/utils/stateHelpers.js +33 -12
  104. package/dist/utils/stateHelpers.js.map +1 -1
  105. package/dist/utils/xor.d.ts +1 -0
  106. package/dist/utils/xor.js +7 -0
  107. package/dist/utils/xor.js.map +1 -0
  108. package/package.json +8 -10
  109. package/dist/functions/join.d.ts +0 -7
  110. package/dist/functions/join.js +0 -12
  111. package/dist/functions/join.js.map +0 -1
  112. package/dist/operations/mutate.d.ts +0 -2
  113. package/dist/operations/mutate.js +0 -55
  114. 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
 
@@ -188,11 +188,14 @@ const def2 = {
188
188
  // }
189
189
  ```
190
190
 
191
- When you transform an array of data with a mapping object, each item in the
192
- data array will be be transformed with the mapping object.
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
- If you want to apply the mapping object to the entire array not each item in
207
- the array set `$iterate: false` on the mapping object or wrap the object in a
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
@@ -306,15 +305,18 @@ below.
306
305
 
307
306
  MapTransform will treat `undefined` as a value that is not set, and so a
308
307
  transform object will not be applied to it. So if an `undefined` value meets
309
- a transform object, it will produce `undefined`, regardsless of the shape of the
308
+ a transform object, it will produce `undefined`, regardless of the shape of the
310
309
  transform object.
311
310
 
312
311
  This is not the case for `null`, though. MapTransform treats `null` as a value,
313
312
  an intended nothing, and will apply a transform object to it, even though it
314
313
  will most likely produce nothing but default values. To change this behavior,
315
- set `mutateNull: false` on the `options` object passed to MapTransform. This
316
- will essentially make MapTransform treat `null` the same way as `undefined` when
317
- it comes to the transform object.
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.
318
320
 
319
321
  #### Directional transform objects
320
322
 
@@ -326,6 +328,17 @@ When running a forward transformation, transform objects marked with
326
328
  `$direction: 'rev'` will be skipped. The same goes for `$direction: 'fwd'` in
327
329
  reverse.
328
330
 
331
+ You may specify aliases for `fwd` and `rev` in the `mapTransform` options:
332
+
333
+ ```javascript
334
+ const options = { fwdAlias: 'from', revAlias: 'to' }
335
+ const mapper = mapTransform(def, options)
336
+ ```
337
+
338
+ In this case, `from` and `to` may be used to specify forward and reverse
339
+ direction respectively. `fwd` and `rev` will still work in addition to the
340
+ aliases.
341
+
329
342
  ### Transform pipeline
330
343
 
331
344
  The idea of the transform pipeline, is that you describe a set of
@@ -553,10 +566,10 @@ See the `transform()` operation for more on how defining as an object works.
553
566
 
554
567
  #### `ifelse(conditionFn, truePipeline, falsePipeline)` operation
555
568
 
556
- The `ifelse()` operation will run the `truePipeline` if the `conditionFn` results
557
- in `true`, otherwise it will run the `falsePipeline`. See
558
- [the `filter()` operation](#filterconditionFn-operation) for more on the
559
- 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`.
560
573
 
561
574
  Both `truePipeline` and `falsePipeline` are optional, in case you only need to
562
575
  apply a pipeline in one of the cases.
@@ -577,6 +590,29 @@ const def31 = [
577
590
  ]
578
591
  ```
579
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
+
580
616
  #### `iterate(pipeline)` operation
581
617
 
582
618
  If you want something to be mapped over the items of an array, the `iterate`
@@ -612,6 +648,9 @@ When an id is passed to the apply operation as `pipelinedId`, the pipeline will
612
648
  be applied in the place of the apply operation and executed as if it was part of
613
649
  the pipeline definition in the first place.
614
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
+
615
654
  ```javascript
616
655
  import { mapTransform, apply, transform } from 'map-transform'
617
656
 
@@ -680,20 +719,20 @@ import { value, alt } from 'map-transform'
680
719
  const def10 = {
681
720
  id: 'data.customerNo',
682
721
  type: value('customer'),
683
- name: ['data.name', alt(value('Anonymous'))],
722
+ name: alt('data.name', value('Anonymous')),
684
723
  }
685
724
  ```
686
725
 
687
726
  The operation will not set anything when mapping with `.onlyMappedValues()`.
688
727
 
689
728
  If you want to define the `value` operation as an operation object, use
690
- `$transform` or `$alt`:
729
+ `$transform` or the short form `$value`:
691
730
 
692
731
  ```javascript
693
732
  const def10asObject = {
694
733
  id: 'data.customerNo',
695
734
  type: { $transform: 'value', value: 'customer' },
696
- name: ['data.name', { $alt: 'value', value: 'Anonymous' }],
735
+ name: { $alt: ['data.name', { $value: 'Anonymous' }] },
697
736
  }
698
737
  ```
699
738
 
@@ -708,14 +747,15 @@ will be included when mapping with `.onlyMappedValues()` as well.
708
747
 
709
748
  #### `alt(pipeline)` operation
710
749
 
711
- The alt operation will apply the pipeline it is given when the data already in
712
- the pipeline is `undefined`. This is how you provide default values in
713
- MapTransform. The pipeline may be as simple as a `value()` operation, a dot
714
- notation path into the source data, or a full pipeline of several operations.
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.
715
755
 
716
- When given an array, the `alt` operation will treat it as a value and do
717
- nothing, as it is not an `undefined` value. To provide the `alt` operation to
718
- every item in the array, please use the `iterate` operation.
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.
719
759
 
720
760
  ```javascript
721
761
  import { alt, transform, functions } from 'map-transform'
@@ -727,11 +767,9 @@ const formatDate = (data) => {
727
767
 
728
768
  const def11 = {
729
769
  id: 'data.id',
730
- name: ['data.name', alt(value('Anonymous'))],
770
+ name: alt('data.name', value('Anonymous')),
731
771
  updatedAt: [
732
- 'data.updateDate',
733
- alt('data.createDate'),
734
- alt(transform(currentDate)),
772
+ alt('data.updateDate', 'data.createDate', transform(currentDate)),
735
773
  transform(formatDate),
736
774
  ],
737
775
  }
@@ -745,16 +783,24 @@ we still have `undefined`, the second alt will call the customer function
745
783
  another transform operation pipes whatever data we get from all of this through
746
784
  the `formatDate` function.
747
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
+
748
796
  You may also define an alt operation as an object:
749
797
 
750
798
  ```javascript
751
799
  const def11asObject = {
752
800
  id: 'data.id',
753
- name: ['data.name', { $alt: 'value', value: 'Anonymous' }],
801
+ name: { $alt: ['data.name', { $value: 'Anonymous' }] },
754
802
  updatedAt: [
755
- 'data.updateDate',
756
- { $alt: 'get', path: 'data.createDate' },
757
- { $alt: 'currentDate' },
803
+ { $alt: ['data.updateDate', 'data.createDate', 'currentDate'] },
758
804
  { $transform: 'formatDate' },
759
805
  ],
760
806
  }
@@ -818,6 +864,27 @@ const response = {
818
864
  Had we ran this without the `modify()` operation, the returned object would only
819
865
  have the `data` prop.
820
866
 
867
+ This is equivalent to setting the `$modify` property to `true` on the object
868
+ mutation object:
869
+
870
+ ```javascript
871
+ const def34b = {
872
+ $modify: true,
873
+ data: 'data.deeply.placed.items',
874
+ }
875
+ ```
876
+
877
+ Note that `$modify` may also be set further down in the object structure. Also,
878
+ in some cases it may make more sense to specify a path in the source data to
879
+ merge with:
880
+
881
+ ```javascript
882
+ const def34c = {
883
+ $modify: 'response',
884
+ data: 'response.data.deeply.placed.items',
885
+ }
886
+ ```
887
+
821
888
  #### `fwd(pipeline)` and `rev(pipeline)` operation
822
889
 
823
890
  All operations in MapTransform will apply in both directions, although some of
@@ -998,7 +1065,51 @@ mapper.rev(mappedData)
998
1065
  // --> { content: { meta: { authors: ['user1', 'user3'] } } }
999
1066
  ```
1000
1067
 
1001
- #### `compare({ path, operator, match, matchPath })` function
1068
+ You may also define this as a transform object:
1069
+
1070
+ ```javascript
1071
+ const def18o = ['content.meta.authors[]', { $lookup: '$users[]', path: 'id' }]
1072
+ ```
1073
+
1074
+ #### `and(pipeline, pipeline, ...)` operation
1075
+
1076
+ Will run all provided pipelines, force their return values to boolean, according
1077
+ to JavaScript rules, and return `true` if they are all `true`, otherwise
1078
+ `false`.
1079
+
1080
+ Typically used together with [`ifelse` operation](#ifelseconditionFn-truePipeline-falsePipeline-operation),
1081
+ to support AND logic:
1082
+
1083
+ ```javascript
1084
+ const def36 = [
1085
+ {
1086
+ $if: { $and: ['active', 'authorized'] },
1087
+ then: 'content',
1088
+ else: { $value: undefined },
1089
+ },
1090
+ ]
1091
+ ```
1092
+
1093
+ #### `or(pipeline, pipeline, ...)` operation
1094
+
1095
+ Will run all provided pipelines, force their return values to boolean, according
1096
+ to JavaScript rules, and return `true` if any of the are `true`, otherwise
1097
+ `false`.
1098
+
1099
+ Typically used together with [`ifelse` operation](#ifelseconditionFn-truePipeline-falsePipeline-operation),
1100
+ to support OR logic:
1101
+
1102
+ ```javascript
1103
+ const def37 = [
1104
+ {
1105
+ $if: { $or: ['active', 'draft'] },
1106
+ then: 'content',
1107
+ else: { $value: undefined },
1108
+ },
1109
+ ]
1110
+ ```
1111
+
1112
+ #### `compare({ path, operator, match, matchPath, not })` function
1002
1113
 
1003
1114
  This is a helper function intended for use with the `filter()` operation. You
1004
1115
  pass a dot notation `path` and a `match` value (string, number, boolean) to
@@ -1011,10 +1122,14 @@ data.
1011
1122
 
1012
1123
  The default is to compare the values resulting from `path` and `match` or
1013
1124
  `matchPath` with equality, but other operations may be set on the `operator`
1014
- property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='`.
1125
+ property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='`, `in`, or
1126
+ `exists`. `in` requires equality to at least one of the elements in an array,
1127
+ and `exists` requires any value besides `undefined`.
1015
1128
 
1016
- If the path points to an array, the value is expected to be one of the values in
1017
- the array.
1129
+ If the `path` points to an array, the value is expected to be one of the values
1130
+ in the array.
1131
+
1132
+ Set `not` to `true` to reverse the result of the comparison.
1018
1133
 
1019
1134
  Here's an example where only data where role is set to 'admin' will be kept:
1020
1135
 
@@ -1043,6 +1158,9 @@ const def19o = [
1043
1158
  ]
1044
1159
  ```
1045
1160
 
1161
+ When you define the `compare` function as a transform object in JSON and need to
1162
+ compare to `undefined`, use `**undefined**` instead.
1163
+
1046
1164
  #### `explode()` function
1047
1165
 
1048
1166
  Given an object, the `explode` helper function will return an array with one
@@ -1081,6 +1199,18 @@ Or as a transform object:
1081
1199
  const def32o = ['currencies', { $transform: 'explode' }]
1082
1200
  ```
1083
1201
 
1202
+ ### `index()` function
1203
+
1204
+ When iterating, this will return the index of the current item in the array.
1205
+ When used outside of an iteration, it always returns `0`.
1206
+
1207
+ #### `implode()` function
1208
+
1209
+ This is the exact opposite of the `explode` helper, imploding from a service and
1210
+ explode in reverse (to a service). See
1211
+ [the documentation for `explode()`](#explode-function), but remember that the
1212
+ directions will be reversed for `implode()`.
1213
+
1084
1214
  #### `map(dictionary)` function
1085
1215
 
1086
1216
  This helper function accepts a dictionary described as an array of tuples, where
@@ -1096,7 +1226,8 @@ is returned instead.
1096
1226
 
1097
1227
  The `map` function only supports primitive values, so any object will be mapped to
1098
1228
  `undefined` or the value given by the wildcard in the dictionary. Arrays will be
1099
- iterated to map each value in the array.
1229
+ iterated to map each value in the array. To map to or from `undefined` with a
1230
+ dictionary defined in JSON, use the value `**undefined**`.
1100
1231
 
1101
1232
  Example:
1102
1233
 
@@ -1115,7 +1246,7 @@ const def28 = {
1115
1246
  }
1116
1247
  ```
1117
1248
 
1118
- When using `map` in an operation object, you may provice a dictionary array
1249
+ When using `map` in an operation object, you may provide a dictionary array
1119
1250
  or a named dictionary on the `dictionary` property. An example of with a named
1120
1251
  dictionary:
1121
1252
 
@@ -1138,6 +1269,40 @@ const def29 = {
1138
1269
  const mapper = mapTransform(def29, { dictionaries: { statusCodes: dictionary } })
1139
1270
  ```
1140
1271
 
1272
+ #### `sort({asc, path})` function
1273
+
1274
+ The `sort` helper function will sort the given array of items in ascending or
1275
+ descending (depending on whether `asc` is `true` or `false`). Ascending is the
1276
+ default. When a `path` is given, the sort is performed on the value at that path
1277
+ on each object in the array. With no `path`, the values in the array are sorted
1278
+ directly.
1279
+
1280
+ Example:
1281
+
1282
+ ```javascript
1283
+ import { mapTransform, transform, functions } from 'map-transform'
1284
+ const { sort } = functions
1285
+
1286
+ const data = {
1287
+ items: [{ id: 'ent5' }, { id: 'ent1' }, { id: 'ent3' }],
1288
+ }
1289
+
1290
+ const def35 = {
1291
+ data: ['items', transform(sort({ asc: true, path: 'id' }))],
1292
+ }
1293
+
1294
+ const ret = mapTransform(def35)(data)
1295
+ // --> { caption: 'Bergen by night. By John F.' }
1296
+ ```
1297
+
1298
+ The `sort` function is also available through a transform object:
1299
+
1300
+ ```javascript
1301
+ const def35o = {
1302
+ data: ['items', { $transform: 'sort', asc: true, path: 'id' }],
1303
+ }
1304
+ ```
1305
+
1141
1306
  #### `template(template)` function
1142
1307
 
1143
1308
  The `template` helper function takes a [handlebars] template and applies the
@@ -1249,7 +1414,7 @@ const def22 = [
1249
1414
  'data.customers[]',
1250
1415
  {
1251
1416
  id: 'customerNo',
1252
- name: ['fullname', alt(value('Anonymous'))],
1417
+ name: [alt('fullname', value('Anonymous'))],
1253
1418
  },
1254
1419
  ]
1255
1420
 
@@ -1363,8 +1528,8 @@ same goes for flipped transform objects if you want to forward transform.
1363
1528
 
1364
1529
  MapTransform will try its best to map the data it gets to the state you want,
1365
1530
  and will always set all properties, even though the mapping you defined result
1366
- in `undefined`. You may include `alt()` operations to provide default or fallback
1367
- values for these cases.
1531
+ in `undefined`. You may include `alt()` operations to provide default or
1532
+ fallback values for these cases.
1368
1533
 
1369
1534
  But sometimes, you want just the data that is actually present in the source
1370
1535
  data, without defaults or properties set to `undefined`. MapTransform's
@@ -1380,7 +1545,7 @@ import { mapTransform, alt, value } from 'map-transform'
1380
1545
 
1381
1546
  const def24 = {
1382
1547
  id: 'customerNo',
1383
- name: ['fullname', alt(value('Anonymous'))],
1548
+ name: alt('fullname', value('Anonymous')),
1384
1549
  }
1385
1550
 
1386
1551
  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 getMatch = matchPath ? (0, pathGetter_1.default)(matchPath) : () => match;
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
- return comparer(value, match);
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":";;AACA,oDAAwC;AAiBxC,MAAM,GAAG,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC,KAAc,EAAE,KAAc,EAAE,EAAE,CACrE,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAEzB,MAAM,mBAAmB,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,C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,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"}
@@ -3,4 +3,5 @@ export interface KeyValue {
3
3
  key: string | number;
4
4
  value: unknown;
5
5
  }
6
- export default function explode(): DataMapper;
6
+ export declare function explode(): DataMapper;
7
+ export declare function implode(): DataMapper;
@@ -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.every((item) => (0, is_1.isObject)(item) && typeof item.key === 'number');
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).map(([key, value]) => ({
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, context) => (context.rev ? doImplode(data) : doExplode(data));
46
+ return (data, state) => (state.rev ? doImplode(data) : doExplode(data));
43
47
  }
44
- exports.default = explode;
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":";;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;YACnB,CAAC,CAAE,EAA8B,CACpC,CAAA;KACF;SAAM;QACL,OAAO,SAAS,CAAA;KACjB;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC9B,IAAI,IAAA,aAAQ,EAAC,IAAI,CAAC,EAAE;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B,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"}
@@ -1,19 +1,24 @@
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
+ 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;
11
13
  explode: typeof explode;
12
14
  fixed: typeof fixed;
13
15
  get: typeof get;
16
+ implode: typeof implode;
17
+ index: typeof index;
14
18
  join: typeof join;
15
19
  logical: typeof logical;
16
20
  map: typeof map;
21
+ sort: typeof sort;
17
22
  split: typeof split;
18
23
  template: typeof template;
19
24
  value: typeof value;
@@ -4,18 +4,23 @@ 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,
13
- explode: explode_1.default,
15
+ explode: explode_1.explode,
14
16
  fixed: value_1.fixed,
15
17
  get: get_1.default,
18
+ implode: explode_1.implode,
19
+ index: indexFn_1.default,
16
20
  join: joinSplit_1.join,
17
21
  logical: logical_1.default,
18
22
  map: map_1.default,
23
+ sort: sort_1.default,
19
24
  split: joinSplit_1.split,
20
25
  template: template_1.default,
21
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,uCAA+B;AAC/B,+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,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,2 @@
1
+ import { DataMapper } from '../types';
2
+ export default function compare(): DataMapper;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function compare() {
4
+ return (_data, state) => {
5
+ return state.index || 0;
6
+ };
7
+ }
8
+ exports.default = compare;
9
+ //# sourceMappingURL=indexFn.js.map
@@ -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"}