Socket
Book a DemoInstallSign in
Socket

is-zero-or-positive-integer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

is-zero-or-positive-integer

Node.js helper function: test variables for being a zero or a positive integer.

unpublished
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

is-zero-or-positive-integer

Node.js helper function: test variables for being a zero or a positive integer.

Installation

npm install is-zero-or-positive-integer

Usage

const isZeroOrPositiveInteger = require('is-zero-or-positive-integer');

/*
    If you only want to check for safe integers:
    const isZeroOrPositiveInteger = require('is-zero-or-positive-integer').onlyTrueIfSafe;
    See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER for further reference.
*/

// numbers
console.log( isZeroOrPositiveInteger(0) ); //true
console.log( isZeroOrPositiveInteger(1) ); //true
console.log( isZeroOrPositiveInteger(-1) ); //false
console.log( isZeroOrPositiveInteger(2147483647) ); //true
console.log( isZeroOrPositiveInteger(-2147483648) ); //false
console.log( isZeroOrPositiveInteger(Number.MAX_SAFE_INTEGER) ); //true
console.log( isZeroOrPositiveInteger(Number.MIN_SAFE_INTEGER) ); //false
console.log( isZeroOrPositiveInteger(1e+23) ); //true
console.log( isZeroOrPositiveInteger(-1e+23) ); //false

// strings
console.log( isZeroOrPositiveInteger('0') ); //true
console.log( isZeroOrPositiveInteger('1') ); //true
console.log( isZeroOrPositiveInteger('01') ); //true
console.log( isZeroOrPositiveInteger('-1') ); //false
console.log( isZeroOrPositiveInteger('2147483647') ); //true
console.log( isZeroOrPositiveInteger('-2147483648') ); //false
console.log( isZeroOrPositiveInteger('9007199254740991') ); //true
console.log( isZeroOrPositiveInteger('-9007199254740991') ); //false
console.log( isZeroOrPositiveInteger('1e+23') ); //true
console.log( isZeroOrPositiveInteger('-1e+23') ); //false
console.log( isZeroOrPositiveInteger('string') ); //false

// other
console.log( isZeroOrPositiveInteger({}) ); //false
console.log( isZeroOrPositiveInteger([]) ); //false
console.log( isZeroOrPositiveInteger(Symbol()) ); //false
console.log( isZeroOrPositiveInteger(new Date()) ); //false
console.log( isZeroOrPositiveInteger(new Date().getTime()) ); //true
console.log( isZeroOrPositiveInteger(function() { return; }) ); //false

/* visual representation mode (vrm): 
   if set true then consider values with 
   - scientific notation (1e+23)
   - leading zeroes ('0123')
   as being no integer!
*/
console.log( isZeroOrPositiveInteger(1e+23, true) ); //false
console.log( isZeroOrPositiveInteger('01', true) ); //false

Keywords

helper

FAQs

Package last updated on 06 Nov 2016

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