isDate.cjs 878 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. exports.isDate = isDate; /**
  3. * @name isDate
  4. * @category Common Helpers
  5. * @summary Is the given value a date?
  6. *
  7. * @description
  8. * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
  9. *
  10. * @param value - The value to check
  11. *
  12. * @returns True if the given value is a date
  13. *
  14. * @example
  15. * // For a valid date:
  16. * const result = isDate(new Date())
  17. * //=> true
  18. *
  19. * @example
  20. * // For an invalid date:
  21. * const result = isDate(new Date(NaN))
  22. * //=> true
  23. *
  24. * @example
  25. * // For some value:
  26. * const result = isDate('2014-02-31')
  27. * //=> false
  28. *
  29. * @example
  30. * // For an object:
  31. * const result = isDate({})
  32. * //=> false
  33. */
  34. function isDate(value) {
  35. return (
  36. value instanceof Date ||
  37. (typeof value === "object" &&
  38. Object.prototype.toString.call(value) === "[object Date]")
  39. );
  40. }