is-natural-number
Check if a value is a natural number
Last updated 9 years ago by shinnn .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install is-natural-number 
SYNC missed versions from official npm registry.

is-natural-number.js

NPM version Bower version Build Status Coverage Status devDependency Status

Check if a value is a natural number

Installation

Package managers

npm

npm install is-natural-number

Bower

bower install is-natural-number

Duo

var isNaturalNumber = require('shinnn/is-natural-number.js');

Standalone

Download the script file directly.

API

isNaturalNumber(number, option)

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.

option.includeZero

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

License

Copyright (c) 2014 - 2016 Shinnosuke Watanabe

Licensed under the MIT License.

Current Tags

  • 4.0.1                                ...           latest (9 years ago)

7 Versions

  • 4.0.1                                ...           9 years ago
  • 4.0.0                                ...           9 years ago
  • 3.0.0                                ...           9 years ago
  • 2.1.1                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 7
Today 0
This Week 0
This Month 7
Last Day 0
Last Week 7
Last Month 0
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE