# qfn

> Qualified Function. Wraps a function so it only gets executed if a condition is true.

Latest version **1.0.1** (published 2018-04-18) · MIT license · 0 weekly downloads

## Install

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

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

## Links

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

## Dependencies (2)

- [pfn](https://npm.io/package/pfn.md) ^1.0.0
- [wfn](https://npm.io/package/wfn.md) ^1.0.0

## 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

- 1.0.1 (latest) — 2018-04-18
- 1.0.0 — 2018-02-14

## README

# Qualified Function (qfn)

Wraps a function so it only gets executed if a condition is true.

## Installation

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

```bash
npm i qfn
```

## API

The module exports a single function.

### Parameters

1. Bindable: `fn` (function): The underlying function that may or may not get called, depending on `test`.
2. `test` (function or boolean): A boolean indicating whether `fn` should be called, or a function that returns such a boolean. If `test` is a function, it will be given all the arguments passed to the returned function.

### Return Value

A function which, when called, returns the return value of `fn`, if `test` is true. If `test` is false, the function returns the first argument passed to it.

## Example

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

function add1 (x) {
  return x + 1
}

qfn(add1, true)(3) // 4
qfn(add1, false)(3) // 3

const add1IfEven = qfn(add1, x => x % 2 === 0)
add1IfEven(3) // 3
add1IfEven(4) // 5
```

## Related

For more projects like this, check out [@lamansky/fn](https://github.com/lamansky/fn).

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