is-natural-number-string

Check if a given value is a string that represents natural number

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
is-natural-number-string
001.0.17 years ago7 years agoMinified + gzip package size for is-natural-number-string in KB

Readme

is-natural-number-string
NPM version Bower version Build Status Coverage Status devDependency Status
Check if a given value is a string that represents natural number
isNaturalNumberString('9478123289889839898438984843498934894'); //=> true
isNaturalNumberString('-1'); //=> false

Unlike is-natural-number, is-natural-number-string can handle a too large number that exceeds the JavaScript maximum safe integer 9007199254740991.

Installation

Package managers

npm

npm install is-natural-number-string

bower

bower install is-natural-number-string

Standalone

Download the script file directly.

API

isNaturalNumberString(val , option)

val: String
option: Object
Return: Boolean
isNaturalNumberString('15'); //=> true
isNaturalNumberString('4.3'); //=> false

isNaturalNumberString('1'); //=> true
isNaturalNumberString('1.0'); //=> true
isNaturalNumberString('1.00000000000000000000000000'); //=> true

// non-string
isNaturalNumberString(15); //=> false
isNaturalNumberString(); //=> false

option.includeZero

Type: Boolean
Default: false
Determine whether this library regards 0 as a natural number or not.
isNaturalNumberString('0'); //=> false
isNaturalNumberString('0', {includeZero: true}); //=> true

License

Copyright (c) 2016 Shinnosuke Watanabe
Licensed under the MIT License.