@stryke/helpers
Version:
A package containing miscellaneous helper functions that are used across many different Storm Software projects.
39 lines (38 loc) • 1.48 kB
TypeScript
/**
* Converts an array of path segments into a deep key string.
*
* This function takes an array of strings and numbers representing path segments and combines them into a deep key string.
*
* @example
* toDeepKey(['a', 'b', 'c']) // Returns 'a.b.c'
* toDeepKey(['a', 0, 'c']) // Returns 'a[0].c'
* toDeepKey(['', 'a', 'b', 'c']) // Returns '.a.b.c'
* toDeepKey(['a', 'b.c', 'd']) // Returns 'a.b.c.d'
* toDeepKey([]) // Returns ''
* toDeepKey(['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']) // Returns '.a.b.c.d.e.f.g.h'
*
* @param path - An array of strings and numbers representing path segments.
* @returns A deep key string.
*/
export declare function toDeepKey(path: string[]): string;
/**
* Adds a path segment to a deep key string.
*
* @remarks
* This function takes a deep key string and a path segment and combines them into a new deep key string.
*
* @example
* ```ts
* addPathToDeepKey('a.b', 'c') // Returns 'a.b.c'
* addPathToDeepKey('a[0]', 'c') // Returns 'a[0].c'
* addPathToDeepKey('.a.b', 'c') // Returns '.a.b.c'
* addPathToDeepKey('a.b', 'b.c') // Returns 'a.b.b.c'
* addPathToDeepKey('', 'a') // Returns 'a'
* addPathToDeepKey('.a.b', 'c.d') // Returns '.a.b.c.d'
* ```
*
* @param deepKey - The deep key string to add the path segment to.
* @param path - The path segment to add to the deep key string.
* @returns A new deep key string.
*/
export declare function addPathToDeepKey(deepKey: string, path: string | number): string;