Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

want assert.integer #5

Open
trentm opened this issue Oct 30, 2012 · 2 comments
Open

want assert.integer #5

trentm opened this issue Oct 30, 2012 · 2 comments

Comments

@trentm
Copy link
Contributor

trentm commented Oct 30, 2012

"number" isn't specific enough sometimes.

@trentm
Copy link
Contributor Author

trentm commented Oct 30, 2012

Maybe this is featuritis. Dunno. E.g. would want to specify if it is a positive int. Anyway, just noting this here.

@bahamas10
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants