Narcissistic Preening Monarch

    isnumeric

    0.3.3 • Public • Published

    isNumeric Build Status npm version devDependency Status

    Determine if a JavaScript object is numeric.

    Using npm

    npm install isnumeric
    

    To then include isnumeric in your node app:

    var isNumeric = require("isnumeric");
    

    Direct dependency

    Download the minified version here, reference the js file and isNumeric will become a global variable.

    Truthy test cases

    Integers

    expect(isNumeric(1)).toBeTruthy();
    expect(isNumeric(-1)).toBeTruthy();
    expect(isNumeric(0)).toBeTruthy();
    expect(isNumeric("1")).toBeTruthy();
    expect(isNumeric("-1")).toBeTruthy();
    expect(isNumeric("0")).toBeTruthy();
    expect(isNumeric("1.")).toBeTruthy();

    Max / min numbers

    expect(isNumeric(Number.MAX_VALUE)).toBeTruthy();
    expect(isNumeric(Number.MIN_VALUE)).toBeTruthy();

    Octals

    expect(isNumeric(0144)).toBeTruthy();
    expect(isNumeric("0144")).toBeTruthy();

    Hexadecimals

    expect(isNumeric(0xFF)).toBeTruthy();
    expect(isNumeric("0xFF")).toBeTruthy();

    Floating-points

    expect(isNumeric(1.1)).toBeTruthy();
    expect(isNumeric(0.1)).toBeTruthy();
    expect(isNumeric(-1.1)).toBeTruthy();
    expect(isNumeric(-0.1)).toBeTruthy();
    expect(isNumeric("1.1")).toBeTruthy();
    expect(isNumeric("0.1")).toBeTruthy();
    expect(isNumeric("-1.1")).toBeTruthy();
    expect(isNumeric("-0.1")).toBeTruthy();
    expect(isNumeric(".1")).toBeTruthy();

    Exponentials

    expect(isNumeric(3e5)).toBeTruthy();
    expect(isNumeric(123e-2)).toBeTruthy();
    expect(isNumeric("3e5")).toBeTruthy();
    expect(isNumeric("123e-2")).toBeTruthy();

    Decimal commas

    expect(isNumeric(1,1)).toBeTruthy();
    expect(isNumeric("1,1")).toBeTruthy();

    Install

    npm i isnumeric

    Homepage

    ilee.co.uk

    DownloadsWeekly Downloads

    219,702

    Version

    0.3.3

    License

    MIT

    Unpacked Size

    10.5 kB

    Total Files

    8

    Last publish

    Collaborators

    • leecrossley