ts-time-utils
Version:
A comprehensive TypeScript utility library for time, dates, durations, and calendar operations with full tree-shaking support
94 lines • 3.94 kB
TypeScript
import type { DateInput, SupportedLocale, LocaleConfig, RelativeTimeOptions } from './types.js';
/**
* Register a custom locale configuration
*/
export declare function registerLocale(config: LocaleConfig): void;
/**
* Get locale configuration, with fallback to base language or English
*/
export declare function getLocaleConfig(locale: SupportedLocale): LocaleConfig;
/**
* Get list of all registered locales
*/
export declare function getSupportedLocales(): SupportedLocale[];
/**
* Format relative time in the specified locale
*/
export declare function formatRelativeTime(date: DateInput, options?: RelativeTimeOptions): string;
/**
* Format date in locale-specific format
*/
export declare function formatDateLocale(date: DateInput, locale?: SupportedLocale, style?: 'short' | 'medium' | 'long' | 'full'): string;
/**
* Format time in locale-specific format
*/
export declare function formatTimeLocale(date: DateInput, locale?: SupportedLocale, style?: 'short' | 'medium' | 'long' | 'full'): string;
/**
* Format both date and time in locale-specific format
*/
export declare function formatDateTimeLocale(date: DateInput, locale?: SupportedLocale, dateStyle?: 'short' | 'medium' | 'long' | 'full', timeStyle?: 'short' | 'medium' | 'long' | 'full'): string;
/**
* Get localized month names
*/
export declare function getMonthNames(locale?: SupportedLocale, short?: boolean): string[];
/**
* Get localized day names
*/
export declare function getDayNames(locale?: SupportedLocale, short?: boolean): string[];
/**
* Get the first day of week for a locale (0 = Sunday, 1 = Monday, etc.)
*/
export declare function getFirstDayOfWeek(locale?: SupportedLocale): number;
/**
* Check if a locale is supported
*/
export declare function isLocaleSupported(locale: string): locale is SupportedLocale;
/**
* Get the best matching locale from a list of preferences
*/
export declare function getBestMatchingLocale(preferences: string[], fallback?: SupportedLocale): SupportedLocale;
/**
* Auto-detect locale from browser or system (if available)
*/
export declare function detectLocale(fallback?: SupportedLocale): SupportedLocale;
/**
* Convert a relative time string from one locale to another
* Attempts to parse the relative time and reformat in target locale
*/
export declare function convertRelativeTime(relativeTimeString: string, fromLocale: SupportedLocale, toLocale: SupportedLocale): string | null;
/**
* Detect the locale of a formatted relative time string
* Returns the most likely locale or null if detection fails
*/
export declare function detectLocaleFromRelativeTime(relativeTimeString: string): SupportedLocale | null;
/**
* Convert a date format pattern from one locale's convention to another
*/
export declare function convertFormatPattern(pattern: string, fromLocale: SupportedLocale, toLocale: SupportedLocale, style?: 'short' | 'medium' | 'long' | 'full'): string;
/**
* Convert a formatted date string from one locale to another
* Attempts to parse the date and reformat in target locale
*/
export declare function convertFormattedDate(formattedDate: string, fromLocale: SupportedLocale, toLocale: SupportedLocale, targetStyle?: 'short' | 'medium' | 'long' | 'full'): string | null;
/**
* Bulk convert an array of relative time strings to a different locale
*/
export declare function convertRelativeTimeArray(relativeTimeStrings: string[], fromLocale: SupportedLocale, toLocale: SupportedLocale): (string | null)[];
/**
* Get format pattern differences between two locales
*/
export declare function compareLocaleFormats(locale1: SupportedLocale, locale2: SupportedLocale): {
dateFormats: Record<string, {
locale1: string;
locale2: string;
}>;
timeFormats: Record<string, {
locale1: string;
locale2: string;
}>;
weekStartsOn: {
locale1: number;
locale2: number;
};
};
//# sourceMappingURL=locale.d.ts.map