Skip to content

MarcusMathiassen/shallow-equal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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

Footnotes

  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

About

*Might* be the fastest around

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published