The `shallow-equal` library provides minimalistic, TypeScript-compatible utilities for performing shallow equality checks on arrays and objects. It currently stands at version 3.1.0, offering highly optimized functions like `shallowEqualArrays` and `shallowEqualObjects` for specific data types, alongside a generic `shallowEqual` function that includes runtime type checking. The project emphasizes being super light with no external dependencies, ensuring a small footprint. Its release cadence is stable, focusing on minor enhancements and maintenance rather than frequent, large-scale breaking changes, typical for foundational utility packages. A key differentiator is its explicit separation of array and object equality functions, allowing developers to choose the most performant option when the type is known, avoiding the overhead of runtime type inference inherent in more generic solutions.
npm install shallow-equalVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `shallowEqualArrays` and `shallowEqualObjects` for efficient shallow comparisons, clarifying that nested non-primitives are compared by reference, not recursively.
Use `shallowEqualArrays` for arrays and `shallowEqualObjects` for objects when the input type is statically known.
Understand the distinction between shallow and deep equality. For deep comparisons, you will need a different library (e.g., `lodash.isequal` or a custom recursive comparison).
Ensure your project's `tsconfig.json` `module` and `moduleResolution` settings align with your runtime environment (e.g., `"module": "esnext", "moduleResolution": "bundler"` for modern setups) and consistently use `import` statements.
Ensure you are using `import { shallowEqualArrays } from 'shallow-equal';` for ESM. If strictly using CommonJS, check if the package provides a CJS entry point that you can `require('shallow-equal').shallowEqualArrays;`.Use a named import: `import { shallowEqualObjects } from 'shallow-equal';`. Verify your `tsconfig.json`'s `module` and `moduleResolution` settings are compatible with how your bundler or Node.js resolves modules.No dependency data recorded yet.