# filter-iter

> Filters an iterable object so that it only yields values which pass a test function.

Latest version **1.1.0** (published 2018-02-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install filter-iter
pnpm add filter-iter
yarn add filter-iter
bun add filter-iter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-02-06 |
| First published | 2017-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 3 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | John Lamansky |
| Maintainers | lamansky |
| Keywords | filter, iterable, iterator, generator, limit |

## Links

- npm: https://www.npmjs.com/package/filter-iter
- Repository: https://github.com/lamansky/filter-iter
- Issues: https://github.com/lamansky/filter-iter/issues
- npm.io page: https://npm.io/package/filter-iter

## Dependencies (3)

- [pfn](https://npm.io/package/pfn.md) ^1.0.0
- [sbo](https://npm.io/package/sbo.md) ^1.0.0
- [is-plain-object](https://npm.io/package/is-plain-object.md) ^2.0.4

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-02-06
- 1.0.0 — 2017-12-14

## README

# filter-iter

Filters an iterable object so that it only yields values which pass a test function.

Optionally lets you set a numeric limit on total filtered values yielded.

## Installation

Requires [Node.js](https://nodejs.org/) 6.0.0 or above.

```bash
npm i filter-iter
```

## API

The module exports a single function.

### Parameters

1. Bindable: `iter` (iterable): The iterable whose values should be filtered.
2. Optional: `test` (Function): A callback to which each iterated value is passed. The callback should return true if the value should be kept. If this argument is omitted, values will be filtered by truthiness.
3. Object argument:
    * Optional: `limit` (integer): The maximum number of items to yield. Defaults to `Infinity`.

### Return Value

An iterable object with the filtered values from `iter`.

## Example

```javascript
const filter = require('filter-iter')

const even = n => n % 2 === 0

filter([1, 2, 3, 4, 5], even) // yields 2 and 4

// A limit parameter is supported.
filter([1, 2, 3, 4, 5], even, {limit: 1}) // yields 2

// Values are filtered by truthiness if no callback is provided.
filter([0, 1, 2, 3]) // yields 1, 2, and 3
filter([0, 1, 2, 3], {limit: 2}) // yields 1 and 2

// Supports the bind operator
[0, 1, 2]::filter() // yields 1 and 2
[1, 2, 3, 4, 5]::filter(even) // yields 2 and 4
[1, 2, 3, 4, 5]::filter(even, {limit: 1}) // yields 2
```

## Related

* [partition-iterable](https://github.com/lamansky/partition-iterable): Divides iterated values into those that match a filter and those that don’t.
* [reduce-iterable](https://github.com/lamansky/reduce-iterable): Applies a function to iterated values to reduce them to a single value.
* [unique-iterable](https://github.com/lamansky/unique-iterable): Filters an iterable object so it doesn’t yield the same value more than once.
* [unique-iterable-by](https://github.com/lamansky/unique-iterable-by): Filters yielded values by testing uniqueness with an index, key, or callback.

---
_Source: https://npm.io/package/filter-iter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
