import { FormatNumberOptions, FormatRelativeTimeOptions, FormatDateOptions, IntlFormatters as IntlFormatters$1, MessageDescriptor, ResolvedIntlConfig, Formatters, IntlConfig, IntlCache } from '@formatjs/intl'; export { createIntlCache } from '@formatjs/intl'; import { MessageFormatElement } from '@formatjs/icu-messageformat-parser'; import { PrimitiveType, FormatXMLElementFn, Options } from 'intl-messageformat'; type FormatCompactNumberOptions = Omit; declare const CompactNumberSym: unique symbol; /** * {@link CompactNumber} is a value object created for a number and with specific * formatting options, that can be converted to string, in which case it will * return the formatted number in compact notation, or to a number in which case * it will return rounded number that can be used to select correct plural case, * matching the formatted number. * * This object implements both `valueOf` and `toString` methods, so it's * possible to pass it directly to {@link String} and {@link Number} functions to * get the desired values. It is lazy implementation, so values are computed * once they accessed and cached afterwards. * * To use this object {@link Intl.NumberFormat} must be polyfilled since it * requires CLDR data to function. It does not support {@link BigInt}. */ interface CompactNumber { [CompactNumberSym]: true; valueOf(): number; toString(): string; toParts(): Intl.NumberFormatPart[]; } declare function isCompactNumber(value: unknown): value is CompactNumber; /** * Describes a union of types that can be used or converted to a timestamp. * * It must be either: * * - `string` which can be used to construct [`Date`]({@link Date}) object. * - `number` that contains a timestamp, a number of seconds since 1 Jan 1970 UTC. * - [`Date`]({@link Date}) object on which [`getTime`]({@link Date#getTime}) will * be executed. */ type TimeRangePart = Date | string | number; /** * Describes a type of parameter that contains a time range. Can be either a * `from` date (as is or wrapped in an array), or both `from` and `to` dates * wrapped in an array. If `to` is not provided it is assumed to be the current * date at the moment of executing any function accepting this type. */ type TimeRange = TimeRangePart | { from: TimeRangePart; to?: TimeRangePart; }; interface FormatTimeDifferenceOptions extends FormatRelativeTimeOptions { /** * Maximum unit after which formatting to relative time should be abandoned * and instead end date must be formatted using `dateTimeOptions`. * * If set to `'none'`, then time difference that exceeds `minimumUnit` will be * formatted in relative time. * * @default 'none' */ maximumUnit?: Intl.RelativeTimeFormatUnit | 'none'; /** * Minimum unit before which formatting to relative time should be abandoned * and instead end date must be formatted using `dateTimeOptions`. * * If set to `'none'`, then any time difference that does not exceed * `maximumUnit` will be formatted in relative time. * * @default 'none' */ minimumUnit?: Intl.RelativeTimeFormatUnit | 'none'; /** * Options for datetime formatting when it reaches the cut-off unit. * * @default { dateStyle: 'long', timeStyle: 'short' } */ dateTimeOptions?: FormatDateOptions; /** * Units to never use for relative time formatting. * * @default ['quarter'] */ excludedUnits?: Intl.RelativeTimeFormatUnit[]; } type IntlFormatters = IntlFormatters$1 & { /** * Given a specific time range or just a start date calculates the time * difference between the two (if just start date is provided, then the end * date assumed is to be the time at the moment of the call), it then selects * the preferable unit to display that difference and returns a formatted * string using that unit (e.g. in 1 day, 2 days ago). * * It uses {@link Intl.RelativeTimeFormat} under the hood, but with one notable * difference - option `numeric` is set to `'auto'` be default, meaning * differences such as +1 day will be formatted as 'tomorrow' and -1 day as * 'yesterday'. This default can be fully overridden via options to match the * original behaviour of {@link Intl.RelativeTimeFormat}, which is to use * `'always'` by default for `numeric`. * * @param range Range for which time difference is calculated. * @param options Options for relative time formatter. * @returns Largest unit available to display the time. */ formatTimeDifference(range: TimeRange, options?: FormatTimeDifferenceOptions): string; /** Shorthand for {@link IntlFormatters.formatTimeDifference}. */ $ago(range: TimeRange, options?: FormatTimeDifferenceOptions): string; formatCompactNumber(value: number, opts?: FormatCompactNumberOptions): CompactNumber; /** * Formats custom message using the provided values. * * @param message Message to format. * @param values Values to format message with. * @param opts Formatter options. * @returns Formatted message contents. */ formatCustomMessage(message: string | MessageFormatElement[], values?: Record>, opts?: Options): string; /** * Formats custom message using the provided values. * * @param message Message to format. * @param values Values to format message with. * @param opts Formatter options. * @returns Formatted message contents. */ formatCustomMessage(message: string | MessageFormatElement[], values?: Record>, opts?: Options): string | T | (T | string)[]; formatMessage(descriptor: MessageDescriptor, values?: Record>, opts?: Options): string; formatMessage(descriptor: MessageDescriptor, values?: Record>, opts?: Options): string | T | (T | string)[]; $t(descriptor: MessageDescriptor, values?: Record>, opts?: Options): string; $t(descriptor: MessageDescriptor, values?: Record>, opts?: Options): string | T | (T | string)[]; }; interface IntlShape extends ResolvedIntlConfig, IntlFormatters { formatters: Formatters; } declare function createIntl(config: IntlConfig, cache?: IntlCache): IntlShape; interface NumberFormatLocaleData { nu: string[]; numbers: { nu: string[]; decimal: { [numericSystem: string]: { short: Record; long: Record; }; }; currency: { [numericSystem: string]: { short: Record; long: Record; }; }; }; } declare function setDefaultLocaleDataLocale(value: string): void; declare function addLocaleData(locale: string, data: NumberFormatLocaleData): void; export { CompactNumber, IntlFormatters, IntlShape, addLocaleData as addNumberFormatData, createIntl, isCompactNumber, setDefaultLocaleDataLocale as setDefaultNumberFormatDataLocale };