/* eslint-disable no-unused-vars */ import type { Day, Era, FirstWeekContainsDate, Month, Quarter, Unit, } from '../types' import type { BuildLocalizeFnArgCallback, LocalizeUnitValues, LocalizeUnitValuesIndex, } from './_lib/buildLocalizeFn' export interface Locale { code: string formatDistance: FormatDistanceFn formatRelative: FormatRelativeFn localize: Localize formatLong: FormatLong match: Match options?: LocaleOptions } export interface LocaleOptions { weekStartsOn?: Day firstWeekContainsDate?: FirstWeekContainsDate } export type FormatDistanceToken = | 'lessThanXSeconds' | 'xSeconds' | 'halfAMinute' | 'lessThanXMinutes' | 'xMinutes' | 'aboutXHours' | 'xHours' | 'xDays' | 'aboutXWeeks' | 'xWeeks' | 'aboutXMonths' | 'xMonths' | 'aboutXYears' | 'xYears' | 'overXYears' | 'almostXYears' export type FormatDistanceLocale = { [token in FormatDistanceToken]: Value } export interface FormatDistanceFnOptions { addSuffix?: boolean comparison?: -1 | 0 | 1 } export type FormatDistanceTokenFn = ( count: number, options?: FormatDistanceFnOptions ) => string export interface FormatDistanceFnOptions { addSuffix?: boolean comparison?: -1 | 0 | 1 } export type FormatDistanceFn = ( token: FormatDistanceToken, count: number, options?: FormatDistanceFnOptions ) => string export type FormatRelativeTokenFn = ( date: Date | number, baseDate: Date | number, options?: { weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 } ) => string export type FormatRelativeToken = | 'lastWeek' | 'yesterday' | 'today' | 'tomorrow' | 'nextWeek' | 'other' export interface FormatRelativeFnOptions { weekStartsOn?: Day locale?: Locale } export type FormatRelativeFn = ( token: FormatRelativeToken, date: Date, baseDate: Date, options?: FormatRelativeFnOptions ) => string // TODO: You're real champion if you're actually get back to it. Proud of you! // Try to get rid of this and (especially) ArgCallback types because the only // case when it's helpful is when using quarter. Maybe. export type LocalizeUnitIndex< Unit extends LocaleUnit | number > = Unit extends LocaleUnit ? LocalizeUnitValuesIndex> : number export type LocalizeFn< Result extends LocaleUnit | number, ArgCallback extends BuildLocalizeFnArgCallback | undefined = undefined > = ( value: ArgCallback extends undefined ? Result : Result extends Quarter ? Quarter : LocalizeUnitIndex, options?: { width?: LocalePatternWidth context?: 'formatting' | 'standalone' unit?: Unit } ) => string export interface Localize { ordinalNumber: LocalizeFn< number, BuildLocalizeFnArgCallback | undefined > era: LocalizeFn quarter: LocalizeFn> month: LocalizeFn day: LocalizeFn dayPeriod: LocalizeFn } export interface BuildMatchFnArgs< Result extends LocaleUnit, DefaultMatchWidth extends LocalePatternWidth, DefaultParseWidth extends LocalePatternWidth > { matchPatterns: MatchPatterns defaultMatchWidth: DefaultMatchWidth parsePatterns: ParsePatterns defaultParseWidth: DefaultParseWidth valueCallback?: MatchValueCallback< Result extends LocaleDayPeriod ? string : number, Result > } export type MatchPatterns = { [pattern in LocalePatternWidth]?: RegExp } & { [key in DefaultWidth]: RegExp } export type ParsePatterns< Result extends LocaleUnit, DefaultWidth extends LocalePatternWidth > = { [pattern in LocalePatternWidth]?: ParsePattern } & { [key in DefaultWidth]: ParsePattern } export type ParsePattern< Result extends LocaleUnit > = Result extends LocaleDayPeriod ? Record : Result extends Quarter ? readonly [RegExp, RegExp, RegExp, RegExp] : Result extends Era ? readonly [RegExp, RegExp] : Result extends Day ? readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp] : Result extends Month ? readonly [ RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp ] : never export type BuildMatchFn< Result extends LocaleUnit, DefaultMatchWidth extends LocalePatternWidth, DefaultParseWidth extends LocalePatternWidth > = ( args: BuildMatchFnArgs ) => MatchFn export type MatchFn> = ( str: string, options?: { width?: LocalePatternWidth /** * @deprecated Map the value manually instead. * @example * const matchResult = locale.match.ordinalNumber('1st') * if (matchResult) { * matchResult.value = valueCallback(matchResult.value) * } */ valueCallback?: MatchValueCallback } & ExtraOptions ) => { value: Result; rest: string } | null export type MatchValueCallback = (value: Arg) => Result export interface Match { ordinalNumber: MatchFn< number, { unit: LocaleOrdinalUnit } > era: MatchFn quarter: MatchFn month: MatchFn day: MatchFn dayPeriod: MatchFn } export type LocaleOrdinalUnit = | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date' | 'dayOfYear' export type LocalePatternWidth = | 'narrow' | 'short' | 'abbreviated' | 'wide' | 'any' export type LocaleDayPeriod = | 'am' | 'pm' | 'midnight' | 'noon' | 'morning' | 'afternoon' | 'evening' | 'night' export type LocaleOptionUnit = | 'year' | 'quarter' | 'month' | 'week' | 'date' | 'dayOfYear' | 'day' | 'hour' | 'minute' | 'second' export type FormatLongWidth = 'full' | 'long' | 'medium' | 'short' | 'any' export type DateTimeFormat = { [format in FormatLongWidth]: string } export type LocaleUnit = Era | Quarter | Month | Day | LocaleDayPeriod export interface FormatLong { date: FormatLongFn time: FormatLongFn dateTime: FormatLongFn } export interface FormatLongFnOptions { width?: FormatLongWidth } export type FormatLongFn = (options: FormatLongFnOptions) => string