@primitive/is-number
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

is-number

NPM NPM LICENSE

Determine if a value is a number.

A value is a number if it is of primitive type number, or is an instance of reference type Number.

Usage

    npm install @primitive/is-number --save   # Install package via NPM
    yarn add @primitive/is-number             # Install package via Yarn
    import { expect } from "chai";
    import isNumber from "@primitive/is-number";

    expect(isNumber(42)).to.be.true;
    expect(isNumber(0))to.be.true;
    expect(isNumber(new Number(1000))).to.be.true;

    expect(isNumber(undefined)).to.be.false;
    expect(isNumber(null)).to.be.false;
    expect(isNumber("42").to.be.false;

This package contains TypeScript type declarations. Furthermore, the package uses TypeScript type guards to allow type inference to influence intellisense.

    if (isNumber(x)) {
        // IntelliSense now knows `x` is a number.
        let y: number = x;
    }

Build & Test

This package uses Gulp for building, and Chai and Mocha for testing.

    npm install     # Installs dependencies.
    npm run build   # Build the project.
    npm test        # Run tests.

License

Refer to the LICENSE file for license information.

Readme

Keywords

Package Sidebar

Install

npm i @primitive/is-number

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • mgthomas99