You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.jsnext.js 774B

1234567891011121314151617181920212223242526272829
  1. /*!
  2. * is-natural-number.js | MIT (c) Shinnosuke Watanabe
  3. * https://github.com/shinnn/is-natural-number.js
  4. */
  5. export default function isNaturalNumber(val, option) {
  6. if (option) {
  7. if (typeof option !== 'object') {
  8. throw new TypeError(
  9. String(option) +
  10. ' is not an object. Expected an object that has boolean `includeZero` property.'
  11. );
  12. }
  13. if ('includeZero' in option) {
  14. if (typeof option.includeZero !== 'boolean') {
  15. throw new TypeError(
  16. String(option.includeZero) +
  17. ' is neither true nor false. `includeZero` option must be a Boolean value.'
  18. );
  19. }
  20. if (option.includeZero && val === 0) {
  21. return true;
  22. }
  23. }
  24. }
  25. return Number.isSafeInteger(val) && val >= 1;
  26. }