isp0int.mjs

  1. import isint from './isint.mjs'
  2. import cint from './cint.mjs'
  3. /**
  4. * 判斷是否為大於等於0整數(非負整數)
  5. * 非負整數包含0
  6. *
  7. * Unit Test: {@link https://github.com/yuda-lyu/wsemi/blob/master/test/isp0int.test.mjs Github}
  8. * @memberOf wsemi
  9. * @param {*} v 輸入任意資料
  10. * @returns {Boolean} 回傳判斷布林值
  11. * @example
  12. *
  13. * console.log(isp0int(0))
  14. * // => true
  15. *
  16. * console.log(isp0int('0'))
  17. * // => true
  18. *
  19. * console.log(isp0int(125))
  20. * // => true
  21. *
  22. * console.log(isp0int(1.25))
  23. * // => false
  24. *
  25. * console.log(isp0int('125'))
  26. * // => true
  27. *
  28. * console.log(isp0int('1.25'))
  29. * // => false
  30. * console.log(isp0int(-125))
  31. * // => false
  32. *
  33. * console.log(isp0int(-1.25))
  34. * // => false
  35. *
  36. * console.log(isp0int('-125'))
  37. * // => false
  38. *
  39. * console.log(isp0int('-1.25'))
  40. * // => false
  41. *
  42. */
  43. function isp0int(v) {
  44. //check
  45. if (!isint(v)) {
  46. return false
  47. }
  48. let r = cint(v) >= 0
  49. return r
  50. }
  51. export default isp0int