# ffn

> Turns arrays and values into Filtering Functions.

Latest version **2.1.0** (published 2018-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ffn
pnpm add ffn
yarn add ffn
bun add ffn
```

## 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 | 2.1.0 |
| Published | 2018-04-14 |
| First published | 2018-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Lamansky |
| Maintainers | lamansky |
| Keywords | filter, comparison, test, function |

## Links

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

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2018-04-14
- 2.0.0 — 2018-02-06

## README

# ffn

Turns arrays and values into Filtering Functions.

Many projects use callbacks to filter values. Sometimes this filtering involves complex conditions that need a function. Other times one just wants to test if the value equals another, or if the value appears in an array of acceptable values. Instead of making your project’s end-users write filters like `x => x === 'value'` or `x => ['ok', 'also ok'].includes(x)`, let them provide the value or the array directly, and `ffn` will turn it into a filtering function.

## Installation

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

```bash
npm i ffn
```

## API

The module exports a single function.

### Parameters

1. `f` (any): A Function, an Array, or some other value.
2. Object argument:
    * Optional: `blacklist` (bool): Set to `true` if `ffn` is being used to create a blacklist. This will make falsey values test true when `f` is undefined. Defaults to `false`.

### Return Values

* If `f` is a Function: returns `f`
* If `f` is omitted or otherwise undefined: returns a function that tests whether its argument is truthy (unless `blacklist` is `true`)
* If `f` is an Array: returns a function that tests whether its argument is included in `f`
* Otherwise: returns a function that tests whether its argument is strictly equal to `f`

## Example

```javascript
const ffn = require('ffn')

const arr = [1, 2, 3, 4, 5]

// ffn returns functions as-is
arr.find(ffn(x => x % 2 === 0)) // 2

// ffn creates a function which checks for inclusion in the array
arr.find(ffn([4, 5])) // 4

// ffn creates a function which checks for equality with the value
arr.find(ffn(3)) // 3
```

## Related

For more projects like this, check out the [xfn](https://github.com/lamansky/xfn) family of modules.

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