@ctrl/golang-template 1.3.0 → 1.4.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 +17 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +31 -7
- package/dist/index.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.js +3 -2
- package/dist/util.js.map +1 -1
- package/package.json +15 -25
package/README.md
CHANGED
@@ -50,5 +50,21 @@ parse('{{ re_replace .category "[^a-zA-Z0-9]+" "%" }}', { categories });
|
|
50
50
|
// 1;2;3;
|
51
51
|
```
|
52
52
|
|
53
|
+
#### index
|
54
|
+
```ts
|
55
|
+
const data = {
|
56
|
+
object: {
|
57
|
+
value: 'foo'
|
58
|
+
},
|
59
|
+
array: [
|
60
|
+
'bar'
|
61
|
+
]
|
62
|
+
}
|
63
|
+
parse('{{ index .object "value" }}', data);
|
64
|
+
//foo
|
65
|
+
parse('{{ index .array 0 }}', data);
|
66
|
+
//foo
|
67
|
+
```
|
68
|
+
|
53
69
|
### Warnings
|
54
|
-
This is probably not safe for user
|
70
|
+
This is probably not safe for user input.
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
export declare function reReplace(str: string, variables:
|
2
|
-
export declare function joinReplace(str: string, variables:
|
3
|
-
export declare function ifElseReplace(str: string, variables:
|
4
|
-
export declare function rangeReplace(str: string, variables:
|
5
|
-
export declare function variableReplace(str: string, variables:
|
1
|
+
export declare function reReplace(str: string, variables: Record<string, any>): string;
|
2
|
+
export declare function joinReplace(str: string, variables: Record<string, any>): string;
|
3
|
+
export declare function ifElseReplace(str: string, variables: Record<string, any>): string;
|
4
|
+
export declare function rangeReplace(str: string, variables: Record<string, any>): string;
|
5
|
+
export declare function variableReplace(str: string, variables: Record<string, any>): string;
|
6
|
+
export declare function indexReplace(str: string, variables: Record<string, any>): string;
|
6
7
|
/**
|
7
|
-
*
|
8
|
+
* Parse template and insert variables
|
8
9
|
* @param str golang style template
|
9
10
|
* @param variables object of variables to insert
|
10
11
|
*/
|
11
|
-
export declare function parse(str: string, variables:
|
12
|
+
export declare function parse(str: string, variables: Record<string, any>): string;
|
package/dist/index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parse = exports.indexReplace = exports.variableReplace = exports.rangeReplace = exports.ifElseReplace = exports.joinReplace = exports.reReplace = void 0;
|
3
4
|
const util_1 = require("./util");
|
4
5
|
function reReplace(str, variables) {
|
5
6
|
const regex = /{{\s*re_replace\s+(\..+?)\s+"(.*?)"\s+"(.*?)"\s*}}/;
|
@@ -11,7 +12,7 @@ function reReplace(str, variables) {
|
|
11
12
|
const regexp = m[2];
|
12
13
|
const newvalue = m[3];
|
13
14
|
const replaceRegex = new RegExp(regexp, 'g');
|
14
|
-
const input = util_1.get(variables, prop.substring(1));
|
15
|
+
const input = (0, util_1.get)(variables, prop.substring(1));
|
15
16
|
const expanded = input.replace(replaceRegex, newvalue);
|
16
17
|
result = result.replace(all, expanded);
|
17
18
|
}
|
@@ -26,7 +27,7 @@ function joinReplace(str, variables) {
|
|
26
27
|
const all = m[0];
|
27
28
|
const prop = m[1];
|
28
29
|
const delimiter = m[2];
|
29
|
-
const input = util_1.get(variables, prop);
|
30
|
+
const input = (0, util_1.get)(variables, prop);
|
30
31
|
const expanded = input.join(delimiter);
|
31
32
|
result = result.replace(all, expanded);
|
32
33
|
}
|
@@ -34,7 +35,7 @@ function joinReplace(str, variables) {
|
|
34
35
|
}
|
35
36
|
exports.joinReplace = joinReplace;
|
36
37
|
function ifElseReplace(str, variables) {
|
37
|
-
const regex = /{{\s*if\s*(.+?)\s*}}(
|
38
|
+
const regex = /{{\s*if\s*(.+?)\s*}}([\S\s]*?){{\s*else\s*}}([\S\s]*?){{\s*end\s*}}/;
|
38
39
|
let result = str;
|
39
40
|
let m;
|
40
41
|
while ((m = regex.exec(result)) !== null) {
|
@@ -45,7 +46,7 @@ function ifElseReplace(str, variables) {
|
|
45
46
|
const onFalse = m[3];
|
46
47
|
if (condition.startsWith('.')) {
|
47
48
|
let conditionResultState = false;
|
48
|
-
const value = util_1.get(variables, condition.substring(1));
|
49
|
+
const value = (0, util_1.get)(variables, condition.substring(1));
|
49
50
|
if (value === null || value === undefined) {
|
50
51
|
conditionResultState = false;
|
51
52
|
}
|
@@ -81,7 +82,7 @@ function rangeReplace(str, variables) {
|
|
81
82
|
const prop = m[1];
|
82
83
|
const prefix = m[2];
|
83
84
|
const postfix = m[3];
|
84
|
-
const arr = util_1.get(variables, prop.substring(1));
|
85
|
+
const arr = (0, util_1.get)(variables, prop.substring(1));
|
85
86
|
if (arr && Array.isArray(arr)) {
|
86
87
|
for (const value of arr) {
|
87
88
|
expanded += `${prefix}${value}${postfix}`;
|
@@ -99,14 +100,36 @@ function variableReplace(str, variables) {
|
|
99
100
|
while ((m = regex.exec(result)) !== null) {
|
100
101
|
const all = m[0];
|
101
102
|
const prop = m[1];
|
102
|
-
const value = util_1.get(variables, prop.substring(1));
|
103
|
+
const value = (0, util_1.get)(variables, prop.substring(1));
|
103
104
|
result = result.replace(all, value);
|
104
105
|
}
|
105
106
|
return result;
|
106
107
|
}
|
107
108
|
exports.variableReplace = variableReplace;
|
109
|
+
function indexReplace(str, variables) {
|
110
|
+
const regex = /{{\s*index\s*(\..+?)\s+(.+?)\s*}}/;
|
111
|
+
let result = str;
|
112
|
+
let m;
|
113
|
+
while ((m = regex.exec(result)) !== null) {
|
114
|
+
const all = m[0];
|
115
|
+
const prop = m[1];
|
116
|
+
const index = m[2];
|
117
|
+
const top = (0, util_1.get)(variables, prop.substring(1));
|
118
|
+
let value;
|
119
|
+
// @ts-expect-error
|
120
|
+
if (isNaN(index)) {
|
121
|
+
value = top[index.substring(1, index.length - 1)];
|
122
|
+
}
|
123
|
+
else {
|
124
|
+
value = top[parseInt(index, 10)];
|
125
|
+
}
|
126
|
+
result = result.replace(all, value);
|
127
|
+
}
|
128
|
+
return result;
|
129
|
+
}
|
130
|
+
exports.indexReplace = indexReplace;
|
108
131
|
/**
|
109
|
-
*
|
132
|
+
* Parse template and insert variables
|
110
133
|
* @param str golang style template
|
111
134
|
* @param variables object of variables to insert
|
112
135
|
*/
|
@@ -116,6 +139,7 @@ function parse(str, variables) {
|
|
116
139
|
result = ifElseReplace(result, variables);
|
117
140
|
result = rangeReplace(result, variables);
|
118
141
|
result = variableReplace(result, variables);
|
142
|
+
result = indexReplace(result, variables);
|
119
143
|
return result;
|
120
144
|
}
|
121
145
|
exports.parse = parse;
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,SAAgB,SAAS,CAAC,GAAW,EAAE,SAA8B;IACnE,MAAM,KAAK,GAAG,oDAAoD,CAAC;IACnE,IAAI,MAAM,GAAG,GAAG,CAAC;IACjB,IAAI,CAA0B,CAAC;IAE/B,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE;QACxC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACjB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAClB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtB,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAW,IAAA,UAAG,EAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO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AAS,CAAC,CAAC;IAC1C,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACzC,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC5C,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,sBAQC","sourcesContent":["import { get } from './util';\n\nexport function reReplace(str: string, variables: Record<string, any>): string {\n const regex = /{{\\s*re_replace\\s+(\\..+?)\\s+\"(.*?)\"\\s+\"(.*?)\"\\s*}}/;\n let result = str;\n let m: RegExpMatchArray | null;\n\n while ((m = regex.exec(result)) !== null) {\n const all = m[0];\n const prop = m[1];\n const regexp = m[2];\n const newvalue = m[3];\n\n const replaceRegex = new RegExp(regexp, 'g');\n const input: string = get(variables, prop.substring(1));\n const expanded = input.replace(replaceRegex, newvalue);\n\n result = result.replace(all, expanded);\n }\n\n return result;\n}\n\nexport function joinReplace(str: string, variables: Record<string, any>): string {\n const regex = /{{\\s*join\\s+\\.(.+?)\\s+\"(.*?)\"\\s*}}/;\n let result = str;\n let m: RegExpMatchArray | null;\n\n while ((m = regex.exec(result)) !== null) {\n const all = m[0];\n const prop = m[1];\n const delimiter = m[2];\n\n const input: string[] = get(variables, prop);\n const expanded = input.join(delimiter);\n\n result = result.replace(all, expanded);\n }\n\n return result;\n}\n\nexport function ifElseReplace(str: string, variables: Record<string, any>): string {\n const regex = /{{\\s*if\\s*(.+?)\\s*}}([\\S\\s]*?){{\\s*else\\s*}}([\\S\\s]*?){{\\s*end\\s*}}/;\n let result = str;\n let m: RegExpMatchArray | null;\n\n while ((m = regex.exec(result)) !== null) {\n let conditionResult: string;\n\n const all = m[0];\n const condition = m[1];\n const onTrue = m[2];\n const onFalse = m[3];\n\n if (condition.startsWith('.')) {\n let conditionResultState = false;\n const value = get(variables, condition.substring(1));\n if (value === null || value === undefined) {\n conditionResultState = false;\n } else if (typeof value === 'string') {\n conditionResultState = value.length > 0;\n } else if (Array.isArray(value)) {\n conditionResultState = value.length > 0;\n } else if (typeof value === 'boolean') {\n conditionResultState = value;\n } else {\n throw new Error(`Unexpceted type for variable ${condition}: ${typeof value}`);\n }\n\n conditionResult = conditionResultState ? onTrue : onFalse;\n } else {\n throw new Error('Functionality not implemented');\n }\n\n result = result.replace(all, conditionResult);\n }\n\n return result;\n}\n\nexport function rangeReplace(str: string, variables: Record<string, any>): string {\n const regex = /{{\\s*range\\s*(.+?)\\s*}}(.*?){{\\.}}(.*?){{end}}/;\n let result = str;\n let m: RegExpMatchArray | null;\n\n while ((m = regex.exec(result)) !== null) {\n let expanded = '';\n\n const all = m[0];\n const prop = m[1];\n const prefix = m[2];\n const postfix = m[3];\n\n const arr: unknown = get(variables, prop.substring(1));\n if (arr && Array.isArray(arr)) {\n for (const value of arr as string[]) {\n expanded += `${prefix}${value}${postfix}`;\n }\n }\n\n result = result.replace(all, expanded);\n }\n\n return result;\n}\n\nexport function variableReplace(str: string, variables: Record<string, any>): string {\n const regex = /{{\\s*(\\..+?)\\s*}}/;\n let result = str;\n let m: RegExpMatchArray | null;\n\n while ((m = regex.exec(result)) !== null) {\n const all = m[0];\n const prop = m[1];\n\n const value = get(variables, prop.substring(1));\n result = result.replace(all, value);\n }\n\n return result;\n}\n\nexport function indexReplace(str: string, variables: Record<string, any>): string {\n const regex = /{{\\s*index\\s*(\\..+?)\\s+(.+?)\\s*}}/;\n let result = str;\n let m: RegExpMatchArray | null;\n\n while ((m = regex.exec(result)) !== null) {\n const all = m[0];\n const prop = m[1];\n const index = m[2];\n\n const top = get(variables, prop.substring(1));\n let value;\n // @ts-expect-error\n if (isNaN(index)) {\n value = top[index.substring(1, index.length - 1)];\n } else {\n value = top[parseInt(index, 10)];\n }\n\n result = result.replace(all, value);\n }\n\n return result;\n}\n\n/**\n * Parse template and insert variables\n * @param str golang style template\n * @param variables object of variables to insert\n */\nexport function parse(str: string, variables: Record<string, any>): string {\n let result = reReplace(str, variables);\n result = joinReplace(result, variables);\n result = ifElseReplace(result, variables);\n result = rangeReplace(result, variables);\n result = variableReplace(result, variables);\n result = indexReplace(result, variables);\n return result;\n}\n"]}
|
package/dist/util.d.ts
CHANGED
package/dist/util.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.get = void 0;
|
3
4
|
/**
|
4
5
|
* Gets the value at `path` of `object`.
|
5
6
|
* @param object
|
@@ -8,9 +9,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
9
|
*/
|
9
10
|
function get(object, path) {
|
10
11
|
if (typeof path === 'string') {
|
11
|
-
path = path.split('.').filter(key => key.length);
|
12
|
+
path = path.split('.').filter((key) => key.length);
|
12
13
|
}
|
13
|
-
return path.reduce((dive, key) => dive
|
14
|
+
return path.reduce((dive, key) => dive === null || dive === void 0 ? void 0 : dive[key], object);
|
14
15
|
}
|
15
16
|
exports.get = get;
|
16
17
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,GAAG,CAAC,MAA2B,EAAE,IAAoB;IACnE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KACpD;IAED,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAND,kBAMC","sourcesContent":["/**\n * Gets the value at `path` of `object`.\n * @param object\n * @param path\n * @returns value if exists else undefined\n */\nexport function get(object: Record<string, any>, path: string | any[]): any {\n if (typeof path === 'string') {\n path = path.split('.').filter((key) => key.length);\n }\n\n return path.reduce((dive, key) => dive?.[key], object);\n}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ctrl/golang-template",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.1",
|
4
4
|
"description": "Basic golang template parsing in js",
|
5
5
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
6
6
|
"license": "MIT",
|
@@ -19,39 +19,29 @@
|
|
19
19
|
],
|
20
20
|
"sideEffects": false,
|
21
21
|
"scripts": {
|
22
|
-
"lint": "eslint
|
23
|
-
"lint:fix": "eslint --fix
|
22
|
+
"lint": "eslint --ext .ts .",
|
23
|
+
"lint:fix": "eslint --fix --ext .ts .",
|
24
24
|
"prepare": "npm run build",
|
25
25
|
"build": "tsc -p tsconfig.build.json",
|
26
|
-
"test": "
|
27
|
-
"test:watch": "
|
28
|
-
"test:ci": "
|
29
|
-
"semantic-release": "semantic-release"
|
26
|
+
"test": "vitest run",
|
27
|
+
"test:watch": "vitest",
|
28
|
+
"test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
|
30
29
|
},
|
31
|
-
"dependencies": {},
|
32
30
|
"devDependencies": {
|
33
|
-
"@
|
34
|
-
"@types/node": "
|
35
|
-
"@
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"eslint-config-xo-typescript": "0.21.0",
|
40
|
-
"eslint-plugin-import": "2.18.2",
|
41
|
-
"jest": "24.9.0",
|
42
|
-
"semantic-release": "15.13.30",
|
43
|
-
"ts-jest": "24.1.0",
|
44
|
-
"typescript": "3.7.2"
|
31
|
+
"@ctrl/eslint-config": "3.4.10",
|
32
|
+
"@types/node": "18.7.15",
|
33
|
+
"@vitest/coverage-c8": "^0.23.1",
|
34
|
+
"c8": "7.11.3",
|
35
|
+
"typescript": "4.8.2",
|
36
|
+
"vitest": "0.15.2"
|
45
37
|
},
|
46
38
|
"publishConfig": {
|
47
39
|
"access": "public"
|
48
40
|
},
|
49
|
-
"jest": {
|
50
|
-
"preset": "ts-jest",
|
51
|
-
"testEnvironment": "node"
|
52
|
-
},
|
53
41
|
"release": {
|
54
|
-
"
|
42
|
+
"branches": [
|
43
|
+
"master"
|
44
|
+
]
|
55
45
|
},
|
56
46
|
"engines": {
|
57
47
|
"node": ">=8.0.0"
|