tcompare is a JavaScript/TypeScript library designed for deep object comparison, primarily intended for use within test frameworks. It provides a suite of comparison functions with varying levels of strictness, such as `match`, `same`, `strict`, `has`, and `matchOnly`, allowing developers to precisely define how objects should be evaluated against patterns. Beyond a simple boolean result, it generates human-readable diff strings and patch-style diffs, highlighting differences between actual and expected values. The library currently stands at version 9.3.1 and appears to maintain a release cadence in alignment with its parent project, `tap`, suggesting active development and maintenance. Its key differentiators include fine-grained control over comparison logic and robust diff generation capabilities, making it valuable for detailed assertion failure reporting.
npm install tcompareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core `match` function, showcasing how to compare objects against patterns and interpret the `Result` object for both match status and diff output. It also illustrates direct usage of the `MatchOnly` class and a `same` comparison.
Carefully review the documentation for each comparison method and select the one that precisely matches your assertion requirements. For example, `match` is very loose, `strict` is very strict, and `matchOnly` requires an exact property match.
Always append `Strict` to the comparison method name (e.g., `strict()`, `matchStrict()`) if JavaScript's `===` equality is desired for all comparisons within the object structure.
Ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json`) if using `import`. Verify that your build tools correctly transpile or bundle modules.
Remember that tcompare methods return a `Result` object `{ match: boolean, diff: string }`. Always access `result.match` for the boolean outcome and `result.diff` for the diff string. Ensure you have `import type { Result } from 'tcompare'` if using TypeScript.No dependency data recorded yet.