Easy extendable method collection for asserting values on runtime
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test/lib
.gitignore
Makefile
README.md
index.js
package.json

README.md

Runtime checks made easy

Example

// This line is for NodeJS. In browser, you just have to the JS-File
// using <script src="..." type="text/javascript"></script>
var VC = require('valuechecker');

/**
 * This method demonstrates the ValueChecker interface.
 *
 * @param {String} a_string  A string with length between 10 and 12.
 * @param {Integer} an_int   Just an int.
 * @param {CoolObj} cool_obj An object of type CoolObj.
 */
function noop(a_string, an_int, cool_obj) {
    a_string = VC.string(a_string, "a_string", null, 12, 10);
    an_int = VC.int(an_int, "an_int");
    cool_obj = VC.instance_of(cool_obj, "cool_obj", CoolObj);
};

Explanation

The ValueChecker methods checks the given value for the type and additional criteria you want to check. If it does not match, an exception is thrown telling exactly what has happend (e.g. type mismatch or string is too short etc). If it does match, the value to check is returned casted to the type you wanted. Therefore if you pass for instance the string "2" to VC.int, it will pass the test and the int value 2 will be returend. Because "2" is lossless convertable to an int.