use-intl 2.9.2-alpha.0 → 2.10.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +463 -0
  2. package/dist/core/use-intl.esm.js +140 -27
  3. package/dist/core/use-intl.esm.js.map +1 -1
  4. package/dist/core/use-intl.esm2.js +27 -140
  5. package/dist/core/use-intl.esm2.js.map +1 -1
  6. package/dist/core/use-intl.esm3.js +2 -2
  7. package/dist/core/use-intl.esm4.js +12 -56
  8. package/dist/core/use-intl.esm4.js.map +1 -1
  9. package/dist/core/use-intl.esm5.js +56 -12
  10. package/dist/core/use-intl.esm5.js.map +1 -1
  11. package/dist/core/use-intl.esm6.js +7 -29
  12. package/dist/core/use-intl.esm6.js.map +1 -1
  13. package/dist/core/use-intl.esm7.js +9 -9
  14. package/dist/core/use-intl.esm7.js.map +1 -1
  15. package/dist/core/use-intl.esm8.js +29 -7
  16. package/dist/core/use-intl.esm8.js.map +1 -1
  17. package/dist/react/IntlContext.d.ts +2 -19
  18. package/dist/react/IntlContextValue.d.ts +19 -0
  19. package/dist/react/IntlProvider.d.ts +2 -16
  20. package/dist/react/IntlProviderProps.d.ts +15 -0
  21. package/dist/react/getIntlContextValue.d.ts +18 -0
  22. package/dist/react/use-intl.esm.js +12 -21
  23. package/dist/react/use-intl.esm.js.map +1 -1
  24. package/dist/react/use-intl.esm10.js +44 -0
  25. package/dist/react/use-intl.esm10.js.map +1 -0
  26. package/dist/react/use-intl.esm2.js +2 -2
  27. package/dist/react/use-intl.esm3.js +20 -30
  28. package/dist/react/use-intl.esm3.js.map +1 -1
  29. package/dist/react/use-intl.esm4.js +46 -4
  30. package/dist/react/use-intl.esm4.js.map +1 -1
  31. package/dist/react/use-intl.esm5.js +1 -1
  32. package/dist/react/use-intl.esm6.js +4 -46
  33. package/dist/react/use-intl.esm6.js.map +1 -1
  34. package/dist/react/use-intl.esm7.js +3 -12
  35. package/dist/react/use-intl.esm7.js.map +1 -1
  36. package/dist/react/use-intl.esm8.js +30 -3
  37. package/dist/react/use-intl.esm8.js.map +1 -1
  38. package/dist/react/use-intl.esm9.js +9 -38
  39. package/dist/react/use-intl.esm9.js.map +1 -1
  40. package/dist/react/useIntlContext.d.ts +1 -1
  41. package/dist/src/core/AbstractIntlMessages.d.ts +9 -0
  42. package/dist/src/core/AbstractIntlMessages.js +2 -0
  43. package/dist/src/core/AbstractIntlMessages.js.map +1 -0
  44. package/dist/src/core/DateTimeFormatOptions.d.ts +72 -0
  45. package/dist/src/core/DateTimeFormatOptions.js +3 -0
  46. package/dist/src/core/DateTimeFormatOptions.js.map +1 -0
  47. package/dist/src/core/Formats.d.ts +7 -0
  48. package/dist/src/core/Formats.js +2 -0
  49. package/dist/src/core/Formats.js.map +1 -0
  50. package/dist/src/core/IntlConfiguration.d.ts +46 -0
  51. package/dist/src/core/IntlConfiguration.js +2 -0
  52. package/dist/src/core/IntlConfiguration.js.map +1 -0
  53. package/dist/src/core/IntlError.d.ts +13 -0
  54. package/dist/src/core/IntlError.js +23 -0
  55. package/dist/src/core/IntlError.js.map +1 -0
  56. package/dist/src/core/IntlMessages.d.ts +2 -0
  57. package/dist/src/core/IntlMessages.js +4 -0
  58. package/dist/src/core/IntlMessages.js.map +1 -0
  59. package/dist/src/core/NumberFormatOptions.d.ts +2 -0
  60. package/dist/src/core/NumberFormatOptions.js +2 -0
  61. package/dist/src/core/NumberFormatOptions.js.map +1 -0
  62. package/dist/src/core/TranslationValues.d.ts +5 -0
  63. package/dist/src/core/TranslationValues.js +2 -0
  64. package/dist/src/core/TranslationValues.js.map +1 -0
  65. package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +10 -0
  66. package/dist/src/core/convertFormatsToIntlMessageFormat.js +31 -0
  67. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -0
  68. package/dist/src/core/createBaseTranslator.d.ts +26 -0
  69. package/dist/src/core/createBaseTranslator.js +185 -0
  70. package/dist/src/core/createBaseTranslator.js.map +1 -0
  71. package/dist/src/core/createIntl.d.ts +17 -0
  72. package/dist/src/core/createIntl.js +126 -0
  73. package/dist/src/core/createIntl.js.map +1 -0
  74. package/dist/src/core/createTranslator.d.ts +48 -0
  75. package/dist/src/core/createTranslator.js +24 -0
  76. package/dist/src/core/createTranslator.js.map +1 -0
  77. package/dist/src/core/createTranslatorImpl.d.ts +14 -0
  78. package/dist/src/core/createTranslatorImpl.js +43 -0
  79. package/dist/src/core/createTranslatorImpl.js.map +1 -0
  80. package/dist/src/core/defaults.d.ts +11 -0
  81. package/dist/src/core/defaults.js +11 -0
  82. package/dist/src/core/defaults.js.map +1 -0
  83. package/dist/src/core/index.d.ts +8 -0
  84. package/dist/src/core/index.js +4 -0
  85. package/dist/src/core/index.js.map +1 -0
  86. package/dist/src/core/resolveNamespace.d.ts +5 -0
  87. package/dist/src/core/resolveNamespace.js +10 -0
  88. package/dist/src/core/resolveNamespace.js.map +1 -0
  89. package/dist/src/core/utils/MessageKeys.d.ts +5 -0
  90. package/dist/src/core/utils/MessageKeys.js +2 -0
  91. package/dist/src/core/utils/MessageKeys.js.map +1 -0
  92. package/dist/src/core/utils/NamespaceKeys.d.ts +5 -0
  93. package/dist/src/core/utils/NamespaceKeys.js +2 -0
  94. package/dist/src/core/utils/NamespaceKeys.js.map +1 -0
  95. package/dist/src/core/utils/NestedKeyOf.d.ts +4 -0
  96. package/dist/src/core/utils/NestedKeyOf.js +2 -0
  97. package/dist/src/core/utils/NestedKeyOf.js.map +1 -0
  98. package/dist/src/core/utils/NestedValueOf.d.ts +2 -0
  99. package/dist/src/core/utils/NestedValueOf.js +2 -0
  100. package/dist/src/core/utils/NestedValueOf.js.map +1 -0
  101. package/dist/src/core/validateMessages.d.ts +3 -0
  102. package/dist/src/core/validateMessages.js +22 -0
  103. package/dist/src/core/validateMessages.js.map +1 -0
  104. package/dist/src/index.d.ts +2 -0
  105. package/dist/src/index.js +3 -0
  106. package/dist/src/index.js.map +1 -0
  107. package/dist/src/react/IntlContext.d.ts +4 -0
  108. package/dist/src/react/IntlContext.js +4 -0
  109. package/dist/src/react/IntlContext.js.map +1 -0
  110. package/dist/src/react/IntlContextValue.d.ts +19 -0
  111. package/dist/src/react/IntlContextValue.js +2 -0
  112. package/dist/src/react/IntlContextValue.js.map +1 -0
  113. package/dist/src/react/IntlProvider.d.ts +2 -0
  114. package/dist/src/react/IntlProvider.js +7 -0
  115. package/dist/src/react/IntlProvider.js.map +1 -0
  116. package/dist/src/react/IntlProviderProps.d.ts +15 -0
  117. package/dist/src/react/IntlProviderProps.js +2 -0
  118. package/dist/src/react/IntlProviderProps.js.map +1 -0
  119. package/dist/src/react/getIntlContextValue.d.ts +18 -0
  120. package/dist/src/react/getIntlContextValue.js +21 -0
  121. package/dist/src/react/getIntlContextValue.js.map +1 -0
  122. package/dist/src/react/index.d.ts +6 -0
  123. package/dist/src/react/index.js +7 -0
  124. package/dist/src/react/index.js.map +1 -0
  125. package/dist/src/react/useIntl.d.ts +5 -0
  126. package/dist/src/react/useIntl.js +14 -0
  127. package/dist/src/react/useIntl.js.map +1 -0
  128. package/dist/src/react/useIntlContext.d.ts +1 -0
  129. package/dist/src/react/useIntlContext.js +12 -0
  130. package/dist/src/react/useIntlContext.js.map +1 -0
  131. package/dist/src/react/useLocale.d.ts +1 -0
  132. package/dist/src/react/useLocale.js +5 -0
  133. package/dist/src/react/useLocale.js.map +1 -0
  134. package/dist/src/react/useNow.d.ts +23 -0
  135. package/dist/src/react/useNow.js +40 -0
  136. package/dist/src/react/useNow.js.map +1 -0
  137. package/dist/src/react/useTimeZone.d.ts +1 -0
  138. package/dist/src/react/useTimeZone.js +5 -0
  139. package/dist/src/react/useTimeZone.js.map +1 -0
  140. package/dist/src/react/useTranslations.d.ts +44 -0
  141. package/dist/src/react/useTranslations.js +21 -0
  142. package/dist/src/react/useTranslations.js.map +1 -0
  143. package/dist/src/react/useTranslationsImpl.d.ts +8 -0
  144. package/dist/src/react/useTranslationsImpl.js +35 -0
  145. package/dist/src/react/useTranslationsImpl.js.map +1 -0
  146. package/dist/use-intl.cjs.development.js +37 -28
  147. package/dist/use-intl.cjs.development.js.map +1 -1
  148. package/dist/use-intl.cjs.production.min.js +1 -1
  149. package/dist/use-intl.cjs.production.min.js.map +1 -1
  150. package/dist/use-intl.esm.js +6 -6
  151. package/package.json +6 -5
  152. package/src/core/createBaseTranslator.tsx +11 -7
  153. package/src/core/createIntl.tsx +2 -2
  154. package/src/core/createTranslatorImpl.tsx +1 -1
  155. package/src/react/IntlContext.tsx +2 -20
  156. package/src/react/IntlContextValue.tsx +21 -0
  157. package/src/react/IntlProvider.tsx +5 -36
  158. package/src/react/IntlProviderProps.tsx +17 -0
  159. package/src/react/getIntlContextValue.tsx +30 -0
  160. package/src/react/useIntlContext.tsx +1 -1
  161. package/LICENSE +0 -21
@@ -0,0 +1,126 @@
1
+ import IntlError, { IntlErrorCode } from './IntlError';
2
+ import { defaultOnError } from './defaults';
3
+ const MINUTE = 60;
4
+ const HOUR = MINUTE * 60;
5
+ const DAY = HOUR * 24;
6
+ const WEEK = DAY * 7;
7
+ const MONTH = DAY * (365 / 12); // Approximation
8
+ const YEAR = DAY * 365;
9
+ function getRelativeTimeFormatConfig(seconds) {
10
+ const absValue = Math.abs(seconds);
11
+ let value, unit;
12
+ // We have to round the resulting values, as `Intl.RelativeTimeFormat`
13
+ // will include fractions like '2.1 hours ago'.
14
+ if (absValue < MINUTE) {
15
+ unit = 'second';
16
+ value = Math.round(seconds);
17
+ }
18
+ else if (absValue < HOUR) {
19
+ unit = 'minute';
20
+ value = Math.round(seconds / MINUTE);
21
+ }
22
+ else if (absValue < DAY) {
23
+ unit = 'hour';
24
+ value = Math.round(seconds / HOUR);
25
+ }
26
+ else if (absValue < WEEK) {
27
+ unit = 'day';
28
+ value = Math.round(seconds / DAY);
29
+ }
30
+ else if (absValue < MONTH) {
31
+ unit = 'week';
32
+ value = Math.round(seconds / WEEK);
33
+ }
34
+ else if (absValue < YEAR) {
35
+ unit = 'month';
36
+ value = Math.round(seconds / MONTH);
37
+ }
38
+ else {
39
+ unit = 'year';
40
+ value = Math.round(seconds / YEAR);
41
+ }
42
+ return { value, unit };
43
+ }
44
+ export default function createIntl({ formats, locale, now: globalNow, onError = defaultOnError, timeZone }) {
45
+ function resolveFormatOrOptions(typeFormats, formatOrOptions) {
46
+ let options;
47
+ if (typeof formatOrOptions === 'string') {
48
+ const formatName = formatOrOptions;
49
+ options = typeFormats?.[formatName];
50
+ if (!options) {
51
+ const error = new IntlError(IntlErrorCode.MISSING_FORMAT, process.env.NODE_ENV !== 'production'
52
+ ? `Format \`${formatName}\` is not available. You can configure it on the provider or provide custom options.`
53
+ : undefined);
54
+ onError(error);
55
+ throw error;
56
+ }
57
+ }
58
+ else {
59
+ options = formatOrOptions;
60
+ }
61
+ return options;
62
+ }
63
+ function getFormattedValue(value, formatOrOptions, typeFormats, formatter) {
64
+ let options;
65
+ try {
66
+ options = resolveFormatOrOptions(typeFormats, formatOrOptions);
67
+ }
68
+ catch (error) {
69
+ return String(value);
70
+ }
71
+ try {
72
+ return formatter(options);
73
+ }
74
+ catch (error) {
75
+ onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
76
+ return String(value);
77
+ }
78
+ }
79
+ function formatDateTime(
80
+ /** If a number is supplied, this is interpreted as a UTC timestamp. */
81
+ value,
82
+ /** If a time zone is supplied, the `value` is converted to that time zone.
83
+ * Otherwise the user time zone will be used. */
84
+ formatOrOptions) {
85
+ return getFormattedValue(value, formatOrOptions, formats?.dateTime, (options) => {
86
+ if (timeZone && !options?.timeZone) {
87
+ options = { ...options, timeZone };
88
+ }
89
+ return new Intl.DateTimeFormat(locale, options).format(value);
90
+ });
91
+ }
92
+ function formatNumber(value, formatOrOptions) {
93
+ return getFormattedValue(value, formatOrOptions, formats?.number, (options) => new Intl.NumberFormat(locale, options).format(value));
94
+ }
95
+ function formatRelativeTime(
96
+ /** The date time that needs to be formatted. */
97
+ date,
98
+ /** The reference point in time to which `date` will be formatted in relation to. */
99
+ now) {
100
+ try {
101
+ if (!now) {
102
+ if (globalNow) {
103
+ now = globalNow;
104
+ }
105
+ else {
106
+ throw new Error(process.env.NODE_ENV !== 'production'
107
+ ? `The \`now\` parameter wasn't provided to \`formatRelativeTime\` and there was no global fallback configured on the provider.`
108
+ : undefined);
109
+ }
110
+ }
111
+ const dateDate = date instanceof Date ? date : new Date(date);
112
+ const nowDate = now instanceof Date ? now : new Date(now);
113
+ const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
114
+ const { unit, value } = getRelativeTimeFormatConfig(seconds);
115
+ return new Intl.RelativeTimeFormat(locale, {
116
+ numeric: 'auto'
117
+ }).format(value, unit);
118
+ }
119
+ catch (error) {
120
+ onError(new IntlError(IntlErrorCode.FORMATTING_ERROR, error.message));
121
+ return String(date);
122
+ }
123
+ }
124
+ return { formatDateTime, formatNumber, formatRelativeTime };
125
+ }
126
+ //# sourceMappingURL=createIntl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createIntl.js","sourceRoot":"","sources":["../../../src/core/createIntl.tsx"],"names":[],"mappings":"AAEA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,IAAI,GAAG,MAAM,GAAG,EAAE,CAAC;AACzB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;AACtB,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC;AACrB,MAAM,KAAK,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAgB;AAChD,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;AAEvB,SAAS,2BAA2B,CAAC,OAAe;IAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,I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BAA2B,CAAC,OAAO,CAAC,CAAC;YAE3D,OAAO,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE;gBACzC,OAAO,EAAE,MAAM;aAChB,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACxB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CACL,IAAI,SAAS,CAAC,aAAa,CAAC,gBAAgB,EAAG,KAAe,CAAC,OAAO,CAAC,CACxE,CAAC;YACF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;SACrB;IACH,CAAC;IAED,OAAO,EAAC,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,48 @@
1
+ import Formats from './Formats';
2
+ import IntlConfiguration from './IntlConfiguration';
3
+ import TranslationValues from './TranslationValues';
4
+ import { CoreRichTranslationValues } from './createTranslatorImpl';
5
+ import MessageKeys from './utils/MessageKeys';
6
+ import NamespaceKeys from './utils/NamespaceKeys';
7
+ import NestedKeyOf from './utils/NestedKeyOf';
8
+ import NestedValueOf from './utils/NestedValueOf';
9
+ /**
10
+ * Translates messages from the given namespace by using the ICU syntax.
11
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
12
+ *
13
+ * If no namespace is provided, all available messages are returned.
14
+ * The namespace can also indicate nesting by using a dot
15
+ * (e.g. `namespace.Component`).
16
+ */
17
+ export default function createTranslator<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>({ onError, getMessageFallback, messages, namespace, ...rest }: IntlConfiguration & {
18
+ messages: IntlMessages;
19
+ namespace?: NestedKey;
20
+ }): {
21
+ <TargetKey extends MessageKeys<NestedValueOf<{
22
+ '!': IntlMessages;
23
+ }, [
24
+ NestedKey
25
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
26
+ '!': IntlMessages;
27
+ }, [
28
+ NestedKey
29
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
30
+ rich<TargetKey extends MessageKeys<NestedValueOf<{
31
+ '!': IntlMessages;
32
+ }, [
33
+ NestedKey
34
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
35
+ '!': IntlMessages;
36
+ }, [
37
+ NestedKey
38
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: CoreRichTranslationValues, formats?: Partial<Formats>): string;
39
+ raw<TargetKey extends MessageKeys<NestedValueOf<{
40
+ '!': IntlMessages;
41
+ }, [
42
+ NestedKey
43
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
44
+ '!': IntlMessages;
45
+ }, [
46
+ NestedKey
47
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
48
+ };
@@ -0,0 +1,24 @@
1
+ import createTranslatorImpl from './createTranslatorImpl';
2
+ import { defaultGetMessageFallback, defaultOnError } from './defaults';
3
+ /**
4
+ * Translates messages from the given namespace by using the ICU syntax.
5
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
6
+ *
7
+ * If no namespace is provided, all available messages are returned.
8
+ * The namespace can also indicate nesting by using a dot
9
+ * (e.g. `namespace.Component`).
10
+ */
11
+ export default function createTranslator({ onError = defaultOnError, getMessageFallback = defaultGetMessageFallback, messages, namespace, ...rest }) {
12
+ // We have to wrap the actual function so the type inference for the optional
13
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
14
+ // The prefix ("!") is arbitrary.
15
+ return createTranslatorImpl({
16
+ ...rest,
17
+ onError,
18
+ getMessageFallback,
19
+ messages: { '!': messages },
20
+ // @ts-ignore
21
+ namespace: namespace ? `!.${namespace}` : '!'
22
+ }, '!');
23
+ }
24
+ //# sourceMappingURL=createTranslator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTranslator.js","sourceRoot":"","sources":["../../../src/core/createTranslator.tsx"],"names":[],"mappings":"AAGA,OAAO,oBAEN,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAMrE;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAKtC,EACA,OAAO,GAAG,cAAc,EACxB,kBAAkB,GAAG,yBAAyB,EAC9C,QAAQ,EACR,SAAS,EACT,GAAG,IAAI,EAIR;IA4DC,6EAA6E;IAC7E,6EAA6E;IAC7E,iCAAiC;IACjC,OAAO,oBAAoB,CAIzB;QACE,GAAG,IAAI;QACP,OAAO;QACP,kBAAkB;QAClB,QAAQ,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC;QACzB,aAAa;QACb,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG;KAC9C,EACD,GAAG,CACJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import AbstractIntlMessages from './AbstractIntlMessages';
2
+ import { InitializedIntlConfiguration } from './IntlConfiguration';
3
+ import { TranslationValue } from './TranslationValues';
4
+ import NestedKeyOf from './utils/NestedKeyOf';
5
+ export declare type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
6
+ export declare type CreateTranslatorImplProps<Messages> = InitializedIntlConfiguration & {
7
+ namespace: string;
8
+ messages: Messages;
9
+ };
10
+ export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ getMessageFallback, messages, namespace, onError, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
11
+ (key: import("./utils/MessageKeys").default<import("./utils/NestedValueOf").default<Messages, NestedKey>, NestedKeyOf<import("./utils/NestedValueOf").default<Messages, NestedKey>>>, values?: import("./TranslationValues").default | undefined, formats?: Partial<import("./Formats").default> | undefined): string;
12
+ rich(key: string, values: CoreRichTranslationValues, formats?: Partial<import("./Formats").default> | undefined): string;
13
+ raw: (key: string) => any;
14
+ };
@@ -0,0 +1,43 @@
1
+ import IntlError, { IntlErrorCode } from './IntlError';
2
+ import createBaseTranslator, { getMessagesOrError } from './createBaseTranslator';
3
+ import resolveNamespace from './resolveNamespace';
4
+ export default function createTranslatorImpl({ getMessageFallback, messages, namespace, onError, ...rest }, namespacePrefix) {
5
+ // The `namespacePrefix` is part of the type system.
6
+ // See the comment in the function invocation.
7
+ messages = messages[namespacePrefix];
8
+ namespace = resolveNamespace(namespace, namespacePrefix);
9
+ const translator = createBaseTranslator({
10
+ ...rest,
11
+ onError,
12
+ getMessageFallback,
13
+ messagesOrError: getMessagesOrError({
14
+ messages,
15
+ namespace,
16
+ onError
17
+ })
18
+ });
19
+ const originalRich = translator.rich;
20
+ function base(...args) {
21
+ return translator(...args);
22
+ }
23
+ // Augment `t.rich` to return plain strings
24
+ base.rich = (key,
25
+ /** Key value pairs for values to interpolate into the message. */
26
+ values, formats) => {
27
+ // `chunks` is returned as a string when no React element
28
+ // is used, therefore it's safe to cast this type.
29
+ const result = originalRich(key, values, formats);
30
+ // When only string chunks are provided to the parser, only strings should be returned here.
31
+ if (typeof result !== 'string') {
32
+ const error = new IntlError(IntlErrorCode.FORMATTING_ERROR, process.env.NODE_ENV !== 'production'
33
+ ? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})"
34
+ : undefined);
35
+ onError(error);
36
+ return getMessageFallback({ error, key, namespace });
37
+ }
38
+ return result;
39
+ };
40
+ base.raw = translator.raw;
41
+ return base;
42
+ }
43
+ //# sourceMappingURL=createTranslatorImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTranslatorImpl.js","sourceRoot":"","sources":["../../../src/core/createTranslatorImpl.tsx"],"names":[],"mappings":"AAEA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,OAAO,oBAAoB,EAAE,EAAC,kBAAkB,EAAC,MAAM,w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pD;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;IAE1B,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,11 @@
1
+ import IntlError from './IntlError';
2
+ /**
3
+ * Contains defaults that are used for all entry points into the core.
4
+ * See also `InitializedIntlConfiguration`.
5
+ */
6
+ export declare function defaultGetMessageFallback(props: {
7
+ error: IntlError;
8
+ key: string;
9
+ namespace?: string;
10
+ }): string;
11
+ export declare function defaultOnError(error: IntlError): void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Contains defaults that are used for all entry points into the core.
3
+ * See also `InitializedIntlConfiguration`.
4
+ */
5
+ export function defaultGetMessageFallback(props) {
6
+ return [props.namespace, props.key].filter((part) => part != null).join('.');
7
+ }
8
+ export function defaultOnError(error) {
9
+ console.error(error);
10
+ }
11
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../src/core/defaults.tsx"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,MAAM,UAAU,yBAAyB,CAAC,KAIzC;IACC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAgB;IAC7C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { default as AbstractIntlMessages } from './AbstractIntlMessages';
2
+ export { default as TranslationValues, RichTranslationValues } from './TranslationValues';
3
+ export { default as Formats } from './Formats';
4
+ export { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
5
+ export { default as NumberFormatOptions } from './NumberFormatOptions';
6
+ export { default as IntlError, IntlErrorCode } from './IntlError';
7
+ export { default as createTranslator } from './createTranslator';
8
+ export { default as createIntl } from './createIntl';
@@ -0,0 +1,4 @@
1
+ export { default as IntlError, IntlErrorCode } from './IntlError';
2
+ export { default as createTranslator } from './createTranslator';
3
+ export { default as createIntl } from './createIntl';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAC,OAAO,IAAI,SAAS,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAChE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * For the strictly typed messages to work we have to wrap the namespace into
3
+ * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
+ */
5
+ export default function resolveNamespace(namespace: string, namespacePrefix: string): string | undefined;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * For the strictly typed messages to work we have to wrap the namespace into
3
+ * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
+ */
5
+ export default function resolveNamespace(namespace, namespacePrefix) {
6
+ return namespace === namespacePrefix
7
+ ? undefined
8
+ : namespace.slice((namespacePrefix + '.').length);
9
+ }
10
+ //# sourceMappingURL=resolveNamespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveNamespace.js","sourceRoot":"","sources":["../../../src/core/resolveNamespace.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,SAAiB,EACjB,eAAuB;IAEvB,OAAO,SAAS,KAAK,eAAe;QAClC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,eAAe,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import NestedValueOf from './NestedValueOf';
2
+ declare type MessageKeys<ObjectType, Keys extends string> = {
3
+ [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? Property : never;
4
+ }[Keys];
5
+ export default MessageKeys;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MessageKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageKeys.js","sourceRoot":"","sources":["../../../../src/core/utils/MessageKeys.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import NestedValueOf from './NestedValueOf';
2
+ declare type NamespaceKeys<ObjectType, Keys extends string> = {
3
+ [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? never : Property;
4
+ }[Keys];
5
+ export default NamespaceKeys;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=NamespaceKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NamespaceKeys.js","sourceRoot":"","sources":["../../../../src/core/utils/NamespaceKeys.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ declare type NestedKeyOf<ObjectType> = ObjectType extends object ? {
2
+ [Key in keyof ObjectType]: `${Key & string}` | `${Key & string}.${NestedKeyOf<ObjectType[Key]>}`;
3
+ }[keyof ObjectType] : never;
4
+ export default NestedKeyOf;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=NestedKeyOf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NestedKeyOf.js","sourceRoot":"","sources":["../../../../src/core/utils/NestedKeyOf.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ declare type NestedValueOf<ObjectType, Property extends string> = Property extends `${infer Key}.${infer Rest}` ? Key extends keyof ObjectType ? NestedValueOf<ObjectType[Key], Rest> : never : Property extends keyof ObjectType ? ObjectType[Property] : never;
2
+ export default NestedValueOf;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=NestedValueOf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NestedValueOf.js","sourceRoot":"","sources":["../../../../src/core/utils/NestedValueOf.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import AbstractIntlMessages from './AbstractIntlMessages';
2
+ import IntlError from './IntlError';
3
+ export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
@@ -0,0 +1,22 @@
1
+ import IntlError, { IntlErrorCode } from './IntlError';
2
+ function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
3
+ Object.entries(messages).forEach(([key, messageOrMessages]) => {
4
+ if (key.includes('.')) {
5
+ let keyLabel = key;
6
+ if (parentPath)
7
+ keyLabel += ` (at ${parentPath})`;
8
+ invalidKeyLabels.push(keyLabel);
9
+ }
10
+ if (messageOrMessages != null && typeof messageOrMessages === 'object') {
11
+ validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter((part) => part != null).join('.'));
12
+ }
13
+ });
14
+ }
15
+ export default function validateMessages(messages, onError) {
16
+ const invalidKeyLabels = [];
17
+ validateMessagesSegment(messages, invalidKeyLabels);
18
+ if (invalidKeyLabels.length > 0) {
19
+ onError(new IntlError(IntlErrorCode.INVALID_KEY, `Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid ${invalidKeyLabels.length === 1 ? 'key' : 'keys'}: ${invalidKeyLabels.join(', ')}`));
20
+ }
21
+ }
22
+ //# sourceMappingURL=validateMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateMessages.js","sourceRoot":"","sources":["../../../src/core/validateMessages.tsx"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,SAAS,uBAAuB,CAC9B,QAA8B,EAC9B,gBAA+B,EAC/B,UAAmB;IAEnB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,iBAAiB,CAAC,EAAE,EAAE;QAC5D,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACrB,IAAI,QAAQ,GAAG,GAAG,CAAC;YACnB,IAAI,UAAU;gBAAE,QAAQ,IAAI,QAAQ,UAAU,GAAG,CAAC;YAClD,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;QAED,IAAI,iBAAiB,IAAI,IAAI,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACtE,uBAAuB,CACrB,iBAAiB,EACjB,gBAAgB,EAChB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAC;SACH;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,QAA8B,EAC9B,OAAmC;IAEnC,MAAM,gBAAgB,GAAkB,EAAE,CAAC;IAC3C,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAEpD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,CACL,IAAI,SAAS,CACX,aAAa,CAAC,WAAW,EACzB,0JACE,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAC1C,KAAK,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACnC,CACF,CAAC;KACH;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ export * from './react';
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export * from './react';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import IntlContextValue from './IntlContextValue';
3
+ declare const IntlContext: import("react").Context<IntlContextValue | undefined>;
4
+ export default IntlContext;
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+ const IntlContext = createContext(undefined);
3
+ export default IntlContext;
4
+ //# sourceMappingURL=IntlContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlContext.js","sourceRoot":"","sources":["../../../src/react/IntlContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAGpC,MAAM,WAAW,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAE3E,eAAe,WAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
+ import Formats from '../core/Formats';
3
+ import IntlError from '../core/IntlError';
4
+ import { RichTranslationValues } from '../core/TranslationValues';
5
+ declare type IntlContextValue = {
6
+ messages?: AbstractIntlMessages;
7
+ locale: string;
8
+ formats?: Partial<Formats>;
9
+ timeZone?: string;
10
+ onError(error: IntlError): void;
11
+ getMessageFallback(info: {
12
+ error: IntlError;
13
+ key: string;
14
+ namespace?: string;
15
+ }): string;
16
+ now?: Date;
17
+ defaultTranslationValues?: RichTranslationValues;
18
+ };
19
+ export default IntlContextValue;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IntlContextValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlContextValue.js","sourceRoot":"","sources":["../../../src/react/IntlContextValue.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import IntlProviderProps from './IntlProviderProps';
2
+ export default function IntlProvider({ children, ...props }: IntlProviderProps): JSX.Element;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import IntlContext from './IntlContext';
3
+ import getIntlContextValue from './getIntlContextValue';
4
+ export default function IntlProvider({ children, ...props }) {
5
+ return (React.createElement(IntlContext.Provider, { value: getIntlContextValue(props) }, children));
6
+ }
7
+ //# sourceMappingURL=IntlProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlProvider.js","sourceRoot":"","sources":["../../../src/react/IntlProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAC,QAAQ,EAAE,GAAG,KAAK,EAAoB;IAC1E,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC,IACpD,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import { AbstractIntlMessages } from '../core';
3
+ import IntlConfiguration from '../core/IntlConfiguration';
4
+ import { RichTranslationValues } from '../core/TranslationValues';
5
+ declare type IntlProviderProps = IntlConfiguration & {
6
+ /** All components that use the provided hooks should be within this tree. */
7
+ children: ReactNode;
8
+ /** Global default values for translation values and rich text elements.
9
+ * Can be used for consistent usage or styling of rich text elements.
10
+ * Defaults will be overidden by locally provided values. */
11
+ defaultTranslationValues?: RichTranslationValues;
12
+ /** All messages that will be available in your components. */
13
+ messages?: AbstractIntlMessages;
14
+ };
15
+ export default IntlProviderProps;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IntlProviderProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlProviderProps.js","sourceRoot":"","sources":["../../../src/react/IntlProviderProps.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import IntlProviderProps from './IntlProviderProps';
2
+ /**
3
+ * Enhances the incoming props with defaults.
4
+ */
5
+ export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }: Omit<IntlProviderProps, 'children'>): {
6
+ messages: import("../core/AbstractIntlMessages").default | undefined;
7
+ onError: (error: import("..").IntlError) => void;
8
+ getMessageFallback: (info: {
9
+ error: import("..").IntlError;
10
+ key: string;
11
+ namespace?: string | undefined;
12
+ }) => string;
13
+ defaultTranslationValues?: import("..").RichTranslationValues | undefined;
14
+ formats?: Partial<import("../core/Formats").default> | undefined;
15
+ locale: string;
16
+ timeZone?: string | undefined;
17
+ now?: Date | undefined;
18
+ };
@@ -0,0 +1,21 @@
1
+ import { defaultGetMessageFallback, defaultOnError } from '../core/defaults';
2
+ import validateMessages from '../core/validateMessages';
3
+ /**
4
+ * Enhances the incoming props with defaults.
5
+ */
6
+ export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }) {
7
+ const finalOnError = onError || defaultOnError;
8
+ const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
9
+ if (process.env.NODE_ENV !== 'production') {
10
+ if (messages) {
11
+ validateMessages(messages, finalOnError);
12
+ }
13
+ }
14
+ return {
15
+ ...rest,
16
+ messages,
17
+ onError: finalOnError,
18
+ getMessageFallback: finalGetMessageFallback
19
+ };
20
+ }
21
+ //# sourceMappingURL=getIntlContextValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIntlContextValue.js","sourceRoot":"","sources":["../../../src/react/getIntlContextValue.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC3E,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AAGxD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,kBAAkB,EAClB,QAAQ,EACR,OAAO,EACP,GAAG,IAAI,EAC6B;IACpC,MAAM,YAAY,GAAG,OAAO,IAAI,cAAc,CAAC;IAC/C,MAAM,uBAAuB,GAC3B,kBAAkB,IAAI,yBAAyB,CAAC;IAElD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,IAAI,QAAQ,EAAE;YACZ,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;SAC1C;KACF;IAED,OAAO;QACL,GAAG,IAAI;QACP,QAAQ;QACR,OAAO,EAAE,YAAY;QACrB,kBAAkB,EAAE,uBAAuB;KAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { default as IntlProvider } from './IntlProvider';
2
+ export { default as useTranslations } from './useTranslations';
3
+ export { default as useIntl } from './useIntl';
4
+ export { default as useLocale } from './useLocale';
5
+ export { default as useNow } from './useNow';
6
+ export { default as useTimeZone } from './useTimeZone';
@@ -0,0 +1,7 @@
1
+ export { default as IntlProvider } from './IntlProvider';
2
+ export { default as useTranslations } from './useTranslations';
3
+ export { default as useIntl } from './useIntl';
4
+ export { default as useLocale } from './useLocale';
5
+ export { default as useNow } from './useNow';
6
+ export { default as useTimeZone } from './useTimeZone';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ export default function useIntl(): {
2
+ formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
+ formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
4
+ formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
5
+ };