https://github.com/busterc/similars
:dancers: Find similar objects and partial duplicates in collections
https://github.com/busterc/similars
arrays collections duplicate-detection duplicates similar-objects similarity-search
Last synced: 7 months ago
JSON representation
:dancers: Find similar objects and partial duplicates in collections
- Host: GitHub
- URL: https://github.com/busterc/similars
- Owner: busterc
- License: isc
- Created: 2018-03-29T16:47:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-25T22:00:35.000Z (over 7 years ago)
- Last Synced: 2025-06-02T08:52:11.428Z (7 months ago)
- Topics: arrays, collections, duplicate-detection, duplicates, similar-objects, similarity-search
- Language: JavaScript
- Size: 76.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# similars [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]
> Find similar objects and partial duplicates in collections
## Installation
```sh
$ npm install --save similars
```
## Usage
```js
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](https://github.com/visionmedia/node-progress) on long running executions
## License
ISC © [Buster Collings](https://about.me/buster)
[npm-image]: https://badge.fury.io/js/similars.svg
[npm-url]: https://npmjs.org/package/similars
[travis-image]: https://travis-ci.org/busterc/similars.svg?branch=master
[travis-url]: https://travis-ci.org/busterc/similars
[daviddm-image]: https://david-dm.org/busterc/similars.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/busterc/similars
[coveralls-image]: https://coveralls.io/repos/busterc/similars/badge.svg
[coveralls-url]: https://coveralls.io/r/busterc/similars