@marcm/shallow-equal

1.0.4 • Public • Published

@marcm/shallow-equal

Mighty fast shallow equals (~524 bytes gzipped)

Install

npm install @marcm/shallow-equal
yarn add @marcm/shallow-equal

Supports

  • Object
  • Array
  • TypedArray
  • RegExp
  • Promise
  • Date
  • NaN
  • Set
  • Map

Benchmark1 (from fast-equals)

Package Ops / sec
@marcm/shallow-equal 13,079.405
fast-equals (shallowEqual) 8,437.492
shallow-equal (shallowEqualObjects) 6,777.645
shallowequal 6,335.283
fast-shallow-equal 5,659.316

Passes the full test suite of fast-equals

Usage

const { shallowEqual } = require('@marcm/shallow-equal')
// or
import { shallowEqual } from '@marcm/shallow-equal'

// Typed Arrays
shallowEqual(new Float32Array([3, 4, 6]), new Float32Array([3, 4, 6])) // true
shallowEqual(new Float32Array([3, 4, 6]), new Float32Array([3, 4, 8])) // false
// Objects and array
shallowEqual({ a: 'a', b: 'b' }, { a: 'a', b: 'b' }) // true
shallowEqual([{ a: 'a' }, { b: 'b' }], [{ a: 'a' }, { b: 'b' }]) // false
// Dates
shallowEqual(new Date('2017-06-16T21:36:48.362Z'), new Date('2016-06-16T21:36:48.362Z')) // false
shallowEqual(new Date('2017-06-16T21:36:48.362Z'), new Date('2017-06-16T21:36:48.362Z')) // true
  1. showing benchmark 'overall averages'. Ran on an M1 Pro (macOS 13.1). Run yourself by adding @marcm/shallow-equal to the fast-equals benchmark

Package Sidebar

Install

npm i @marcm/shallow-equal

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

5.81 kB

Total Files

4

Last publish

Collaborators

  • marcm