index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isDate;
  6. var _index = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. /**
  9. * @name isDate
  10. * @category Common Helpers
  11. * @summary Is the given value a date?
  12. *
  13. * @description
  14. * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
  15. *
  16. * ### v2.0.0 breaking changes:
  17. *
  18. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  19. *
  20. * @param {*} value - the value to check
  21. * @returns {boolean} true if the given value is a date
  22. * @throws {TypeError} 1 arguments required
  23. *
  24. * @example
  25. * // For a valid date:
  26. * const result = isDate(new Date())
  27. * //=> true
  28. *
  29. * @example
  30. * // For an invalid date:
  31. * const result = isDate(new Date(NaN))
  32. * //=> true
  33. *
  34. * @example
  35. * // For some value:
  36. * const result = isDate('2014-02-31')
  37. * //=> false
  38. *
  39. * @example
  40. * // For an object:
  41. * const result = isDate({})
  42. * //=> false
  43. */
  44. function isDate(value) {
  45. (0, _index.default)(1, arguments);
  46. return value instanceof Date || typeof value === 'object' && Object.prototype.toString.call(value) === '[object Date]';
  47. }
  48. module.exports = exports.default;