each-diff
v1.2.2
Published
Run on each unique object of the lists and bring the same object from the other lists and give them to you, so you can be able to compare them. If the object does not exist in some list you get an undefined in is place.
Downloads
3
Maintainers
Readme
eachDiff
Run on each unique object of the lists and bring the same object from the other lists and give them to you, so you can be able to compare them. If the object does not exist in some list you get an undefined in is place.
Usage: eachDiff<T>(lists: Array<Array<T>>, callback: (items: Array<T>, indexes: Array<number>, lists) => void, detectBy?: keyof T): lists
import { eachDiff } from 'each-diff'
const
listVersionA = [
{
name: `Sharon`,
stars: 100
},
{
name: `Adrien`,
stars: 100
}
],
listVersionB = [
{
name: `Skye`,
stars: 100
},
{
name: `Adrien`,
stars: 150
}
]
eachDiff(
[listVersionA, listVersionB], // It can be any length of lists
([obVersionA, obVersionB]) => {
if (obVersionA === undefined) console.log(`${obVersionB.name} is newer`)
else if (obVersionB === undefined) console.log(`${obVersionA.name} deleted`)
else if (obVersionB.stars > obVersionA.stars) console.log(`${obVersionA.name} have now ${obVersionB.stars} stars instad of ${obVersionA.stars}`)
},
`name` // unique unchangeable property to determain that it is the same object in another version
)
// Output: "Skye is newer" and "Sharon deleted" and "Adrien have now 150 stars instad of 100"
This module exported from utilizes project.