validateDate function checks if a date string is valid, based on an input format and optional configurations such as a minimum and maximum year.ts
import { validateDate } from "@arkyn/shared";
string): The date string to validate.ValidateDateConfig, optional): Configuration object to customize the validation.inputFormat ("DD/MM/YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD"): The expected date format. Default: "DD/MM/YYYY".minYear (number): The minimum allowed year. Default: 1900.maxYear (number): The maximum year allowed. Default: 3000.boolean): Returns true if the date is valid, otherwise false.Error: Throws an error if an invalid date format is provided in the configuration.ts
import { validateDate } from "./validateDate";validateDate("12/31/2023"); // truevalidateDate("12-31-2023", { inputFormat: "MM-DD-YYYY" }); // truevalidateDate("29/02/2023", { inputFormat: "DD/MM/YYYY" }); // false (not a leap year)