JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q46440F
  • License ISC

Check if an input is numeric, and within a given bound

Package Exports

  • is-bounded-number

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-bounded-number) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Is Bounded Number (is-bounded-number)

npm version

Provides a very simple and compact check on whether an input is all of these:

  • Numeric
  • Finite (i.e. not Infinity or NaN)
  • Within a given range (defaulting to +/- 1e15)

Note that this range has been chosen to be comfortably within Number.MAX_SAFE_INTEGER, which is approx 9e15.

Install

npm install is-bounded-number

Test

npm test

Usage

var ibn = require('is-bounded-number')

ibn(0)             // true
ibn(1)             // true
ibn(1000000)       // true
ibn(1e15)          // true
ibn(1e15+1)        // false - outside default limit of +/- 1e15

ibn(1000, 1e6)     // true - 1000 is less than 1e6
ibn(1e6, 1000)     // true - 1e6 is not within bounds +/- 1000

ibn(null)          // false
ibn("aString")     // false
ibn(true)          // false
ibn(false)         // false
ibn(Infinity)      // false
ibn(NaN)           // false

API

ibn(input)         // Checks whether input is within +/- 1e15
ibn(input, limit)  // Checks whether input is within +/- limit