codetrix
Version:
A lightweight lodash-style utility library
25 lines (24 loc) • 974 B
TypeScript
/**
* Formats a date as a string in `YYYY-MM-DD` format (or custom separator).
*
* @param date - The Date object to format.
* @param separator - Optional separator to use between year, month, and day (default: `-`).
* @returns A formatted date string.
*
* @example
* formatDate(new Date(2025, 6, 23)); // '2025-07-23'
* formatDate(new Date(2025, 6, 23), '/'); // '2025/07/23'
*/
export declare function formatDate(date: Date, separator?: string): string;
/**
* Returns a human-readable string describing how far a given date is from today.
*
* @param date - The Date object to compare with today.
* @returns A relative time string like 'today', 'tomorrow', 'yesterday', or 'X days ago' / 'in X days'.
*
* @example
* formatRelative(new Date()); // 'today'
* formatRelative(new Date(Date.now() + 86400000)); // 'tomorrow'
* formatRelative(new Date(Date.now() - 2 * 86400000)); // '2 days ago'
*/
export declare function formatRelative(date: Date): string;