5.7.0 • Published 6 years ago

defunction v5.7.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

defunction

Defensive javascript functions with run-time validation

Install

Install with npm

$ 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

Author


License

Copyright © 2017 Licensed under the MIT license.


This file was generated by readme-generator on January 21, 2017.

5.7.0

6 years ago

5.6.0

6 years ago

5.5.0

6 years ago

5.4.0

6 years ago

5.3.0

6 years ago

5.2.0

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.0

6 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago