@guanghechen/equal
v2.0.1
Published
The fastest deep equal with ES6 Map, Set and Typed arrays support.
Readme
The fastest deep equal with ES6 Map, Set and Typed arrays support. Inspired by fast-deep-equal, re-published with ESM support.
Install
npm
npm install --save @guanghechen/equalyarn
yarn add @guanghechen/equal
Usage
Basic Comparison
import isEqual from '@guanghechen/equal'
// Primitives
isEqual(1, 1) // true
isEqual('a', 'a') // true
isEqual(null, null) // true
isEqual(undefined, undefined) // true
// Objects
isEqual({ a: 1, b: 2 }, { a: 1, b: 2 }) // true
isEqual({ a: 1 }, { a: 2 }) // false
// Arrays
isEqual([1, 2, 3], [1, 2, 3]) // true
isEqual([1, 2], [1, 2, 3]) // false
// Nested structures
isEqual(
{ user: { name: 'John', tags: ['admin'] } },
{ user: { name: 'John', tags: ['admin'] } }
) // trueNamed Export
import { isEqual } from '@guanghechen/equal'
isEqual({ foo: 'bar' }, { foo: 'bar' }) // trueSpecial Types
import isEqual from '@guanghechen/equal'
// RegExp
isEqual(/abc/gi, /abc/gi) // true
isEqual(/abc/g, /abc/i) // false
// Date
isEqual(new Date('2024-01-01'), new Date('2024-01-01')) // true
// Custom valueOf/toString
class Point {
constructor(public x: number, public y: number) {}
valueOf() { return this.x * 1000 + this.y }
}
isEqual(new Point(1, 2), new Point(1, 2)) // trueReference
- homepage
- Inspired by fast-deep-equal
