@tmlmobilidade/utils 20260509.331.19 → 20260509.340.15
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.
|
@@ -21,12 +21,4 @@ export type PathValue<T, P extends string> = P extends `${infer Key}.${infer Res
|
|
|
21
21
|
* @returns The value at the given path or undefined if the path is invalid.
|
|
22
22
|
*/
|
|
23
23
|
export declare function getValueAtPath<T, P extends DotPath<T>>(obj: T, path: P): PathValue<T, P>;
|
|
24
|
-
/**
|
|
25
|
-
* Sets a value at a specified dot-separated path within an object.
|
|
26
|
-
* If intermediate objects or arrays do not exist, they are created.
|
|
27
|
-
* @param obj The object to set the value in.
|
|
28
|
-
* @param path The dot-separated path where the value should be set.
|
|
29
|
-
* @param value The value to set at the specified path.
|
|
30
|
-
* @returns The updated object with the value set at the specified path.
|
|
31
|
-
*/
|
|
32
24
|
export declare function setValueAtPath<T extends object, P extends DotPath<T>>(obj: T, path: P, value: PathValue<T, P>): T;
|
|
@@ -19,8 +19,14 @@ export function getValueAtPath(obj, path) {
|
|
|
19
19
|
* @param value The value to set at the specified path.
|
|
20
20
|
* @returns The updated object with the value set at the specified path.
|
|
21
21
|
*/
|
|
22
|
+
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
22
23
|
export function setValueAtPath(obj, path, value) {
|
|
23
24
|
const keys = path.split('.');
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
if (UNSAFE_KEYS.has(key)) {
|
|
27
|
+
throw new Error(`Unsafe path segment: "${key}"`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
24
30
|
let current = obj;
|
|
25
31
|
keys.slice(0, -1).forEach((key) => {
|
|
26
32
|
if (!(key in current)) {
|