/** * Objects manipulation module * * @module objects * * @example * Import object utilities: * ```typescript * import { * clone, * resolvePath, * getValueByPath, * setValueByPath, * isPrimitive * } from '@vvlad1973/utils'; * ``` */ /** * Creates a deep clone of an object * * Uses structuredClone() when available (Node.js 17+), falls back to JSON serialization. * * @template T - Type of the object * @param object - Object to clone * @returns Cloned object or undefined if cloning fails * * @remarks * Limitations when using JSON fallback: * - Functions are not cloned * - Symbol properties are not cloned * - undefined values are converted to null * - Date objects become strings * - RegExp, Map, Set are not properly cloned * - Circular references will cause an error * * @example * ```typescript * const original = { name: 'John', age: 30, nested: { value: 42 } }; * const cloned = clone(original); * // cloned is a deep copy of original * * // Works with Date objects (when using structuredClone) * const withDate = { date: new Date(), data: [1, 2, 3] }; * const clonedDate = clone(withDate); * ``` */ export declare function clone(object: T): T | undefined; /** * Resolves a nested path in an object (supports promises) * * @template T - Type of the return value * @param object - Object to traverse * @param path - Dot-separated path string * @param defaultValue - Default value if path not found * @returns Promise resolving to the value at path or defaultValue * * @example * ```typescript * const obj = { user: { name: 'John' } }; * const name = await resolvePath(obj, 'user.name'); * // name: 'John' * ``` */ export declare function resolvePath(object: any, path: string, defaultValue?: T): Promise; /** * Converts object structure to dot-separated path string * * @param obj - Object to convert * @param path - Current path (used internally for recursion) * @returns Dot-separated paths of all object keys * * @example * ```typescript * const obj = { user: { name: 'John', age: 30 } }; * const paths = objectToPath(obj); * // paths: "user.name.user.age" * ``` */ export declare function objectToPath(obj: Record, path?: string): string; /** * Sets a value at a specific path in an object * * @template T - Type of the object * @param obj - Object to modify * @param path - Dot-separated path where to set the value * @param value - Value to set * @returns Modified object * @throws {TypeError} If obj is not an object * @throws {Error} If path segment is missing or not an object * * @example * ```typescript * const obj = { user: { name: 'John' } }; * setValueByPath(obj, 'user.name', 'Jane'); * // obj.user.name is now 'Jane' * ``` */ export declare function setValueByPath>(obj: T, path: string, value: any): T; /** * Gets value by extended path supporting method calls and array access * * @template T - Type of the return value * @param obj - Object to traverse * @param path - Extended path string (supports method calls and brackets) * @param context - Context object for variable resolution * @returns Promise resolving to the value at path * * @example * ```typescript * const obj = { text: 'hello world' }; * const result = await getValueByPathExt(obj, 'text.toUpperCase()'); * // result: 'HELLO WORLD' * ``` */ export declare function getValueByPathExt(obj: any, path: string, context?: Record): Promise; /** * Gets value by path from object (supports promises) * * @template T - Type of the return value * @param obj - Object to traverse * @param path - Dot-separated path string or array of keys * @returns Promise resolving to the value at path * * @example * ```typescript * const obj = { user: { name: 'John' } }; * const name = await getValueByPath(obj, 'user.name'); * // name: 'John' * ``` */ export declare function getValueByPath(obj: any, path: string | string[]): Promise; /** * Gets value by path from object (synchronous version) * * @template T - Type of the return value * @param obj - Object to traverse * @param path - Dot-separated path string * @returns Value at path or undefined * * @example * ```typescript * const obj = { user: { name: 'John' } }; * const name = getValueByPathSync(obj, 'user.name'); * // name: 'John' * ``` */ export declare function getValueByPathSync(obj: any, path: string): T | undefined; /** * Gets a random value from an object where keys match a regex pattern * * @template T - Type of the values * @param pattern - Regular expression pattern to match keys * @param list - Object with key-value pairs * @returns Random value from matching keys or undefined * * @example * ```typescript * const strings = { * HELLO_1: 'Hi', * HELLO_2: 'Hello', * HELLO_3: 'Hey', * OTHER: 'Other' * }; * const greeting = getRandomValue('HELLO_\\d', strings); * // returns one of: 'Hi', 'Hello', 'Hey' * ``` */ export declare function getRandomValue(pattern: string, list: Record): T | undefined; /** * Checks if a value is a primitive type * * @param value - Value to check * @returns True if value is primitive, false otherwise * * @example * ```typescript * isPrimitive(42); // true * isPrimitive('hello'); // true * isPrimitive({}); // false * isPrimitive([]); // false * ``` */ export declare function isPrimitive(value: unknown): boolean; /** * Checks if a value is a Promise * * @param obj - Value to check * @returns True if value is a Promise, false otherwise * * @example * ```typescript * isPromise(Promise.resolve(42)); // true * isPromise(42); // false * ``` */ export declare function isPromise(obj: unknown): obj is Promise;