shallowequal CI Downloads npm version
shallowequalis like lodash'sisEqual(v3.10.1) but for shallow (strict) equal.
shallowequal(value, other, [customizer], [thisArg])
Performs a shallow equality comparison between two values (i.e. value and other) to determine if they are equivalent.
The equality check returns true if value and other are already strictly equal, OR when all the following are true:
valueandotherare both objects with the same keys- For each key, the value in
valueandotherare strictly equal (===)
If customizer (expected to be a function) is provided it is invoked to compare values. If customizer returns undefined (i.e. void 0), then comparisons are handled by the shallowequal function instead.
The customizer is bound to thisArg and invoked with three arguments: (value, other, key).
NOTE: Docs are (shamelessly) adapted from lodash's v3.x docs
pnpm add shallowequal # or npm install shallowequal # or yarn add shallowequal
import shallowequal from "shallowequal"; const object = { user: "fred" }; const other = { user: "fred" }; object == other; // → false shallowequal(object, other); // → true
This package includes TypeScript type definitions:
import shallowequal, { Comparator } from "shallowequal"; const customCompare: Comparator = (a, b, key) => { // Custom comparison logic return undefined; // Fall back to default comparison }; shallowequal({ a: 1 }, { a: 1 }, customCompare); // → true
Code for shallowEqual originated from https://github.com/gaearon/react-pure-render/ and has since been refactored to have the exact same API as lodash.isEqualWith (as of v4.17.4).
Prerequisites:
pnpm install
Using Make:
make install # Install dependencies make build # Build the project make test # Run tests make test-watch # Run tests in watch mode make lint # Run linter make typecheck # Run type checking make clean # Clean build artifacts make ci # Run full CI pipeline
Or using pnpm directly:
pnpm install # Install dependencies pnpm build # Build the project pnpm test # Run tests pnpm test:watch # Run tests in watch mode pnpm lint # Run linter pnpm typecheck # Run type checking
MIT.