@augment-vir/common 28.2.1 → 28.2.3
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.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getValueFromNestedKeys = exports.setValueWithNestedKeys = void 0;
|
|
4
4
|
const run_time_assertions_1 = require("run-time-assertions");
|
|
5
|
+
const tuple_1 = require("../tuple");
|
|
5
6
|
const object_1 = require("./object");
|
|
6
7
|
const typed_has_property_1 = require("./typed-has-property");
|
|
7
8
|
/** This mutates the {@link originalObject} input. */
|
|
@@ -19,21 +20,18 @@ function setValueWithNestedKeys(originalObject, nestedKeys, value) {
|
|
|
19
20
|
setValueWithNestedKeys(entry, nestedKeysInput, value);
|
|
20
21
|
}
|
|
21
22
|
});
|
|
22
|
-
return;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const nextParent = inputObject[nextKey];
|
|
32
|
-
if (nestedKeysInput.length > 2) {
|
|
24
|
+
else if ((0, tuple_1.isLengthAtLeast)(nestedKeysInput, 2)) {
|
|
25
|
+
/** If there are more keys to traverse into. */
|
|
26
|
+
const nextKey = nestedKeysInput[0];
|
|
27
|
+
if (!(nextKey in inputObject)) {
|
|
28
|
+
inputObject[nextKey] = {};
|
|
29
|
+
}
|
|
30
|
+
const nextParent = inputObject[nextKey];
|
|
33
31
|
setValueWithNestedKeys(nextParent, nestedKeysInput.slice(1), value);
|
|
34
32
|
}
|
|
35
|
-
else {
|
|
36
|
-
|
|
33
|
+
else if ((0, tuple_1.isLengthAtLeast)(nestedKeysInput, 1)) {
|
|
34
|
+
inputObject[nestedKeysInput[0]] = value;
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
exports.setValueWithNestedKeys = setValueWithNestedKeys;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isRunTimeType } from 'run-time-assertions';
|
|
2
|
+
import { isLengthAtLeast } from '../tuple';
|
|
2
3
|
import { isObject } from './object';
|
|
3
4
|
import { typedHasProperty } from './typed-has-property';
|
|
4
5
|
/** This mutates the {@link originalObject} input. */
|
|
@@ -16,21 +17,18 @@ export function setValueWithNestedKeys(originalObject, nestedKeys, value) {
|
|
|
16
17
|
setValueWithNestedKeys(entry, nestedKeysInput, value);
|
|
17
18
|
}
|
|
18
19
|
});
|
|
19
|
-
return;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const nextParent = inputObject[nextKey];
|
|
29
|
-
if (nestedKeysInput.length > 2) {
|
|
21
|
+
else if (isLengthAtLeast(nestedKeysInput, 2)) {
|
|
22
|
+
/** If there are more keys to traverse into. */
|
|
23
|
+
const nextKey = nestedKeysInput[0];
|
|
24
|
+
if (!(nextKey in inputObject)) {
|
|
25
|
+
inputObject[nextKey] = {};
|
|
26
|
+
}
|
|
27
|
+
const nextParent = inputObject[nextKey];
|
|
30
28
|
setValueWithNestedKeys(nextParent, nestedKeysInput.slice(1), value);
|
|
31
29
|
}
|
|
32
|
-
else {
|
|
33
|
-
|
|
30
|
+
else if (isLengthAtLeast(nestedKeysInput, 1)) {
|
|
31
|
+
inputObject[nestedKeysInput[0]] = value;
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
export function getValueFromNestedKeys(originalObject, nestedKeys) {
|