You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

num-or-not

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

num-or-not

Check for a valid Number value.


Version published
Weekly downloads
3.4K
decreased by-4.32%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

num-or-not Build Status

Check for a valid Number value.

Numbers, and values that can be cast or evaluated to numbers will return true.

All other values will return false.

Installation

$ npm install --save num-or-not

Usage

const isNumber = require('num-or-not');

// Integers
isNumber(5);            // => true
isNumber(-5);           // => true
isNumber('5');          // => true
isNumber('-5');         // => true

// Floats (Decimal & Comma)
isNumber(5.0);          // => true
isNumber('5.0');        // => true
isNumber('5,0');        // => true

// Octal (ES6)
isNumber(0o144);        // => true
isNumber(0O144);        // => true
isNumber('0o144');      // => true
isNumber('0O144');      // => true

// Binary (ES6)
isNumber(0b0);          // => true
isNumber('0b0');        // => true
   
// Hexadecimal
isNumber(0xFF);         // => true    
isNumber('0xFF');       // => true

// Exponential
isNumber(6e3);          // => true
isNumber(12e-2);        // => true
isNumber('6e3');        // => true
isNumber('12e-2');      // => true

// Currency Values
isNumber('12,456,789'); // => true
isNumber('45,678.123'); // => true

// "Evaluates to Int" values
isNumber(+'');          // => true
isNumber(+[]);          // => true
isNumber(+[0]);         // => true
isNumber(+true);        // => true
isNumber(+new Date);    // => true

Known Limitations

  • These binary and octal formats are only supported in ES6 environments:

  • Binary: 0b0

  • Octal: 0o144 & 0O144

  • In order to support numbers with commas or decimals (currencies, Dewey Decimal System, etc), some unique values can pass as valid numbers (see Issue #1):

  • 1,2,3.4.5

  • 1,2,3,4.5

  • Open a pull request or issue if you think we need tighter control over these limitations.

Why?

Why do we need another open source number validator in Javascript? We don't, but I wanted one to help keep me accountable of the data type nuances in JS.

License

MIT @ Michael Wuergler

Keywords

FAQs

Package last updated on 10 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc