1.0.0 • Published 8 years ago
similars v1.0.0
similars

Find similar objects and partial duplicates in collections
Installation
$ npm install --save similarsUsage
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
collectionRequired:Arraycontaining objects
matcherRequired:Functionthat compares each item in the collection and returns aBoolean- e.g.
(a, b) => a.name.toLowerCase() === b.name.toLowerCase()
onEachOptional:Functionthat executes once for each item in thecollection- Is good for showing progress on long running executions
License
ISC © Buster Collings
1.0.0
8 years ago