UNPKG

2.23 kBTypeScriptView Raw
1import React from 'react';
2import { ProcessedMessages, UserProvidedMessages } from './messages';
3export declare type DateTimePartType = 'day' | 'dayPeriod' | 'era' | 'hour' | 'literal' | 'minute' | 'month' | 'second' | 'weekday' | 'year' | 'millisecond';
4export declare type DateTimePart = {
5 type: DateTimePartType;
6 value: string;
7};
8export declare type RequiredDateMethods = 'date' | 'time' | 'datetime' | 'header' | 'weekday' | 'dayOfMonth' | 'month' | 'year' | 'decade' | 'century';
9export declare type DateLocalizer<TD> = {
10 parse(dateString: string, format?: TD): Date | null;
11 firstOfWeek(): number;
12} & {
13 [Key in RequiredDateMethods]: (date: Date, format?: TD) => string;
14};
15export interface NumberLocalizer<TN> {
16 parse(numberString: string, format?: TN): number | null;
17 decimalCharacter(): string;
18 format(value: number, format?: TN): string;
19}
20export interface Localizer<TD = unknown, TN = unknown> {
21 formatOverrides: FormatterOverrides<TD, TN>;
22 messages: ProcessedMessages;
23 formatDate(value: Date, formatter: RequiredDateMethods, userFormat?: TD): string;
24 formatNumber(value: number, userFormat?: TN): string;
25 parseDate(dateString: string, format?: TD): Date | null;
26 parseNumber(numberString: string, format?: TN): number | null;
27 firstOfWeek(): number;
28 decimalCharacter(): string;
29}
30export declare type DateFormats<TFormat> = {
31 [Key in RequiredDateMethods]?: TFormat;
32};
33export declare type FormatterOverrides<TD, TN> = DateFormats<TD> & {
34 number?: TN;
35};
36declare type ProviderProps = {
37 date?: DateLocalizer<any>;
38 number?: NumberLocalizer<any>;
39 messages?: UserProvidedMessages;
40 children?: React.ReactNode;
41};
42declare const Localization: {
43 ({ date, number, messages, children, }: ProviderProps): JSX.Element;
44 useLocalizer: (messages?: Partial<import("./messages").Messages> | undefined, formats?: FormatterOverrides<any, any> | undefined) => Localizer<unknown, unknown>;
45};
46export declare const useLocalizer: (messages?: Partial<import("./messages").Messages> | undefined, formats?: FormatterOverrides<any, any> | undefined) => Localizer<unknown, unknown>;
47export default Localization;
48//# sourceMappingURL=Localization.d.ts.map
\No newline at end of file