Created
February 24, 2013 23:33
-
-
Save arian/5026246 to your computer and use it in GitHub Desktop.
better asserts, that can be switched of with a DEV variable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
if (typeof DEV == 'undefined') return; | |
function assert(condition, message){ | |
if (!condition) throw new Error(message || "Assertion fault"); | |
} | |
exports.assert = assert; | |
exports.assertFunction = function(fn, message){ | |
assert(typeof fn == 'function', message || 'expected a function'); | |
}; | |
exports.assertNumber = function(num, message){ | |
assert(typeof num == 'number', message || 'expected a number'); | |
}; | |
exports.assertNumber = function(str, message){ | |
assert(typeof str == 'string', message || 'expected a string'); | |
}; | |
exports.assertLength = function(obj, len, message){ | |
assert(obj && obj.length === len, message || 'expect object to have a length of ' + len); | |
}; | |
exports.assertMinLength = function(obj, len, message){ | |
assert(obj && obj.length >= len, message || 'expect object to have a minimum length of ' + len); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment