/** * Object-focused utility helpers. * * @module bquery/core/utils/object */ /** * Checks if a value is a plain object (not null, array, or class instance). * * @param value - The value to check * @returns True if the value is a plain object */ export declare function isPlainObject(value: unknown): value is Record; /** * Checks if a key could cause prototype pollution. * These keys are dangerous when used in object merging operations. * * @param key - The key to check * @returns True if the key is a prototype pollution vector * * @internal */ export declare function isPrototypePollutionKey(key: string): boolean; /** * Creates a deep clone using structuredClone if available, otherwise fallback to JSON. * * @template T - The type of value being cloned * @param value - The value to clone * @returns A deep copy of the value * * @remarks * When `structuredClone` is available (modern browsers, Node 17+, Bun), this function * provides full deep cloning including circular references, Date, Map, Set, ArrayBuffer, etc. * * **JSON fallback limitations** (older environments without `structuredClone`): * - **Throws** on circular references * - **Drops** functions, `undefined`, and Symbol properties * - **Transforms** Date → ISO string, Map/Set → empty object, BigInt → throws * - **Loses** prototype chains and non-enumerable properties * * For guaranteed safe cloning of arbitrary data, ensure your environment supports * `structuredClone` or pre-validate your data structure. * * @example * ```ts * const original = { nested: { value: 1 } }; * const copy = clone(original); * copy.nested.value = 2; * console.log(original.nested.value); // 1 * ``` */ export declare function clone(value: T): T; /** * Deep-merges plain objects into a new object. * Later sources override earlier ones for primitive values. * Objects are recursively merged. * * @param sources - Objects to merge * @returns A new object with all sources merged as an intersection type * * @remarks * This function uses overloads to provide accurate intersection types for up to 5 sources. * For more than 5 sources, the return type falls back to `Record`. * * Note that deep merging creates a shallow intersection at the type level. Nested objects * are merged at runtime, but TypeScript sees them as intersected types which may not * perfectly represent the merged structure for deeply nested conflicting types. * * @example * ```ts * const result = merge( * { a: 1, nested: { x: 1 } }, * { b: 2, nested: { y: 2 } } * ); * // Result: { a: 1, b: 2, nested: { x: 1, y: 2 } } * // Type: { a: number; nested: { x: number } } & { b: number; nested: { y: number } } * ``` * * @security This method is protected against prototype pollution attacks. * Keys like `__proto__`, `constructor`, and `prototype` are ignored. */ export declare function merge>(source1: T1): T1; export declare function merge, T2 extends Record>(source1: T1, source2: T2): T1 & T2; export declare function merge, T2 extends Record, T3 extends Record>(source1: T1, source2: T2, source3: T3): T1 & T2 & T3; export declare function merge, T2 extends Record, T3 extends Record, T4 extends Record>(source1: T1, source2: T2, source3: T3, source4: T4): T1 & T2 & T3 & T4; export declare function merge, T2 extends Record, T3 extends Record, T4 extends Record, T5 extends Record>(source1: T1, source2: T2, source3: T3, source4: T4, source5: T5): T1 & T2 & T3 & T4 & T5; export declare function merge(...sources: Record[]): Record; /** * Picks specified keys from an object. * * @template T - The object type * @template K - The key type * @param obj - The source object * @param keys - Keys to pick * @returns A new object with only the specified keys * * @example * ```ts * const user = { name: 'John', age: 30, email: 'john@example.com' }; * pick(user, ['name', 'email']); // { name: 'John', email: 'john@example.com' } * ``` */ export declare function pick, K extends keyof T>(obj: T, keys: K[]): Pick; /** * Omits specified keys from an object. * * @template T - The object type * @template K - The key type * @param obj - The source object * @param keys - Keys to omit * @returns A new object without the specified keys * * @example * ```ts * const user = { name: 'John', age: 30, password: 'secret' }; * omit(user, ['password']); // { name: 'John', age: 30 } * ``` */ export declare function omit, K extends keyof T>(obj: T, keys: K[]): Omit; /** * Checks if an object has a given own property. * * @template T - The object type * @param obj - The object to check * @param key - The property key * @returns True if the property exists on the object * * @example * ```ts * hasOwn({ a: 1 }, 'a'); // true * ``` */ export declare function hasOwn(obj: T, key: PropertyKey): key is keyof T; /** * Safely reads a deeply nested value from an object/array. * Returns `defaultValue` if any intermediate step is `undefined` / `null`. * * Path supports dot notation (`'a.b.c'`), array indices (`'list[0].name'`), * or a pre-split key array. * * @security Prototype-pollution keys (`__proto__`, `constructor`, `prototype`) * are skipped during traversal. * * @example * ```ts * get({ a: { b: { c: 42 } } }, 'a.b.c'); // 42 * get({ list: [{ name: 'x' }] }, 'list[0].name'); // 'x' * get({}, 'a.b', 'fallback'); // 'fallback' * ``` */ export declare function get(obj: unknown, path: string | readonly PropertyKey[]): T | undefined; export declare function get(obj: unknown, path: string | readonly PropertyKey[], defaultValue: T): T; export declare function set(obj: T, path: string | readonly PropertyKey[], value: unknown): T; /** * Returns true if the object has a value at the given path. Refuses to * follow prototype-pollution keys. */ export declare function has(obj: unknown, path: string | readonly PropertyKey[]): boolean; /** * Maps the values of an object using a transform function. Keys are * preserved. Iteration follows `Object.entries()` order. */ export declare function mapValues, R>(obj: T, fn: (value: T[keyof T], key: keyof T, object: T) => R): { [K in keyof T]: R; }; /** * Maps the keys of an object using a transform function. Values are * preserved. Later collisions override earlier ones. */ export declare function mapKeys>(obj: T, fn: (key: keyof T, value: T[keyof T], object: T) => string): Record; /** * Returns a new object whose keys and values have been swapped. * * @example * ```ts * invert({ a: 1, b: 2 }); // { '1': 'a', '2': 'b' } * ``` */ export declare function invert>(obj: T): Record; /** * Recursively compares two values for structural equality. Handles plain * objects, arrays, Dates, RegExps, Maps, Sets, and primitive equality * (including `NaN === NaN`). */ export declare function deepEqual(a: unknown, b: unknown): boolean; /** * Convenience alias for {@link deepEqual}. */ export declare const isEqual: typeof deepEqual; /** * Recursively freezes an object and all nested object values. Returns the * same reference. Functions and primitives are returned unchanged. */ export declare function freeze(value: T): Readonly; /** * Fills in `target` keys that are `undefined` with values from `sources` * (first source wins). Mutates `target` and also returns it. * * @security Prototype-pollution keys are ignored. */ export declare function defaults>(target: T, ...sources: Array>): T; /** * Typed wrapper around `Object.entries()` preserving key types. */ export declare function entriesTyped>(obj: T): Array<[keyof T & string, T[keyof T]]>; /** * Typed wrapper around `Object.keys()` preserving key types. */ export declare function keysTyped>(obj: T): Array; //# sourceMappingURL=object.d.ts.map