index.js 894 B

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