![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
hyperdiff
Advanced tools
Readme
Find common, removed and added element between two collections.
$ npm install hyperdiff --save
Using a flat Array
:
const diff = require('hyperdiff')
const 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')
const 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
.
❯ node bench.js
simpleArrayDiff*1000: 143.742ms
hyperDiff*1000: 80.234ms
simpleArrayDiff*1000: 143.405ms
hyperDiff*1000: 75.803ms
Required
Type: array
First array for be compared.
Required
Type: array
Second array for be compared. Notes the results are modeled from the second array.
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
.
MIT © Kiko Beats.
FAQs
Find common, removed and added element between two arrays.
The npm package hyperdiff receives a total of 407 weekly downloads. As such, hyperdiff popularity was classified as not popular.
We found that hyperdiff demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.