map-transform 0.4.0-alpha.3 → 0.4.0-alpha.4
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.
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const Mustache = require("mustache");
|
|
4
4
|
const mapAny = require("map-any");
|
|
5
5
|
const pathGetter_1 = require("../utils/pathGetter");
|
|
6
6
|
const extractOperands = (operands) => typeof operands === 'string' ? { template: operands } : operands;
|
|
7
|
+
function parseAndCreateGenerator(templateStr) {
|
|
8
|
+
Mustache.parse(templateStr);
|
|
9
|
+
return (data) => mapAny((data) => Mustache.render(templateStr, data), data);
|
|
10
|
+
}
|
|
7
11
|
function template(operands) {
|
|
8
12
|
const { template: templateStr, templatePath } = extractOperands(operands);
|
|
9
13
|
if (typeof templateStr === 'string') {
|
|
10
|
-
|
|
11
|
-
return (data) => mapAny((data) => generate(data), data);
|
|
14
|
+
return parseAndCreateGenerator(templateStr);
|
|
12
15
|
}
|
|
13
16
|
else if (typeof templatePath === 'string') {
|
|
14
17
|
const getFn = (0, pathGetter_1.default)(templatePath);
|
|
15
18
|
return (data) => {
|
|
16
19
|
const templateStr = getFn(data);
|
|
17
20
|
if (typeof templateStr === 'string') {
|
|
18
|
-
|
|
19
|
-
return mapAny((data) => generate(data), data);
|
|
21
|
+
return parseAndCreateGenerator(templateStr)(data);
|
|
20
22
|
}
|
|
21
23
|
return undefined;
|
|
22
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/functions/template.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/functions/template.ts"],"names":[],"mappings":";;AAAA,qCAAqC;AACrC,kCAAkC;AAClC,oDAAwC;AAQxC,MAAM,eAAe,GAAG,CAAC,QAA2B,EAAE,EAAE,CACtD,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAA;AAElE,SAAS,uBAAuB,CAAC,WAAmB;IAClD,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IAC3B,OAAO,CAAC,IAAa,EAAE,EAAE,CACvB,MAAM,CAAC,CAAC,IAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;AACvE,CAAC;AAED,SAAwB,QAAQ,CAAC,QAA2B;IAC1D,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAA;IAEzE,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QAEnC,OAAO,uBAAuB,CAAC,WAAW,CAAC,CAAA;KAC5C;SAAM,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;QAG3C,MAAM,KAAK,GAAG,IAAA,oBAAM,EAAC,YAAY,CAAC,CAAA;QAClC,OAAO,CAAC,IAAI,EAAE,EAAE;YACd,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;YAC/B,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;gBACnC,OAAO,uBAAuB,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAA;aAClD;YACD,OAAO,SAAS,CAAA;QAClB,CAAC,CAAA;KACF;IAED,OAAO,GAAG,EAAE,CAAC,SAAS,CAAA;AACxB,CAAC;AApBD,2BAoBC"}
|
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.4",
|
|
4
4
|
"description": "Map and transform objects with mapping definitions",
|
|
5
5
|
"author": "Kjell-Morten Bratsberg Thorsen <post@kjellmorten.no>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -37,11 +37,12 @@
|
|
|
37
37
|
"homepage": "https://github.com/integreat-io/map-transform#readme",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@types/lodash.merge": "^4.6.6",
|
|
40
|
-
"@types/
|
|
40
|
+
"@types/mustache": "^4.1.2",
|
|
41
|
+
"@types/ramda": "^0.27.50",
|
|
41
42
|
"ajv": "^6.12.6",
|
|
42
|
-
"handlebars": "^4.7.7",
|
|
43
43
|
"lodash.merge": "^4.6.2",
|
|
44
44
|
"map-any": "^0.2.1",
|
|
45
|
+
"mustache": "^4.2.0",
|
|
45
46
|
"ramda": "^0.27.1"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|