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.
- Host: GitHub
- URL: https://github.com/palashmon/is-positive-int
- Owner: palashmon
- License: mit
- Created: 2017-09-17T18:28:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T08:26:25.000Z (over 1 year ago)
- Last Synced: 2024-10-29T09:47:47.472Z (over 1 year ago)
- Topics: integer, javascript, max-safe-integer, node, positive, validation
- Language: TypeScript
- Homepage:
- Size: 133 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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

[](http://npm.im/is-positive-int)
[](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)