similars

1.0.0 • Public • Published

similars NPM version Build Status Dependency Status Coverage percentage

Find similar objects and partial duplicates in collections

Installation

$ npm install --save similars

Usage

const similars = require('similars');
 
const bobs = [
  { fn: 'BOB', ln: 'DYLAN', p: 'Musician' },
  { fn: 'B', ln: 'Marley', p: 'Singer' },
  { fn: 'Bob', ln: 'Dylan', p: 'SINGER' },
  { fn: 'Bobby', ln: 'Dylan', p: 'MUSICIAN' },
  { fn: 'BOB', ln: 'MARLEY', p: 'MUSICIAN' }
];
 
// Find Bobs with the same last name (ln) and profession (p)
similars(
  bobs,
  (a, b) =>
    a.ln.toLowerCase() === b.ln.toLowerCase() &&
    a.p.toLowerCase() === b.p.toLowerCase()
).then(found => {
  console.log(found);
  /*
    [
      { fn: 'BOB', ln: 'DYLAN', p: 'Musician' },
      { fn: 'Bobby', ln: 'Dylan', p: 'MUSICIAN' }
    ]
  */
});

API

similars(collection, matcher[, onEach])

Returns a Promise, however, processing is synchronous

  • #### collection
    • Required : Array containing objects
  • #### matcher
    • Required : Function that compares each item in the collection and returns a Boolean
    • e.g. (a, b) => a.name.toLowerCase() === b.name.toLowerCase()
  • #### onEach
    • Optional : Function that executes once for each item in the collection
    • Is good for showing progress on long running executions

License

ISC © Buster Collings

Package Sidebar

Install

npm i similars

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

6.29 kB

Total Files

5

Last publish

Collaborators

  • buster