@tmlmobilidade/utils 20260504.1123.42 → 20260504.1132.55

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.
@@ -1,2 +1 @@
1
- export * from './get-value-at-path.js';
2
- export * from './set-value-at-path.js';
1
+ export * from './value-at-path.js';
@@ -1,2 +1 @@
1
- export * from './get-value-at-path.js';
2
- export * from './set-value-at-path.js';
1
+ export * from './value-at-path.js';
@@ -14,6 +14,13 @@ export type DotPath<T, Prev extends string = ''> = {
14
14
  * @template P The dot-separated path to the value.
15
15
  */
16
16
  export type PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? T[Key] extends (infer U)[] ? Rest extends `${number}.${infer SubRest}` ? PathValue<U, SubRest> : Rest extends `${number}` ? U : never : PathValue<T[Key], Rest> : never : P extends keyof T ? T[P] : T extends (infer U)[] ? P extends `${number}` ? U : never : never;
17
+ /**
18
+ * Utility function that returns the value at a given path in an object.
19
+ * @param obj The object to retrieve the value from.
20
+ * @param path The path to the value in the object.
21
+ * @returns The value at the given path or undefined if the path is invalid.
22
+ */
23
+ export declare function getValueAtPath<T, P extends DotPath<T>>(obj: T, path: P): PathValue<T, P>;
17
24
  /**
18
25
  * Sets a value at a specified dot-separated path within an object.
19
26
  * If intermediate objects or arrays do not exist, they are created.
@@ -1,4 +1,16 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * Utility function that returns the value at a given path in an object.
4
+ * @param obj The object to retrieve the value from.
5
+ * @param path The path to the value in the object.
6
+ * @returns The value at the given path or undefined if the path is invalid.
7
+ */
8
+ export function getValueAtPath(obj, path) {
9
+ if (!path)
10
+ return undefined;
11
+ const pathArray = path.match(/([^[.\]])+/g);
12
+ return pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj);
13
+ }
2
14
  /**
3
15
  * Sets a value at a specified dot-separated path within an object.
4
16
  * If intermediate objects or arrays do not exist, they are created.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/utils",
3
- "version": "20260504.1123.42",
3
+ "version": "20260504.1132.55",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"
@@ -1,7 +0,0 @@
1
- /**
2
- * Utility function that returns the value at a given path in an object.
3
- * @param obj The object to retrieve the value from.
4
- * @param path The path to the value in the object.
5
- * @returns The value at the given path or undefined if the path is invalid.
6
- */
7
- export declare function getValueAtPath<T>(obj: T, path: keyof T | (NonNullable<unknown> & string)): unknown;
@@ -1,13 +0,0 @@
1
- /* * */
2
- /**
3
- * Utility function that returns the value at a given path in an object.
4
- * @param obj The object to retrieve the value from.
5
- * @param path The path to the value in the object.
6
- * @returns The value at the given path or undefined if the path is invalid.
7
- */
8
- export function getValueAtPath(obj, path) {
9
- if (!path)
10
- return undefined;
11
- const pathArray = path.match(/([^[.\]])+/g);
12
- return pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj);
13
- }