map-transform 0.4.0-alpha.14 → 0.4.0-alpha.15
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 +9 -4
- package/dist/functions/compare.js +9 -1
- package/dist/functions/compare.js.map +1 -1
- package/dist/functions/map.js +3 -2
- package/dist/functions/map.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/package.json +2 -2
package/README.md
CHANGED
|
@@ -1067,8 +1067,9 @@ data.
|
|
|
1067
1067
|
|
|
1068
1068
|
The default is to compare the values resulting from `path` and `match` or
|
|
1069
1069
|
`matchPath` with equality, but other operations may be set on the `operator`
|
|
1070
|
-
property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='`,
|
|
1071
|
-
|
|
1070
|
+
property. Alternatives: `'='`, `'!='`, `'>'`, `'>='`, `'<'`, or `'<='`, `in`, or
|
|
1071
|
+
`exists`. `in` requires equality to at least one of the elements in an array,
|
|
1072
|
+
and `exists` requires any value besides `undefined`.
|
|
1072
1073
|
|
|
1073
1074
|
If the `path` points to an array, the value is expected to be one of the values
|
|
1074
1075
|
in the array.
|
|
@@ -1102,6 +1103,9 @@ const def19o = [
|
|
|
1102
1103
|
]
|
|
1103
1104
|
```
|
|
1104
1105
|
|
|
1106
|
+
When you define the `compare` function as a transform object in JSON and need to
|
|
1107
|
+
compare to `undefined`, use `**undefined**` instead.
|
|
1108
|
+
|
|
1105
1109
|
#### `explode()` function
|
|
1106
1110
|
|
|
1107
1111
|
Given an object, the `explode` helper function will return an array with one
|
|
@@ -1162,7 +1166,8 @@ is returned instead.
|
|
|
1162
1166
|
|
|
1163
1167
|
The `map` function only supports primitive values, so any object will be mapped to
|
|
1164
1168
|
`undefined` or the value given by the wildcard in the dictionary. Arrays will be
|
|
1165
|
-
iterated to map each value in the array.
|
|
1169
|
+
iterated to map each value in the array. To map to or from `undefined` with a
|
|
1170
|
+
dictionary defined in JSON, use the value `**undefined**`.
|
|
1166
1171
|
|
|
1167
1172
|
Example:
|
|
1168
1173
|
|
|
@@ -1181,7 +1186,7 @@ const def28 = {
|
|
|
1181
1186
|
}
|
|
1182
1187
|
```
|
|
1183
1188
|
|
|
1184
|
-
When using `map` in an operation object, you may
|
|
1189
|
+
When using `map` in an operation object, you may provide a dictionary array
|
|
1185
1190
|
or a named dictionary on the `dictionary` property. An example of with a named
|
|
1186
1191
|
dictionary:
|
|
1187
1192
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mapAny = require("map-any");
|
|
3
4
|
const pathGetter_1 = require("../utils/pathGetter");
|
|
5
|
+
const escape_1 = require("../utils/escape");
|
|
4
6
|
const not = (comparer) => (value, match) => !comparer(value, match);
|
|
5
7
|
const compareArrayOrValue = (comparer) => (value, match) => Array.isArray(value)
|
|
6
8
|
? value.some((value) => comparer(value, match))
|
|
@@ -11,6 +13,7 @@ const compareEqual = compareArrayOrValue((value, match) => value === match);
|
|
|
11
13
|
const compareIn = (value, match) => Array.isArray(match)
|
|
12
14
|
? match.some((item) => compareEqual(value, item))
|
|
13
15
|
: compareEqual(value, match);
|
|
16
|
+
const exists = (value) => value !== undefined;
|
|
14
17
|
function createComparer(operator) {
|
|
15
18
|
switch (operator) {
|
|
16
19
|
case '=':
|
|
@@ -27,6 +30,8 @@ function createComparer(operator) {
|
|
|
27
30
|
return compareArrayOrValueNumeric((value, match) => value <= match);
|
|
28
31
|
case 'in':
|
|
29
32
|
return compareIn;
|
|
33
|
+
case 'exists':
|
|
34
|
+
return exists;
|
|
30
35
|
default:
|
|
31
36
|
return (_value, _match) => false;
|
|
32
37
|
}
|
|
@@ -35,7 +40,10 @@ function compare({ path = '.', operator = '=', match, matchPath, not = false, })
|
|
|
35
40
|
const getValue = (0, pathGetter_1.default)(path);
|
|
36
41
|
const useRoot = typeof matchPath === 'string' && matchPath[0] === '^';
|
|
37
42
|
const realMatchPath = useRoot ? matchPath.slice(1) : matchPath;
|
|
38
|
-
const
|
|
43
|
+
const realMatchValue = mapAny(escape_1.unescapeValue, match);
|
|
44
|
+
const getMatch = typeof realMatchPath === 'string'
|
|
45
|
+
? (0, pathGetter_1.default)(realMatchPath)
|
|
46
|
+
: () => realMatchValue;
|
|
39
47
|
const comparer = createComparer(operator);
|
|
40
48
|
return (data, state) => {
|
|
41
49
|
const value = getValue(data);
|
|
@@ -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":";;AAAA,kCAAkC;AAElC,oDAAwC;AACxC,4CAA+C;AAkB/C,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,GACvB,CAAC,QAAkB,EAAE,EAAE,CAAC,CAAC,KAAc,EAAE,KAAc,EAAE,EAAE,CACzD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAE9B,MAAM,SAAS,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAA;AAEhF,MAAM,0BAA0B,GAAG,CAAC,QAAyB,EAAE,EAAE,CAC/D,mBAAmB,CACjB,CAAC,KAAc,EAAE,KAAc,EAAE,EAAE,CACjC,SAAS,CAAC,KAAK,CAAC,IA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 +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;
|
|
@@ -35,8 +36,8 @@ function map(operands, options) {
|
|
|
35
36
|
}
|
|
36
37
|
return (data, state) => {
|
|
37
38
|
const { rev = false } = state;
|
|
38
|
-
const match = translate(data, dictionary, rev);
|
|
39
|
-
return match === '*' ? data : match;
|
|
39
|
+
const match = translate((0, escape_1.escapeValue)(data), dictionary, rev);
|
|
40
|
+
return match === '*' ? data : (0, escape_1.unescapeValue)(match);
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
exports.default = map;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/functions/map.ts"],"names":[],"mappings":";;AAAA,kCAAkC;
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/functions/map.ts"],"names":[],"mappings":";;AAAA,kCAAkC;AAClC,4CAA4D;AAO5D,MAAM,gBAAgB,GAAG,CAAC,IAAa,EAA2B,EAAE,CAClE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC;IACrD,IAAI,KAAK,IAAI;IACb,IAAI,KAAK,SAAS,CAAA;AAEpB,SAAS,cAAc,CACrB,KAAsB,EACtB,UAAsB,EACtB,SAAgB;IAGhB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,KAAK,CAAC,CAAA;IAClE,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,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oBAAW,EAAC,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;QAC3D,OAAO,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,sBAAa,EAAC,KAAK,CAAC,CAAA;IACpD,CAAC,CAAA;AACH,CAAC;AAhBD,sBAgBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unescapeValue = exports.escapeValue = void 0;
|
|
4
|
+
const escapeValue = (value) => value === undefined ? '**undefined**' : value;
|
|
5
|
+
exports.escapeValue = escapeValue;
|
|
6
|
+
const unescapeValue = (value) => value === '**undefined**' ? undefined : value;
|
|
7
|
+
exports.unescapeValue = unescapeValue;
|
|
8
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/utils/escape.ts"],"names":[],"mappings":";;;AAAO,MAAM,WAAW,GAAG,CAAC,KAAc,EAAE,EAAE,CAC5C,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAA;AADlC,QAAA,WAAW,eACuB;AAExC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAE,EAAE,CAC9C,KAAK,KAAK,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAA;AADlC,QAAA,aAAa,iBACqB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "map-transform",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.15",
|
|
4
4
|
"description": "Map and transform objects with mapping definitions",
|
|
5
5
|
"author": "Kjell-Morten Bratsberg Thorsen <post@kjellmorten.no>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@integreat/ts-dev-setup": "^2.3.0",
|
|
47
47
|
"@types/deep-freeze": "^0.1.2",
|
|
48
|
-
"@types/sinon": "^10.0.
|
|
48
|
+
"@types/sinon": "^10.0.12",
|
|
49
49
|
"deep-freeze": "0.0.1",
|
|
50
50
|
"sinon": "^14.0.0"
|
|
51
51
|
}
|