is-number
A simple utility to Check the value is number or can convert to a number, for example string ' 123 ' can be converted to 123.
Installation
yarn add @alwatr/is-number
Usage
import {isNumber} from '@alwatr/is-number';
isNumber('1');
Why is this needed?
console.log(typeof '123');
console.log(+[]);
console.log(+'');
console.log(+' ');
console.log(typeof NaN);
console.log(typeof Infinity);
True
isNumber(5e3);
isNumber(0xff);
isNumber(-1.1);
isNumber(0);
isNumber(1);
isNumber(1.1);
isNumber('-1.1');
isNumber('0');
isNumber('0xff');
isNumber('1');
isNumber('1.1');
isNumber('5e3');
isNumber('012');
isNumber(parseInt('012'));
isNumber(parseFloat('012'));
False
isNumber(Infinity);
isNumber(NaN);
isNumber(null);
isNumber(undefined);
isNumber('');
isNumber(' ');
isNumber('foo');
isNumber([1]);
isNumber([]);
isNumber(function () {});
isNumber({});
The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.
Contributing
Contributions are welcome! Please read our contribution guidelines before submitting a pull request.
License
This project is licensed under the AGPL-3.0 License.