1.0.0 • Published 8 years ago

typecheck.js v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

typecheck.js

this module allows you to check the types of variables. made for use in sanity-checking function parameters.

usage

const check = require('typecheck')

function foo(param) {
  check.isArray(param)
  console.log('all good!')
}

foo([1, 2, 3, 4])
=> all good!

foo('')
=> TypeError

typecheck currently exposes six methods: isArray, isBool, isString, isNotNullOrUndefined, and isTruthy. they each take one parameter; if the parameter is of the correct type, nothing happens. the code returns undefined. if there is a type mismatch, it throws a TypeError.

testing

grab the package, cd into the root directory, and run npm test. you can find test suites in /spec/typecheck/TypecheckSpec.js.

future

i'm accepting feature requests and PRs! i'll be adding to this as i come up with new features, but i definitely welcome pull requests for new features.