https://github.com/lamansky/unique-iterable-by
[Node.js] Filters yielded values by testing uniqueness with an index, key, or callback.
https://github.com/lamansky/unique-iterable-by
Last synced: about 1 month ago
JSON representation
[Node.js] Filters yielded values by testing uniqueness with an index, key, or callback.
- Host: GitHub
- URL: https://github.com/lamansky/unique-iterable-by
- Owner: lamansky
- License: mit
- Created: 2017-12-20T15:06:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-20T15:09:01.000Z (over 8 years ago)
- Last Synced: 2025-10-09T11:35:50.798Z (9 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# unique-iterable-by
Filters yielded values by testing uniqueness with an index, key, or callback.
Optionally lets you set a numeric limit on total unique values yielded.
## Installation
```bash
npm install unique-iterable-by --save
```
The module exports a single function.
## Usage Example
Let’s say you have an iterable collection of person objects and you only want one person with any given name.
```javascript
const uniqueIterableBy = require('unique-iterable-by')
const people = [
{name: 'John'},
{name: 'John'},
{name: 'Stephen'},
]
const u = uniqueIterableBy(people, 'name')
u.next().value // {name: 'John'}
u.next().value // {name: 'Stephen'}
u.next().done // true
```
Or you can use a callback that retrieves the significant value:
```javascript
uniqueIterableBy(people, person => person.name)
```
You can also use the `limit` argument to cap the number of total unique values yielded:
```javascript
const u = uniqueIterableBy(people, 'name', {limit: 1})
u.next().value // {name: 'John'}
u.next().done // true
```
## Related Projects
* [deduplicate](https://github.com/lamansky/deduplicate)
* [unique-array-by](https://github.com/lamansky/unique-array-by)
* [unique-iterable](https://github.com/lamansky/unique-iterable)
* [unique-map](https://github.com/lamansky/unique-map)
* [unique-map-by](https://github.com/lamansky/unique-map-by)