@domql/utils 2.3.142 → 2.3.146
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/object.js +0 -2
- package/dist/cjs/string.js +17 -0
- package/object.js +1 -2
- package/package.json +2 -2
- package/string.js +20 -3
package/dist/cjs/object.js
CHANGED
|
@@ -347,8 +347,6 @@ const overwriteDeep = (obj, params, excludeFrom = []) => {
|
|
|
347
347
|
continue;
|
|
348
348
|
const objProp = obj[e];
|
|
349
349
|
const paramsProp = params[e];
|
|
350
|
-
if (!obj.hasOwnProperty(e) || e === "__proto__" || e === "constructor")
|
|
351
|
-
continue;
|
|
352
350
|
if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
|
|
353
351
|
overwriteDeep(objProp, paramsProp);
|
|
354
352
|
} else if (paramsProp !== void 0) {
|
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,19 @@ 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.split("../").filter(Boolean).length;
|
|
37
|
+
let parentState = state;
|
|
38
|
+
for (let i = 0; i < parentLevels; i++) {
|
|
39
|
+
parentState = parentState.parent;
|
|
40
|
+
}
|
|
41
|
+
const value = parentState[variable.trim()];
|
|
42
|
+
return value ? `${value}` : "";
|
|
43
|
+
} else {
|
|
44
|
+
const value = state[variable.trim()];
|
|
45
|
+
return value ? `${value}` : "";
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
package/object.js
CHANGED
|
@@ -83,7 +83,7 @@ export const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
83
83
|
return o
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
// Merge array, but exclude keys listed in 'excl'
|
|
86
|
+
// Merge array, but exclude keys listed in 'excl'z
|
|
87
87
|
export const mergeArrayExclude = (arr, excl = []) => {
|
|
88
88
|
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {})
|
|
89
89
|
}
|
|
@@ -335,7 +335,6 @@ export const overwriteDeep = (obj, params, excludeFrom = []) => {
|
|
|
335
335
|
if (excludeFrom.includes(e) || e.startsWith('__')) continue
|
|
336
336
|
const objProp = obj[e]
|
|
337
337
|
const paramsProp = params[e]
|
|
338
|
-
if (!obj.hasOwnProperty(e) || e === '__proto__' || e === 'constructor') continue
|
|
339
338
|
if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
|
|
340
339
|
overwriteDeep(objProp, paramsProp)
|
|
341
340
|
} else if (paramsProp !== undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.146",
|
|
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": "96ed22cf144f9b80ad0532ce6af1393677b5249f",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|
package/string.js
CHANGED
|
@@ -3,8 +3,25 @@
|
|
|
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.split('../').filter(Boolean).length
|
|
16
|
+
let parentState = state
|
|
17
|
+
for (let i = 0; i < parentLevels; i++) {
|
|
18
|
+
parentState = parentState.parent
|
|
19
|
+
}
|
|
20
|
+
const value = parentState[variable.trim()]
|
|
21
|
+
return value ? `${value}` : ''
|
|
22
|
+
} else {
|
|
23
|
+
const value = state[variable.trim()]
|
|
24
|
+
return value ? `${value}` : ''
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|