@domql/utils 2.3.143 → 2.3.147
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/dist/cjs/string.js +20 -0
- package/package.json +2 -2
- package/string.js +23 -3
package/dist/cjs/string.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var string_exports = {};
|
|
20
20
|
__export(string_exports, {
|
|
21
|
+
replaceLiteralsWithObjectFields: () => replaceLiteralsWithObjectFields,
|
|
21
22
|
stringIncludesAny: () => stringIncludesAny
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(string_exports);
|
|
@@ -29,3 +30,22 @@ const stringIncludesAny = (str, characters) => {
|
|
|
29
30
|
}
|
|
30
31
|
return false;
|
|
31
32
|
};
|
|
33
|
+
const replaceLiteralsWithObjectFields = (str, state) => {
|
|
34
|
+
return str.replace(/\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g, (_, parentPath, variable) => {
|
|
35
|
+
if (parentPath) {
|
|
36
|
+
const parentLevels = parentPath.match(/\.\.\//g).length;
|
|
37
|
+
let parentState = state;
|
|
38
|
+
for (let i = 0; i < parentLevels; i++) {
|
|
39
|
+
parentState = parentState.parent;
|
|
40
|
+
if (!parentState) {
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const value = parentState[variable.trim()];
|
|
45
|
+
return value !== void 0 ? `${value}` : "";
|
|
46
|
+
} else {
|
|
47
|
+
const value = state[variable.trim()];
|
|
48
|
+
return value !== void 0 ? `${value}` : "";
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.147",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@domql/key": "latest",
|
|
24
24
|
"@domql/tags": "latest"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "88a525ab8e7fca820d53bb0c284d36bd68f3a147",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|
package/string.js
CHANGED
|
@@ -3,8 +3,28 @@
|
|
|
3
3
|
export const stringIncludesAny = (str, characters) => {
|
|
4
4
|
for (const char of characters) {
|
|
5
5
|
if (str.includes(char)) {
|
|
6
|
-
return true
|
|
6
|
+
return true
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const replaceLiteralsWithObjectFields = (str, state) => {
|
|
13
|
+
return str.replace(/\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g, (_, parentPath, variable) => {
|
|
14
|
+
if (parentPath) {
|
|
15
|
+
const parentLevels = parentPath.match(/\.\.\//g).length
|
|
16
|
+
let parentState = state
|
|
17
|
+
for (let i = 0; i < parentLevels; i++) {
|
|
18
|
+
parentState = parentState.parent
|
|
19
|
+
if (!parentState) {
|
|
20
|
+
return '' // Return an empty string if the parent level doesn't exist
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const value = parentState[variable.trim()]
|
|
24
|
+
return value !== undefined ? `${value}` : ''
|
|
25
|
+
} else {
|
|
26
|
+
const value = state[variable.trim()]
|
|
27
|
+
return value !== undefined ? `${value}` : ''
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|