/** * Deep Merge Utility * src/utils/DeepMerge.ts * * This module provides the utility class `DeepMerge` for deep merging objects and * manipulating nested properties using path strings. It allows you to get, set, * check, and delete values at deeply nested paths within an object, as well as * merge two objects together while preserving their structure. * * It supports dot and bracket notation (e.g. `a.b[0].c`) as well as escaped keys. * * @module Utils * @name DeepMerge * @author Paul Köhler * @license MIT */ /** * DeepMerge class provides static methods for deep merging objects and * manipulating nested properties using path strings. */ export declare class DeepMerge { /** Regular expression to match bracket notation in paths */ private static readonly BRACKET_PATTERN; /** Path cache for efficient parsing */ private static readonly PATH_CACHE; /** * Walk through an object using an array of keys and return * whether the path exists and its value. * * @param {any} obj - The object to walk through * @param {( string | number )[]} keys - An array of keys representing the path to walk * @returns {{ exists: false } | { exists: true, value: any }} - * An object indicating whether the path exists and its value if it does */ private static walk; /** * Parse a path string into an array of keys. * * @param {string} p - The path string, e.g. `a.b.c` or `a[0].b` * @returns {( string | number )[]} - An array of keys, e.g. `['a', 'b', 'c']` or `['a', 0, 'b']` */ static parse(p: string): (string | number)[]; /** * Check if a path exists in an object. * * @template T - The type of the object to get the value from * @param {T} t - The object to check * @param {string} path - The path string, e.g. `a.b.c` * @returns {boolean} - True if the path exists, otherwise false */ static has>(t: T, path: string): boolean; /** * Deeply get a value from an object by a path string. * * @template T - The type of the object to get the value from * @template R - The return type of the value * @param {T} t - The object to get the value from * @param {string} path - The path string, e.g. `a.b.c` * @param {any} fb - The default value to return if the path does not exist * @returns {R | undefined} - The value at the specified path, otherwise the default value */ static get, R = any>(t: T, path: string, fb?: R): R | undefined; /** * Deeply set a value in an object by a path string. * * @template T - The type of the object to get the value from * @param {T} t - The object to set the value in * @param {string} path - The path string, e.g. `a.b.c` * @param {any} value - The value to set at the specified path * @returns {T} - The modified object with the value set at the specified path * @throws {CmpStrUsageError} - If the path is invalid or if a non-object value is encountered along the path */ static set>(t: T, path: string, value: any): T; /** * Delete a value at a specified path in an object. * * @template T - The type of the object to get the value from * @param {T} t - The object to delete the value from * @param {string} path - The path string, e.g. `a.b.c` * @param {boolean} [preserveEmpty=false] - Whether to preserve empty objects/arrays * @returns {T} - The modified object with the value deleted at the specified path */ static rmv>(t: T, path: string, preserveEmpty?: boolean): T; /** * Deeply merge two objects, where the second object overrides the first. * * @template T - The type of the object to get the value from * @param {T} t - The target object to merge into * @param {T} o - The source object to merge from * @param {boolean} [mergeUndefined=false] - Whether to merge undefined values * @returns {T} - The merged object */ static merge>(t?: T | undefined, o?: T | undefined, mergeUndefined?: boolean): T; }