VALINT: Does This String Represent A (Base 10) Integer?
this is a simple library to check whether a character sequence represents an integer: 'A'
, '[b]'
, 'hello'
, 12.54
, '0.000040and the like don't, for example; but
'0',
'0x5',
'05',
'5.',
'5.0'`, etc. all represent valid integers.
Installation
npm install valint
Functions
tests whether a string represents an integer, regardless of its base. its argument has to be a String, or else an error will be thrown.
tests whether a string represents a base 10 integer. its first argument has to be a string; otherwise, an error will be thrown.
The default behaviour is rejecting any digit sequence that contains a floating point,
even things like '5.'
and '5.0'
which are indeed valid integers.
The second argument, allowTail
, modifies this behaviour:
when true
, it causes isBase10Int
to accept strings like '12.'
and '12.00000000000'
as valid integers too.
when false
, it cause isBase10Int
to only accept "pure" base 10 strings, like '5'
, '12'
, '120'
, '55'
, '40000'
, etc.
Usage
var valint = ; console; // falseconsole; // false console; // trueconsole; // true console; // falseconsole; // false console; // trueconsole; // false console; // trueconsole; // falseconsole; true