formatDate
The formatDate function formats a date in a locale-specific format. Under the hood, it's basically only calling the Date.prototype.toLocaleDateString method with improved user-error handling.
Usage example
import { formatDate } from 'calendar-widgets';
const formattedDate = formatDate(4, 9, 2023);
console.log(formattedDate); // Output: 04/09/2023
Parameters
- Name
 month- Type
 - number
 - Description
 
- Name
 day- Type
 - number
 - Description
 
- Name
 year- Type
 - number
 - Description
 
- Name
 locale- Type
 - string (optional)
 - Description
 
- Name
 options- Type
 - Intl.DateTimeFormatOptions (optional)
 - Description
 
Return Value
The function returns a string representing the formatted & localized date.
Errors
The function throws an error if any of the following conditions are met:
- The 
monthparameter is not an integer between 1 and 12. - The 
dayparameter is not an integer between 1 and 31. - The 
yearparameter is not an integer between 1900 and 2100. - The 
localeparameter is a string.