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,126 +1,11 @@
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 };
1
+ import createFormatter from './createFormatter';
2
+ /** @deprecated Switch to `createFormatter` */
3
+ export default function createIntl(...args) {
4
+ const formatter = createFormatter(...args);
5
+ return {
6
+ formatDateTime: formatter.dateTime,
7
+ formatNumber: formatter.number,
8
+ formatRelativeTime: formatter.relativeTime
9
+ };
125
10
  }
126
11
  //# sourceMappingURL=createIntl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createIntl.js","sourceRoot":"","sources":["../../../src/core/createIntl.tsx"],"names":[],"mappings":"AAEA,OAAO,SAAS,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,CAAC,QAAQ;QAClC,YAAY,EAAE,SAAS,CAAC,MAAM;QAC9B,kBAAkB,EAAE,SAAS,CAAC,YAAY;KAC3C,CAAC;AACJ,CAAC"}
@@ -5,4 +5,5 @@ export { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
5
5
  export { default as NumberFormatOptions } from './NumberFormatOptions';
6
6
  export { default as IntlError, IntlErrorCode } from './IntlError';
7
7
  export { default as createTranslator } from './createTranslator';
8
+ export { default as createFormatter } from './createFormatter';
8
9
  export { default as createIntl } from './createIntl';
@@ -1,4 +1,6 @@
1
1
  export { default as IntlError, IntlErrorCode } from './IntlError';
2
2
  export { default as createTranslator } from './createTranslator';
3
+ export { default as createFormatter } from './createFormatter';
4
+ // TODO: Remove in next major version
3
5
  export { default as createIntl } from './createIntl';
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +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"}
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,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAE7D,qCAAqC;AACrC,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,cAAc,CAAC"}
@@ -1,4 +1,21 @@
1
1
  /// <reference types="react" />
2
- import IntlContextValue from './IntlContextValue';
3
- declare const IntlContext: import("react").Context<IntlContextValue | undefined>;
2
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
+ import Formats from '../core/Formats';
4
+ import IntlError from '../core/IntlError';
5
+ import { RichTranslationValues } from '../core/TranslationValues';
6
+ export declare type IntlContextShape = {
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
+ declare const IntlContext: import("react").Context<IntlContextShape | undefined>;
4
21
  export default IntlContext;
@@ -1 +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"}
1
+ {"version":3,"file":"IntlContext.js","sourceRoot":"","sources":["../../../src/react/IntlContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAqBpC,MAAM,WAAW,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAE3E,eAAe,WAAW,CAAC"}
@@ -1,2 +1,16 @@
1
- import IntlProviderProps from './IntlProviderProps';
2
- export default function IntlProvider({ children, ...props }: IntlProviderProps): JSX.Element;
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 Props = 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 function IntlProvider({ children, onError, getMessageFallback, messages, ...contextValues }: Props): JSX.Element;
16
+ export {};
@@ -1,7 +1,16 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
+ import { defaultGetMessageFallback, defaultOnError } from '../core/defaults';
3
+ import validateMessages from '../core/validateMessages';
2
4
  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));
5
+ export default function IntlProvider({ children, onError = defaultOnError, getMessageFallback = defaultGetMessageFallback, messages, ...contextValues }) {
6
+ if (process.env.NODE_ENV !== 'production') {
7
+ // eslint-disable-next-line react-hooks/rules-of-hooks
8
+ useEffect(() => {
9
+ if (messages) {
10
+ validateMessages(messages, onError);
11
+ }
12
+ }, [messages, onError]);
13
+ }
14
+ return (React.createElement(IntlContext.Provider, { value: { ...contextValues, messages, onError, getMessageFallback } }, children));
6
15
  }
7
16
  //# sourceMappingURL=IntlProvider.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"IntlProvider.js","sourceRoot":"","sources":["../../../src/react/IntlProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAY,SAAS,EAAC,MAAM,OAAO,CAAC;AAIlD,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC3E,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,WAAW,MAAM,eAAe,CAAC;AAaxC,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,QAAQ,EACR,OAAO,GAAG,cAAc,EACxB,kBAAkB,GAAG,yBAAyB,EAC9C,QAAQ,EACR,GAAG,aAAa,EACV;IACN,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,sDAAsD;QACtD,SAAS,CAAC,GAAG,EAAE;YACb,IAAI,QAAQ,EAAE;gBACZ,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;aACrC;QACH,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;KACzB;IAED,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,IACnB,KAAK,EAAE,EAAC,GAAG,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,kBAAkB,EAAC,IAE/D,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC"}
@@ -1,6 +1,7 @@
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
+ export { default as useIntl } from './useIntl';
@@ -1,7 +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
+ // TODO: Remove in next major version
8
+ export { default as useIntl } from './useIntl';
7
9
  //# sourceMappingURL=index.js.map
@@ -1 +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"}
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,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;AACrD,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAEvD,qCAAqC;AACrC,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ export default function useFormatter(): {
2
+ dateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
+ number: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
4
+ relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
5
+ };
@@ -0,0 +1,14 @@
1
+ import { useMemo } from 'react';
2
+ import createFormatter from '../core/createFormatter';
3
+ import useIntlContext from './useIntlContext';
4
+ export default function useFormatter() {
5
+ const { formats, locale, now: globalNow, onError, timeZone } = useIntlContext();
6
+ return useMemo(() => createFormatter({
7
+ formats,
8
+ locale,
9
+ now: globalNow,
10
+ onError,
11
+ timeZone
12
+ }), [formats, globalNow, locale, onError, timeZone]);
13
+ }
14
+ //# sourceMappingURL=useFormatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormatter.js","sourceRoot":"","sources":["../../../src/react/useFormatter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,YAAY;IAClC,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,cAAc,EAAE,CAAC;IAE9E,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,eAAe,CAAC;QACd,OAAO;QACP,MAAM;QACN,GAAG,EAAE,SAAS;QACd,OAAO;QACP,QAAQ;KACT,CAAC,EACJ,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAChD,CAAC;AACJ,CAAC"}
@@ -1,3 +1,4 @@
1
+ /** @deprecated Switch to `useFormatter` */
1
2
  export default function useIntl(): {
2
3
  formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
4
  formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
@@ -1,8 +1,14 @@
1
1
  import { useMemo } from 'react';
2
2
  import createIntl from '../core/createIntl';
3
3
  import useIntlContext from './useIntlContext';
4
+ let hasWarned = false;
5
+ /** @deprecated Switch to `useFormatter` */
4
6
  export default function useIntl() {
5
7
  const { formats, locale, now: globalNow, onError, timeZone } = useIntlContext();
8
+ if (!hasWarned) {
9
+ hasWarned = true;
10
+ console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
11
+ }
6
12
  return useMemo(() => createIntl({
7
13
  formats,
8
14
  locale,
@@ -1 +1 @@
1
- {"version":3,"file":"useIntl.js","sourceRoot":"","sources":["../../../src/react/useIntl.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,OAAO;IAC7B,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,cAAc,EAAE,CAAC;IAE9E,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,UAAU,CAAC;QACT,OAAO;QACP,MAAM;QACN,GAAG,EAAE,SAAS;QACd,OAAO;QACP,QAAQ;KACT,CAAC,EACJ,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAChD,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"useIntl.js","sourceRoot":"","sources":["../../../src/react/useIntl.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,4CAA4C;AAC5C,MAAM,CAAC,OAAO,UAAU,OAAO;IAC7B,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,cAAc,EAAE,CAAC;IAE9E,IAAI,CAAC,SAAS,EAAE;QACd,SAAS,GAAG,IAAI,CAAC;QACjB,OAAO,CAAC,IAAI,CACV,6GAA6G,CAC9G,CAAC;KACH;IAED,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,UAAU,CAAC;QACT,OAAO;QACP,MAAM;QACN,GAAG,EAAE,SAAS;QACd,OAAO;QACP,QAAQ;KACT,CAAC,EACJ,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAChD,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- export default function useIntlContext(): import("./IntlContextValue").default;
1
+ export default function useIntlContext(): import("./IntlContext").IntlContextShape;
@@ -323,7 +323,15 @@ function createBaseTranslator(_ref2) {
323
323
  }
324
324
 
325
325
  var messages = messagesOrError;
326
- var cacheKey = [namespace, key].filter(function (part) {
326
+ var message;
327
+
328
+ try {
329
+ message = resolvePath(messages, key, namespace);
330
+ } catch (error) {
331
+ return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.MISSING_MESSAGE, error.message);
332
+ }
333
+
334
+ var cacheKey = [namespace, key, message].filter(function (part) {
327
335
  return part != null;
328
336
  }).join('.');
329
337
  var messageFormat;
@@ -331,14 +339,6 @@ function createBaseTranslator(_ref2) {
331
339
  if (cachedFormatsByLocale != null && (_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
332
340
  messageFormat = cachedFormatsByLocale == null ? void 0 : cachedFormatsByLocale[locale][cacheKey];
333
341
  } else {
334
- var message;
335
-
336
- try {
337
- message = resolvePath(messages, key, namespace);
338
- } catch (error) {
339
- return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.MISSING_MESSAGE, error.message);
340
- }
341
-
342
342
  if (typeof message === 'object') {
343
343
  return getFallbackFromErrorAndNotify(key, exports.IntlErrorCode.INSUFFICIENT_PATH, "Insufficient path specified for `" + key + "` in `" + (namespace ? "`" + namespace + "`" : 'messages') + "`." );
344
344
  }
@@ -427,13 +427,13 @@ function resolveNamespace(namespace, namespacePrefix) {
427
427
  return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
428
428
  }
429
429
 
430
- var _excluded$3 = ["getMessageFallback", "messages", "namespace", "onError"];
430
+ var _excluded$2 = ["getMessageFallback", "messages", "namespace", "onError"];
431
431
  function createTranslatorImpl(_ref, namespacePrefix) {
432
432
  var getMessageFallback = _ref.getMessageFallback,
433
433
  messages = _ref.messages,
434
434
  namespace = _ref.namespace,
435
435
  onError = _ref.onError,
436
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
436
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
437
437
 
438
438
  // The `namespacePrefix` is part of the type system.
439
439
  // See the comment in the function invocation.
@@ -479,7 +479,7 @@ function createTranslatorImpl(_ref, namespacePrefix) {
479
479
  return base;
480
480
  }
481
481
 
482
- var _excluded$2 = ["onError", "getMessageFallback", "messages", "namespace"];
482
+ var _excluded$1 = ["onError", "getMessageFallback", "messages", "namespace"];
483
483
  /**
484
484
  * Translates messages from the given namespace by using the ICU syntax.
485
485
  * See https://formatjs.io/docs/core-concepts/icu-syntax.
@@ -496,7 +496,7 @@ function createTranslator(_ref) {
496
496
  getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
497
497
  messages = _ref.messages,
498
498
  namespace = _ref.namespace,
499
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
499
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
500
500
 
501
501
  // We have to wrap the actual function so the type inference for the optional
502
502
  // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
@@ -554,7 +554,7 @@ function getRelativeTimeFormatConfig(seconds) {
554
554
  };
555
555
  }
556
556
 
557
- function createIntl(_ref) {
557
+ function createFormatter(_ref) {
558
558
  var formats = _ref.formats,
559
559
  locale = _ref.locale,
560
560
  globalNow = _ref.now,
@@ -598,7 +598,7 @@ function createIntl(_ref) {
598
598
  }
599
599
  }
600
600
 
601
- function formatDateTime(
601
+ function dateTime(
602
602
  /** If a number is supplied, this is interpreted as a UTC timestamp. */
603
603
  value,
604
604
  /** If a time zone is supplied, the `value` is converted to that time zone.
@@ -617,13 +617,13 @@ function createIntl(_ref) {
617
617
  });
618
618
  }
619
619
 
620
- function formatNumber(value, formatOrOptions) {
620
+ function number(value, formatOrOptions) {
621
621
  return getFormattedValue(value, formatOrOptions, formats == null ? void 0 : formats.number, function (options) {
622
622
  return new Intl.NumberFormat(locale, options).format(value);
623
623
  });
624
624
  }
625
625
 
626
- function formatRelativeTime(
626
+ function relativeTime(
627
627
  /** The date time that needs to be formatted. */
628
628
  date,
629
629
  /** The reference point in time to which `date` will be formatted in relation to. */
@@ -633,7 +633,7 @@ function createIntl(_ref) {
633
633
  if (globalNow) {
634
634
  now = globalNow;
635
635
  } else {
636
- throw new Error("development" !== 'production' ? "The `now` parameter wasn't provided to `formatRelativeTime` and there was no global fallback configured on the provider." : undefined);
636
+ throw new Error("development" !== 'production' ? "The `now` parameter wasn't provided and there was no global fallback configured on the provider." : undefined);
637
637
  }
638
638
  }
639
639
 
@@ -655,13 +655,22 @@ function createIntl(_ref) {
655
655
  }
656
656
 
657
657
  return {
658
- formatDateTime: formatDateTime,
659
- formatNumber: formatNumber,
660
- formatRelativeTime: formatRelativeTime
658
+ dateTime: dateTime,
659
+ number: number,
660
+ relativeTime: relativeTime
661
661
  };
662
662
  }
663
663
 
664
- var IntlContext = /*#__PURE__*/React.createContext(undefined);
664
+ /** @deprecated Switch to `createFormatter` */
665
+
666
+ function createIntl() {
667
+ var formatter = createFormatter.apply(void 0, arguments);
668
+ return {
669
+ formatDateTime: formatter.dateTime,
670
+ formatNumber: formatter.number,
671
+ formatRelativeTime: formatter.relativeTime
672
+ };
673
+ }
665
674
 
666
675
  function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
667
676
  Object.entries(messages).forEach(function (_ref) {
@@ -691,40 +700,33 @@ function validateMessages(messages, onError) {
691
700
  }
692
701
  }
693
702
 
694
- var _excluded$1 = ["getMessageFallback", "messages", "onError"];
695
- /**
696
- * Enhances the incoming props with defaults.
697
- */
703
+ var IntlContext = /*#__PURE__*/React.createContext(undefined);
698
704
 
699
- function getIntlContextValue(_ref) {
700
- var getMessageFallback = _ref.getMessageFallback,
705
+ var _excluded = ["children", "onError", "getMessageFallback", "messages"];
706
+ function IntlProvider(_ref) {
707
+ var children = _ref.children,
708
+ _ref$onError = _ref.onError,
709
+ onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
710
+ _ref$getMessageFallba = _ref.getMessageFallback,
711
+ getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
701
712
  messages = _ref.messages,
702
- onError = _ref.onError,
703
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
704
-
705
- var finalOnError = onError || defaultOnError;
706
- var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
713
+ contextValues = _objectWithoutPropertiesLoose(_ref, _excluded);
707
714
 
708
715
  {
709
- if (messages) {
710
- validateMessages(messages, finalOnError);
711
- }
716
+ // eslint-disable-next-line react-hooks/rules-of-hooks
717
+ React.useEffect(function () {
718
+ if (messages) {
719
+ validateMessages(messages, onError);
720
+ }
721
+ }, [messages, onError]);
712
722
  }
713
723
 
714
- return _extends({}, rest, {
715
- messages: messages,
716
- onError: finalOnError,
717
- getMessageFallback: finalGetMessageFallback
718
- });
719
- }
720
-
721
- var _excluded = ["children"];
722
- function IntlProvider(_ref) {
723
- var children = _ref.children,
724
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
725
-
726
724
  return React__default["default"].createElement(IntlContext.Provider, {
727
- value: getIntlContextValue(props)
725
+ value: _extends({}, contextValues, {
726
+ messages: messages,
727
+ onError: onError,
728
+ getMessageFallback: getMessageFallback
729
+ })
728
730
  }, children);
729
731
  }
730
732
 
@@ -796,25 +798,6 @@ function useTranslations(namespace) {
796
798
  namespace ? "!." + namespace : '!', '!');
797
799
  }
798
800
 
799
- function useIntl() {
800
- var _useIntlContext = useIntlContext(),
801
- formats = _useIntlContext.formats,
802
- locale = _useIntlContext.locale,
803
- globalNow = _useIntlContext.now,
804
- onError = _useIntlContext.onError,
805
- timeZone = _useIntlContext.timeZone;
806
-
807
- return React.useMemo(function () {
808
- return createIntl({
809
- formats: formats,
810
- locale: locale,
811
- now: globalNow,
812
- onError: onError,
813
- timeZone: timeZone
814
- });
815
- }, [formats, globalNow, locale, onError, timeZone]);
816
- }
817
-
818
801
  function useLocale() {
819
802
  return useIntlContext().locale;
820
803
  }
@@ -868,10 +851,58 @@ function useTimeZone() {
868
851
  return useIntlContext().timeZone;
869
852
  }
870
853
 
854
+ function useFormatter() {
855
+ var _useIntlContext = useIntlContext(),
856
+ formats = _useIntlContext.formats,
857
+ locale = _useIntlContext.locale,
858
+ globalNow = _useIntlContext.now,
859
+ onError = _useIntlContext.onError,
860
+ timeZone = _useIntlContext.timeZone;
861
+
862
+ return React.useMemo(function () {
863
+ return createFormatter({
864
+ formats: formats,
865
+ locale: locale,
866
+ now: globalNow,
867
+ onError: onError,
868
+ timeZone: timeZone
869
+ });
870
+ }, [formats, globalNow, locale, onError, timeZone]);
871
+ }
872
+
873
+ var hasWarned = false;
874
+ /** @deprecated Switch to `useFormatter` */
875
+
876
+ function useIntl() {
877
+ var _useIntlContext = useIntlContext(),
878
+ formats = _useIntlContext.formats,
879
+ locale = _useIntlContext.locale,
880
+ globalNow = _useIntlContext.now,
881
+ onError = _useIntlContext.onError,
882
+ timeZone = _useIntlContext.timeZone;
883
+
884
+ if (!hasWarned) {
885
+ hasWarned = true;
886
+ console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
887
+ }
888
+
889
+ return React.useMemo(function () {
890
+ return createIntl({
891
+ formats: formats,
892
+ locale: locale,
893
+ now: globalNow,
894
+ onError: onError,
895
+ timeZone: timeZone
896
+ });
897
+ }, [formats, globalNow, locale, onError, timeZone]);
898
+ }
899
+
871
900
  exports.IntlError = IntlError;
872
901
  exports.IntlProvider = IntlProvider;
902
+ exports.createFormatter = createFormatter;
873
903
  exports.createIntl = createIntl;
874
904
  exports.createTranslator = createTranslator;
905
+ exports.useFormatter = useFormatter;
875
906
  exports.useIntl = useIntl;
876
907
  exports.useLocale = useLocale;
877
908
  exports.useNow = useNow;