UNPKG

dbl-utils

Version:

Utilities for dbl, adba and others projects

53 lines (52 loc) 1.83 kB
type MutationFunction = (key: string, value: any, data: any) => any; interface MergeOptions { mutation: MutationFunction; ommit?: string[]; data?: any; } interface ConfigOptions { fix?: (target: any, source: any) => any; } interface TransformOptions { beforeFunc?: (context: Context) => any; duringFunc?: (context: Context) => any; afterFunc?: (context: Context) => any; nonObjectFunc?: (context: Context) => any; filter?: string | string[] | ((context: Context) => boolean); key?: string; root?: any; } interface Context { input: any; key: string | null; parentObj: any; parentKey: string | null; path: string; } /** * Execute a mutation function on the object and merge results. * @param target - The target object to be merged with mutation. * @param options - Options for mutation, ommit keys and additional data. * @param parentKey - Internal tracking key for recursion. * @returns The mutated and merged target object. */ export declare function mergeWithMutation(target: any, { mutation, ommit, data }: MergeOptions, parentKey?: string): Promise<any>; /** * Deep merge multiple objects. * @param target - The target object where other objects will be merged. * @param sources - Other objects to be merged into the target. * @returns The merged object. */ export declare function deepMerge(target: any, ...sources: any[]): any; export declare namespace deepMerge { var setConfig: (config: ConfigOptions) => void; } /** * Transforms and flattens a JSON object. * * @param json - The JSON object to be transformed. * @param options - Options for the mutation functions. * @returns An array with the modified object and the flattened object. */ export declare function transformJson(json: any, options?: TransformOptions): [any, any]; export {};