@domql/utils 2.5.178 → 2.5.179
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 +30 -0
- package/dist/cjs/string.js +1 -1
- package/dist/esm/object.js +30 -0
- package/dist/esm/string.js +1 -1
- package/object.js +38 -0
- package/package.json +2 -2
- package/string.js +1 -1
package/dist/cjs/object.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(object_exports, {
|
|
|
36
36
|
excludeKeysFromObject: () => excludeKeysFromObject,
|
|
37
37
|
exec: () => exec,
|
|
38
38
|
flattenRecursive: () => flattenRecursive,
|
|
39
|
+
getInObjectByPath: () => getInObjectByPath,
|
|
39
40
|
hasOwnProperty: () => hasOwnProperty,
|
|
40
41
|
isCyclic: () => isCyclic,
|
|
41
42
|
isEmpty: () => isEmpty,
|
|
@@ -52,6 +53,7 @@ __export(object_exports, {
|
|
|
52
53
|
overwriteShallow: () => overwriteShallow,
|
|
53
54
|
removeFromObject: () => removeFromObject,
|
|
54
55
|
removeNestedKeyByPath: () => removeNestedKeyByPath,
|
|
56
|
+
setInObjectByPath: () => setInObjectByPath,
|
|
55
57
|
stringToObject: () => stringToObject
|
|
56
58
|
});
|
|
57
59
|
module.exports = __toCommonJS(object_exports);
|
|
@@ -614,6 +616,34 @@ const removeNestedKeyByPath = (obj, path) => {
|
|
|
614
616
|
delete current[lastKey];
|
|
615
617
|
}
|
|
616
618
|
};
|
|
619
|
+
const setInObjectByPath = (obj, path, value) => {
|
|
620
|
+
if (!Array.isArray(path)) {
|
|
621
|
+
throw new Error("Path must be an array.");
|
|
622
|
+
}
|
|
623
|
+
let current = obj;
|
|
624
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
625
|
+
if (!current[path[i]] || typeof current[path[i]] !== "object") {
|
|
626
|
+
current[path[i]] = {};
|
|
627
|
+
}
|
|
628
|
+
current = current[path[i]];
|
|
629
|
+
}
|
|
630
|
+
const lastKey = path[path.length - 1];
|
|
631
|
+
current[lastKey] = value;
|
|
632
|
+
return obj;
|
|
633
|
+
};
|
|
634
|
+
const getInObjectByPath = (obj, path) => {
|
|
635
|
+
if (!Array.isArray(path)) {
|
|
636
|
+
throw new Error("Path must be an array.");
|
|
637
|
+
}
|
|
638
|
+
let current = obj;
|
|
639
|
+
for (let i = 0; i < path.length; i++) {
|
|
640
|
+
if (current === void 0 || current === null) {
|
|
641
|
+
return void 0;
|
|
642
|
+
}
|
|
643
|
+
current = current[path[i]];
|
|
644
|
+
}
|
|
645
|
+
return current;
|
|
646
|
+
};
|
|
617
647
|
const detectInfiniteLoop = (arr) => {
|
|
618
648
|
const maxRepeats = 10;
|
|
619
649
|
let pattern = [];
|
package/dist/cjs/string.js
CHANGED
|
@@ -50,7 +50,7 @@ function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
|
|
|
50
50
|
if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
|
|
51
51
|
return str;
|
|
52
52
|
const reg = brackRegex[options.bracketsLength || 2];
|
|
53
|
-
const obj = forcedState || this.state || {};
|
|
53
|
+
const obj = forcedState || (this == null ? void 0 : this.state) || {};
|
|
54
54
|
return str.replace(reg, (_, parentPath, variable) => {
|
|
55
55
|
if (parentPath) {
|
|
56
56
|
const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
|
package/dist/esm/object.js
CHANGED
|
@@ -585,6 +585,34 @@ const removeNestedKeyByPath = (obj, path) => {
|
|
|
585
585
|
delete current[lastKey];
|
|
586
586
|
}
|
|
587
587
|
};
|
|
588
|
+
const setInObjectByPath = (obj, path, value) => {
|
|
589
|
+
if (!Array.isArray(path)) {
|
|
590
|
+
throw new Error("Path must be an array.");
|
|
591
|
+
}
|
|
592
|
+
let current = obj;
|
|
593
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
594
|
+
if (!current[path[i]] || typeof current[path[i]] !== "object") {
|
|
595
|
+
current[path[i]] = {};
|
|
596
|
+
}
|
|
597
|
+
current = current[path[i]];
|
|
598
|
+
}
|
|
599
|
+
const lastKey = path[path.length - 1];
|
|
600
|
+
current[lastKey] = value;
|
|
601
|
+
return obj;
|
|
602
|
+
};
|
|
603
|
+
const getInObjectByPath = (obj, path) => {
|
|
604
|
+
if (!Array.isArray(path)) {
|
|
605
|
+
throw new Error("Path must be an array.");
|
|
606
|
+
}
|
|
607
|
+
let current = obj;
|
|
608
|
+
for (let i = 0; i < path.length; i++) {
|
|
609
|
+
if (current === void 0 || current === null) {
|
|
610
|
+
return void 0;
|
|
611
|
+
}
|
|
612
|
+
current = current[path[i]];
|
|
613
|
+
}
|
|
614
|
+
return current;
|
|
615
|
+
};
|
|
588
616
|
const detectInfiniteLoop = (arr) => {
|
|
589
617
|
const maxRepeats = 10;
|
|
590
618
|
let pattern = [];
|
|
@@ -651,6 +679,7 @@ export {
|
|
|
651
679
|
excludeKeysFromObject,
|
|
652
680
|
exec,
|
|
653
681
|
flattenRecursive,
|
|
682
|
+
getInObjectByPath,
|
|
654
683
|
hasOwnProperty,
|
|
655
684
|
isCyclic,
|
|
656
685
|
isEmpty,
|
|
@@ -667,5 +696,6 @@ export {
|
|
|
667
696
|
overwriteShallow,
|
|
668
697
|
removeFromObject,
|
|
669
698
|
removeNestedKeyByPath,
|
|
699
|
+
setInObjectByPath,
|
|
670
700
|
stringToObject
|
|
671
701
|
};
|
package/dist/esm/string.js
CHANGED
|
@@ -18,7 +18,7 @@ function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
|
|
|
18
18
|
if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
|
|
19
19
|
return str;
|
|
20
20
|
const reg = brackRegex[options.bracketsLength || 2];
|
|
21
|
-
const obj = forcedState || this.state || {};
|
|
21
|
+
const obj = forcedState || (this == null ? void 0 : this.state) || {};
|
|
22
22
|
return str.replace(reg, (_, parentPath, variable) => {
|
|
23
23
|
if (parentPath) {
|
|
24
24
|
const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
|
package/object.js
CHANGED
|
@@ -737,6 +737,44 @@ export const removeNestedKeyByPath = (obj, path) => {
|
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
+
export const setInObjectByPath = (obj, path, value) => {
|
|
741
|
+
if (!Array.isArray(path)) {
|
|
742
|
+
throw new Error('Path must be an array.')
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
let current = obj
|
|
746
|
+
|
|
747
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
748
|
+
// If the current path segment doesn't exist or isn't an object, create it
|
|
749
|
+
if (!current[path[i]] || typeof current[path[i]] !== 'object') {
|
|
750
|
+
current[path[i]] = {}
|
|
751
|
+
}
|
|
752
|
+
current = current[path[i]]
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
const lastKey = path[path.length - 1]
|
|
756
|
+
current[lastKey] = value
|
|
757
|
+
|
|
758
|
+
return obj
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export const getInObjectByPath = (obj, path) => {
|
|
762
|
+
if (!Array.isArray(path)) {
|
|
763
|
+
throw new Error('Path must be an array.')
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
let current = obj
|
|
767
|
+
|
|
768
|
+
for (let i = 0; i < path.length; i++) {
|
|
769
|
+
if (current === undefined || current === null) {
|
|
770
|
+
return undefined
|
|
771
|
+
}
|
|
772
|
+
current = current[path[i]]
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
return current
|
|
776
|
+
}
|
|
777
|
+
|
|
740
778
|
export const detectInfiniteLoop = arr => {
|
|
741
779
|
const maxRepeats = 10 // Maximum allowed repetitions
|
|
742
780
|
let pattern = []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.179",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "npm run build:cjs; npm run build:esm",
|
|
26
26
|
"prepublish": "rimraf -I dist; npm run build; npm run copy:package:cjs"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "6dd81dc7848b03bd9bf564dbc82cd95af713ae21",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|
package/string.js
CHANGED
|
@@ -32,7 +32,7 @@ const brackRegex = {
|
|
|
32
32
|
export function replaceLiteralsWithObjectFields (str, options = {}, forcedState) {
|
|
33
33
|
if (!str.includes(options.bracketsLength === 3 ? '{{{' : '{{')) return str
|
|
34
34
|
const reg = brackRegex[options.bracketsLength || 2]
|
|
35
|
-
const obj = forcedState || this
|
|
35
|
+
const obj = forcedState || this?.state || {}
|
|
36
36
|
return str.replace(reg, (_, parentPath, variable) => {
|
|
37
37
|
if (parentPath) {
|
|
38
38
|
const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length
|