variable-diff is a JavaScript/TypeScript library designed to generate a visual diff between two JavaScript variables, primarily objects or JSON structures. It focuses on presenting only the differences (additions, deletions, and modifications) in a human-readable, formatted output, making it easier to identify changes without sifting through identical data. The current stable version is 2.0.2. While there isn't an explicit release cadence, the project appears to be actively maintained, with recent updates introducing new features like an options argument in version 2.0.1. Its key differentiator is its emphasis on clear, colored, and indented output directly within the console or logs, making it particularly useful for debugging and comparing configuration objects or data states efficiently.
npm install variable-diffVerified import paths — ran on the pinned version, not inferred.
Demonstrates the basic usage of `variable-diff` to visually compare two TypeScript objects (simulated user profiles), highlighting changes with custom indentation and color options, and also showing how to check if changes were detected programmatically.
To ensure universal readability, set `color: false` in the options object if the output target does not support ANSI colors. If using a custom `wrap` function, ensure the coloring library is installed and compatible with the target environment, or provide a fallback without colors.
Always use `import diff from 'variable-diff';` for ES Modules. For CommonJS, use `const diff = require('variable-diff');`.Before diffing, preprocess objects to break circular references, for example, by serializing and deserializing (`JSON.parse(JSON.stringify(obj))`) if possible, or by explicitly removing properties that cause circularity.
Correct the import statement: for CommonJS, use `const diff = require('variable-diff');`; for ES Modules, use `import diff from 'variable-diff';`.To resolve, either install `chalk` as a dependency (`npm install chalk`) if you intend to use its coloring features, or remove the `wrap` function from your options to let `variable-diff` use its default color handling (or no colors if `color: false` is set).
No dependency data recorded yet.