check if a number is a positive integer
JavaScript
Latest commit fcf3498 Mar 27, 2016 @tjmehta Merge pull request #14 from hoschiCZ/patch-1
Add test for NaN
Permalink
Failed to load latest commit information.
test Add test for NaN Mar 27, 2016
.gitignore init w/ 100% test coverage Feb 16, 2016
.travis.yml 0.10 and 0.12 typo in travis.ml Feb 16, 2016
LICENSE Initial commit Feb 16, 2016
README.md readme nits Mar 23, 2016
index.js tab tidy Mar 24, 2016
package.json 1.1.1 Mar 24, 2016

README.md

is-positive-integer Build Status js-standard-style

check if a number is a positive integer

Installation

npm --save i is-positive-integer

Usage

var isPositiveInteger = require('is-positive-integer')

isPositiveInteger(1) // true
isPositiveInteger(10) // true
isPositiveInteger(100) // true
isPositiveInteger(1000) // true
isPositiveInteger(0) // false
isPositiveInteger(-1) // false
isPositiveInteger(-10) // false
isPositiveInteger(-100) // false
isPositiveInteger(-1000) // false
isPositiveInteger(1.1) // false
isPositiveInteger(10.1) // false
isPositiveInteger(100.1) // false
isPositiveInteger(1000.1) // false
isPositiveInteger(-1.1) // false
isPositiveInteger(-10.1) // false
isPositiveInteger(-100.1) // false
isPositiveInteger(-1000.1) // false
isPositiveInteger(Infinity) // false
isPositiveInteger({}) // false
isPositiveInteger([]) // false
isPositiveInteger('10') // false
isPositiveInteger('what') // false
isPositiveInteger(/what/) // false
isPositiveInteger(null) // false
// ...

isSafePositiveInteger

Ensure positive integer less than Number.MAX_SAFE_INTEGER https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

var isSafePositiveInteger = require('is-positive-integer').isSafePositiveInteger
// max safe integer doesn't exist in older engines
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991

isSafePositiveInteger(MAX_SAFE_INTEGER) // true
isSafePositiveInteger(MAX_SAFE_INTEGER + 1) // false
isSafePositiveInteger(Number.MAX_VALUE) // false
// ...

License

MIT