项目作者: palashmon

项目描述 :
Validate if a value is a positive integer between 0 & maximum safe integer in JavaScript
高级语言: JavaScript
项目地址: git://github.com/palashmon/is-positive-int.git
创建时间: 2017-09-17T18:28:27Z
项目社区:https://github.com/palashmon/is-positive-int

开源协议:MIT License

下载


is-positive-int

Validate if a value is a positive integer between 0 & maximum safe integer in JavaScript

CI
npm version
npm downloads

Install

  1. npm install is-positive-int

Usage

  1. import isPositiveInt from 'is-positive-int';
  2. // Test cases
  3. // Valid positive values
  4. isPositiveInt(0); // true
  5. isPositiveInt(1); // true
  6. isPositiveInt(5034); // true
  7. isPositiveInt(Math.pow(2, 53) - 1); // true
  8. isPositiveInt(Number.MAX_SAFE_INTEGER); // true
  9. isPositiveInt(1.0); // true
  10. isPositiveInt(5e2); // true, 500 in exponential notation
  11. isPositiveInt(9.007199254740991e15); // true, Number.MAX_SAFE_INTEGER.toExponential()
  12. // Invalid values
  13. isPositiveInt(-5034); // false
  14. isPositiveInt(-Math.pow(2, 53) - 1); // false
  15. isPositiveInt(-Number.MAX_SAFE_INTEGER); // false
  16. isPositiveInt(Number.MIN_SAFE_INTEGER); // false
  17. isPositiveInt(1.1); // false
  18. isPositiveInt(-5e2); // false
  19. isPositiveInt(NaN); // false
  20. isPositiveInt(Infinity); // false
  21. isPositiveInt(-Infinity); // false
  22. isPositiveInt(null); // false
  23. isPositiveInt(undefined); // false
  24. isPositiveInt(Math.pow(2, 53)); // false
  25. isPositiveInt(-Math.pow(2, 53)); // false
  26. isPositiveInt(Number.MAX_SAFE_INTEGER + 1); // false
  27. isPositiveInt(-Number.MAX_SAFE_INTEGER - 1);// false
  28. isPositiveInt(Number.MIN_SAFE_INTEGER - 1); // false
  29. isPositiveInt(Math.PI); // false
  30. isPositiveInt(-9.007199254740991e15); // false
  31. isPositiveInt(9.007199254740991e15 + 1); // false
  32. isPositiveInt('10'); // false
  33. isPositiveInt(true); // false
  34. isPositiveInt(false); // false
  35. isPositiveInt([1]); // false
  36. isPositiveInt({}); // false

License

MIT © Palash Mondal