TritonDataCenter / node-assert-plus

Extra assertions on top of node's assert module
MIT License
122 stars 25 forks source link

want `assert.integer` #5

Open trentm opened 12 years ago

trentm commented 12 years ago

"number" isn't specific enough sometimes.

trentm commented 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.

bahamas10 commented 9 years ago

+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;
}