Another biased type checking solution for Javascript
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

1.1 KiB

typeforce

build status Coverage Status Version

Examples

var typeforce = require('typeforce')

var unknown = [{ prop: 'foo' }, { prop: 'bar' }]
typeforce('Array', unknown)
// supported primitives 'Array', 'Boolean', 'Buffer', 'Number', 'Object', 'String'

typeforce(['Object'], unknown)
// array types only support 1 element type

var element = unknown.pop()
typeforce({ prop: 'String' }, element)
// supports recursive type templating

typeforce([{
  {
    prop: 'String'
  }
}], unknown)
// works for array types too

typeforce('Object', unknown)
// will also pass as an Array is an Object

typeforce('Number', unknown)
// THROWS 'Expected Number, got Array ...

License

This library is free and open-source software released under the MIT license.