/** * Compares two values structurally. * * Supported types: all primitives (including `NaN === NaN`), `null`, `undefined`, * `Array`, plain `object`, `Date`, `RegExp`, `Set`, `Map`. * * @group Object * @param a any value to compare * @param b any value to compare * @returns `true` if values are structurally equal */ export declare function isEqual(a: unknown, b: unknown): boolean; /** * Converts object to entries, maps it with provided callback and flattens entry list. * * @example * ``` * flatMapRecord({'a': 2}, ([k, v]) => [[k, v]]) * >> {'a': 2, 'b': 3} * flatMapRecord({'a': 2, 'b': 3}, ([k, v]) => v === 2 ? [[k, v]] : []) * >> {'a': 2} * ``` * @deprecated Use [[flatMap]] from `iterable` instead — it handles `Record` directly along with `Array`, `Set`, `Map`, and (async) iterables. * @group Object * @param obj `Record` like object * @param callback map callback, accepts entry pair (`[key, value]`) and should return list of entry pairs * @returns new mapped object */ export declare function flatMapRecord(obj: Record, callback: (entry: [K, V]) => Array<[RK, RV]>): Record; /** * Converts object to entries and maps it with provided callback. * * @example * ``` * mapRecord({'a': 2}, ([k, v]) => [v, k * 2]) * >> {'b': 4} * mapRecord({'a': 'b'}, ([k, v]) => [v, k]) * >> {'b': 'a'} * ``` * @deprecated Use [[map]] from `iterable` instead — it handles `Record` directly along with `Array`, `Set`, `Map`, and (async) iterables. * @group Object * @param obj `Record` like plain object * @param callback map callback, accepts entry pair (`[key, value]`) and should return entry pair * @returns new mapped object */ export declare function mapRecord(obj: Record, callback: (entry: [K, V]) => [RK, RV]): Record; /** * Filter object by provided callback. * * @example * ``` * filterRecord({'a': 2, 'b': 3}, ([k, v]) => v === 2) * >> {'a': 2} * ``` * @deprecated Use [[filter]] from `iterable` instead — it handles `Record` directly along with `Array`, `Set`, `Map`, and (async) iterables. * @group Object * @param obj `Record` like plain object * @param callback map callback, accepts entry pair (`[key, value]`) and should boolean value * @returns new filtered object */ export declare function filterRecord(obj: Record, callback: (entry: [K, V]) => boolean): Record; /** * Options accepted by [[merge]]. * * @group Object */ export type MergeOptions = { /** * When `source` has `null` or `undefined` value, do not overwrite `target` * * @default false */ skipNulls?: boolean; /** * Array merge policy, default is `overwrite` * * Available policies: * * `overwrite` - always replace `target` array with `source` * * `merge` - merge `target` and `source` array values * * `(target, source) => result` - custom array merge function * * @default 'overwrite' */ arrayPolicy?: 'overwrite' | 'merge' | ((target: unknown[], source: unknown[]) => unknown); }; /** * Computes the [[merge]] return type. Arrays are special-cased on * `arrayPolicy`; everything else falls back to `A & B` (which deeply * intersects nested objects). */ type MergeResult = A extends readonly unknown[] ? B extends readonly unknown[] ? O extends { arrayPolicy: 'merge'; } ? (A[number] | B[number])[] : O extends { arrayPolicy: (target: unknown[], source: unknown[]) => infer R; } ? R : B : A & B : A & B; /** * Merges `source` to `target` recursively. * * The return type is inferred from the inputs. For objects it's `A & B` * (which deeply intersects nested objects, so * `merge({ a: { x: 1 } }, { a: { y: 2 } })` is typed as * `{ a: { x: number; y: number } }`). For arrays the result depends on * `arrayPolicy`: * * * `'overwrite'` (default) → `B` * * `'merge'` → `(A[number] | B[number])[]` * * `(t, s) => …` → the function's return type * * @example * ``` * merge({ a: 1 }, { b: 2 }) * // { a: number; b: number } * * merge([1, 2], ['a'], { arrayPolicy: 'merge' }) * // (number | string)[] * ``` * @group Object */ export declare function merge(target: A, source: B, options?: O): MergeResult; /** * Return a clone of given value. * * Handles plain objects, arrays, `Date`, `RegExp`, `Set`, `Map`. Other types * (class instances, functions, primitives) are returned as-is. * * @group Object * @param value any value * @param recursive should recursive values (object, array, set, map) be cloned */ export declare function clone(value: T, recursive?: boolean): T; /** * Returns a new object containing only the given keys from `obj`. * * Missing keys are omitted from the result rather than producing * `undefined`-valued properties. * * @example * ``` * pick({ a: 1, b: 2, c: 3 }, ['a', 'c']) * // { a: 1, c: 3 } * ``` * @group Object */ export declare function pick(obj: T, keys: ReadonlyArray): Pick; /** * Returns a new object with the given keys removed from `obj`. * * Own enumerable properties are copied. Inherited properties are not. * * @example * ``` * omit({ a: 1, b: 2, c: 3 }, ['b']) * // { a: 1, c: 3 } * ``` * @group Object */ export declare function omit(obj: T, keys: ReadonlyArray): Omit; /** * Parse one level object to nested structure based on key separator * * @example * ``` * // ENV: config__host=0.0.0.0 config__port=3000 * convertToNested(process.env, { separator: '__' }) * // {config: { host: '0.0.0.0', port: 3000 } } * * // ENV: CONFIG__PRIVATE_KEY="my key" * // ENV: CONFIG__PUBLIC_KEY="my key" * // ENV: CONFIG__ALLOWED_IPS='["127.0.0.1", "localhost"]' * convertToNested(process.env, { * separator: '__', * transformKey: camelCase * }).config * // { privateKey: 'my key', publicKey: 'my key', allowedIps: ['127.0.0.1', 'localhost'] } * ``` * @group Object */ export declare function convertToNested>(array: Record, options?: { /** * Key separator, default `.` */ separator?: string; /** * Key transform function, e.g. `camelCase` or `pascalCase` */ transformKey?: (value: string) => string; /** * Value transform function, by default `JSON.parse` is used. */ transformValue?: (value: unknown) => unknown; }): T; /** * Splits a dotted path literal into a tuple of segments at the type level. * `'a.b.c'` → `['a', 'b', 'c']`. Non-literal strings collapse to `string[]`. */ type SplitPath = string extends S ? string[] : S extends `${infer Head}.${infer Tail}` ? [Head, ...SplitPath] : [S]; /** * Indexes `T` by a single path segment `K`. Handles tuples (numeric-string * keys), homogeneous arrays (`T[number]`), records, and unknown shapes. */ type IndexBySegment = T extends readonly unknown[] ? K extends keyof T ? T[K] : K extends `${number}` | number ? T[number] | undefined : undefined : T extends object ? K extends keyof T ? T[K] : K extends `${number}` ? `${number}` extends keyof T ? T[`${number}` & keyof T] : undefined : K extends number ? `${K}` extends keyof T ? T[`${K}` & keyof T] : undefined : undefined : undefined; /** * Walks a tuple of path segments through `T`. At each step, an inaccessible * segment yields `undefined` and short-circuits. */ type WalkPath = Path extends readonly [] ? T : Path extends readonly [infer Head, ...infer Rest] ? Rest extends readonly unknown[] ? WalkPath, Rest> : undefined : undefined; /** * Compute the return type of `getByKey(T, P)`. * * - For a string literal path `'a.b.c'` the path is split on `.`. * - For a tuple path the segments are walked directly. * - For a `string` (non-literal) or `(string | number)[]` (non-tuple) input, * the result falls back to `unknown` — the caller can pass `T` explicitly * when the path isn't statically known. */ type GetByPath = P extends string ? string extends P ? unknown : WalkPath> : P extends readonly (string | number)[] ? number extends P['length'] ? unknown : WalkPath : unknown; /** * Get object value by nested keys. * * When the path is a string literal (`'a.b.c'`) or a tuple of literals * (`['a', 'b'] as const`), the return type is inferred from `T` by walking * the path. For dynamic paths (variable strings or non-tuple arrays) the * return type is `unknown`; pass `T` explicitly via the first generic if * you know what to expect. * * @example * ``` * getByKey({ a: [1, 2, { b: 'value' }] }, 'a.2.b') * // 'value' — inferred as string * * getByKey({ a: [1, 2, { b: 'value' }] }, ['a', 2, 'b'] as const) * // 'value' — inferred as string * * getByKey(data, somePathVariable) * // explicit fallback for dynamic paths * ``` * @group Object */ export declare function getByKey(target: T, keys: P): GetByPath; export declare function getByKey(target: unknown, keys: (string | number)[] | string): R; export {};