index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isExists;
  6. /**
  7. * @name isExists
  8. * @category Common Helpers
  9. * @summary Is the given date exists?
  10. *
  11. * @description
  12. * Checks if the given arguments convert to an existing date.
  13. *
  14. * @param {Number} year of the date to check
  15. * @param {Number} month of the date to check
  16. * @param {Number} day of the date to check
  17. * @returns {Boolean} the date exists
  18. * @throws {TypeError} 3 arguments required
  19. *
  20. * @example
  21. * // For the valid date:
  22. * const result = isExists(2018, 0, 31)
  23. * //=> true
  24. *
  25. * @example
  26. * // For the invalid date:
  27. * const result = isExists(2018, 1, 31)
  28. * //=> false
  29. */
  30. function isExists(year, month, day) {
  31. if (arguments.length < 3) {
  32. throw new TypeError('3 argument required, but only ' + arguments.length + ' present');
  33. }
  34. var date = new Date(year, month, day);
  35. return date.getFullYear() === year && date.getMonth() === month && date.getDate() === day;
  36. }
  37. module.exports = exports.default;