Open trentm opened 12 years ago
Maybe this is featuritis. Dunno. E.g. would want to specify if it is a positive int. Anyway, just noting this here.
+1 I could see benefit to this. They way I see assert-plus
is as a library that adds certainty to variable types that compiled languages get for free... for example:
void func(int a, char *b) {
}
When func
is called, you know 100% you have an int
and char
pointer. whereas with javascript, we can emulate it with:
function func(a, b) {
assert.integer(a);
assert.string(b);
}
I still maintain, however, that NDEBUG is key here, and a proper development cycle should render it that, in production, these assertions are unnecessary.
Regardless, I'm +1 on assert.integer
and assert.positiveInteger
function isInteger(i) {
return typeof (i) === 'number' && i % 1 === 0;
}
function isPositiveInteger(i) {
return isInteger(i) && i >= 0;
}
"number" isn't specific enough sometimes.