UNPKG

@astech/deepdiff

Version:

A fast, lightweight TypeScript library for comparing deeply nested objects and detecting changes with detailed diff information.

50 lines (48 loc) 1.67 kB
interface DiffResult { path: string; type: "added" | "removed" | "changed"; before?: any; after?: any; summary: string; description: string; } interface CompareOptions { /** Include null/undefined values in the diff */ includeNulls?: boolean; /** Custom function to determine if two values are equal */ customEqual?: (a: any, b: any) => boolean; /** Maximum depth to traverse (prevents stack overflow) */ maxDepth?: number; /** Keys to ignore during comparison */ ignoreKeys?: string[]; /** Whether to ignore case for string comparisons */ ignoreCase?: boolean; } declare function deepDiff(a: any, b: any, path?: string[], visited?: WeakSet<object>, options?: CompareOptions, depth?: number): Generator<DiffResult>; declare function compare(a: any, b: any, options?: CompareOptions): DiffResult[]; /** * Filter diff results by type */ declare function filterByType(diffs: DiffResult[], type: DiffResult["type"]): DiffResult[]; /** * Group diff results by type */ declare function groupByType(diffs: DiffResult[]): Record<DiffResult["type"], DiffResult[]>; /** * Get a summary of changes */ declare function getSummary(diffs: DiffResult[]): { total: number; added: number; removed: number; changed: number; }; /** * Check if objects are deeply equal */ declare function isDeepEqual(a: any, b: any, options?: CompareOptions): boolean; /** * Get only the paths that changed */ declare function getChangedPaths(diffs: DiffResult[]): string[]; export { type CompareOptions, type DiffResult, compare, deepDiff, filterByType, getChangedPaths, getSummary, groupByType, isDeepEqual };