UNPKG

@qntm-code/utils

Version:

A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.

33 lines (31 loc) 1.29 kB
export interface MergeOptions { /** * The function to use for merging arrays. Defaults to concatenating the arrays */ arrayMerge: <X extends unknown[], Y extends unknown[]>(x: X, y: Y, options: MergeOptions) => X & Y; /** * The function to use for merging objects. Defaults to merging the objects */ customMerge?: (key: string, options?: MergeOptions) => ((x: any, y: any) => any) | undefined; /** * The function to use for determining if a value is mergeable. Defaults to isPlainObject */ isMergeableObject: (value: any) => boolean; /** * NOT OVERRIDABLE */ cloneUnlessOtherwiseSpecified: (value: any, options: any) => any; } /** * Merges two objects x and y deeply, returning a new merged object with the elements from both x and y. * * If an element at the same key is present for both x and y, the value from y will appear in the result. * * Merging creates a new object, so that neither x or y is modified. * * Note: By default, arrays are merged by concatenating them. */ export declare function merge<X, Y>(x: Partial<X>, y: Partial<Y>, options?: Partial<MergeOptions>): X & Y; export declare namespace merge { var all: <T>(array: Partial<T>[], options?: Partial<MergeOptions> | undefined) => T; }