@unmilley/compare-arrays
v3.0.0
Published
Comparing the contents of the two arrays with additional results.
Readme
@unmilley/compare-arrays
Comparing the contents of the two arrays with additional results.
[!IMPORTANT]
Compare only the contents of an array with the contents of another array.
Neither the order nor the index
Usage
Install the package:
# pnpm
pnpm add @unmilley/compare-arrays
# yarn
yarn add @unmilley/compare-arrays
# npm
npm install @unmilley/compare-arraysImport:
import { compareArrays } from "@unmilley/compare-arrays";
// Option 1: Simple comparison (returns boolean)
const arraysEqual = compareArrays(oldData, newData);
console.log(arraysEqual); // true or false
// Option 2: Getting change counters
const changes = compareArrays(oldData, newData, { withCounter: true });
console.log(changes); // { added: 2, deleted: 1 }
// Option 3: Explicit indication of changes
const changes = compareArrays(oldData, newData, { withModified: true });
console.log(changes); // { added: [{...}, {...}], deleted: [{...}] }Development
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable - Install dependencies using
pnpm install - Run interactive tests using
pnpm dev
License
MIT. Made with 💛
