0.0.10 • Published 7 years ago

arg-types v0.0.10

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

arg types Build Status js-standard-style

A very simple module to do runtime argument type checking of functions.

Usage

Installation:

Use yarn or npm:

$ [sudo] npm install --save arg-types

Example:

The very contrived example below would stop "33" being returned by the function.

var argTypes = require('./')

// define your function signature, the next line returns a function
// which expects an `arguments` object
var helloSignature = argTypes(['number', 'number', 'number'])

function hello (a, b, c) {
  helloSignature(arguments) // add this line as the first one in the target function

  return a + b + c
}

try {
  hello(1, 2, '3')
} catch (ex) {
  assert(ex.message === 'Expected "number" but got "string" at argument 3.')
}