1.0.13 • Published 2 years ago

arrays-otherness v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Arrays otherness

Npm package version Small size Testing Building

Get and handle a matching, missing and excess items of an array based on target array

.

  • Install

npm i arrays-otherness
  • Usage

arraysOtherness<T>(
    // Array for checking
    currentArray: T[], 
    // Etalon array
    targetArray: T[], 
    // Function of matching arrays items
    matchFn: (res) => boolean
): {
    // Execute callback if items in two arrays
    match: (callback: (res) => void) => this,
    // Execute callback if target item missing in current array
    missing: (callback: (res) => void) => this,
    // Execute callback if current item is excess in target array
    excess: (callback: (res) => void) => this,
}
  • Example

const arraysOtherness = require('arrays-otherness');

const currentArray = [
    { id: 1, name: 'John' },
    { id: 2, name: 'Sam' },
    { id: 3, name: 'Nick' },
];

const targetArray = [
    { id: 1, name: 'Jonny' },
    { id: 3, name: 'Nick' },
    { id: 4, name: 'Lisa' },
    { id: 5, name: 'Frank' },
];

arraysOtherness(currentArray, targetArray, ({ current, target }) => (current.id === target.id))
    .match(({ target, current }) => {
        console.log('matched =', target, 'and', current);
    })
    .missing(({ target }) => {
        console.log('to create =', target);
    })
    .excess(({ current }) => {
        console.log('to delele =', current);
    });
1.0.13

2 years ago

1.0.11

2 years ago

1.0.12

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago