import type { DateArg, Day, Era, FirstWeekContainsDateOptions, LocalizedOptions, Month, Quarter, WeekOptions, } from "../types.js"; /** * The locale object with all functions and data needed to parse and format * dates. This is what each locale implements and exports. */ export interface Locale { /** The locale code (ISO 639-1 + optional country code) */ code: string; /** The function to format distance */ formatDistance: FormatDistanceFn; /** The function to relative time */ formatRelative: FormatRelativeFn; /** The object with functions used to localize various values */ localize: Localize; /** The object with functions that return localized formats */ formatLong: FormatLong; /** The object with functions used to match and parse various localized values */ match: Match; /** An object with locale options */ options?: LocaleOptions; } /** * The locale options. */ export interface LocaleOptions extends WeekOptions, FirstWeekContainsDateOptions {} /** * The function that takes a token (i.e. halfAMinute) passed by `formatDistance` * or `formatDistanceStrict` and payload, and returns localized distance. * * @param token - The token to localize * @param count - The distance number * @param options - The object with options * * @returns The localized distance in words */ export type FormatDistanceFn = ( token: FormatDistanceToken, count: number, options?: FormatDistanceFnOptions, ) => string; /** * The {@link FormatDistanceFn} function options. */ export interface FormatDistanceFnOptions { /** Add "X ago"/"in X" in the locale language */ addSuffix?: boolean; /** The distance vector. -1 represents past and 1 future. Tells which suffix * to use. */ comparison?: -1 | 0 | 1; } /** * The function used inside the {@link FormatDistanceFn} function, implementing * formatting for a particular token. */ export type FormatDistanceTokenFn = ( /** The distance as number to format */ count: number, /** The object with options */ options?: FormatDistanceFnOptions, ) => string; /** * The tokens map to string templates used in the format distance function. * It looks like this: * * const formatDistanceLocale: FormatDistanceLocale = { * lessThanXSeconds: 'តិចជាង {{count}} វិនាទី', * xSeconds: '{{count}} វិនាទី', * // ... * } * * @typeParam Template - The property value type. */ export type FormatDistanceLocale