/** * @fileoverview Deep difference comparison utility for JavaScript objects * * This module provides comprehensive utilities to generate detailed diffs between * any two JavaScript objects, arrays, or primitive values. It recursively traverses * nested structures and produces both machine-readable change objects and human-readable * formatted output. * * Key features: * - Deep recursive comparison of objects and arrays * - Configurable depth limits and output formatting * - Path tracking for nested changes * - Summary statistics for change types * - Human-readable formatted output * - Type-safe change tracking * * @module @memberjunction/global * @author MemberJunction.com * @since 2.63.0 * * @example * ```typescript * const differ = new DeepDiffer(); * const diff = differ.diff( * { name: 'John', age: 30, hobbies: ['reading'] }, * { name: 'John', age: 31, hobbies: ['reading', 'gaming'] } * ); * console.log(diff.formatted); * // Output: * // Modified: age * // Changed from 30 to 31 * // Modified: hobbies * // Array length changed from 1 to 2 * // Added: hobbies[1] * // Added "gaming" * ``` * * @example * ```typescript * // With treatNullAsUndefined option * const differ = new DeepDiffer({ treatNullAsUndefined: true }); * const diff = differ.diff( * { name: null, status: 'active', oldProp: 'value' }, * { name: 'John', status: null, newProp: 'value' } * ); * // name: shows as Added (not Modified) * // status: shows as Removed (not Modified) * // oldProp: shows as Removed * // newProp: shows as Added * ``` */ /** * Types of changes that can occur in a deep diff operation */ export declare enum DiffChangeType { /** A new property or value was added */ Added = "added", /** An existing property or value was removed */ Removed = "removed", /** An existing value was changed to a different value */ Modified = "modified", /** No change detected (only included when includeUnchanged is true) */ Unchanged = "unchanged" } /** * Represents a single change detected during diff operation */ export interface DiffChange { /** The path to the changed value (e.g., "user.profile.name" or "items[2].id") */ path: string; /** The type of change that occurred */ type: DiffChangeType; /** The original value (undefined for Added changes) */ oldValue?: any; /** The new value (undefined for Removed changes) */ newValue?: any; /** Human-readable description of the change */ description: string; } /** * Complete result of a deep diff operation */ export interface DeepDiffResult { /** Array of all detected changes */ changes: DiffChange[]; /** Summary statistics about the diff */ summary: { /** Number of properties/values that were added */ added: number; /** Number of properties/values that were removed */ removed: number; /** Number of properties/values that were modified */ modified: number; /** Number of properties/values that remained unchanged (if tracked) */ unchanged: number; /** Total number of paths examined */ totalPaths: number; }; /** Human-readable formatted diff output suitable for display or logging */ formatted: string; } /** * Configuration options for deep diff generation */ export interface DeepDiffConfig { /** * Whether to include unchanged paths in the diff results. * Useful for seeing the complete structure comparison. * @default false */ includeUnchanged: boolean; /** * Maximum depth to traverse in nested objects. * Prevents infinite recursion and controls performance. * @default 10 */ maxDepth: number; /** * Maximum string length before truncation in formatted output. * Helps keep the output readable for large text values. * @default 100 */ maxStringLength: number; /** * Whether to include array indices in paths (e.g., "items[0]" vs "items"). * Provides more precise change tracking for arrays. * @default true */ includeArrayIndices: boolean; /** * Whether to treat null values as equivalent to undefined. * When true, transitions between null and undefined are not considered changes, * and null values in the old object are treated as "not present" for new values. * Useful for APIs where null and undefined are used interchangeably. * @default false */ treatNullAsUndefined: boolean; /** * Custom value formatter for the formatted output. * Allows customization of how values are displayed. * @param value - The value to format * @param type - The type of the value * @returns Formatted string representation */ valueFormatter?: (value: any, type: string) => string; } /** * Deep difference generator for comparing JavaScript objects, arrays, and primitives. * * This class provides comprehensive comparison capabilities with configurable * output formatting and depth control. */ export declare class DeepDiffer { private config; /** * Creates a new DeepDiffer instance * @param config - Optional configuration overrides */ constructor(config?: Partial); /** * Generate a deep diff between two values * * @param oldValue - The original value * @param newValue - The new value to compare against * @returns Complete diff results including changes, summary, and formatted output * * @example * ```typescript * const differ = new DeepDiffer({ includeUnchanged: true }); * const result = differ.diff( * { users: [{ id: 1, name: 'Alice' }] }, * { users: [{ id: 1, name: 'Alice Cooper' }] } * ); * ``` */ diff(oldValue: T, newValue: T): DeepDiffResult; /** * Update configuration options * @param config - Partial configuration to merge with existing config */ updateConfig(config: Partial): void; /** * Recursively generate diff between two values * @private */ private generateDiff; /** * Compare two arrays and generate diff * @private */ private diffArrays; /** * Compare two objects and generate diff * @private */ private diffObjects; /** * Create a human-readable description of a value * @private */ private describeValue; /** * Get a description of a value for display * @private */ private getValueDescription; /** * Format the diff results as a human-readable string * @private */ private formatDiff; } //# sourceMappingURL=DeepDiff.d.ts.map