Source

isZero.js

  1. /**
  2. * Checks if a given value is zero or a string representing zero.
  3. * For string values, what we want is "0" or "0.0" but not "" or " " (which also coerce to zero).
  4. *
  5. * @function
  6. * @name isZero
  7. * @param {number|string} val A value to verify is zero or a zero-like string.
  8. * @returns {boolean} Whether or not the given value is zero or a zero-like string.
  9. */
  10. function isZero(val) {
  11. return val === 0 || (
  12. typeof val === "string"
  13. && val.trim().length > 0
  14. && +val === 0
  15. )
  16. }
  17. export default isZero