Giter VIP home page Giter VIP logo

depicts-whole-number's Introduction

depicts-whole-number

Test a variable to see if it represents a whole number.[1]

Build Status Test Coverage Code Climate

Dependency Status devDependencies Status

Standard - JavaScript Style Guide

Installation

$ npm install depicts-whole-number

Usage

const depictsWholeNumber = require('depicts-whole-number')

depictsWholeNumber(0) // true
depictsWholeNumber(123) // true
depictsWholeNumber(-123) // false
depictsWholeNumber(1.23) // false
depictsWholeNumber(1e+21) // false
depictsWholeNumber(Number.MAX_VALUE) // false
depictsWholeNumber(Infinity) // false

depictsWholeNumber('0') // true
depictsWholeNumber('123') // true
depictsWholeNumber('-123') // false
depictsWholeNumber('1.23') // false
depictsWholeNumber('1e3') // false
depictsWholeNumber('1e+3') // false
depictsWholeNumber('0123') // false
depictsWholeNumber('123s45') // false

depictsWholeNumber('') // false
depictsWholeNumber(null) // false
depictsWholeNumber(undefined) // false
depictsWholeNumber(NaN) // false

Take a look into the test folder for more examples.

Note: The following numbers are not whole numbers, but identical up to an isomorphism:[2]

  • 1e+3 (scientific notation) ~ 1000
  • 1000.00 (natural number with a fraction) ~ 1000

Only Safe Numbers

When using this option, true is only returned for whole numbers being less or equal than Number.MAX_SAFE_INTEGER.
Visit developer.mozilla.org for further reference.

const depictsWholeNumber = require('depicts-whole-number').onlySafeNumbers

depictsWholeNumber(Number.MAX_SAFE_INTEGER) // true
depictsWholeNumber(Number.MAX_SAFE_INTEGER + 1) // false

depictsWholeNumber('9007199254740991') // true
depictsWholeNumber('9007199254740992') // false

License

ISC

ย 

[1] Whole numbers are natural numbers (including zero) written in decimal notation without a decimal fraction.
[2] Isomorphism: Sameness between two different structures.

depicts-whole-number's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.