Bolshakova Anna ab21a11190 lab | 2 weeks ago | |
---|---|---|
.. | ||
LICENSE | 2 weeks ago | |
README.md | 2 weeks ago | |
index.js | 2 weeks ago | |
index.jsnext.js | 2 weeks ago | |
package.json | 2 weeks ago |
Check if a value is a natural number
npm install is-natural-number
bower install is-natural-number
var isNaturalNumber = require('shinnn/is-natural-number.js');
Download the script file directly.
number: Number
option: Object
Return: Boolean
It returns true
if the first argument is one of the natural numbers. If not, or the argument is not a number, it returns false
.
isNaturalNumber(10); //=> true
isNaturalNumber(-10); //=> false
isNaturalNumber(10.5); //=> false
isNaturalNumber(Infinity); //=> false
isNaturalNumber('10'); //=> false
Check the test for more detailed specifications.
Type: Boolean
Default: false
By default the number 0
is not regarded as a natural number.
Setting this option true
makes 0
regarded as a natural number.
isNaturalNumber(0); //=> false
isNaturalNumber(0, {includeZero: true}); //=> true
Copyright (c) 2014 - 2016 Shinnosuke Watanabe
Licensed under the MIT License.