UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

52 lines (51 loc) 2.71 kB
import { type PartialDeep } from 'type-fest'; /** * Extract all nested object keys and values that are different between the two given objects. * * @category Object * @category Package : @augment-vir/common * @returns An empty tuple if the values are equal. Otherwise, the first tuple entry contains the * changes in the first value, second entry contains the changes in the second value. * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function diffObjects<T0 extends Readonly<Record<PropertyKey, unknown>>, T1 extends Readonly<Record<PropertyKey, unknown>>>(object0: T0, object1: T1): [PartialDeep<T0>, PartialDeep<T1>] | []; /** * Extract all entries in the given arrays that are not equal. * * @category Object * @category Package : @augment-vir/common * @returns An empty tuple if the values are equal. Otherwise, the first tuple entry contains the * changes in the first value, second entry contains the changes in the second value. * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function diffArrays<T0, T1>(array0: ReadonlyArray<T0>, array1: ReadonlyArray<T1>): [Array<T0>, Array<T1>] | []; /** * Callback for checking equality between two values that can be of different types. * * @category Object * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type AreEqualCallback<T0, T1> = (value0: T0, value1: T1) => boolean; /** * Simple diff check that is useful simply to return the same format as the other diff functions. * * @category Object * @category Package : @augment-vir/common * @returns An empty tuple if the values are equal. Otherwise, the first tuple entry contains the * changes in the first value, second entry contains the changes in the second value. * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function diffBasic<T0, T1>(value0: T0, value1: T1, /** A custom equality checker. Defaults to a strict equality check (`===`). */ areEqual?: AreEqualCallback<T0, T1>): [T0, T1] | []; /** * Diff any values. For diffing objects, use `diffObjects` to get better types. * * @category Object * @category Package : @augment-vir/common * @returns An empty tuple if the values are equal. Otherwise, the first tuple entry contains the * changes in the first value, second entry contains the changes in the second value. * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function diffValues<T0, T1>(value0: T0, value1: T1): [T0, T1] | [];