An open API service indexing awesome lists of open source software.

https://github.com/palashmon/is-positive-int

Validate if a value is a positive integer between 0 & the maximum safe integer.
https://github.com/palashmon/is-positive-int

integer javascript max-safe-integer node positive validation

Last synced: 11 months ago
JSON representation

Validate if a value is a positive integer between 0 & the maximum safe integer.

Awesome Lists containing this project

README

          

# is-positive-int
> Validate if a value is a positive integer between 0 & [maximum safe integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) in JavaScript

![CI](https://github.com/palashmon/is-positive-int/actions/workflows/main.yml/badge.svg)
[![npm version](https://img.shields.io/npm/v/is-positive-int.svg)](http://npm.im/is-positive-int)
[![npm downloads](https://img.shields.io/npm/dm/is-positive-int.svg)](http://npm.im/is-positive-int)

## Install

```
npm install is-positive-int
```

## Usage

```js
import isPositiveInt from 'is-positive-int';

// Test cases
// Valid positive values
isPositiveInt(0); // true
isPositiveInt(1); // true
isPositiveInt(5034); // true
isPositiveInt(Math.pow(2, 53) - 1); // true
isPositiveInt(Number.MAX_SAFE_INTEGER); // true
isPositiveInt(1.0); // true
isPositiveInt(5e2); // true, 500 in exponential notation
isPositiveInt(9.007199254740991e15); // true, Number.MAX_SAFE_INTEGER.toExponential()

// Invalid values
isPositiveInt(-5034); // false
isPositiveInt(-Math.pow(2, 53) - 1); // false
isPositiveInt(-Number.MAX_SAFE_INTEGER); // false
isPositiveInt(Number.MIN_SAFE_INTEGER); // false
isPositiveInt(1.1); // false
isPositiveInt(-5e2); // false
isPositiveInt(NaN); // false
isPositiveInt(Infinity); // false
isPositiveInt(-Infinity); // false
isPositiveInt(null); // false
isPositiveInt(undefined); // false
isPositiveInt(Math.pow(2, 53)); // false
isPositiveInt(-Math.pow(2, 53)); // false
isPositiveInt(Number.MAX_SAFE_INTEGER + 1); // false
isPositiveInt(-Number.MAX_SAFE_INTEGER - 1);// false
isPositiveInt(Number.MIN_SAFE_INTEGER - 1); // false
isPositiveInt(Math.PI); // false
isPositiveInt(-9.007199254740991e15); // false
isPositiveInt(9.007199254740991e15 + 1); // false
isPositiveInt('10'); // false
isPositiveInt(true); // false
isPositiveInt(false); // false
isPositiveInt([1]); // false
isPositiveInt({}); // false
```

## License

MIT © [Palash Mondal](https://github.com/palashmon)