index.js 551 B

123456789101112131415161718192021
  1. 'use strict';
  2. var getDay = Date.prototype.getDay;
  3. var tryDateObject = function tryDateObject(value) {
  4. try {
  5. getDay.call(value);
  6. return true;
  7. } catch (e) {
  8. return false;
  9. }
  10. };
  11. var toStr = Object.prototype.toString;
  12. var dateClass = '[object Date]';
  13. var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
  14. module.exports = function isDateObject(value) {
  15. if (typeof value !== 'object' || value === null) { return false; }
  16. return hasToStringTag ? tryDateObject(value) : toStr.call(value) === dateClass;
  17. };