Returns
true
if the value is a string number written in fixed notation and in decimal base.
Motivation
This utility module has a front-end purpose. As JavaScript doesn't provide a clean and unique way to check if a value is a number or written in a specific notation or base, type checking on numbers is hard.
Front-end developers often have to deal with user inputs, especially within
forms. The need, here, is to validate a string
value as a simple number in
decimal base and fixed notation.
Code example
// => true // => false // => false // => false // => false
More details on the usage section.
Install
Install with npm:
$ npm install --save is-string-a-number
Usage
With CommonJs:
const isStringANumber =
With ECMAScript module:
true
// => true // => true // => true // => true // => true // => true
false
// => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false // => false
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/Ynote/is-string-a-number. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Code of Conduct
Everyone interacting in the is-string-a-number project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Credits
Special thanks to Jon Schlinkert for his great is-number module that inspired me.
Resources
- The global parseFloat top-level function
- Displaying numbers in JavaScript by Axel Rauschmayer
- How numbers are encoded in JavaScript by Axel Rauschmayer
Licence
The module is available as open source under the terms of the MIT License.
MIT © Ynote_hk