# defunction

> Strict argument validation with testable errors

Latest version **5.7.0** (published 2018-01-30) · MIT license · 0 weekly downloads

## Install

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

## 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 | 5.7.0 |
| Published | 2018-01-30 |
| First published | 2017-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | aakilfernandes |

## Links

- npm: https://www.npmjs.com/package/defunction
- Repository: https://github.com/protecol/defunction
- Homepage: https://github.com/protecol/defunction#readme
- Issues: https://github.com/protecol/defunction/issues
- npm.io page: https://npm.io/package/defunction

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4

## Recent versions

- 5.7.0 (latest) — 2018-01-30
- 5.6.0 — 2018-01-29
- 5.5.0 — 2018-01-26
- 5.4.0 — 2018-01-26
- 5.3.0 — 2018-01-25
- 5.2.0 — 2018-01-24
- 5.1.1 — 2018-01-22
- 5.1.0 — 2018-01-22
- 5.0.0 — 2018-01-22
- 4.0.4 — 2017-09-27
- 4.0.3 — 2017-09-27
- 4.0.2 — 2017-09-27
- 4.0.1 — 2017-09-27
- 3.0.1 — 2017-09-24
- 3.0.0 — 2017-09-24

## README

# defunction

> Defensive javascript functions with run-time validation

## Install

Install with [npm](https://www.npmjs.com/)

```sh
$ npm i defunction --save-dev
```

## Usage

defunction takes three arguments.

`defunction([validateArgument, validateArgument, ...], validateReturned, func)`

And returns a defensive javascript function.



```
function validateNumber(label, arg) {
  if (typeof arg !== 'number') {
    throw new Error(`${label} type should be "number", not "${typeof arg}"`)
  }
  return arg
}

const add = defunction([validateNumber, validateNumber], validateNumber, function add(a, b) {
  return a + b
})

add(1, '2')
>> Error: add:arguments[1] type should be "number", not "string"
```

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/SafeMarket/defunction/issues)

## Author

***

* [github/---](https://github.com/---)
* [twitter/---](http://twitter.com/---)

## License

Copyright © 2017 []()
Licensed under the MIT license.

***

_This file was generated by [readme-generator](https://github.com/jonschlinkert/readme-generator) on January 21, 2017._

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