use-intl 2.11.0-alpha.2 → 2.11.0-useFormatter-alpha.1

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 (106) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +32 -20
  3. package/dist/core/createFormatter.d.ts +17 -0
  4. package/dist/core/createIntl.d.ts +5 -15
  5. package/dist/core/index.d.ts +1 -0
  6. package/dist/core/use-intl.esm.js +38 -41
  7. package/dist/core/use-intl.esm.js.map +1 -1
  8. package/dist/core/use-intl.esm10.js +34 -0
  9. package/dist/core/use-intl.esm10.js.map +1 -0
  10. package/dist/core/use-intl.esm2.js +151 -35
  11. package/dist/core/use-intl.esm2.js.map +1 -1
  12. package/dist/core/use-intl.esm3.js +27 -140
  13. package/dist/core/use-intl.esm3.js.map +1 -1
  14. package/dist/core/use-intl.esm4.js +9 -53
  15. package/dist/core/use-intl.esm4.js.map +1 -1
  16. package/dist/core/use-intl.esm5.js +28 -11
  17. package/dist/core/use-intl.esm5.js.map +1 -1
  18. package/dist/core/use-intl.esm6.js +11 -209
  19. package/dist/core/use-intl.esm6.js.map +1 -1
  20. package/dist/core/use-intl.esm7.js +56 -7
  21. package/dist/core/use-intl.esm7.js.map +1 -1
  22. package/dist/core/use-intl.esm8.js +200 -19
  23. package/dist/core/use-intl.esm8.js.map +1 -1
  24. package/dist/core/use-intl.esm9.js +5 -29
  25. package/dist/core/use-intl.esm9.js.map +1 -1
  26. package/dist/react/IntlContext.d.ts +19 -2
  27. package/dist/react/IntlProvider.d.ts +16 -2
  28. package/dist/react/index.d.ts +2 -1
  29. package/dist/react/use-intl.esm.js +26 -7
  30. package/dist/react/use-intl.esm.js.map +1 -1
  31. package/dist/react/use-intl.esm10.js +2 -2
  32. package/dist/react/use-intl.esm2.js +3 -20
  33. package/dist/react/use-intl.esm2.js.map +1 -1
  34. package/dist/react/use-intl.esm3.js +40 -16
  35. package/dist/react/use-intl.esm3.js.map +1 -1
  36. package/dist/react/use-intl.esm4.js +21 -3
  37. package/dist/react/use-intl.esm4.js.map +1 -1
  38. package/dist/react/use-intl.esm5.js +20 -3
  39. package/dist/react/use-intl.esm5.js.map +1 -1
  40. package/dist/react/use-intl.esm6.js +24 -41
  41. package/dist/react/use-intl.esm6.js.map +1 -1
  42. package/dist/react/use-intl.esm7.js +5 -3
  43. package/dist/react/use-intl.esm7.js.map +1 -1
  44. package/dist/react/use-intl.esm8.js +3 -30
  45. package/dist/react/use-intl.esm8.js.map +1 -1
  46. package/dist/react/use-intl.esm9.js +1 -1
  47. package/dist/react/useFormatter.d.ts +5 -0
  48. package/dist/react/useIntl.d.ts +1 -0
  49. package/dist/react/useIntlContext.d.ts +1 -1
  50. package/dist/src/core/createBaseTranslator.js +10 -8
  51. package/dist/src/core/createBaseTranslator.js.map +1 -1
  52. package/dist/src/core/createFormatter.d.ts +17 -0
  53. package/dist/src/core/createFormatter.js +126 -0
  54. package/dist/src/core/createFormatter.js.map +1 -0
  55. package/dist/src/core/createIntl.d.ts +5 -15
  56. package/dist/src/core/createIntl.js +9 -124
  57. package/dist/src/core/createIntl.js.map +1 -1
  58. package/dist/src/core/index.d.ts +1 -0
  59. package/dist/src/core/index.js +2 -0
  60. package/dist/src/core/index.js.map +1 -1
  61. package/dist/src/react/IntlContext.d.ts +19 -2
  62. package/dist/src/react/IntlContext.js.map +1 -1
  63. package/dist/src/react/IntlProvider.d.ts +16 -2
  64. package/dist/src/react/IntlProvider.js +13 -4
  65. package/dist/src/react/IntlProvider.js.map +1 -1
  66. package/dist/src/react/index.d.ts +2 -1
  67. package/dist/src/react/index.js +3 -1
  68. package/dist/src/react/index.js.map +1 -1
  69. package/dist/src/react/useFormatter.d.ts +5 -0
  70. package/dist/src/react/useFormatter.js +14 -0
  71. package/dist/src/react/useFormatter.js.map +1 -0
  72. package/dist/src/react/useIntl.d.ts +1 -0
  73. package/dist/src/react/useIntl.js +6 -0
  74. package/dist/src/react/useIntl.js.map +1 -1
  75. package/dist/src/react/useIntlContext.d.ts +1 -1
  76. package/dist/use-intl.cjs.development.js +99 -68
  77. package/dist/use-intl.cjs.development.js.map +1 -1
  78. package/dist/use-intl.cjs.production.min.js +1 -1
  79. package/dist/use-intl.cjs.production.min.js.map +1 -1
  80. package/dist/use-intl.esm.js +10 -8
  81. package/dist/use-intl.esm.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/core/createBaseTranslator.tsx +14 -12
  84. package/src/core/createFormatter.tsx +181 -0
  85. package/src/core/createIntl.tsx +12 -180
  86. package/src/core/index.tsx +3 -0
  87. package/src/react/IntlContext.tsx +20 -2
  88. package/src/react/IntlProvider.tsx +36 -5
  89. package/src/react/index.tsx +4 -1
  90. package/src/react/useFormatter.tsx +19 -0
  91. package/src/react/useIntl.tsx +10 -0
  92. package/dist/react/IntlContextValue.d.ts +0 -19
  93. package/dist/react/IntlProviderProps.d.ts +0 -15
  94. package/dist/react/getIntlContextValue.d.ts +0 -18
  95. package/dist/src/react/IntlContextValue.d.ts +0 -19
  96. package/dist/src/react/IntlContextValue.js +0 -2
  97. package/dist/src/react/IntlContextValue.js.map +0 -1
  98. package/dist/src/react/IntlProviderProps.d.ts +0 -15
  99. package/dist/src/react/IntlProviderProps.js +0 -2
  100. package/dist/src/react/IntlProviderProps.js.map +0 -1
  101. package/dist/src/react/getIntlContextValue.d.ts +0 -18
  102. package/dist/src/react/getIntlContextValue.js +0 -21
  103. package/dist/src/react/getIntlContextValue.js.map +0 -1
  104. package/src/react/IntlContextValue.tsx +0 -21
  105. package/src/react/IntlProviderProps.tsx +0 -17
  106. package/src/react/getIntlContextValue.tsx +0 -30
@@ -1,181 +1,13 @@
1
- import DateTimeFormatOptions from './DateTimeFormatOptions';
2
- import Formats from './Formats';
3
- import IntlError, {IntlErrorCode} from './IntlError';
4
- import NumberFormatOptions from './NumberFormatOptions';
5
- import {defaultOnError} from './defaults';
6
-
7
- const MINUTE = 60;
8
- const HOUR = MINUTE * 60;
9
- const DAY = HOUR * 24;
10
- const WEEK = DAY * 7;
11
- const MONTH = DAY * (365 / 12); // Approximation
12
- const YEAR = DAY * 365;
13
-
14
- function getRelativeTimeFormatConfig(seconds: number) {
15
- const absValue = Math.abs(seconds);
16
- let value, unit: Intl.RelativeTimeFormatUnit;
17
-
18
- // We have to round the resulting values, as `Intl.RelativeTimeFormat`
19
- // will include fractions like '2.1 hours ago'.
20
-
21
- if (absValue < MINUTE) {
22
- unit = 'second';
23
- value = Math.round(seconds);
24
- } else if (absValue < HOUR) {
25
- unit = 'minute';
26
- value = Math.round(seconds / MINUTE);
27
- } else if (absValue < DAY) {
28
- unit = 'hour';
29
- value = Math.round(seconds / HOUR);
30
- } else if (absValue < WEEK) {
31
- unit = 'day';
32
- value = Math.round(seconds / DAY);
33
- } else if (absValue < MONTH) {
34
- unit = 'week';
35
- value = Math.round(seconds / WEEK);
36
- } else if (absValue < YEAR) {
37
- unit = 'month';
38
- value = Math.round(seconds / MONTH);
39
- } else {
40
- unit = 'year';
41
- value = Math.round(seconds / YEAR);
42
- }
43
-
44
- return {value, unit};
45
- }
46
-
47
- type Props = {
48
- locale: string;
49
- timeZone?: string;
50
- onError?(error: IntlError): void;
51
- formats?: Partial<Formats>;
52
- now?: Date;
53
- };
54
-
55
- export default function createIntl({
56
- formats,
57
- locale,
58
- now: globalNow,
59
- onError = defaultOnError,
60
- timeZone
61
- }: Props) {
62
- function resolveFormatOrOptions<Options>(
63
- typeFormats: Record<string, Options> | undefined,
64
- formatOrOptions?: string | Options
65
- ) {
66
- let options;
67
- if (typeof formatOrOptions === 'string') {
68
- const formatName = formatOrOptions;
69
- options = typeFormats?.[formatName];
70
-
71
- if (!options) {
72
- const error = new IntlError(
73
- IntlErrorCode.MISSING_FORMAT,
74
- process.env.NODE_ENV !== 'production'
75
- ? `Format \`${formatName}\` is not available. You can configure it on the provider or provide custom options.`
76
- : undefined
77
- );
78
- onError(error);
79
- throw error;
80
- }
81
- } else {
82
- options = formatOrOptions;
83
- }
84
-
85
- return options;
86
- }
87
-
88
- function getFormattedValue<Value, Options>(
89
- value: Value,
90
- formatOrOptions: string | Options | undefined,
91
- typeFormats: Record<string, Options> | undefined,
92
- formatter: (options?: Options) => string
93
- ) {
94
- let options;
95
- try {
96
- options = resolveFormatOrOptions(typeFormats, formatOrOptions);
97
- } catch (error) {
98
- return String(value);
99
- }
100
-
101
- try {
102
- return formatter(options);
103
- } catch (error) {
104
- onError(
105
- new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)
106
- );
107
- return String(value);
108
- }
109
- }
110
-
111
- function formatDateTime(
112
- /** If a number is supplied, this is interpreted as a UTC timestamp. */
113
- value: Date | number,
114
- /** If a time zone is supplied, the `value` is converted to that time zone.
115
- * Otherwise the user time zone will be used. */
116
- formatOrOptions?: string | DateTimeFormatOptions
117
- ) {
118
- return getFormattedValue(
119
- value,
120
- formatOrOptions,
121
- formats?.dateTime,
122
- (options) => {
123
- if (timeZone && !options?.timeZone) {
124
- options = {...options, timeZone};
125
- }
126
-
127
- return new Intl.DateTimeFormat(locale, options).format(value);
128
- }
129
- );
130
- }
131
-
132
- function formatNumber(
133
- value: number,
134
- formatOrOptions?: string | NumberFormatOptions
135
- ) {
136
- return getFormattedValue(
137
- value,
138
- formatOrOptions,
139
- formats?.number,
140
- (options) => new Intl.NumberFormat(locale, options).format(value)
141
- );
142
- }
143
-
144
- function formatRelativeTime(
145
- /** The date time that needs to be formatted. */
146
- date: number | Date,
147
- /** The reference point in time to which `date` will be formatted in relation to. */
148
- now?: number | Date
149
- ) {
150
- try {
151
- if (!now) {
152
- if (globalNow) {
153
- now = globalNow;
154
- } else {
155
- throw new Error(
156
- process.env.NODE_ENV !== 'production'
157
- ? `The \`now\` parameter wasn't provided to \`formatRelativeTime\` and there was no global fallback configured on the provider.`
158
- : undefined
159
- );
160
- }
161
- }
162
-
163
- const dateDate = date instanceof Date ? date : new Date(date);
164
- const nowDate = now instanceof Date ? now : new Date(now);
165
-
166
- const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;
167
- const {unit, value} = getRelativeTimeFormatConfig(seconds);
168
-
169
- return new Intl.RelativeTimeFormat(locale, {
170
- numeric: 'auto'
171
- }).format(value, unit);
172
- } catch (error) {
173
- onError(
174
- new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)
175
- );
176
- return String(date);
177
- }
178
- }
179
-
180
- return {formatDateTime, formatNumber, formatRelativeTime};
1
+ import createFormatter from './createFormatter';
2
+
3
+ /** @deprecated Switch to `createFormatter` */
4
+ export default function createIntl(
5
+ ...args: Parameters<typeof createFormatter>
6
+ ) {
7
+ const formatter = createFormatter(...args);
8
+ return {
9
+ formatDateTime: formatter.dateTime,
10
+ formatNumber: formatter.number,
11
+ formatRelativeTime: formatter.relativeTime
12
+ };
181
13
  }
@@ -8,4 +8,7 @@ export {default as DateTimeFormatOptions} from './DateTimeFormatOptions';
8
8
  export {default as NumberFormatOptions} from './NumberFormatOptions';
9
9
  export {default as IntlError, IntlErrorCode} from './IntlError';
10
10
  export {default as createTranslator} from './createTranslator';
11
+ export {default as createFormatter} from './createFormatter';
12
+
13
+ // TODO: Remove in next major version
11
14
  export {default as createIntl} from './createIntl';
@@ -1,6 +1,24 @@
1
1
  import {createContext} from 'react';
2
- import IntlContextValue from './IntlContextValue';
2
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
+ import Formats from '../core/Formats';
4
+ import IntlError from '../core/IntlError';
5
+ import {RichTranslationValues} from '../core/TranslationValues';
3
6
 
4
- const IntlContext = createContext<IntlContextValue | undefined>(undefined);
7
+ export type IntlContextShape = {
8
+ messages?: AbstractIntlMessages;
9
+ locale: string;
10
+ formats?: Partial<Formats>;
11
+ timeZone?: string;
12
+ onError(error: IntlError): void;
13
+ getMessageFallback(info: {
14
+ error: IntlError;
15
+ key: string;
16
+ namespace?: string;
17
+ }): string;
18
+ now?: Date;
19
+ defaultTranslationValues?: RichTranslationValues;
20
+ };
21
+
22
+ const IntlContext = createContext<IntlContextShape | undefined>(undefined);
5
23
 
6
24
  export default IntlContext;
@@ -1,11 +1,42 @@
1
- import React from 'react';
1
+ import React, {ReactNode, useEffect} from 'react';
2
+ import {AbstractIntlMessages} from '../core';
3
+ import IntlConfiguration from '../core/IntlConfiguration';
4
+ import {RichTranslationValues} from '../core/TranslationValues';
5
+ import {defaultGetMessageFallback, defaultOnError} from '../core/defaults';
6
+ import validateMessages from '../core/validateMessages';
2
7
  import IntlContext from './IntlContext';
3
- import IntlProviderProps from './IntlProviderProps';
4
- import getIntlContextValue from './getIntlContextValue';
5
8
 
6
- export default function IntlProvider({children, ...props}: IntlProviderProps) {
9
+ type Props = IntlConfiguration & {
10
+ /** All components that use the provided hooks should be within this tree. */
11
+ children: ReactNode;
12
+ /** Global default values for translation values and rich text elements.
13
+ * Can be used for consistent usage or styling of rich text elements.
14
+ * Defaults will be overidden by locally provided values. */
15
+ defaultTranslationValues?: RichTranslationValues;
16
+ /** All messages that will be available in your components. */
17
+ messages?: AbstractIntlMessages;
18
+ };
19
+
20
+ export default function IntlProvider({
21
+ children,
22
+ onError = defaultOnError,
23
+ getMessageFallback = defaultGetMessageFallback,
24
+ messages,
25
+ ...contextValues
26
+ }: Props) {
27
+ if (process.env.NODE_ENV !== 'production') {
28
+ // eslint-disable-next-line react-hooks/rules-of-hooks
29
+ useEffect(() => {
30
+ if (messages) {
31
+ validateMessages(messages, onError);
32
+ }
33
+ }, [messages, onError]);
34
+ }
35
+
7
36
  return (
8
- <IntlContext.Provider value={getIntlContextValue(props)}>
37
+ <IntlContext.Provider
38
+ value={{...contextValues, messages, onError, getMessageFallback}}
39
+ >
9
40
  {children}
10
41
  </IntlContext.Provider>
11
42
  );
@@ -1,6 +1,9 @@
1
1
  export {default as IntlProvider} from './IntlProvider';
2
2
  export {default as useTranslations} from './useTranslations';
3
- export {default as useIntl} from './useIntl';
4
3
  export {default as useLocale} from './useLocale';
5
4
  export {default as useNow} from './useNow';
6
5
  export {default as useTimeZone} from './useTimeZone';
6
+ export {default as useFormatter} from './useFormatter';
7
+
8
+ // TODO: Remove in next major version
9
+ export {default as useIntl} from './useIntl';
@@ -0,0 +1,19 @@
1
+ import {useMemo} from 'react';
2
+ import createFormatter from '../core/createFormatter';
3
+ import useIntlContext from './useIntlContext';
4
+
5
+ export default function useFormatter() {
6
+ const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();
7
+
8
+ return useMemo(
9
+ () =>
10
+ createFormatter({
11
+ formats,
12
+ locale,
13
+ now: globalNow,
14
+ onError,
15
+ timeZone
16
+ }),
17
+ [formats, globalNow, locale, onError, timeZone]
18
+ );
19
+ }
@@ -2,9 +2,19 @@ import {useMemo} from 'react';
2
2
  import createIntl from '../core/createIntl';
3
3
  import useIntlContext from './useIntlContext';
4
4
 
5
+ let hasWarned = false;
6
+
7
+ /** @deprecated Switch to `useFormatter` */
5
8
  export default function useIntl() {
6
9
  const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();
7
10
 
11
+ if (!hasWarned) {
12
+ hasWarned = true;
13
+ console.warn(
14
+ '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'
15
+ );
16
+ }
17
+
8
18
  return useMemo(
9
19
  () =>
10
20
  createIntl({
@@ -1,19 +0,0 @@
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;
@@ -1,15 +0,0 @@
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;
@@ -1,18 +0,0 @@
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
- locale: string;
14
- formats?: Partial<import("../core/Formats").default> | undefined;
15
- timeZone?: string | undefined;
16
- now?: Date | undefined;
17
- defaultTranslationValues?: import("..").RichTranslationValues | undefined;
18
- };
@@ -1,19 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IntlContextValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntlContextValue.js","sourceRoot":"","sources":["../../../src/react/IntlContextValue.tsx"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IntlProviderProps.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntlProviderProps.js","sourceRoot":"","sources":["../../../src/react/IntlProviderProps.tsx"],"names":[],"mappings":""}
@@ -1,18 +0,0 @@
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
- };
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,21 +0,0 @@
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
-
6
- type IntlContextValue = {
7
- messages?: AbstractIntlMessages;
8
- locale: string;
9
- formats?: Partial<Formats>;
10
- timeZone?: string;
11
- onError(error: IntlError): void;
12
- getMessageFallback(info: {
13
- error: IntlError;
14
- key: string;
15
- namespace?: string;
16
- }): string;
17
- now?: Date;
18
- defaultTranslationValues?: RichTranslationValues;
19
- };
20
-
21
- export default IntlContextValue;
@@ -1,17 +0,0 @@
1
- import {ReactNode} from 'react';
2
- import {AbstractIntlMessages} from '../core';
3
- import IntlConfiguration from '../core/IntlConfiguration';
4
- import {RichTranslationValues} from '../core/TranslationValues';
5
-
6
- type IntlProviderProps = IntlConfiguration & {
7
- /** All components that use the provided hooks should be within this tree. */
8
- children: ReactNode;
9
- /** Global default values for translation values and rich text elements.
10
- * Can be used for consistent usage or styling of rich text elements.
11
- * Defaults will be overidden by locally provided values. */
12
- defaultTranslationValues?: RichTranslationValues;
13
- /** All messages that will be available in your components. */
14
- messages?: AbstractIntlMessages;
15
- };
16
-
17
- export default IntlProviderProps;
@@ -1,30 +0,0 @@
1
- import {defaultGetMessageFallback, defaultOnError} from '../core/defaults';
2
- import validateMessages from '../core/validateMessages';
3
- import IntlProviderProps from './IntlProviderProps';
4
-
5
- /**
6
- * Enhances the incoming props with defaults.
7
- */
8
- export default function getIntlContextValue({
9
- getMessageFallback,
10
- messages,
11
- onError,
12
- ...rest
13
- }: Omit<IntlProviderProps, 'children'>) {
14
- const finalOnError = onError || defaultOnError;
15
- const finalGetMessageFallback =
16
- getMessageFallback || defaultGetMessageFallback;
17
-
18
- if (process.env.NODE_ENV !== 'production') {
19
- if (messages) {
20
- validateMessages(messages, finalOnError);
21
- }
22
- }
23
-
24
- return {
25
- ...rest,
26
- messages,
27
- onError: finalOnError,
28
- getMessageFallback: finalGetMessageFallback
29
- };
30
- }