datemapper
Version:
A lightweight date utility for format conversion, validation, and date manipulation.
17 lines (16 loc) • 974 B
TypeScript
/**
* Converts date format placeholders between Unix-style (`%Y-%m-%d`) and Moment.js (`YYYY-MM-DD`).
*
* - If `toNewFormat` is `true`, it converts from Unix-style (`%Y`, `%m`, etc.) to Moment.js format (`YYYY`, `MM`, etc.).
* - If `toNewFormat` is `false`, it converts from Moment.js format back to Unix-style.
* - Ensures that only valid placeholders are present before conversion.
*
* @param format - The date format string containing placeholders.
* @param toNewFormat - Boolean flag to control conversion direction.
* - `true` (default): Convert Unix-style (`%Y-%m-%d`) to Moment.js (`YYYY-MM-DD`).
* - `false`: Convert Moment.js (`YYYY-MM-DD`) back to Unix-style (`%Y-%m-%d`).
* @returns The reformatted date format string.
* @throws {Error} If the format contains unrecognized placeholders.
*/
declare const convertDateFormat: (format: string, toNewFormat?: boolean) => string;
export default convertDateFormat;