Skip to content

warren-bank/node-fast-equal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fork of fast-deep-equal

Differences:

  • equal(a, b, options)
    • options:
      1. key: depth
        • type: integer
          • default value = Infinity
          • summary:
            • provides fine grain control to configure how deep to recurse into a data structure to test equality
              • typically, you're given 2 choices:
                • shallow
                  • equivalent to: {depth: 1}
                  • equality occurs when either:
                    • a === b
                    • a and b are both: Arrays, Objects, ES6 Maps
                      • same length
                      • all children: a[i] === b[i]
                • deep
                  • equivalent to: {depth: Infinity}
                  • equality occurs when either:
                    • shallow equality is true
                    • for all children where: a[i] !== b[i]
                      • a[i] and b[i] are both: Arrays, Objects, ES6 Maps
                      • same length
                      • all children: a[i][j] and b[i][j] exhibit deep equality
      2. key: shallow
        • type: boolean
          • default value = false
          • summary:
            • true
              • equivalent to: {depth: 1}
            • false
              • equivalent to: {depth: Infinity}
      3. key: react
        • type: boolean
          • default value = false
          • summary:
            • avoid traversing React elements' _owner
            • _owner contains circular references and is not needed when comparing the actual elements
      4. key: es6
        • type: Object || boolean
          • Object
            • keys can include: ['Map', 'Set', 'ArrayBuffer']
            • values are boolean
          • boolean
            • shortcut for assigning this boolean value to all Object keys
          • default value = false
    • notes:
      • the shallow key provides a quick way to configure the depth key with one of the two most common use cases (ie: shallow and deep)
        • these two keys shouldn't be used together
          • depth takes priority

Install:

  npm install --save '@warren-bank/fast-equal'

Usage:

  const equal = require('@warren-bank/fast-equal')

  const a = {foo: 'bar', hello: 'world'}
  const b = {...a}

  if (equal(a, b, {shallow: true})) {
    // profit!
  }

Legal: