use-intl 2.22.0 → 2.22.2

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 (298) hide show
  1. package/README.md +1 -1
  2. package/_IntlProvider.d.ts +1 -0
  3. package/_useLocale.d.ts +1 -0
  4. package/core.d.ts +1 -0
  5. package/dist/_IntlProvider.js +7 -0
  6. package/dist/_useLocale.js +7 -0
  7. package/dist/core.js +7 -0
  8. package/dist/development/IntlContext-b5cc6be8.js +8 -0
  9. package/dist/development/_IntlProvider.js +53 -0
  10. package/dist/development/_useLocale-321e619f.js +19 -0
  11. package/dist/development/_useLocale.js +11 -0
  12. package/dist/development/core.js +66 -0
  13. package/dist/development/createFormatter-4848f6c8.js +453 -0
  14. package/dist/development/index.js +28 -0
  15. package/dist/development/initializeConfig-0a0b87a7.js +120 -0
  16. package/dist/development/react.js +145 -0
  17. package/dist/esm/IntlContext-381f3ce4.js +1 -0
  18. package/dist/esm/_IntlProvider.js +1 -0
  19. package/dist/esm/_useLocale-89b32eb9.js +1 -0
  20. package/dist/esm/_useLocale.js +1 -0
  21. package/dist/esm/core.js +1 -0
  22. package/dist/esm/createFormatter-c871a8ce.js +1 -0
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/initializeConfig-29e7ba4c.js +1 -0
  25. package/dist/esm/react.js +1 -0
  26. package/dist/index.js +3 -4
  27. package/dist/production/IntlContext-381f3ce4.js +1 -0
  28. package/dist/production/_IntlProvider.js +1 -0
  29. package/dist/production/_useLocale-8e23751a.js +1 -0
  30. package/dist/production/_useLocale.js +1 -0
  31. package/dist/production/core.js +1 -0
  32. package/dist/production/createFormatter-7a8c6f36.js +1 -0
  33. package/dist/production/index.js +1 -0
  34. package/dist/production/initializeConfig-984a566d.js +1 -0
  35. package/dist/production/react.js +1 -0
  36. package/dist/react.js +7 -0
  37. package/dist/types/src/_IntlProvider.d.ts +1 -0
  38. package/dist/types/src/_useLocale.d.ts +1 -0
  39. package/dist/{src → types/src}/core/IntlConfig.d.ts +1 -1
  40. package/dist/{core → types/src/core}/TranslationValues.d.ts +6 -5
  41. package/dist/{src → types/src}/core/createBaseTranslator.d.ts +5 -9
  42. package/dist/{src → types/src}/core/createTranslator.d.ts +16 -4
  43. package/dist/types/src/core/createTranslatorImpl.d.ts +16 -0
  44. package/dist/{core → types/src/core}/index.d.ts +14 -9
  45. package/dist/types/src/core/initializeConfig.d.ts +14 -0
  46. package/dist/types/src/core.d.ts +1 -0
  47. package/dist/types/src/react/IntlProvider.d.ts +7 -0
  48. package/dist/{src → types/src}/react/index.d.ts +0 -1
  49. package/dist/types/src/react/useMessages.d.ts +2 -0
  50. package/dist/{src → types/src}/react/useTranslations.d.ts +10 -1
  51. package/dist/{src → types/src}/react/useTranslationsImpl.d.ts +2 -1
  52. package/dist/types/src/react.d.ts +1 -0
  53. package/dist/types/test/core/createFormatter.test.d.ts +1 -0
  54. package/dist/types/test/core/createTranslator.test.d.ts +1 -0
  55. package/dist/types/test/react/IntlProvider.test.d.ts +1 -0
  56. package/dist/types/test/react/useFormatter.test.d.ts +1 -0
  57. package/dist/types/test/react/useLocale.test.d.ts +1 -0
  58. package/dist/types/test/react/useMessages.test.d.ts +1 -0
  59. package/dist/types/test/react/useNow.test.d.ts +1 -0
  60. package/dist/types/test/react/useTimeZone.test.d.ts +1 -0
  61. package/dist/types/test/react/useTranslations.test.d.ts +1 -0
  62. package/dist/types/test/setup.d.ts +1 -0
  63. package/package.json +38 -21
  64. package/react.d.ts +1 -0
  65. package/dist/_virtual/use-intl.esm.js +0 -102
  66. package/dist/_virtual/use-intl.esm.js.map +0 -1
  67. package/dist/core/AbstractIntlMessages.d.ts +0 -9
  68. package/dist/core/DateTimeFormatOptions.d.ts +0 -73
  69. package/dist/core/Formats.d.ts +0 -8
  70. package/dist/core/IntlConfig.d.ts +0 -54
  71. package/dist/core/IntlError.d.ts +0 -14
  72. package/dist/core/MessageFormatCache.d.ts +0 -5
  73. package/dist/core/NumberFormatOptions.d.ts +0 -2
  74. package/dist/core/RelativeTimeFormatOptions.d.ts +0 -5
  75. package/dist/core/TimeZone.d.ts +0 -2
  76. package/dist/core/convertFormatsToIntlMessageFormat.d.ts +0 -11
  77. package/dist/core/createBaseTranslator.d.ts +0 -26
  78. package/dist/core/createFormatter.d.ts +0 -20
  79. package/dist/core/createIntl.d.ts +0 -7
  80. package/dist/core/createTranslator.d.ts +0 -48
  81. package/dist/core/createTranslatorImpl.d.ts +0 -14
  82. package/dist/core/defaults.d.ts +0 -11
  83. package/dist/core/resolveNamespace.d.ts +0 -5
  84. package/dist/core/use-intl.esm.js +0 -34
  85. package/dist/core/use-intl.esm.js.map +0 -1
  86. package/dist/core/use-intl.esm10.js +0 -37
  87. package/dist/core/use-intl.esm10.js.map +0 -1
  88. package/dist/core/use-intl.esm2.js +0 -36
  89. package/dist/core/use-intl.esm2.js.map +0 -1
  90. package/dist/core/use-intl.esm3.js +0 -161
  91. package/dist/core/use-intl.esm3.js.map +0 -1
  92. package/dist/core/use-intl.esm4.js +0 -14
  93. package/dist/core/use-intl.esm4.js.map +0 -1
  94. package/dist/core/use-intl.esm5.js +0 -53
  95. package/dist/core/use-intl.esm5.js.map +0 -1
  96. package/dist/core/use-intl.esm6.js +0 -15
  97. package/dist/core/use-intl.esm6.js.map +0 -1
  98. package/dist/core/use-intl.esm7.js +0 -10
  99. package/dist/core/use-intl.esm7.js.map +0 -1
  100. package/dist/core/use-intl.esm8.js +0 -200
  101. package/dist/core/use-intl.esm8.js.map +0 -1
  102. package/dist/core/use-intl.esm9.js +0 -28
  103. package/dist/core/use-intl.esm9.js.map +0 -1
  104. package/dist/core/utils/MessageKeys.d.ts +0 -5
  105. package/dist/core/utils/NamespaceKeys.d.ts +0 -5
  106. package/dist/core/utils/NestedKeyOf.d.ts +0 -4
  107. package/dist/core/utils/NestedValueOf.d.ts +0 -2
  108. package/dist/core/validateMessages.d.ts +0 -3
  109. package/dist/index.d.ts +0 -2
  110. package/dist/react/IntlContext.d.ts +0 -13
  111. package/dist/react/IntlProvider.d.ts +0 -7
  112. package/dist/react/getInitializedConfig.d.ts +0 -13
  113. package/dist/react/index.d.ts +0 -8
  114. package/dist/react/use-intl.esm.js +0 -22
  115. package/dist/react/use-intl.esm.js.map +0 -1
  116. package/dist/react/use-intl.esm10.js +0 -29
  117. package/dist/react/use-intl.esm10.js.map +0 -1
  118. package/dist/react/use-intl.esm11.js +0 -13
  119. package/dist/react/use-intl.esm11.js.map +0 -1
  120. package/dist/react/use-intl.esm12.js +0 -43
  121. package/dist/react/use-intl.esm12.js.map +0 -1
  122. package/dist/react/use-intl.esm2.js +0 -26
  123. package/dist/react/use-intl.esm2.js.map +0 -1
  124. package/dist/react/use-intl.esm3.js +0 -8
  125. package/dist/react/use-intl.esm3.js.map +0 -1
  126. package/dist/react/use-intl.esm4.js +0 -45
  127. package/dist/react/use-intl.esm4.js.map +0 -1
  128. package/dist/react/use-intl.esm5.js +0 -8
  129. package/dist/react/use-intl.esm5.js.map +0 -1
  130. package/dist/react/use-intl.esm6.js +0 -8
  131. package/dist/react/use-intl.esm6.js.map +0 -1
  132. package/dist/react/use-intl.esm7.js +0 -24
  133. package/dist/react/use-intl.esm7.js.map +0 -1
  134. package/dist/react/use-intl.esm8.js +0 -30
  135. package/dist/react/use-intl.esm8.js.map +0 -1
  136. package/dist/react/use-intl.esm9.js +0 -6
  137. package/dist/react/use-intl.esm9.js.map +0 -1
  138. package/dist/react/useFormatter.d.ts +0 -6
  139. package/dist/react/useIntl.d.ts +0 -6
  140. package/dist/react/useIntlContext.d.ts +0 -10
  141. package/dist/react/useLocale.d.ts +0 -1
  142. package/dist/react/useMessages.d.ts +0 -1
  143. package/dist/react/useNow.d.ts +0 -23
  144. package/dist/react/useTimeZone.d.ts +0 -1
  145. package/dist/react/useTranslations.d.ts +0 -44
  146. package/dist/react/useTranslationsImpl.d.ts +0 -8
  147. package/dist/src/core/AbstractIntlMessages.js +0 -2
  148. package/dist/src/core/AbstractIntlMessages.js.map +0 -1
  149. package/dist/src/core/DateTimeFormatOptions.js +0 -3
  150. package/dist/src/core/DateTimeFormatOptions.js.map +0 -1
  151. package/dist/src/core/Formats.js +0 -2
  152. package/dist/src/core/Formats.js.map +0 -1
  153. package/dist/src/core/IntlConfig.js +0 -2
  154. package/dist/src/core/IntlConfig.js.map +0 -1
  155. package/dist/src/core/IntlError.js +0 -24
  156. package/dist/src/core/IntlError.js.map +0 -1
  157. package/dist/src/core/MessageFormatCache.js +0 -2
  158. package/dist/src/core/MessageFormatCache.js.map +0 -1
  159. package/dist/src/core/NumberFormatOptions.js +0 -2
  160. package/dist/src/core/NumberFormatOptions.js.map +0 -1
  161. package/dist/src/core/RelativeTimeFormatOptions.js +0 -2
  162. package/dist/src/core/RelativeTimeFormatOptions.js.map +0 -1
  163. package/dist/src/core/TimeZone.js +0 -2
  164. package/dist/src/core/TimeZone.js.map +0 -1
  165. package/dist/src/core/TranslationValues.d.ts +0 -5
  166. package/dist/src/core/TranslationValues.js +0 -2
  167. package/dist/src/core/TranslationValues.js.map +0 -1
  168. package/dist/src/core/convertFormatsToIntlMessageFormat.js +0 -47
  169. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +0 -1
  170. package/dist/src/core/createBaseTranslator.js +0 -218
  171. package/dist/src/core/createBaseTranslator.js.map +0 -1
  172. package/dist/src/core/createFormatter.js +0 -163
  173. package/dist/src/core/createFormatter.js.map +0 -1
  174. package/dist/src/core/createIntl.d.ts +0 -7
  175. package/dist/src/core/createIntl.js +0 -11
  176. package/dist/src/core/createIntl.js.map +0 -1
  177. package/dist/src/core/createTranslator.js +0 -23
  178. package/dist/src/core/createTranslator.js.map +0 -1
  179. package/dist/src/core/createTranslatorImpl.d.ts +0 -14
  180. package/dist/src/core/createTranslatorImpl.js +0 -43
  181. package/dist/src/core/createTranslatorImpl.js.map +0 -1
  182. package/dist/src/core/defaults.js +0 -11
  183. package/dist/src/core/defaults.js.map +0 -1
  184. package/dist/src/core/index.d.ts +0 -9
  185. package/dist/src/core/index.js +0 -6
  186. package/dist/src/core/index.js.map +0 -1
  187. package/dist/src/core/resolveNamespace.js +0 -10
  188. package/dist/src/core/resolveNamespace.js.map +0 -1
  189. package/dist/src/core/utils/MessageKeys.js +0 -2
  190. package/dist/src/core/utils/MessageKeys.js.map +0 -1
  191. package/dist/src/core/utils/NamespaceKeys.js +0 -2
  192. package/dist/src/core/utils/NamespaceKeys.js.map +0 -1
  193. package/dist/src/core/utils/NestedKeyOf.js +0 -2
  194. package/dist/src/core/utils/NestedKeyOf.js.map +0 -1
  195. package/dist/src/core/utils/NestedValueOf.js +0 -2
  196. package/dist/src/core/utils/NestedValueOf.js.map +0 -1
  197. package/dist/src/core/validateMessages.js +0 -56
  198. package/dist/src/core/validateMessages.js.map +0 -1
  199. package/dist/src/index.js +0 -3
  200. package/dist/src/index.js.map +0 -1
  201. package/dist/src/react/IntlContext.js +0 -4
  202. package/dist/src/react/IntlContext.js.map +0 -1
  203. package/dist/src/react/IntlProvider.d.ts +0 -7
  204. package/dist/src/react/IntlProvider.js +0 -11
  205. package/dist/src/react/IntlProvider.js.map +0 -1
  206. package/dist/src/react/getInitializedConfig.d.ts +0 -13
  207. package/dist/src/react/getInitializedConfig.js +0 -21
  208. package/dist/src/react/getInitializedConfig.js.map +0 -1
  209. package/dist/src/react/index.js +0 -10
  210. package/dist/src/react/index.js.map +0 -1
  211. package/dist/src/react/useFormatter.js +0 -14
  212. package/dist/src/react/useFormatter.js.map +0 -1
  213. package/dist/src/react/useIntl.d.ts +0 -6
  214. package/dist/src/react/useIntl.js +0 -20
  215. package/dist/src/react/useIntl.js.map +0 -1
  216. package/dist/src/react/useIntlContext.js +0 -12
  217. package/dist/src/react/useIntlContext.js.map +0 -1
  218. package/dist/src/react/useLocale.js +0 -5
  219. package/dist/src/react/useLocale.js.map +0 -1
  220. package/dist/src/react/useMessages.d.ts +0 -1
  221. package/dist/src/react/useMessages.js +0 -5
  222. package/dist/src/react/useMessages.js.map +0 -1
  223. package/dist/src/react/useNow.js +0 -40
  224. package/dist/src/react/useNow.js.map +0 -1
  225. package/dist/src/react/useTimeZone.js +0 -5
  226. package/dist/src/react/useTimeZone.js.map +0 -1
  227. package/dist/src/react/useTranslations.js +0 -21
  228. package/dist/src/react/useTranslations.js.map +0 -1
  229. package/dist/src/react/useTranslationsImpl.js +0 -35
  230. package/dist/src/react/useTranslationsImpl.js.map +0 -1
  231. package/dist/use-intl.cjs.development.js +0 -863
  232. package/dist/use-intl.cjs.development.js.map +0 -1
  233. package/dist/use-intl.cjs.production.min.js +0 -2
  234. package/dist/use-intl.cjs.production.min.js.map +0 -1
  235. package/dist/use-intl.esm.js +0 -13
  236. package/dist/use-intl.esm.js.map +0 -1
  237. package/src/core/AbstractIntlMessages.tsx +0 -10
  238. package/src/core/DateTimeFormatOptions.tsx +0 -130
  239. package/src/core/Formats.tsx +0 -10
  240. package/src/core/IntlConfig.tsx +0 -59
  241. package/src/core/IntlError.tsx +0 -27
  242. package/src/core/MessageFormatCache.tsx +0 -10
  243. package/src/core/NumberFormatOptions.tsx +0 -3
  244. package/src/core/RelativeTimeFormatOptions.tsx +0 -6
  245. package/src/core/TimeZone.tsx +0 -426
  246. package/src/core/TranslationValues.tsx +0 -22
  247. package/src/core/convertFormatsToIntlMessageFormat.tsx +0 -63
  248. package/src/core/createBaseTranslator.tsx +0 -352
  249. package/src/core/createFormatter.tsx +0 -242
  250. package/src/core/createIntl.tsx +0 -13
  251. package/src/core/createTranslator.tsx +0 -111
  252. package/src/core/createTranslatorImpl.tsx +0 -87
  253. package/src/core/defaults.tsx +0 -18
  254. package/src/core/index.tsx +0 -14
  255. package/src/core/resolveNamespace.tsx +0 -12
  256. package/src/core/utils/MessageKeys.tsx +0 -9
  257. package/src/core/utils/NamespaceKeys.tsx +0 -9
  258. package/src/core/utils/NestedKeyOf.tsx +0 -9
  259. package/src/core/utils/NestedValueOf.tsx +0 -12
  260. package/src/core/validateMessages.tsx +0 -77
  261. package/src/index.tsx +0 -2
  262. package/src/react/IntlContext.tsx +0 -12
  263. package/src/react/IntlProvider.tsx +0 -23
  264. package/src/react/getInitializedConfig.tsx +0 -29
  265. package/src/react/index.tsx +0 -10
  266. package/src/react/useFormatter.tsx +0 -19
  267. package/src/react/useIntl.tsx +0 -29
  268. package/src/react/useIntlContext.tsx +0 -16
  269. package/src/react/useLocale.tsx +0 -5
  270. package/src/react/useMessages.tsx +0 -5
  271. package/src/react/useNow.tsx +0 -49
  272. package/src/react/useTimeZone.tsx +0 -5
  273. package/src/react/useTranslations.tsx +0 -103
  274. package/src/react/useTranslationsImpl.tsx +0 -61
  275. /package/dist/{src → types/src}/core/AbstractIntlMessages.d.ts +0 -0
  276. /package/dist/{src → types/src}/core/DateTimeFormatOptions.d.ts +0 -0
  277. /package/dist/{src → types/src}/core/Formats.d.ts +0 -0
  278. /package/dist/{src → types/src}/core/IntlError.d.ts +0 -0
  279. /package/dist/{src → types/src}/core/MessageFormatCache.d.ts +0 -0
  280. /package/dist/{src → types/src}/core/NumberFormatOptions.d.ts +0 -0
  281. /package/dist/{src → types/src}/core/RelativeTimeFormatOptions.d.ts +0 -0
  282. /package/dist/{src → types/src}/core/TimeZone.d.ts +0 -0
  283. /package/dist/{src → types/src}/core/convertFormatsToIntlMessageFormat.d.ts +0 -0
  284. /package/dist/{src → types/src}/core/createFormatter.d.ts +0 -0
  285. /package/dist/{src → types/src}/core/defaults.d.ts +0 -0
  286. /package/dist/{src → types/src}/core/resolveNamespace.d.ts +0 -0
  287. /package/dist/{src → types/src}/core/utils/MessageKeys.d.ts +0 -0
  288. /package/dist/{src → types/src}/core/utils/NamespaceKeys.d.ts +0 -0
  289. /package/dist/{src → types/src}/core/utils/NestedKeyOf.d.ts +0 -0
  290. /package/dist/{src → types/src}/core/utils/NestedValueOf.d.ts +0 -0
  291. /package/dist/{src → types/src}/core/validateMessages.d.ts +0 -0
  292. /package/dist/{src → types/src}/index.d.ts +0 -0
  293. /package/dist/{src → types/src}/react/IntlContext.d.ts +0 -0
  294. /package/dist/{src → types/src}/react/useFormatter.d.ts +0 -0
  295. /package/dist/{src → types/src}/react/useIntlContext.d.ts +0 -0
  296. /package/dist/{src → types/src}/react/useLocale.d.ts +0 -0
  297. /package/dist/{src → types/src}/react/useNow.d.ts +0 -0
  298. /package/dist/{src → types/src}/react/useTimeZone.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm8.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport MessageFormatCache from './MessageFormatCache';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nexport function getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n};\n\nfunction getPlainMessage(candidate: string, values?: unknown) {\n if (values) return undefined;\n\n const unescapedMessage = candidate.replace(/'([{}])/gi, '$1');\n\n // Placeholders can be in the message if there are default values,\n // or if the user has forgotten to provide values. In the latter\n // case we need to compile the message to receive an error.\n const hasPlaceholders = /<|{/.test(unescapedMessage);\n\n if (!hasPlaceholders) {\n return unescapedMessage;\n }\n\n return undefined;\n}\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messageFormatCache,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n function joinPath(parts: Array<string | undefined>) {\n return parts.filter((part) => part != null).join('.');\n }\n\n const cacheKey = joinPath([locale, namespace, key, String(message)]);\n\n let messageFormat: IntlMessageFormat;\n if (messageFormatCache?.has(cacheKey)) {\n messageFormat = messageFormatCache.get(cacheKey)!;\n } else {\n if (typeof message === 'object') {\n let code, errorMessage;\n if (Array.isArray(message)) {\n code = IntlErrorCode.INVALID_MESSAGE;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;\n }\n } else {\n code = IntlErrorCode.INSUFFICIENT_PATH;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an object, but only strings are supported. Use a \\`.\\` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages`;\n }\n }\n\n return getFallbackFromErrorAndNotify(key, code, errorMessage);\n }\n\n // Hot path that avoids creating an `IntlMessageFormat` instance\n const plainMessage = getPlainMessage(message as string, values);\n if (plainMessage) return plainMessage;\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n messageFormatCache?.set(cacheKey, messageFormat);\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"names":["resolvePath","messages","key","namespace","Error","process","env","NODE_ENV","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","_ref","_ref$onError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","getPlainMessage","candidate","unescapedMessage","replace","hasPlaceholders","test","createBaseTranslator","_ref2","defaultTranslationValues","globalFormats","formats","_ref2$getMessageFallb","getMessageFallback","defaultGetMessageFallback","locale","messageFormatCache","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","joinPath","parts","filter","join","cacheKey","String","messageFormat","has","get","errorMessage","Array","isArray","INVALID_MESSAGE","INSUFFICIENT_PATH","plainMessage","IntlMessageFormat","convertFormatsToIntlMessageFormat","_extends","set","formattedMessage","format","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAqBA,SAASA,WAAWA,CAClBC,QAA0C,EAC1CC,GAAW,EACXC,SAAkB,EAAA;EAElB,IAAI,CAACF,QAAQ,EAAE;AACb,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAAA,4BAAA,GACHJ,SAAS,GAAA,IAAA,GACvCK,SAAS,CACd,CAAA;AACF,GAAA;EAED,IAAIC,OAAO,GAAGR,QAAQ,CAAA;EAEtBC,GAAG,CAACQ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AG,GAClBC,OAAAA,IAAAA,SAAS,GAAkBA,aAAAA,GAAAA,SAAS,GAAO,GAAA,GAAA,UAC7C,CACAK,GAAAA,qFAAAA,GAAAA,SAAS,CACd,CAAA;AACF,KAAA;AAED,IAAA,OAAOgB,MAAM,CAAA;AACf,GAAA;EAEAyD,WAAW,CAACC,IAAI,GAAGxB,eAAe,CAAA;EAElCuB,WAAW,CAACE,GAAG,GAAG;AAEhBjF,EAAAA,GAAW,EACJ;IACP,IAAIoD,eAAe,YAAYnB,SAAS,EAAE;AACxC;AACA,MAAA,OAAOe,kBAAkB,CAAC;AACxBjB,QAAAA,KAAK,EAAEqB,eAAe;AACtBpD,QAAAA,GAAG,EAAHA,GAAG;AACHC,QAAAA,SAAS,EAATA,SAAAA;AACD,OAAA,CAAC,CAAA;AACH,KAAA;IACD,IAAMF,QAAQ,GAAGqD,eAAe,CAAA;IAEhC,IAAI;AACF,MAAA,OAAOtD,WAAW,CAACC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,CAAC,CAAA;KAC7C,CAAC,OAAO8B,KAAK,EAAE;MACd,OAAOuB,6BAA6B,CAClCtD,GAAG,EACHkC,aAAa,CAACC,eAAe,EAC5BJ,KAAe,CAACxB,OAAO,CACzB,CAAA;AACF,KAAA;GACF,CAAA;AAED,EAAA,OAAOwE,WAAW,CAAA;AACpB;;;;"}
@@ -1,28 +0,0 @@
1
- import IntlError, { IntlErrorCode } from './use-intl.esm.js';
2
-
3
- function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
4
- Object.entries(messages).forEach(function (_ref) {
5
- var key = _ref[0],
6
- messageOrMessages = _ref[1];
7
- if (key.includes('.')) {
8
- var keyLabel = key;
9
- if (parentPath) keyLabel += " (at " + parentPath + ")";
10
- invalidKeyLabels.push(keyLabel);
11
- }
12
- if (messageOrMessages != null && typeof messageOrMessages === 'object') {
13
- validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
14
- return part != null;
15
- }).join('.'));
16
- }
17
- });
18
- }
19
- function validateMessages(messages, onError) {
20
- var invalidKeyLabels = [];
21
- validateMessagesSegment(messages, invalidKeyLabels);
22
- if (invalidKeyLabels.length > 0) {
23
- onError(new IntlError(IntlErrorCode.INVALID_KEY, process.env.NODE_ENV !== 'production' ? "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ') + "\n\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n" : undefined));
24
- }
25
- }
26
-
27
- export { validateMessages as default };
28
- //# sourceMappingURL=use-intl.esm9.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm9.js","sources":["../../src/core/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n process.env.NODE_ENV !== 'production'\n ? `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}\n\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n`\n : undefined\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","_ref","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY","process","env","NODE_ENV","undefined"],"mappings":";;AAGA,SAASA,uBAAuBA,CAC9BC,QAA8B,EAC9BC,gBAA+B,EAC/BC,UAAmB,EAAA;EAEnBC,MAAM,CAACC,OAAO,CAACJ,QAAQ,CAAC,CAACK,OAAO,CAAC,UAAAC,IAAA,EAA6B;IAAA,IAA3BC,GAAG,GAAAD,IAAA,CAAA,CAAA,CAAA;AAAEE,MAAAA,iBAAiB,GAAAF,IAAA,CAAA,CAAA,CAAA,CAAA;AACvD,IAAA,IAAIC,GAAG,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;MACrB,IAAIC,QAAQ,GAAGH,GAAG,CAAA;AAClB,MAAA,IAAIL,UAAU,EAAEQ,QAAQ,IAAA,OAAA,GAAYR,UAAU,GAAG,GAAA,CAAA;AACjDD,MAAAA,gBAAgB,CAACU,IAAI,CAACD,QAAQ,CAAC,CAAA;AAChC,KAAA;IAED,IAAIF,iBAAiB,IAAI,IAAI,IAAI,OAAOA,iBAAiB,KAAK,QAAQ,EAAE;AACtET,MAAAA,uBAAuB,CACrBS,iBAAiB,EACjBP,gBAAgB,EAChB,CAACC,UAAU,EAAEK,GAAG,CAAC,CAACK,MAAM,CAAC,UAACC,IAAI,EAAA;QAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,OAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAA;AACF,KAAA;AACH,GAAC,CAAC,CAAA;AACJ,CAAA;AAEc,SAAUC,gBAAgBA,CACtCf,QAA8B,EAC9BgB,OAAmC,EAAA;EAEnC,IAAMf,gBAAgB,GAAkB,EAAE,CAAA;AAC1CF,EAAAA,uBAAuB,CAACC,QAAQ,EAAEC,gBAAgB,CAAC,CAAA;AAEnD,EAAA,IAAIA,gBAAgB,CAACgB,MAAM,GAAG,CAAC,EAAE;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAS,CACXC,aAAa,CAACC,WAAW,EACzBC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAI/BtB,2JAAAA,IAAAA,gBAAgB,CAACgB,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,MAC1C,CAAKhB,GAAAA,IAAAA,GAAAA,gBAAgB,CAACa,IAAI,CAAC,IAAI,CAAC,GA+BhCU,4gBAAAA,GAAAA,SAAS,CACd,CACF,CAAA;AACF,GAAA;AACH;;;;"}
@@ -1,5 +0,0 @@
1
- import NestedValueOf from './NestedValueOf';
2
- type MessageKeys<ObjectType, Keys extends string> = {
3
- [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? Property : never;
4
- }[Keys];
5
- export default MessageKeys;
@@ -1,5 +0,0 @@
1
- import NestedValueOf from './NestedValueOf';
2
- type NamespaceKeys<ObjectType, Keys extends string> = {
3
- [Property in Keys]: NestedValueOf<ObjectType, Property> extends string ? never : Property;
4
- }[Keys];
5
- export default NamespaceKeys;
@@ -1,4 +0,0 @@
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 +0,0 @@
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 +0,0 @@
1
- import AbstractIntlMessages from './AbstractIntlMessages';
2
- import IntlError from './IntlError';
3
- export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './core';
2
- export * from './react';
@@ -1,13 +0,0 @@
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 +0,0 @@
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, ...props }: Props): JSX.Element;
7
- export {};
@@ -1,13 +0,0 @@
1
- import IntlConfig from '../core/IntlConfig';
2
- /**
3
- * Enhances the incoming props with defaults.
4
- */
5
- export default function getInitializedConfig<Props extends Omit<IntlConfig, 'children'>>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
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
- };
@@ -1,8 +0,0 @@
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,22 +0,0 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import React, { useState } from 'react';
3
- import IntlContext from './use-intl.esm9.js';
4
- import getInitializedConfig from './use-intl.esm10.js';
5
-
6
- var _excluded = ["children"];
7
- function IntlProvider(_ref) {
8
- var children = _ref.children,
9
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
10
- var _useState = useState(function () {
11
- return new Map();
12
- }),
13
- messageFormatCache = _useState[0];
14
- return React.createElement(IntlContext.Provider, {
15
- value: _extends({}, getInitializedConfig(props), {
16
- messageFormatCache: messageFormatCache
17
- })
18
- }, children);
19
- }
20
-
21
- export { IntlProvider as default };
22
- //# sourceMappingURL=use-intl.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm.js","sources":["../../src/react/IntlProvider.tsx"],"sourcesContent":["import React, {ReactNode, useState} from 'react';\nimport IntlConfig from '../core/IntlConfig';\nimport IntlContext from './IntlContext';\nimport getInitializedConfig from './getInitializedConfig';\n\ntype Props = IntlConfig & {\n children: ReactNode;\n};\n\nexport default function IntlProvider({children, ...props}: Props) {\n const [messageFormatCache] = useState(() => new Map());\n\n return (\n <IntlContext.Provider\n value={{\n ...getInitializedConfig(props),\n messageFormatCache\n }}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n"],"names":["IntlProvider","_ref","children","props","_objectWithoutPropertiesLoose","_excluded","_useState","useState","Map","messageFormatCache","React","createElement","IntlContext","Provider","value","_extends","getInitializedConfig"],"mappings":";;;;;;AASc,SAAUA,YAAYA,CAAAC,IAAA,EAA4B;AAAA,EAAA,IAA1BC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;AAAKC,IAAAA,KAAK,GAAAC,6BAAA,CAAAH,IAAA,EAAAI,SAAA,CAAA,CAAA;EACtD,IAAAC,SAAA,GAA6BC,QAAQ,CAAC,YAAA;MAAA,OAAM,IAAIC,GAAG,EAAE,CAAA;KAAC,CAAA;AAA/CC,IAAAA,kBAAkB,GAAAH,SAAA,CAAA,CAAA,CAAA,CAAA;AAEzB,EAAA,OACEI,KAAC,CAAAC,aAAA,CAAAC,WAAW,CAACC,QAAQ,EAAA;AACnBC,IAAAA,KAAK,EAAAC,QAAA,CAAA,EAAA,EACAC,oBAAoB,CAACb,KAAK,CAAC,EAAA;AAC9BM,MAAAA,kBAAkB,EAAlBA,kBAAAA;AAAkB,KAAA,CAAA;GAGnB,EAAAP,QAAQ,CACY,CAAA;AAE3B;;;;"}
@@ -1,29 +0,0 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm6.js';
3
- import validateMessages from '../core/use-intl.esm9.js';
4
-
5
- var _excluded = ["getMessageFallback", "messages", "onError"];
6
- /**
7
- * Enhances the incoming props with defaults.
8
- */
9
- function getInitializedConfig(_ref) {
10
- var getMessageFallback = _ref.getMessageFallback,
11
- messages = _ref.messages,
12
- onError = _ref.onError,
13
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
14
- var finalOnError = onError || defaultOnError;
15
- var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
16
- if (process.env.NODE_ENV !== 'production') {
17
- if (messages) {
18
- validateMessages(messages, finalOnError);
19
- }
20
- }
21
- return _extends({}, rest, {
22
- messages: messages,
23
- onError: finalOnError,
24
- getMessageFallback: finalGetMessageFallback
25
- });
26
- }
27
-
28
- export { getInitializedConfig as default };
29
- //# sourceMappingURL=use-intl.esm10.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm10.js","sources":["../../src/react/getInitializedConfig.tsx"],"sourcesContent":["import IntlConfig from '../core/IntlConfig';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/defaults';\nimport validateMessages from '../core/validateMessages';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function getInitializedConfig<\n // This is a generic to allow for stricter typing. E.g.\n // the RSC integration always provides a `now` value.\n Props extends Omit<IntlConfig, 'children'>\n>({getMessageFallback, messages, onError, ...rest}: Props) {\n const finalOnError = onError || defaultOnError;\n const finalGetMessageFallback =\n getMessageFallback || defaultGetMessageFallback;\n\n if (process.env.NODE_ENV !== 'production') {\n if (messages) {\n validateMessages(messages, finalOnError);\n }\n }\n\n return {\n ...rest,\n messages,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback\n };\n}\n"],"names":["getInitializedConfig","_ref","getMessageFallback","messages","onError","rest","_objectWithoutPropertiesLoose","_excluded","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages","_extends"],"mappings":";;;;;AAIA;;AAEG;AACqB,SAAAA,oBAAoBA,CAAAC,IAAA,EAIa;AAAA,EAAA,IAAtDC,kBAAkB,GAAAD,IAAA,CAAlBC,kBAAkB;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAEC,OAAO,GAAAH,IAAA,CAAPG,OAAO;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAL,IAAA,EAAAM,SAAA,CAAA,CAAA;AAC/C,EAAA,IAAMC,YAAY,GAAGJ,OAAO,IAAIK,cAAc,CAAA;AAC9C,EAAA,IAAMC,uBAAuB,GAC3BR,kBAAkB,IAAIS,yBAAyB,CAAA;AAEjD,EAAA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;AACzC,IAAA,IAAIX,QAAQ,EAAE;AACZY,MAAAA,gBAAgB,CAACZ,QAAQ,EAAEK,YAAY,CAAC,CAAA;AACzC,KAAA;AACF,GAAA;EAED,OAAAQ,QAAA,KACKX,IAAI,EAAA;AACPF,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,OAAO,EAAEI,YAAY;AACrBN,IAAAA,kBAAkB,EAAEQ,uBAAAA;AAAuB,GAAA,CAAA,CAAA;AAE/C;;;;"}
@@ -1,13 +0,0 @@
1
- import { useContext } from 'react';
2
- import IntlContext from './use-intl.esm9.js';
3
-
4
- function useIntlContext() {
5
- var context = useContext(IntlContext);
6
- if (!context) {
7
- throw new Error(process.env.NODE_ENV !== 'production' ? 'No intl context found. Have you configured the provider?' : undefined);
8
- }
9
- return context;
10
- }
11
-
12
- export { useIntlContext as default };
13
- //# sourceMappingURL=use-intl.esm11.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm11.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","process","env","NODE_ENV","undefined"],"mappings":";;;AAGc,SAAUA,cAAcA,GAAA;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAW,CAAC,CAAA;EAEvC,IAAI,CAACF,OAAO,EAAE;AACZ,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,0DAA0D,GAC1DC,SAAS,CACd,CAAA;AACF,GAAA;AAED,EAAA,OAAOP,OAAO,CAAA;AAChB;;;;"}
@@ -1,43 +0,0 @@
1
- import { useMemo } from 'react';
2
- import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm8.js';
3
- import resolveNamespace from '../core/use-intl.esm7.js';
4
- import useIntlContext from './use-intl.esm11.js';
5
-
6
- function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
7
- var _useIntlContext = useIntlContext(),
8
- defaultTranslationValues = _useIntlContext.defaultTranslationValues,
9
- globalFormats = _useIntlContext.formats,
10
- getMessageFallback = _useIntlContext.getMessageFallback,
11
- locale = _useIntlContext.locale,
12
- messageFormatCache = _useIntlContext.messageFormatCache,
13
- onError = _useIntlContext.onError,
14
- timeZone = _useIntlContext.timeZone;
15
- // The `namespacePrefix` is part of the type system.
16
- // See the comment in the hook invocation.
17
- allMessages = allMessages[namespacePrefix];
18
- namespace = resolveNamespace(namespace, namespacePrefix);
19
- var messagesOrError = useMemo(function () {
20
- return getMessagesOrError({
21
- messages: allMessages,
22
- namespace: namespace,
23
- onError: onError
24
- });
25
- }, [allMessages, namespace, onError]);
26
- var translate = useMemo(function () {
27
- return createBaseTranslator({
28
- messageFormatCache: messageFormatCache,
29
- getMessageFallback: getMessageFallback,
30
- messagesOrError: messagesOrError,
31
- defaultTranslationValues: defaultTranslationValues,
32
- namespace: namespace,
33
- onError: onError,
34
- formats: globalFormats,
35
- locale: locale,
36
- timeZone: timeZone
37
- });
38
- }, [messageFormatCache, getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
39
- return translate;
40
- }
41
-
42
- export { useTranslationsImpl as default };
43
- //# sourceMappingURL=use-intl.esm12.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm12.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator, {\n getMessagesOrError\n} from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n messageFormatCache,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n messageFormatCache,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n messageFormatCache,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","_useIntlContext","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","messageFormatCache","onError","timeZone","resolveNamespace","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator"],"mappings":";;;;;AASwB,SAAAA,mBAAmBA,CAGzCC,WAAqB,EAAEC,SAAoB,EAAEC,eAAuB,EAAA;AACpE,EAAA,IAAAC,eAAA,GAQIC,cAAc,EAAE;IAPlBC,wBAAwB,GAAAF,eAAA,CAAxBE,wBAAwB;IACfC,aAAa,GAAAH,eAAA,CAAtBI,OAAO;IACPC,kBAAkB,GAAAL,eAAA,CAAlBK,kBAAkB;IAClBC,MAAM,GAAAN,eAAA,CAANM,MAAM;IACNC,kBAAkB,GAAAP,eAAA,CAAlBO,kBAAkB;IAClBC,OAAO,GAAAR,eAAA,CAAPQ,OAAO;IACPC,QAAQ,GAAAT,eAAA,CAARS,QAAQ,CAAA;AAGV;AACA;AACAZ,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAe,CAAa,CAAA;AACtDD,EAAAA,SAAS,GAAGY,gBAAgB,CAACZ,SAAS,EAAEC,eAAe,CAAc,CAAA;EAErE,IAAMY,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAEjB,WAAW;AAAEC,MAAAA,SAAS,EAATA,SAAS;AAAEU,MAAAA,OAAO,EAAPA,OAAAA;AAAO,KAAC,CAAC,CAAA;AAAA,GAAA,EACrE,CAACX,WAAW,EAAEC,SAAS,EAAEU,OAAO,CAAC,CAClC,CAAA;EAED,IAAMO,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;AACnBT,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBF,MAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBM,MAAAA,eAAe,EAAfA,eAAe;AACfT,MAAAA,wBAAwB,EAAxBA,wBAAwB;AACxBJ,MAAAA,SAAS,EAATA,SAAS;AACTU,MAAAA,OAAO,EAAPA,OAAO;AACPJ,MAAAA,OAAO,EAAED,aAAa;AACtBG,MAAAA,MAAM,EAANA,MAAM;AACNG,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;AAAA,GAAA,EACJ,CACEF,kBAAkB,EAClBF,kBAAkB,EAClBM,eAAe,EACfT,wBAAwB,EACxBJ,SAAS,EACTU,OAAO,EACPL,aAAa,EACbG,MAAM,EACNG,QAAQ,CACT,CACF,CAAA;AAED,EAAA,OAAOM,SAAS,CAAA;AAClB;;;;"}
@@ -1,26 +0,0 @@
1
- import useIntlContext from './use-intl.esm11.js';
2
- import useTranslationsImpl from './use-intl.esm12.js';
3
-
4
- /**
5
- * Translates messages from the given namespace by using the ICU syntax.
6
- * See https://formatjs.io/docs/core-concepts/icu-syntax.
7
- *
8
- * If no namespace is provided, all available messages are returned.
9
- * The namespace can also indicate nesting by using a dot
10
- * (e.g. `namespace.Component`).
11
- */
12
- function useTranslations(namespace) {
13
- var context = useIntlContext();
14
- var messages = context.messages;
15
- // We have to wrap the actual hook so the type inference for the optional
16
- // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
17
- // The prefix ("!") is arbitrary.
18
- return useTranslationsImpl({
19
- '!': messages
20
- },
21
- // @ts-expect-error
22
- namespace ? "!." + namespace : '!', '!');
23
- }
24
-
25
- export { useTranslations as default };
26
- //# sourceMappingURL=use-intl.esm2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm2.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-expect-error\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;AACqB,SAAAA,eAAeA,CAMrCC,SAAqB,EAAA;AA6DrB,EAAA,IAAMC,OAAO,GAAGC,cAAc,EAAE,CAAA;AAChC,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAwB,CAAA;AAEjD;AACA;AACA;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAA,GAAG,EAAED,QAAAA;GAAS;AACf;AACAH,EAAAA,SAAS,UAAQA,SAAS,GAAK,GAAG,EAClC,GAAG,CACJ,CAAA;AACH;;;;"}
@@ -1,8 +0,0 @@
1
- import useIntlContext from './use-intl.esm11.js';
2
-
3
- function useLocale() {
4
- return useIntlContext().locale;
5
- }
6
-
7
- export { useLocale as default };
8
- //# sourceMappingURL=use-intl.esm3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAASA,GAAA;AAC/B,EAAA,OAAOC,cAAc,EAAE,CAACC,MAAM,CAAA;AAChC;;;;"}
@@ -1,45 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import useIntlContext from './use-intl.esm11.js';
3
-
4
- function getNow() {
5
- return new Date();
6
- }
7
- /**
8
- * Reading the current date via `new Date()` in components should be avoided, as
9
- * it causes components to be impure and can lead to flaky tests. Instead, this
10
- * hook can be used.
11
- *
12
- * By default, it returns the time when the component mounts. If `updateInterval`
13
- * is specified, the value will be updated based on the interval.
14
- *
15
- * You can however also return a static value from this hook, if you
16
- * configure the `now` parameter on the context provider. Note however,
17
- * that if `updateInterval` is configured in this case, the component
18
- * will initialize with the global value, but will afterwards update
19
- * continuously based on the interval.
20
- *
21
- * For unit tests, this can be mocked to a constant value. For end-to-end
22
- * testing, an environment parameter can be passed to the `now` parameter
23
- * of the provider to mock this to a static value.
24
- */
25
- function useNow(options) {
26
- var updateInterval = options == null ? void 0 : options.updateInterval;
27
- var _useIntlContext = useIntlContext(),
28
- globalNow = _useIntlContext.now;
29
- var _useState = useState(globalNow || getNow()),
30
- now = _useState[0],
31
- setNow = _useState[1];
32
- useEffect(function () {
33
- if (!updateInterval) return;
34
- var intervalId = setInterval(function () {
35
- setNow(getNow());
36
- }, updateInterval);
37
- return function () {
38
- clearInterval(intervalId);
39
- };
40
- }, [globalNow, updateInterval]);
41
- return now;
42
- }
43
-
44
- export { useNow as default };
45
- //# sourceMappingURL=use-intl.esm4.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","_useIntlContext","useIntlContext","globalNow","now","_useState","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAMA,GAAA;EACb,OAAO,IAAIC,IAAI,EAAE,CAAA;AACnB,CAAA;AAEA;;;;;;;;;;;;;;;;;AAiBG;AACqB,SAAAC,MAAMA,CAACC,OAAiB,EAAA;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAO,IAAPA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAc,CAAA;AAE9C,EAAA,IAAAC,eAAA,GAAyBC,cAAc,EAAE;IAA7BC,SAAS,GAAAF,eAAA,CAAdG,GAAG,CAAA;EACV,IAAAC,SAAA,GAAsBC,QAAQ,CAACH,SAAS,IAAIP,MAAM,EAAE,CAAC;AAA9CQ,IAAAA,GAAG,GAAAC,SAAA,CAAA,CAAA,CAAA;AAAEE,IAAAA,MAAM,GAAAF,SAAA,CAAA,CAAA,CAAA,CAAA;AAElBG,EAAAA,SAAS,CAAC,YAAK;IACb,IAAI,CAACR,cAAc,EAAE,OAAA;AAErB,IAAA,IAAMS,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACX,MAAM,EAAE,CAAC,CAAA;KACjB,EAAEI,cAAc,CAAC,CAAA;AAElB,IAAA,OAAO,YAAK;MACVW,aAAa,CAACF,UAAU,CAAC,CAAA;KAC1B,CAAA;AACH,GAAC,EAAE,CAACN,SAAS,EAAEH,cAAc,CAAC,CAAC,CAAA;AAE/B,EAAA,OAAOI,GAAG,CAAA;AACZ;;;;"}
@@ -1,8 +0,0 @@
1
- import useIntlContext from './use-intl.esm11.js';
2
-
3
- function useTimeZone() {
4
- return useIntlContext().timeZone;
5
- }
6
-
7
- export { useTimeZone as default };
8
- //# sourceMappingURL=use-intl.esm5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAWA,GAAA;AACjC,EAAA,OAAOC,cAAc,EAAE,CAACC,QAAQ,CAAA;AAClC;;;;"}
@@ -1,8 +0,0 @@
1
- import useIntlContext from './use-intl.esm11.js';
2
-
3
- function useMessages() {
4
- return useIntlContext().messages;
5
- }
6
-
7
- export { useMessages as default };
8
- //# sourceMappingURL=use-intl.esm6.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useMessages.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useMessages() {\n return useIntlContext().messages;\n}\n"],"names":["useMessages","useIntlContext","messages"],"mappings":";;AAEc,SAAUA,WAAWA,GAAA;AACjC,EAAA,OAAOC,cAAc,EAAE,CAACC,QAAQ,CAAA;AAClC;;;;"}
@@ -1,24 +0,0 @@
1
- import { useMemo } from 'react';
2
- import createFormatter from '../core/use-intl.esm3.js';
3
- import useIntlContext from './use-intl.esm11.js';
4
-
5
- function useFormatter() {
6
- var _useIntlContext = useIntlContext(),
7
- formats = _useIntlContext.formats,
8
- locale = _useIntlContext.locale,
9
- globalNow = _useIntlContext.now,
10
- onError = _useIntlContext.onError,
11
- timeZone = _useIntlContext.timeZone;
12
- return useMemo(function () {
13
- return createFormatter({
14
- formats: formats,
15
- locale: locale,
16
- now: globalNow,
17
- onError: onError,
18
- timeZone: timeZone
19
- });
20
- }, [formats, globalNow, locale, onError, timeZone]);
21
- }
22
-
23
- export { useFormatter as default };
24
- //# sourceMappingURL=use-intl.esm7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/useFormatter.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createFormatter from '../core/createFormatter';\nimport useIntlContext from './useIntlContext';\n\nexport default function useFormatter() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createFormatter({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["useFormatter","_useIntlContext","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createFormatter"],"mappings":";;;;AAIc,SAAUA,YAAYA,GAAA;AAClC,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;AAEzD,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,eAAe,CAAC;AACdP,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
@@ -1,30 +0,0 @@
1
- import { useMemo } from 'react';
2
- import createIntl from '../core/use-intl.esm4.js';
3
- import useIntlContext from './use-intl.esm11.js';
4
-
5
- var hasWarned = false;
6
- /** @deprecated Switch to `useFormatter` instead. */
7
- function useIntl() {
8
- var _useIntlContext = useIntlContext(),
9
- formats = _useIntlContext.formats,
10
- locale = _useIntlContext.locale,
11
- globalNow = _useIntlContext.now,
12
- onError = _useIntlContext.onError,
13
- timeZone = _useIntlContext.timeZone;
14
- if (!hasWarned) {
15
- hasWarned = true;
16
- console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
17
- }
18
- return useMemo(function () {
19
- return createIntl({
20
- formats: formats,
21
- locale: locale,
22
- now: globalNow,
23
- onError: onError,
24
- timeZone: timeZone
25
- });
26
- }, [formats, globalNow, locale, onError, timeZone]);
27
- }
28
-
29
- export { useIntl as default };
30
- //# sourceMappingURL=use-intl.esm8.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nlet hasWarned = false;\n\n/** @deprecated Switch to `useFormatter` instead. */\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n '`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.'\n );\n }\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["hasWarned","useIntl","_useIntlContext","useIntlContext","formats","locale","globalNow","now","onError","timeZone","console","warn","useMemo","createIntl"],"mappings":";;;;AAIA,IAAIA,SAAS,GAAG,KAAK,CAAA;AAErB;AACc,SAAUC,OAAOA,GAAA;AAC7B,EAAA,IAAAC,eAAA,GAA6DC,cAAc,EAAE;IAAtEC,OAAO,GAAAF,eAAA,CAAPE,OAAO;IAAEC,MAAM,GAAAH,eAAA,CAANG,MAAM;IAAOC,SAAS,GAAAJ,eAAA,CAAdK,GAAG;IAAaC,OAAO,GAAAN,eAAA,CAAPM,OAAO;IAAEC,QAAQ,GAAAP,eAAA,CAARO,QAAQ,CAAA;EAEzD,IAAI,CAACT,SAAS,EAAE;AACdA,IAAAA,SAAS,GAAG,IAAI,CAAA;AAChBU,IAAAA,OAAO,CAACC,IAAI,CACV,6GAA6G,CAC9G,CAAA;AACF,GAAA;AAED,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTT,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,MAAM,EAANA,MAAM;AACNE,MAAAA,GAAG,EAAED,SAAS;AACdE,MAAAA,OAAO,EAAPA,OAAO;AACPC,MAAAA,QAAQ,EAARA,QAAAA;AACD,KAAA,CAAC,CAAA;GACJ,EAAA,CAACL,OAAO,EAAEE,SAAS,EAAED,MAAM,EAAEG,OAAO,EAAEC,QAAQ,CAAC,CAChD,CAAA;AACH;;;;"}
@@ -1,6 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- var IntlContext = /*#__PURE__*/createContext(undefined);
4
-
5
- export { IntlContext as default };
6
- //# sourceMappingURL=use-intl.esm9.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport {InitializedIntlConfig} from '../core/IntlConfig';\nimport MessageFormatCache from '../core/MessageFormatCache';\n\nconst IntlContext = createContext<\n | (InitializedIntlConfig & {\n messageFormatCache?: MessageFormatCache;\n })\n | undefined\n>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAIA,IAAMA,WAAW,gBAAGC,aAAa,CAK/BC,SAAS;;;;"}
@@ -1,6 +0,0 @@
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,6 +0,0 @@
1
- /** @deprecated Switch to `useFormatter` instead. */
2
- export default function useIntl(): {
3
- formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
4
- formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
5
- formatRelativeTime: (date: number | Date, nowOrOptions?: number | Date | import("../core/RelativeTimeFormatOptions").default | undefined) => string;
6
- };
@@ -1,10 +0,0 @@
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 +0,0 @@
1
- export default function useLocale(): string;
@@ -1 +0,0 @@
1
- export default function useMessages(): import("../core/AbstractIntlMessages").default | undefined;
@@ -1,23 +0,0 @@
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 +0,0 @@
1
- export default function useTimeZone(): import("../core/TimeZone").default | undefined;