use-intl 3.0.0-beta.2 → 3.0.0-rc.5

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 (204) hide show
  1. package/_IntlProvider.d.ts +1 -0
  2. package/_useLocale.d.ts +1 -0
  3. package/core.d.ts +1 -1
  4. package/dist/_IntlProvider.js +7 -0
  5. package/dist/_useLocale.js +7 -0
  6. package/dist/core.js +3 -4
  7. package/dist/development/IntlContext-b5cc6be8.js +8 -0
  8. package/dist/development/_IntlProvider.js +27 -0
  9. package/dist/development/_useLocale-321e619f.js +19 -0
  10. package/dist/development/_useLocale.js +11 -0
  11. package/dist/development/core.js +91 -0
  12. package/dist/development/createFormatter-bcc5a49f.js +430 -0
  13. package/dist/development/index.js +29 -0
  14. package/dist/development/initializeConfig-0a0b87a7.js +120 -0
  15. package/dist/development/react.js +145 -0
  16. package/dist/esm/IntlContext-381f3ce4.js +1 -0
  17. package/dist/esm/_IntlProvider.js +1 -0
  18. package/dist/esm/_useLocale-89b32eb9.js +1 -0
  19. package/dist/esm/_useLocale.js +1 -0
  20. package/dist/esm/core.js +1 -0
  21. package/dist/esm/createFormatter-cccbd794.js +1 -0
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/initializeConfig-29e7ba4c.js +1 -0
  24. package/dist/esm/react.js +1 -0
  25. package/dist/index.js +3 -4
  26. package/dist/production/IntlContext-381f3ce4.js +1 -0
  27. package/dist/production/_IntlProvider.js +1 -0
  28. package/dist/production/_useLocale-8e23751a.js +1 -0
  29. package/dist/production/_useLocale.js +1 -0
  30. package/dist/production/core.js +1 -0
  31. package/dist/production/createFormatter-8c0b8eb2.js +1 -0
  32. package/dist/production/index.js +1 -0
  33. package/dist/production/initializeConfig-984a566d.js +1 -0
  34. package/dist/production/react.js +1 -0
  35. package/dist/react.js +3 -4
  36. package/dist/types/src/_IntlProvider.d.ts +1 -0
  37. package/dist/types/src/_useLocale.d.ts +1 -0
  38. package/dist/{core → types/src/core}/AbstractIntlMessages.d.ts +9 -9
  39. package/dist/{core → types/src/core}/DateTimeFormatOptions.d.ts +73 -73
  40. package/dist/{core → types/src/core}/Formats.d.ts +8 -8
  41. package/dist/{core → types/src/core}/IntlConfig.d.ts +54 -54
  42. package/dist/{core → types/src/core}/IntlError.d.ts +14 -13
  43. package/dist/{core → types/src/core}/MessageFormatCache.d.ts +5 -5
  44. package/dist/{core → types/src/core}/NumberFormatOptions.d.ts +2 -2
  45. package/dist/types/src/core/RelativeTimeFormatOptions.d.ts +5 -0
  46. package/dist/{core → types/src/core}/TimeZone.d.ts +2 -2
  47. package/dist/{core → types/src/core}/TranslationValues.d.ts +6 -6
  48. package/dist/{core → types/src/core}/convertFormatsToIntlMessageFormat.d.ts +11 -11
  49. package/dist/{core → types/src/core}/createBaseTranslator.d.ts +21 -21
  50. package/dist/{core → types/src/core}/createFormatter.d.ts +20 -19
  51. package/dist/{core → types/src/core}/createTranslator.d.ts +47 -47
  52. package/dist/{core → types/src/core}/createTranslatorImpl.d.ts +13 -13
  53. package/dist/{core → types/src/core}/defaults.d.ts +11 -11
  54. package/dist/{core → types/src/core}/index.d.ts +15 -16
  55. package/dist/{core → types/src/core}/initializeConfig.d.ts +14 -13
  56. package/dist/{core → types/src/core}/resolveNamespace.d.ts +5 -5
  57. package/dist/{core → types/src/core}/utils/MessageKeys.d.ts +5 -5
  58. package/dist/{core → types/src/core}/utils/NamespaceKeys.d.ts +5 -5
  59. package/dist/{core → types/src/core}/utils/NestedKeyOf.d.ts +4 -4
  60. package/dist/{core → types/src/core}/utils/NestedValueOf.d.ts +2 -2
  61. package/dist/{core → types/src/core}/validateMessages.d.ts +3 -3
  62. package/dist/{core.d.ts → types/src/core.d.ts} +1 -1
  63. package/dist/{index.d.ts → types/src/index.d.ts} +2 -2
  64. package/dist/{react → types/src/react}/IntlContext.d.ts +13 -13
  65. package/dist/{react → types/src/react}/IntlProvider.d.ts +7 -7
  66. package/dist/{react → types/src/react}/index.d.ts +7 -8
  67. package/dist/{react → types/src/react}/useFormatter.d.ts +6 -6
  68. package/dist/{react → types/src/react}/useIntlContext.d.ts +10 -10
  69. package/dist/{react → types/src/react}/useLocale.d.ts +1 -1
  70. package/dist/types/src/react/useMessages.d.ts +2 -0
  71. package/dist/{react → types/src/react}/useNow.d.ts +23 -23
  72. package/dist/{react → types/src/react}/useTimeZone.d.ts +1 -1
  73. package/dist/{react → types/src/react}/useTranslations.d.ts +44 -44
  74. package/dist/{react → types/src/react}/useTranslationsImpl.d.ts +8 -8
  75. package/dist/{react.d.ts → types/src/react.d.ts} +1 -1
  76. package/dist/types/test/core/createFormatter.test.d.ts +1 -0
  77. package/dist/types/test/core/createTranslator.test.d.ts +1 -0
  78. package/dist/types/test/react/useFormatter.test.d.ts +1 -0
  79. package/dist/types/test/react/useLocale.test.d.ts +1 -0
  80. package/dist/types/test/react/useMessages.test.d.ts +1 -0
  81. package/dist/types/test/react/useNow.test.d.ts +1 -0
  82. package/dist/types/test/react/useTimeZone.test.d.ts +1 -0
  83. package/dist/types/test/react/useTranslations.test.d.ts +1 -0
  84. package/dist/{test → types/test}/setup.d.ts +1 -1
  85. package/package.json +33 -21
  86. package/react.d.ts +1 -1
  87. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js +0 -102
  88. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
  89. package/dist/_virtual/use-intl.esm.js +0 -102
  90. package/dist/_virtual/use-intl.esm.js.map +0 -1
  91. package/dist/core/IntlError.esm.js +0 -33
  92. package/dist/core/IntlError.esm.js.map +0 -1
  93. package/dist/core/convertFormatsToIntlMessageFormat.esm.js +0 -37
  94. package/dist/core/convertFormatsToIntlMessageFormat.esm.js.map +0 -1
  95. package/dist/core/createBaseTranslator.esm.js +0 -210
  96. package/dist/core/createBaseTranslator.esm.js.map +0 -1
  97. package/dist/core/createFormatter.esm.js +0 -138
  98. package/dist/core/createFormatter.esm.js.map +0 -1
  99. package/dist/core/createIntl.d.ts +0 -7
  100. package/dist/core/createIntl.esm.js +0 -14
  101. package/dist/core/createIntl.esm.js.map +0 -1
  102. package/dist/core/createTranslator.esm.js +0 -37
  103. package/dist/core/createTranslator.esm.js.map +0 -1
  104. package/dist/core/createTranslatorImpl.esm.js +0 -50
  105. package/dist/core/createTranslatorImpl.esm.js.map +0 -1
  106. package/dist/core/defaults.esm.js +0 -15
  107. package/dist/core/defaults.esm.js.map +0 -1
  108. package/dist/core/initializeConfig.esm.js +0 -29
  109. package/dist/core/initializeConfig.esm.js.map +0 -1
  110. package/dist/core/resolveNamespace.esm.js +0 -10
  111. package/dist/core/resolveNamespace.esm.js.map +0 -1
  112. package/dist/core/use-intl.esm.js +0 -33
  113. package/dist/core/use-intl.esm.js.map +0 -1
  114. package/dist/core/use-intl.esm10.js +0 -28
  115. package/dist/core/use-intl.esm10.js.map +0 -1
  116. package/dist/core/use-intl.esm11.js +0 -10
  117. package/dist/core/use-intl.esm11.js.map +0 -1
  118. package/dist/core/use-intl.esm2.js +0 -210
  119. package/dist/core/use-intl.esm2.js.map +0 -1
  120. package/dist/core/use-intl.esm3.js +0 -37
  121. package/dist/core/use-intl.esm3.js.map +0 -1
  122. package/dist/core/use-intl.esm4.js +0 -14
  123. package/dist/core/use-intl.esm4.js.map +0 -1
  124. package/dist/core/use-intl.esm5.js +0 -29
  125. package/dist/core/use-intl.esm5.js.map +0 -1
  126. package/dist/core/use-intl.esm6.js +0 -138
  127. package/dist/core/use-intl.esm6.js.map +0 -1
  128. package/dist/core/use-intl.esm7.js +0 -37
  129. package/dist/core/use-intl.esm7.js.map +0 -1
  130. package/dist/core/use-intl.esm8.js +0 -15
  131. package/dist/core/use-intl.esm8.js.map +0 -1
  132. package/dist/core/use-intl.esm9.js +0 -50
  133. package/dist/core/use-intl.esm9.js.map +0 -1
  134. package/dist/core/validateMessages.esm.js +0 -28
  135. package/dist/core/validateMessages.esm.js.map +0 -1
  136. package/dist/core.cjs.development.js +0 -93
  137. package/dist/core.cjs.development.js.map +0 -1
  138. package/dist/core.cjs.production.min.js +0 -2
  139. package/dist/core.cjs.production.min.js.map +0 -1
  140. package/dist/core.esm.js +0 -7
  141. package/dist/core.esm.js.map +0 -1
  142. package/dist/createIntl-34d4281e.js +0 -592
  143. package/dist/createIntl-34d4281e.js.map +0 -1
  144. package/dist/createIntl-bc325740.js +0 -2
  145. package/dist/createIntl-bc325740.js.map +0 -1
  146. package/dist/react/IntlContext.esm.js +0 -6
  147. package/dist/react/IntlContext.esm.js.map +0 -1
  148. package/dist/react/IntlProvider.esm.js +0 -22
  149. package/dist/react/IntlProvider.esm.js.map +0 -1
  150. package/dist/react/getInitializedConfig.d.ts +0 -1
  151. package/dist/react/use-intl.esm.js +0 -26
  152. package/dist/react/use-intl.esm.js.map +0 -1
  153. package/dist/react/use-intl.esm10.js +0 -13
  154. package/dist/react/use-intl.esm10.js.map +0 -1
  155. package/dist/react/use-intl.esm11.js +0 -6
  156. package/dist/react/use-intl.esm11.js.map +0 -1
  157. package/dist/react/use-intl.esm2.js +0 -8
  158. package/dist/react/use-intl.esm2.js.map +0 -1
  159. package/dist/react/use-intl.esm3.js +0 -30
  160. package/dist/react/use-intl.esm3.js.map +0 -1
  161. package/dist/react/use-intl.esm4.js +0 -22
  162. package/dist/react/use-intl.esm4.js.map +0 -1
  163. package/dist/react/use-intl.esm5.js +0 -24
  164. package/dist/react/use-intl.esm5.js.map +0 -1
  165. package/dist/react/use-intl.esm6.js +0 -45
  166. package/dist/react/use-intl.esm6.js.map +0 -1
  167. package/dist/react/use-intl.esm7.js +0 -8
  168. package/dist/react/use-intl.esm7.js.map +0 -1
  169. package/dist/react/use-intl.esm8.js +0 -8
  170. package/dist/react/use-intl.esm8.js.map +0 -1
  171. package/dist/react/use-intl.esm9.js +0 -36
  172. package/dist/react/use-intl.esm9.js.map +0 -1
  173. package/dist/react/useFormatter.esm.js +0 -24
  174. package/dist/react/useFormatter.esm.js.map +0 -1
  175. package/dist/react/useIntl.d.ts +0 -6
  176. package/dist/react/useIntl.esm.js +0 -30
  177. package/dist/react/useIntl.esm.js.map +0 -1
  178. package/dist/react/useIntlContext.esm.js +0 -13
  179. package/dist/react/useIntlContext.esm.js.map +0 -1
  180. package/dist/react/useLocale.esm.js +0 -8
  181. package/dist/react/useLocale.esm.js.map +0 -1
  182. package/dist/react/useMessages.d.ts +0 -1
  183. package/dist/react/useMessages.esm.js +0 -8
  184. package/dist/react/useMessages.esm.js.map +0 -1
  185. package/dist/react/useNow.esm.js +0 -45
  186. package/dist/react/useNow.esm.js.map +0 -1
  187. package/dist/react/useTimeZone.esm.js +0 -8
  188. package/dist/react/useTimeZone.esm.js.map +0 -1
  189. package/dist/react/useTranslations.esm.js +0 -26
  190. package/dist/react/useTranslations.esm.js.map +0 -1
  191. package/dist/react/useTranslationsImpl.esm.js +0 -36
  192. package/dist/react/useTranslationsImpl.esm.js.map +0 -1
  193. package/dist/react.cjs.development.js +0 -190
  194. package/dist/react.cjs.development.js.map +0 -1
  195. package/dist/react.cjs.production.min.js +0 -2
  196. package/dist/react.cjs.production.min.js.map +0 -1
  197. package/dist/react.esm.js +0 -9
  198. package/dist/react.esm.js.map +0 -1
  199. package/dist/use-intl.cjs.development.js +0 -842
  200. package/dist/use-intl.cjs.development.js.map +0 -1
  201. package/dist/use-intl.cjs.production.min.js +0 -2
  202. package/dist/use-intl.cjs.production.min.js.map +0 -1
  203. package/dist/use-intl.esm.js +0 -15
  204. package/dist/use-intl.esm.js.map +0 -1
@@ -1,4 +1,4 @@
1
- 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;
1
+ 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;
@@ -1,2 +1,2 @@
1
- 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;
1
+ 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;
@@ -1,3 +1,3 @@
1
- import AbstractIntlMessages from './AbstractIntlMessages';
2
- import IntlError from './IntlError';
3
- export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
1
+ import AbstractIntlMessages from './AbstractIntlMessages';
2
+ import IntlError from './IntlError';
3
+ export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
@@ -1 +1 @@
1
- export * from './core/index';
1
+ export * from './core/index';
@@ -1,2 +1,2 @@
1
- export * from './core';
2
- export * from './react';
1
+ export * from './core';
2
+ export * from './react';
@@ -1,13 +1,13 @@
1
- /// <reference types="react" />
2
- import MessageFormatCache from '../core/MessageFormatCache';
3
- declare const IntlContext: import("react").Context<(import("../core/IntlConfig").default<import("../core/AbstractIntlMessages").default> & {
4
- onError: (error: import("..").IntlError) => void;
5
- getMessageFallback: (info: {
6
- error: import("..").IntlError;
7
- key: string;
8
- namespace?: string | undefined;
9
- }) => string;
10
- } & {
11
- messageFormatCache?: MessageFormatCache | undefined;
12
- }) | undefined>;
13
- export default IntlContext;
1
+ /// <reference types="react" />
2
+ import MessageFormatCache from '../core/MessageFormatCache';
3
+ declare const IntlContext: import("react").Context<(import("../core/IntlConfig").default<import("../core/AbstractIntlMessages").default> & {
4
+ onError: (error: import("..").IntlError) => void;
5
+ getMessageFallback: (info: {
6
+ error: import("..").IntlError;
7
+ key: string;
8
+ namespace?: string | undefined;
9
+ }) => string;
10
+ } & {
11
+ messageFormatCache?: MessageFormatCache | undefined;
12
+ }) | undefined>;
13
+ export default IntlContext;
@@ -1,7 +1,7 @@
1
- import { ReactNode } from 'react';
2
- import IntlConfig from '../core/IntlConfig';
3
- type Props = IntlConfig & {
4
- children: ReactNode;
5
- };
6
- export default function IntlProvider({ children, ...config }: Props): JSX.Element;
7
- export {};
1
+ import { ReactNode } from 'react';
2
+ import IntlConfig from '../core/IntlConfig';
3
+ type Props = IntlConfig & {
4
+ children: ReactNode;
5
+ };
6
+ export default function IntlProvider({ children, ...config }: Props): JSX.Element;
7
+ export {};
@@ -1,8 +1,7 @@
1
- export { default as IntlProvider } from './IntlProvider';
2
- export { default as useTranslations } from './useTranslations';
3
- export { default as useLocale } from './useLocale';
4
- export { default as useNow } from './useNow';
5
- export { default as useTimeZone } from './useTimeZone';
6
- export { default as useMessages } from './useMessages';
7
- export { default as useFormatter } from './useFormatter';
8
- export { default as useIntl } from './useIntl';
1
+ export { default as IntlProvider } from './IntlProvider';
2
+ export { default as useTranslations } from './useTranslations';
3
+ export { default as useLocale } from './useLocale';
4
+ export { default as useNow } from './useNow';
5
+ export { default as useTimeZone } from './useTimeZone';
6
+ export { default as useMessages } from './useMessages';
7
+ export { default as useFormatter } from './useFormatter';
@@ -1,6 +1,6 @@
1
- export default function useFormatter(): {
2
- dateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
- number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
4
- relativeTime: (date: number | Date, now?: number | Date | undefined) => string;
5
- list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions | undefined) => string;
6
- };
1
+ export default function useFormatter(): {
2
+ dateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
3
+ number: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
4
+ relativeTime: (date: number | Date, nowOrOptions?: number | Date | import("../core/RelativeTimeFormatOptions").default | undefined) => string;
5
+ list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions | undefined) => string;
6
+ };
@@ -1,10 +1,10 @@
1
- export default function useIntlContext(): import("../core/IntlConfig").default<import("../core/AbstractIntlMessages").default> & {
2
- onError: (error: import("..").IntlError) => void;
3
- getMessageFallback: (info: {
4
- error: import("..").IntlError;
5
- key: string;
6
- namespace?: string | undefined;
7
- }) => string;
8
- } & {
9
- messageFormatCache?: import("../core/MessageFormatCache").default | undefined;
10
- };
1
+ export default function useIntlContext(): import("../core/IntlConfig").default<import("../core/AbstractIntlMessages").default> & {
2
+ onError: (error: import("..").IntlError) => void;
3
+ getMessageFallback: (info: {
4
+ error: import("..").IntlError;
5
+ key: string;
6
+ namespace?: string | undefined;
7
+ }) => string;
8
+ } & {
9
+ messageFormatCache?: import("../core/MessageFormatCache").default | undefined;
10
+ };
@@ -1 +1 @@
1
- export default function useLocale(): string;
1
+ export default function useLocale(): string;
@@ -0,0 +1,2 @@
1
+ import { AbstractIntlMessages } from '../core';
2
+ export default function useMessages(): AbstractIntlMessages;
@@ -1,23 +1,23 @@
1
- type Options = {
2
- updateInterval?: number;
3
- };
4
- /**
5
- * Reading the current date via `new Date()` in components should be avoided, as
6
- * it causes components to be impure and can lead to flaky tests. Instead, this
7
- * hook can be used.
8
- *
9
- * By default, it returns the time when the component mounts. If `updateInterval`
10
- * is specified, the value will be updated based on the interval.
11
- *
12
- * You can however also return a static value from this hook, if you
13
- * configure the `now` parameter on the context provider. Note however,
14
- * that if `updateInterval` is configured in this case, the component
15
- * will initialize with the global value, but will afterwards update
16
- * continuously based on the interval.
17
- *
18
- * For unit tests, this can be mocked to a constant value. For end-to-end
19
- * testing, an environment parameter can be passed to the `now` parameter
20
- * of the provider to mock this to a static value.
21
- */
22
- export default function useNow(options?: Options): Date;
23
- export {};
1
+ type Options = {
2
+ updateInterval?: number;
3
+ };
4
+ /**
5
+ * Reading the current date via `new Date()` in components should be avoided, as
6
+ * it causes components to be impure and can lead to flaky tests. Instead, this
7
+ * hook can be used.
8
+ *
9
+ * By default, it returns the time when the component mounts. If `updateInterval`
10
+ * is specified, the value will be updated based on the interval.
11
+ *
12
+ * You can however also return a static value from this hook, if you
13
+ * configure the `now` parameter on the context provider. Note however,
14
+ * that if `updateInterval` is configured in this case, the component
15
+ * will initialize with the global value, but will afterwards update
16
+ * continuously based on the interval.
17
+ *
18
+ * For unit tests, this can be mocked to a constant value. For end-to-end
19
+ * testing, an environment parameter can be passed to the `now` parameter
20
+ * of the provider to mock this to a static value.
21
+ */
22
+ export default function useNow(options?: Options): Date;
23
+ export {};
@@ -1 +1 @@
1
- export default function useTimeZone(): import("../core/TimeZone").default | undefined;
1
+ export default function useTimeZone(): import("../core/TimeZone").default | undefined;
@@ -1,44 +1,44 @@
1
- import { ReactElement, ReactNodeArray } from 'react';
2
- import Formats from '../core/Formats';
3
- import TranslationValues, { RichTranslationValues } from '../core/TranslationValues';
4
- import MessageKeys from '../core/utils/MessageKeys';
5
- import NamespaceKeys from '../core/utils/NamespaceKeys';
6
- import NestedKeyOf from '../core/utils/NestedKeyOf';
7
- import NestedValueOf from '../core/utils/NestedValueOf';
8
- /**
9
- * Translates messages from the given namespace by using the ICU syntax.
10
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
11
- *
12
- * If no namespace is provided, all available messages are returned.
13
- * The namespace can also indicate nesting by using a dot
14
- * (e.g. `namespace.Component`).
15
- */
16
- export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(namespace?: NestedKey): {
17
- <TargetKey extends MessageKeys<NestedValueOf<{
18
- '!': IntlMessages;
19
- }, [
20
- NestedKey
21
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
22
- '!': IntlMessages;
23
- }, [
24
- NestedKey
25
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
26
- rich<TargetKey extends MessageKeys<NestedValueOf<{
27
- '!': IntlMessages;
28
- }, [
29
- NestedKey
30
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
31
- '!': IntlMessages;
32
- }, [
33
- NestedKey
34
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Partial<Formats>): string | ReactElement | ReactNodeArray;
35
- raw<TargetKey extends MessageKeys<NestedValueOf<{
36
- '!': IntlMessages;
37
- }, [
38
- NestedKey
39
- ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
40
- '!': IntlMessages;
41
- }, [
42
- NestedKey
43
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
44
- };
1
+ import { ReactElement, ReactNodeArray } from 'react';
2
+ import Formats from '../core/Formats';
3
+ import TranslationValues, { RichTranslationValues } from '../core/TranslationValues';
4
+ import MessageKeys from '../core/utils/MessageKeys';
5
+ import NamespaceKeys from '../core/utils/NamespaceKeys';
6
+ import NestedKeyOf from '../core/utils/NestedKeyOf';
7
+ import NestedValueOf from '../core/utils/NestedValueOf';
8
+ /**
9
+ * Translates messages from the given namespace by using the ICU syntax.
10
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
11
+ *
12
+ * If no namespace is provided, all available messages are returned.
13
+ * The namespace can also indicate nesting by using a dot
14
+ * (e.g. `namespace.Component`).
15
+ */
16
+ export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(namespace?: NestedKey): {
17
+ <TargetKey extends MessageKeys<NestedValueOf<{
18
+ '!': IntlMessages;
19
+ }, [
20
+ NestedKey
21
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
22
+ '!': IntlMessages;
23
+ }, [
24
+ NestedKey
25
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
26
+ rich<TargetKey extends MessageKeys<NestedValueOf<{
27
+ '!': IntlMessages;
28
+ }, [
29
+ NestedKey
30
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
31
+ '!': IntlMessages;
32
+ }, [
33
+ NestedKey
34
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Partial<Formats>): string | ReactElement | ReactNodeArray;
35
+ raw<TargetKey extends MessageKeys<NestedValueOf<{
36
+ '!': IntlMessages;
37
+ }, [
38
+ NestedKey
39
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
40
+ '!': IntlMessages;
41
+ }, [
42
+ NestedKey
43
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
44
+ };
@@ -1,8 +1,8 @@
1
- /// <reference types="react" />
2
- import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
- import NestedKeyOf from '../core/utils/NestedKeyOf';
4
- export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string): {
5
- <TargetKey extends unknown>(key: TargetKey, values?: import("../core/TranslationValues").default | undefined, formats?: Partial<import("../core/Formats").default> | undefined): string;
6
- rich: (key: string, values?: import("..").RichTranslationValues | undefined, formats?: Partial<import("../core/Formats").default> | undefined) => string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNodeArray;
7
- raw(key: string): any;
8
- };
1
+ /// <reference types="react" />
2
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
+ import NestedKeyOf from '../core/utils/NestedKeyOf';
4
+ export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string): {
5
+ <TargetKey extends unknown>(key: TargetKey, values?: import("../core/TranslationValues").default | undefined, formats?: Partial<import("../core/Formats").default> | undefined): string;
6
+ rich: (key: string, values?: import("../core").RichTranslationValues | undefined, formats?: Partial<import("../core/Formats").default> | undefined) => string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNodeArray;
7
+ raw(key: string): any;
8
+ };
@@ -1 +1 @@
1
- export * from './react/index';
1
+ export * from './react/index';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-rc.5",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Minimal, but complete solution for managing internationalization in React apps.",
@@ -10,18 +10,37 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/amannn/next-intl/tree/main/packages/use-intl"
12
12
  },
13
- "main": "dist/index.js",
14
- "module": "dist/use-intl.esm.js",
15
- "typings": "dist/index.d.ts",
13
+ "main": "./dist/index.js",
14
+ "module": "dist/esm/index.js",
15
+ "typings": "./dist/types/src/index.d.ts",
16
16
  "exports": {
17
- ".": "./dist/index.js",
18
- "./core": "./dist/core.js",
19
- "./react": "./dist/react.js"
17
+ ".": {
18
+ "types": "./dist/types/src/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./core": {
22
+ "types": "./core.d.ts",
23
+ "default": "./dist/core.js"
24
+ },
25
+ "./react": {
26
+ "types": "./react.d.ts",
27
+ "default": "./dist/react.js"
28
+ },
29
+ "./_useLocale": {
30
+ "types": "./_useLocale.d.ts",
31
+ "default": "./dist/_useLocale.js"
32
+ },
33
+ "./_IntlProvider": {
34
+ "types": "./_IntlProvider.d.ts",
35
+ "default": "./dist/_IntlProvider.js"
36
+ }
20
37
  },
21
38
  "files": [
22
39
  "dist",
23
40
  "core.d.ts",
24
- "react.d.ts"
41
+ "react.d.ts",
42
+ "_useLocale.d.ts",
43
+ "_IntlProvider.d.ts"
25
44
  ],
26
45
  "keywords": [
27
46
  "react",
@@ -47,30 +66,23 @@
47
66
  "@types/node": "^17.0.23",
48
67
  "@types/react": "^18.2.5",
49
68
  "date-fns": "^2.16.1",
50
- "dts-cli": "^1.4.0",
51
- "eslint": "^8.39.0",
52
- "eslint-config-molindo": "^6.0.0",
69
+ "eslint": "^8.46.0",
70
+ "eslint-config-molindo": "^7.0.0",
53
71
  "react": "^18.2.0",
54
72
  "react-dom": "^18.2.0",
73
+ "rollup": "^3.28.1",
55
74
  "size-limit": "^8.2.6",
56
75
  "typescript": "^5.0.0",
57
76
  "vitest": "^0.32.2"
58
77
  },
59
78
  "size-limit": [
60
79
  {
61
- "path": "dist/use-intl.cjs.production.min.js",
62
- "limit": "10.30 kB"
63
- },
64
- {
65
- "path": "dist/use-intl.cjs.development.js",
66
- "limit": "10.30 kB"
80
+ "path": "dist/production/index.js",
81
+ "limit": "12.3 kB"
67
82
  }
68
83
  ],
69
- "engines": {
70
- "node": ">=10"
71
- },
72
84
  "scripts": {
73
- "build": "dts build --entry src/index.tsx && dts build --entry src/core.tsx --entry src/react.tsx --noClean",
85
+ "build": "rm -rf dist && rollup -c",
74
86
  "test": "TZ=Europe/Berlin vitest",
75
87
  "lint": "eslint src test && tsc --noEmit",
76
88
  "size": "size-limit"
package/react.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/react';
1
+ export * from './dist/types/src/react';
@@ -1,102 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign ? Object.assign.bind() : function (target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
- for (var key in source) {
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- function _inheritsLoose(subClass, superClass) {
16
- subClass.prototype = Object.create(superClass.prototype);
17
- subClass.prototype.constructor = subClass;
18
- _setPrototypeOf(subClass, superClass);
19
- }
20
- function _getPrototypeOf(o) {
21
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
22
- return o.__proto__ || Object.getPrototypeOf(o);
23
- };
24
- return _getPrototypeOf(o);
25
- }
26
- function _setPrototypeOf(o, p) {
27
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
28
- o.__proto__ = p;
29
- return o;
30
- };
31
- return _setPrototypeOf(o, p);
32
- }
33
- function _isNativeReflectConstruct() {
34
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
35
- if (Reflect.construct.sham) return false;
36
- if (typeof Proxy === "function") return true;
37
- try {
38
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
39
- return true;
40
- } catch (e) {
41
- return false;
42
- }
43
- }
44
- function _construct(Parent, args, Class) {
45
- if (_isNativeReflectConstruct()) {
46
- _construct = Reflect.construct.bind();
47
- } else {
48
- _construct = function _construct(Parent, args, Class) {
49
- var a = [null];
50
- a.push.apply(a, args);
51
- var Constructor = Function.bind.apply(Parent, a);
52
- var instance = new Constructor();
53
- if (Class) _setPrototypeOf(instance, Class.prototype);
54
- return instance;
55
- };
56
- }
57
- return _construct.apply(null, arguments);
58
- }
59
- function _isNativeFunction(fn) {
60
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
61
- }
62
- function _wrapNativeSuper(Class) {
63
- var _cache = typeof Map === "function" ? new Map() : undefined;
64
- _wrapNativeSuper = function _wrapNativeSuper(Class) {
65
- if (Class === null || !_isNativeFunction(Class)) return Class;
66
- if (typeof Class !== "function") {
67
- throw new TypeError("Super expression must either be null or a function");
68
- }
69
- if (typeof _cache !== "undefined") {
70
- if (_cache.has(Class)) return _cache.get(Class);
71
- _cache.set(Class, Wrapper);
72
- }
73
- function Wrapper() {
74
- return _construct(Class, arguments, _getPrototypeOf(this).constructor);
75
- }
76
- Wrapper.prototype = Object.create(Class.prototype, {
77
- constructor: {
78
- value: Wrapper,
79
- enumerable: false,
80
- writable: true,
81
- configurable: true
82
- }
83
- });
84
- return _setPrototypeOf(Wrapper, Class);
85
- };
86
- return _wrapNativeSuper(Class);
87
- }
88
- function _objectWithoutPropertiesLoose(source, excluded) {
89
- if (source == null) return {};
90
- var target = {};
91
- var sourceKeys = Object.keys(source);
92
- var key, i;
93
- for (i = 0; i < sourceKeys.length; i++) {
94
- key = sourceKeys[i];
95
- if (excluded.indexOf(key) >= 0) continue;
96
- target[key] = source[key];
97
- }
98
- return target;
99
- }
100
-
101
- export { _construct as construct, _extends as extends, _getPrototypeOf as getPrototypeOf, _inheritsLoose as inheritsLoose, _isNativeFunction as isNativeFunction, _isNativeReflectConstruct as isNativeReflectConstruct, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _setPrototypeOf as setPrototypeOf, _wrapNativeSuper as wrapNativeSuper };
102
- //# sourceMappingURL=_rollupPluginBabelHelpers.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,102 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign ? Object.assign.bind() : function (target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
- for (var key in source) {
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- function _inheritsLoose(subClass, superClass) {
16
- subClass.prototype = Object.create(superClass.prototype);
17
- subClass.prototype.constructor = subClass;
18
- _setPrototypeOf(subClass, superClass);
19
- }
20
- function _getPrototypeOf(o) {
21
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
22
- return o.__proto__ || Object.getPrototypeOf(o);
23
- };
24
- return _getPrototypeOf(o);
25
- }
26
- function _setPrototypeOf(o, p) {
27
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
28
- o.__proto__ = p;
29
- return o;
30
- };
31
- return _setPrototypeOf(o, p);
32
- }
33
- function _isNativeReflectConstruct() {
34
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
35
- if (Reflect.construct.sham) return false;
36
- if (typeof Proxy === "function") return true;
37
- try {
38
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
39
- return true;
40
- } catch (e) {
41
- return false;
42
- }
43
- }
44
- function _construct(Parent, args, Class) {
45
- if (_isNativeReflectConstruct()) {
46
- _construct = Reflect.construct.bind();
47
- } else {
48
- _construct = function _construct(Parent, args, Class) {
49
- var a = [null];
50
- a.push.apply(a, args);
51
- var Constructor = Function.bind.apply(Parent, a);
52
- var instance = new Constructor();
53
- if (Class) _setPrototypeOf(instance, Class.prototype);
54
- return instance;
55
- };
56
- }
57
- return _construct.apply(null, arguments);
58
- }
59
- function _isNativeFunction(fn) {
60
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
61
- }
62
- function _wrapNativeSuper(Class) {
63
- var _cache = typeof Map === "function" ? new Map() : undefined;
64
- _wrapNativeSuper = function _wrapNativeSuper(Class) {
65
- if (Class === null || !_isNativeFunction(Class)) return Class;
66
- if (typeof Class !== "function") {
67
- throw new TypeError("Super expression must either be null or a function");
68
- }
69
- if (typeof _cache !== "undefined") {
70
- if (_cache.has(Class)) return _cache.get(Class);
71
- _cache.set(Class, Wrapper);
72
- }
73
- function Wrapper() {
74
- return _construct(Class, arguments, _getPrototypeOf(this).constructor);
75
- }
76
- Wrapper.prototype = Object.create(Class.prototype, {
77
- constructor: {
78
- value: Wrapper,
79
- enumerable: false,
80
- writable: true,
81
- configurable: true
82
- }
83
- });
84
- return _setPrototypeOf(Wrapper, Class);
85
- };
86
- return _wrapNativeSuper(Class);
87
- }
88
- function _objectWithoutPropertiesLoose(source, excluded) {
89
- if (source == null) return {};
90
- var target = {};
91
- var sourceKeys = Object.keys(source);
92
- var key, i;
93
- for (i = 0; i < sourceKeys.length; i++) {
94
- key = sourceKeys[i];
95
- if (excluded.indexOf(key) >= 0) continue;
96
- target[key] = source[key];
97
- }
98
- return target;
99
- }
100
-
101
- export { _construct as construct, _extends as extends, _getPrototypeOf as getPrototypeOf, _inheritsLoose as inheritsLoose, _isNativeFunction as isNativeFunction, _isNativeReflectConstruct as isNativeReflectConstruct, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _setPrototypeOf as setPrototypeOf, _wrapNativeSuper as wrapNativeSuper };
102
- //# sourceMappingURL=use-intl.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}