/** * Compares two values. * * Supported types: all primitives, `null`, `undefined`, `array`, `object`, `Date` * * @group Object * @param a any value to compare * @param b any value to compare * @returns `true` if values are equal */ export declare function isEqual(a: unknown, b: unknown): boolean; /** * Converts object to entries, map's 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} * ``` * @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 map's it with provided callback. * * @example * ``` * mapRecord({'a': 2}, ([k, v]) => [v, k * 2]) * >> {'b': 4} * mapRecord({'a': 'b'}, ([k, v]) => [v, k]) * >> {'b': 'a'} * ``` * @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} * ``` * @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; /** * Merges `source` to `target` recursively * * @example * ``` * merge({ a: 1 }, { b: 2 })) * // { a: 1, b: 2 } * ``` * @group Object */ export declare function merge(target: unknown, source: unknown, options?: { /** * 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) => source` - custom array merge function * * @default 'overwrite' */ arrayPolicy?: 'overwrite' | 'merge' | ((target: unknown[], source: unknown[]) => unknown); }): T; /** * Return a clone of given value * * @group Object * @param value any value * @param recursive should recursive values (object and array) be cloned */ export declare function clone(value: T, recursive?: boolean): T; /** * 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; /** * Get object value by nested keys * * @example * ``` * getByKey({ key1: [1, 2, { key2: 'value' }]}, 'key1.2.key2') * // 'value' * * getByKey({ key1: [1, 2, { key2: 'value' }]}, ['key1', 2, 'key2']) * // 'value' * ``` * @group Object */ export declare function getByKey(target: unknown, keys: (string | number)[] | string): T;