0.2.3 • Published 11 years ago

type-guard v0.2.3

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

Circle CI

Guard

Guard is a simple type checker function that aims to make it easier to check the types of arguments or values in a function. When a guard finds an invalid value it throws an error. The error thrown has a modified stack trace that originates from where guard was called to make for easier debugging.

npm install type-guard
var guard = require('type-guard');


function hello(name) {
  guard('name', name, 'string');
  console.log('Hello ' + name);
}

hello('Robert');
// Hello Robert

hello(1);
// GuardError: name must be a string
//     at hello (/Users/user/Developer/JS/hello.js:14:3)
//     at Object.<anonymous> (/Users/user/Developer/JS/hello.js:18:1)
//     at Module._compile (module.js:456:26)
//     at Object.Module._extensions..js (module.js:474:10)
//     at Module.load (module.js:356:32)
//     at Function.Module._load (module.js:312:12)
//     at Function.Module.runMain (module.js:497:10)

Docs

guard()

guard(string:key, *:val, string:type) => undefined

The guard function accepts a key, the name of your argument, a value, the argument itself, and a type. The supported types are object, string, boolean, number, array, regexp, date, function, null, and undefined.

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago