isExists.cjs 786 B

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. exports.isExists = isExists; /**
  3. * @name isExists
  4. * @category Common Helpers
  5. * @summary Is the given date exists?
  6. *
  7. * @description
  8. * Checks if the given arguments convert to an existing date.
  9. *
  10. * @param year - The year of the date to check
  11. * @param month - The month of the date to check
  12. * @param day - The day of the date to check
  13. *
  14. * @returns `true` if the date exists
  15. *
  16. * @example
  17. * // For the valid date:
  18. * const result = isExists(2018, 0, 31)
  19. * //=> true
  20. *
  21. * @example
  22. * // For the invalid date:
  23. * const result = isExists(2018, 1, 31)
  24. * //=> false
  25. */
  26. function isExists(year, month, day) {
  27. const date = new Date(year, month, day);
  28. return (
  29. date.getFullYear() === year &&
  30. date.getMonth() === month &&
  31. date.getDate() === day
  32. );
  33. }