map-transform 0.4.0-alpha.9 → 0.4.0-beta.0

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 (106) hide show
  1. package/README.md +186 -40
  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.js +4 -3
  6. package/dist/functions/explode.js.map +1 -1
  7. package/dist/functions/index.d.ts +4 -0
  8. package/dist/functions/index.js +4 -0
  9. package/dist/functions/index.js.map +1 -1
  10. package/dist/functions/indexFn.d.ts +2 -0
  11. package/dist/functions/indexFn.js +9 -0
  12. package/dist/functions/indexFn.js.map +1 -0
  13. package/dist/functions/joinSplit.d.ts +4 -4
  14. package/dist/functions/joinSplit.js +12 -4
  15. package/dist/functions/joinSplit.js.map +1 -1
  16. package/dist/functions/map.js +5 -4
  17. package/dist/functions/map.js.map +1 -1
  18. package/dist/functions/not.js +1 -1
  19. package/dist/functions/not.js.map +1 -1
  20. package/dist/functions/sort.d.ts +7 -0
  21. package/dist/functions/sort.js +33 -0
  22. package/dist/functions/sort.js.map +1 -0
  23. package/dist/functions/validate.js +2 -2
  24. package/dist/functions/validate.js.map +1 -1
  25. package/dist/functions/value.js +2 -2
  26. package/dist/functions/value.js.map +1 -1
  27. package/dist/index.d.ts +4 -1
  28. package/dist/index.js +8 -2
  29. package/dist/index.js.map +1 -1
  30. package/dist/operations/alt.d.ts +1 -1
  31. package/dist/operations/alt.js +28 -6
  32. package/dist/operations/alt.js.map +1 -1
  33. package/dist/operations/apply.js +10 -5
  34. package/dist/operations/apply.js.map +1 -1
  35. package/dist/operations/concat.js +9 -5
  36. package/dist/operations/concat.js.map +1 -1
  37. package/dist/operations/directionals.js +7 -6
  38. package/dist/operations/directionals.js.map +1 -1
  39. package/dist/operations/filter.js +5 -6
  40. package/dist/operations/filter.js.map +1 -1
  41. package/dist/operations/fixed.js +2 -4
  42. package/dist/operations/fixed.js.map +1 -1
  43. package/dist/operations/getSet.d.ts +3 -3
  44. package/dist/operations/getSet.js +139 -30
  45. package/dist/operations/getSet.js.map +1 -1
  46. package/dist/operations/ifelse.d.ts +1 -1
  47. package/dist/operations/ifelse.js +21 -10
  48. package/dist/operations/ifelse.js.map +1 -1
  49. package/dist/operations/iterate.d.ts +2 -1
  50. package/dist/operations/iterate.js +14 -10
  51. package/dist/operations/iterate.js.map +1 -1
  52. package/dist/operations/logical.d.ts +3 -0
  53. package/dist/operations/logical.js +17 -0
  54. package/dist/operations/logical.js.map +1 -0
  55. package/dist/operations/lookup.js +9 -5
  56. package/dist/operations/lookup.js.map +1 -1
  57. package/dist/operations/merge.js +9 -7
  58. package/dist/operations/merge.js.map +1 -1
  59. package/dist/operations/modify.js +13 -6
  60. package/dist/operations/modify.js.map +1 -1
  61. package/dist/operations/pipe.js +14 -16
  62. package/dist/operations/pipe.js.map +1 -1
  63. package/dist/operations/plug.js +1 -1
  64. package/dist/operations/plug.js.map +1 -1
  65. package/dist/operations/props.d.ts +2 -0
  66. package/dist/operations/props.js +114 -0
  67. package/dist/operations/props.js.map +1 -0
  68. package/dist/operations/root.js +3 -5
  69. package/dist/operations/root.js.map +1 -1
  70. package/dist/operations/transform.js +4 -2
  71. package/dist/operations/transform.js.map +1 -1
  72. package/dist/operations/value.js +2 -4
  73. package/dist/operations/value.js.map +1 -1
  74. package/dist/types.d.ts +39 -12
  75. package/dist/utils/array.d.ts +1 -0
  76. package/dist/utils/array.js +3 -1
  77. package/dist/utils/array.js.map +1 -1
  78. package/dist/utils/definitionHelpers.d.ts +3 -1
  79. package/dist/utils/definitionHelpers.js +72 -17
  80. package/dist/utils/definitionHelpers.js.map +1 -1
  81. package/dist/utils/escape.d.ts +2 -0
  82. package/dist/utils/escape.js +8 -0
  83. package/dist/utils/escape.js.map +1 -0
  84. package/dist/utils/is.d.ts +2 -0
  85. package/dist/utils/is.js +5 -1
  86. package/dist/utils/is.js.map +1 -1
  87. package/dist/utils/pathGetter.js +12 -3
  88. package/dist/utils/pathGetter.js.map +1 -1
  89. package/dist/utils/pathSetter.d.ts +1 -0
  90. package/dist/utils/pathSetter.js +16 -6
  91. package/dist/utils/pathSetter.js.map +1 -1
  92. package/dist/utils/stateHelpers.d.ts +30 -6
  93. package/dist/utils/stateHelpers.js +30 -14
  94. package/dist/utils/stateHelpers.js.map +1 -1
  95. package/dist/utils/xor.d.ts +1 -0
  96. package/dist/utils/xor.js +7 -0
  97. package/dist/utils/xor.js.map +1 -0
  98. package/package.json +6 -6
  99. package/ava-dist.config.cjs +0 -3
  100. package/ava.config.cjs +0 -5
  101. package/dist/functions/join.d.ts +0 -7
  102. package/dist/functions/join.js +0 -12
  103. package/dist/functions/join.js.map +0 -1
  104. package/dist/operations/mutate.d.ts +0 -2
  105. package/dist/operations/mutate.js +0 -80
  106. 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`, regardsless of the shape of the
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 `mutateNull: false` on the `options` object passed to MapTransform. This
315
- will essentially make MapTransform treat `null` the same way as `undefined` when
316
- 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.
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` results
567
- in `true`, otherwise it will run the `falsePipeline`. See
568
- [the `filter()` operation](#filterconditionFn-operation) for more on the
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: ['data.name', alt(value('Anonymous'))],
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 `$alt`:
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', { $alt: 'value', value: 'Anonymous' }],
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 pipeline it is given when the data already in
724
- the pipeline is `undefined`. This is how you provide default values in
725
- MapTransform. The pipeline may be as simple as a `value()` operation, a dot
726
- 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.
727
755
 
728
- When given an array, the `alt` operation will treat it as a value and do
729
- nothing, as it is not an `undefined` value. To provide the `alt` operation to
730
- 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.
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: ['data.name', alt(value('Anonymous'))],
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', { $alt: 'value', value: 'Anonymous' }],
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
  }
@@ -830,6 +864,27 @@ const response = {
830
864
  Had we ran this without the `modify()` operation, the returned object would only
831
865
  have the `data` prop.
832
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
+
833
888
  #### `fwd(pipeline)` and `rev(pipeline)` operation
834
889
 
835
890
  All operations in MapTransform will apply in both directions, although some of
@@ -1010,7 +1065,51 @@ mapper.rev(mappedData)
1010
1065
  // --> { content: { meta: { authors: ['user1', 'user3'] } } }
1011
1066
  ```
1012
1067
 
1013
- #### `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
1014
1113
 
1015
1114
  This is a helper function intended for use with the `filter()` operation. You
1016
1115
  pass a dot notation `path` and a `match` value (string, number, boolean) to
@@ -1023,10 +1122,14 @@ data.
1023
1122
 
1024
1123
  The default is to compare the values resulting from `path` and `match` or
1025
1124
  `matchPath` with equality, but other operations may be set on the `operator`
1026
- 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`.
1027
1128
 
1028
- If the path points to an array, the value is expected to be one of the values in
1029
- 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.
1030
1133
 
1031
1134
  Here's an example where only data where role is set to 'admin' will be kept:
1032
1135
 
@@ -1055,6 +1158,9 @@ const def19o = [
1055
1158
  ]
1056
1159
  ```
1057
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
+
1058
1164
  #### `explode()` function
1059
1165
 
1060
1166
  Given an object, the `explode` helper function will return an array with one
@@ -1093,6 +1199,11 @@ Or as a transform object:
1093
1199
  const def32o = ['currencies', { $transform: 'explode' }]
1094
1200
  ```
1095
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
+
1096
1207
  #### `implode()` function
1097
1208
 
1098
1209
  This is the exact opposite of the `explode` helper, imploding from a service and
@@ -1115,7 +1226,8 @@ is returned instead.
1115
1226
 
1116
1227
  The `map` function only supports primitive values, so any object will be mapped to
1117
1228
  `undefined` or the value given by the wildcard in the dictionary. Arrays will be
1118
- 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**`.
1119
1231
 
1120
1232
  Example:
1121
1233
 
@@ -1134,7 +1246,7 @@ const def28 = {
1134
1246
  }
1135
1247
  ```
1136
1248
 
1137
- 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
1138
1250
  or a named dictionary on the `dictionary` property. An example of with a named
1139
1251
  dictionary:
1140
1252
 
@@ -1157,6 +1269,40 @@ const def29 = {
1157
1269
  const mapper = mapTransform(def29, { dictionaries: { statusCodes: dictionary } })
1158
1270
  ```
1159
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
+
1160
1306
  #### `template(template)` function
1161
1307
 
1162
1308
  The `template` helper function takes a [handlebars] template and applies the
@@ -1268,7 +1414,7 @@ const def22 = [
1268
1414
  'data.customers[]',
1269
1415
  {
1270
1416
  id: 'customerNo',
1271
- name: ['fullname', alt(value('Anonymous'))],
1417
+ name: [alt('fullname', value('Anonymous'))],
1272
1418
  },
1273
1419
  ]
1274
1420
 
@@ -1382,8 +1528,8 @@ same goes for flipped transform objects if you want to forward transform.
1382
1528
 
1383
1529
  MapTransform will try its best to map the data it gets to the state you want,
1384
1530
  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 fallback
1386
- values for these cases.
1531
+ in `undefined`. You may include `alt()` operations to provide default or
1532
+ fallback values for these cases.
1387
1533
 
1388
1534
  But sometimes, you want just the data that is actually present in the source
1389
1535
  data, without defaults or properties set to `undefined`. MapTransform's
@@ -1399,7 +1545,7 @@ import { mapTransform, alt, value } from 'map-transform'
1399
1545
 
1400
1546
  const def24 = {
1401
1547
  id: 'customerNo',
1402
- name: ['fullname', alt(value('Anonymous'))],
1548
+ name: alt('fullname', value('Anonymous')),
1403
1549
  }
1404
1550
 
1405
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,CAClD,KAAc,EACd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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.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');
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, context) => (context.rev ? doImplode(data) : doExplode(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, context) => (context.rev ? doExplode(data) : doImplode(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,IAA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K,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;
@@ -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,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"}
@@ -1,8 +1,8 @@
1
- import { Operands, DataMapper } from '../types';
2
- interface Options extends Operands {
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: Options): DataMapper;
7
- export declare function split(options: Options): DataMapper;
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
- function joinSplit({ path = [], sep = ' ' }, split) {
7
- const pathArr = [].concat(path);
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 (_data, _context) => undefined;
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 ? !rev : rev) {
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":"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I,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,OAAiB;IACpC,OAAO,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AAClC,CAAC;AAFD,oBAEC;AAED,SAAgB,KAAK,CAAC,OAAiB;IACrC,OAAO,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACjC,CAAC;AAFD,sBAEC"}
@@ -1,6 +1,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, context) => {
37
- const { rev } = context;
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;