isExists.js 813 B

1234567891011121314151617181920212223242526272829303132333435
  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 year - The year of the date to check
  10. * @param month - The month of the date to check
  11. * @param day - The day of the date to check
  12. *
  13. * @returns `true` if the date exists
  14. *
  15. * @example
  16. * // For the valid date:
  17. * const result = isExists(2018, 0, 31)
  18. * //=> true
  19. *
  20. * @example
  21. * // For the invalid date:
  22. * const result = isExists(2018, 1, 31)
  23. * //=> false
  24. */
  25. export function isExists(year, month, day) {
  26. const date = new Date(year, month, day);
  27. return (
  28. date.getFullYear() === year &&
  29. date.getMonth() === month &&
  30. date.getDate() === day
  31. );
  32. }
  33. // Fallback for modularized imports:
  34. export default isExists;