1.2.2 • Published 3 years ago

each-diff v1.2.2

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

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.

1.2.2

3 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.10

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.12

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago