index.js 1.0 KB

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