@storm-stack/utilities
Version:
This package includes various base utility class and various functions to assist in the development process.
36 lines (35 loc) • 1.45 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.
*
* This function takes a deep key string and a path segment and combines them into a new deep key string.
*
* @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.
*
* @example
* 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'
*/
export declare function addPathToDeepKey(deepKey: string, path: string | number): string;