Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hyperdiff

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperdiff

Find common, removed and added element between two arrays.

  • 2.0.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hyperdiff

Last version Build Status Coverage Status Dependency status Dev Dependencies Status NPM Status Donate

Find common, removed and added element between two collections.

Install

$ npm install hyperdiff --save

Usage

Using a flat Array:

const diff = require('hyperdiff')

var result = diff(
  [1, 2, 3, 4, 5, 6],
  [1, 2, 4, 5, 6, 0, 9, 10]
)

console.log(result)

// {
//   added: [ 0, 9, 10 ],
//   removed: [ 3 ],
//   common: [ 1, 2, 4, 5, 6 ]
// }

Using an Array of Object's (in this case you need to provide the unique id):

const diff = require('hyperdiff')
var result = diff(
  [
    {id: 1, name: 'a'},
    {id: 2, name: 'b'},
    {id: 3, name: 'c'},
    {id: 4, name: 'd'},
    {id: 5, name: 'e'}
  ],
  [
    {id: 1, name: 'a'},
    {id: 2, name: 'b'},
    {id: 7, name: 'e'}
  ],
  'id'
)

console.log(result)
// {
//   added: [ { id: 7, name: 'e' } ],
//   removed: [ { id: 3, name: 'c' }, { id: 4, name: 'd' }, { id: 5, name: 'e' } ],
//   common: [ { id: 1, name: 'a' }, { id: 2, name: 'b' } ]
// }

It's also support multiple properties as id or provide a function.

Benchmark

❯ node bench.js
simpleArrayDiff*1000: 143.742ms
hyperDiff*1000: 80.234ms
simpleArrayDiff*1000: 143.405ms
hyperDiff*1000: 75.803ms

API

hyperdiff(orig, dist, [ids])

orig

Required
Type: array

First array for be compared.

dist

Required
Type: array

Second array for be compared. Notes the results are modeled from the second array.

ids

Required
Type: string|array|function

In the case that you provide an Array of Object's, you need to specify the key's to be used as id.

  • redis-diff - Perform a diff comparison backed by redis.

License

MIT © Kiko Beats.

Keywords

FAQs

Package last updated on 01 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc