1.0.1 • Published 9 years ago
is-string-int v1.0.1
is-string-int
Check if a string represents an integer
isStringInt('123'); //=> true
isStringInt('1.23'); //=> false
Installation
Package managers
npm
npm install is-string-int
Bower
bower install is-string-int
Standalone
Download the script file directly.
API
isStringInt(string, option)
string: String
option: Object
Return: Boolean
See the test for more detailed specifications.
isStringInt('1'); //=> true
isStringInt('0'); //=> true
isStringInt('-1'); //=> true
isStringInt('0.1'); //=> false
isStringInt('foo'); //=> false
isStringInt(' 1'); //=> false
isStringInt('01'); //=> false
isStringInt('0x1'); //=> false
isStringInt('0e+0'); //=> false
isStringInt('NaN'); //=> false
option.parseLiteral
Type: Boolean
Default: false
Returns true
even if the string includes octal/hexadecimal expressions and exponential notation. (By default it returns false
in that case.)
isStringInt('01', {parseLiteral: true}); //=> true
isStringInt('0x1', {parseLiteral: true}); //=> true
isStringInt('0e+0', {parseLiteral: true}); //=> true
License
Copyright (c) 2014 - 2015 Shinnosuke Watanabe
Licensed under the MIT License.