use-intl 2.20.0 → 3.0.0-beta.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 (273) hide show
  1. package/core.d.ts +1 -0
  2. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js +102 -0
  3. package/dist/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
  4. package/dist/core/IntlError.esm.js +33 -0
  5. package/dist/core/IntlError.esm.js.map +1 -0
  6. package/dist/core/TranslationValues.d.ts +1 -0
  7. package/dist/core/convertFormatsToIntlMessageFormat.esm.js +37 -0
  8. package/dist/core/convertFormatsToIntlMessageFormat.esm.js.map +1 -0
  9. package/dist/core/createBaseTranslator.d.ts +3 -8
  10. package/dist/core/createBaseTranslator.esm.js +210 -0
  11. package/dist/core/createBaseTranslator.esm.js.map +1 -0
  12. package/dist/core/createFormatter.esm.js +138 -0
  13. package/dist/core/createFormatter.esm.js.map +1 -0
  14. package/dist/core/createIntl.esm.js +14 -0
  15. package/dist/core/createIntl.esm.js.map +1 -0
  16. package/dist/core/createTranslator.d.ts +2 -3
  17. package/dist/core/createTranslator.esm.js +37 -0
  18. package/dist/core/createTranslator.esm.js.map +1 -0
  19. package/dist/core/createTranslatorImpl.d.ts +2 -3
  20. package/dist/core/createTranslatorImpl.esm.js +50 -0
  21. package/dist/core/createTranslatorImpl.esm.js.map +1 -0
  22. package/dist/core/defaults.esm.js +15 -0
  23. package/dist/core/defaults.esm.js.map +1 -0
  24. package/dist/core/index.d.ts +8 -1
  25. package/dist/core/initializeConfig.d.ts +13 -0
  26. package/dist/core/initializeConfig.esm.js +29 -0
  27. package/dist/core/initializeConfig.esm.js.map +1 -0
  28. package/dist/core/resolveNamespace.esm.js +10 -0
  29. package/dist/core/resolveNamespace.esm.js.map +1 -0
  30. package/dist/core/use-intl.esm10.js +23 -32
  31. package/dist/core/use-intl.esm10.js.map +1 -1
  32. package/dist/core/use-intl.esm11.js +10 -0
  33. package/dist/core/use-intl.esm11.js.map +1 -0
  34. package/dist/core/use-intl.esm2.js +204 -31
  35. package/dist/core/use-intl.esm2.js.map +1 -1
  36. package/dist/core/use-intl.esm3.js +31 -132
  37. package/dist/core/use-intl.esm3.js.map +1 -1
  38. package/dist/core/use-intl.esm4.js +1 -1
  39. package/dist/core/use-intl.esm5.js +19 -43
  40. package/dist/core/use-intl.esm5.js.map +1 -1
  41. package/dist/core/use-intl.esm6.js +134 -11
  42. package/dist/core/use-intl.esm6.js.map +1 -1
  43. package/dist/core/use-intl.esm7.js +29 -192
  44. package/dist/core/use-intl.esm7.js.map +1 -1
  45. package/dist/core/use-intl.esm8.js +10 -5
  46. package/dist/core/use-intl.esm8.js.map +1 -1
  47. package/dist/core/use-intl.esm9.js +44 -22
  48. package/dist/core/use-intl.esm9.js.map +1 -1
  49. package/dist/core/validateMessages.esm.js +28 -0
  50. package/dist/core/validateMessages.esm.js.map +1 -0
  51. package/dist/core.cjs.development.js +93 -0
  52. package/dist/core.cjs.development.js.map +1 -0
  53. package/dist/core.cjs.production.min.js +2 -0
  54. package/dist/core.cjs.production.min.js.map +1 -0
  55. package/dist/core.d.ts +1 -0
  56. package/dist/core.esm.js +7 -0
  57. package/dist/core.esm.js.map +1 -0
  58. package/dist/core.js +8 -0
  59. package/dist/createIntl-34d4281e.js +592 -0
  60. package/dist/createIntl-34d4281e.js.map +1 -0
  61. package/dist/createIntl-bc325740.js +2 -0
  62. package/dist/createIntl-bc325740.js.map +1 -0
  63. package/dist/react/IntlContext.esm.js +6 -0
  64. package/dist/react/IntlContext.esm.js.map +1 -0
  65. package/dist/react/IntlProvider.d.ts +1 -1
  66. package/dist/react/IntlProvider.esm.js +22 -0
  67. package/dist/react/IntlProvider.esm.js.map +1 -0
  68. package/dist/react/getInitializedConfig.d.ts +1 -13
  69. package/dist/react/use-intl.esm.js +22 -18
  70. package/dist/react/use-intl.esm.js.map +1 -1
  71. package/dist/react/use-intl.esm10.js +8 -24
  72. package/dist/react/use-intl.esm10.js.map +1 -1
  73. package/dist/react/use-intl.esm11.js +3 -10
  74. package/dist/react/use-intl.esm11.js.map +1 -1
  75. package/dist/react/use-intl.esm2.js +4 -22
  76. package/dist/react/use-intl.esm2.js.map +1 -1
  77. package/dist/react/use-intl.esm3.js +26 -4
  78. package/dist/react/use-intl.esm3.js.map +1 -1
  79. package/dist/react/use-intl.esm4.js +18 -41
  80. package/dist/react/use-intl.esm4.js.map +1 -1
  81. package/dist/react/use-intl.esm5.js +20 -4
  82. package/dist/react/use-intl.esm5.js.map +1 -1
  83. package/dist/react/use-intl.esm6.js +41 -4
  84. package/dist/react/use-intl.esm6.js.map +1 -1
  85. package/dist/react/use-intl.esm7.js +4 -20
  86. package/dist/react/use-intl.esm7.js.map +1 -1
  87. package/dist/react/use-intl.esm8.js +4 -26
  88. package/dist/react/use-intl.esm8.js.map +1 -1
  89. package/dist/react/use-intl.esm9.js +33 -3
  90. package/dist/react/use-intl.esm9.js.map +1 -1
  91. package/dist/react/useFormatter.esm.js +24 -0
  92. package/dist/react/useFormatter.esm.js.map +1 -0
  93. package/dist/react/useIntl.esm.js +30 -0
  94. package/dist/react/useIntl.esm.js.map +1 -0
  95. package/dist/react/useIntlContext.esm.js +13 -0
  96. package/dist/react/useIntlContext.esm.js.map +1 -0
  97. package/dist/react/useLocale.esm.js +8 -0
  98. package/dist/react/useLocale.esm.js.map +1 -0
  99. package/dist/react/useMessages.esm.js +8 -0
  100. package/dist/react/useMessages.esm.js.map +1 -0
  101. package/{src/react/useNow.tsx → dist/react/useNow.esm.js} +32 -36
  102. package/dist/react/useNow.esm.js.map +1 -0
  103. package/dist/react/useTimeZone.esm.js +8 -0
  104. package/dist/react/useTimeZone.esm.js.map +1 -0
  105. package/dist/react/useTranslations.esm.js +26 -0
  106. package/dist/react/useTranslations.esm.js.map +1 -0
  107. package/dist/react/{use-intl.esm12.js → useTranslationsImpl.esm.js} +6 -13
  108. package/dist/react/useTranslationsImpl.esm.js.map +1 -0
  109. package/dist/react.cjs.development.js +190 -0
  110. package/dist/react.cjs.development.js.map +1 -0
  111. package/dist/react.cjs.production.min.js +2 -0
  112. package/dist/react.cjs.production.min.js.map +1 -0
  113. package/dist/react.d.ts +1 -0
  114. package/dist/react.esm.js +9 -0
  115. package/dist/react.esm.js.map +1 -0
  116. package/dist/react.js +8 -0
  117. package/dist/test/setup.d.ts +1 -0
  118. package/dist/use-intl.cjs.development.js +32 -30
  119. package/dist/use-intl.cjs.development.js.map +1 -1
  120. package/dist/use-intl.cjs.production.min.js +1 -1
  121. package/dist/use-intl.cjs.production.min.js.map +1 -1
  122. package/dist/use-intl.esm.js +12 -10
  123. package/dist/use-intl.esm.js.map +1 -1
  124. package/package.json +17 -15
  125. package/react.d.ts +1 -0
  126. package/dist/react/use-intl.esm12.js.map +0 -1
  127. package/dist/src/core/AbstractIntlMessages.d.ts +0 -9
  128. package/dist/src/core/AbstractIntlMessages.js +0 -2
  129. package/dist/src/core/AbstractIntlMessages.js.map +0 -1
  130. package/dist/src/core/DateTimeFormatOptions.d.ts +0 -73
  131. package/dist/src/core/DateTimeFormatOptions.js +0 -3
  132. package/dist/src/core/DateTimeFormatOptions.js.map +0 -1
  133. package/dist/src/core/Formats.d.ts +0 -8
  134. package/dist/src/core/Formats.js +0 -2
  135. package/dist/src/core/Formats.js.map +0 -1
  136. package/dist/src/core/IntlConfig.d.ts +0 -54
  137. package/dist/src/core/IntlConfig.js +0 -2
  138. package/dist/src/core/IntlConfig.js.map +0 -1
  139. package/dist/src/core/IntlError.d.ts +0 -13
  140. package/dist/src/core/IntlError.js +0 -23
  141. package/dist/src/core/IntlError.js.map +0 -1
  142. package/dist/src/core/MessageFormatCache.d.ts +0 -5
  143. package/dist/src/core/MessageFormatCache.js +0 -2
  144. package/dist/src/core/MessageFormatCache.js.map +0 -1
  145. package/dist/src/core/NumberFormatOptions.d.ts +0 -2
  146. package/dist/src/core/NumberFormatOptions.js +0 -2
  147. package/dist/src/core/NumberFormatOptions.js.map +0 -1
  148. package/dist/src/core/TimeZone.d.ts +0 -2
  149. package/dist/src/core/TimeZone.js +0 -2
  150. package/dist/src/core/TimeZone.js.map +0 -1
  151. package/dist/src/core/TranslationValues.d.ts +0 -5
  152. package/dist/src/core/TranslationValues.js +0 -2
  153. package/dist/src/core/TranslationValues.js.map +0 -1
  154. package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +0 -11
  155. package/dist/src/core/convertFormatsToIntlMessageFormat.js +0 -47
  156. package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +0 -1
  157. package/dist/src/core/createBaseTranslator.d.ts +0 -26
  158. package/dist/src/core/createBaseTranslator.js +0 -218
  159. package/dist/src/core/createBaseTranslator.js.map +0 -1
  160. package/dist/src/core/createFormatter.d.ts +0 -19
  161. package/dist/src/core/createFormatter.js +0 -129
  162. package/dist/src/core/createFormatter.js.map +0 -1
  163. package/dist/src/core/createIntl.d.ts +0 -7
  164. package/dist/src/core/createIntl.js +0 -11
  165. package/dist/src/core/createIntl.js.map +0 -1
  166. package/dist/src/core/createTranslator.d.ts +0 -48
  167. package/dist/src/core/createTranslator.js +0 -24
  168. package/dist/src/core/createTranslator.js.map +0 -1
  169. package/dist/src/core/createTranslatorImpl.d.ts +0 -14
  170. package/dist/src/core/createTranslatorImpl.js +0 -43
  171. package/dist/src/core/createTranslatorImpl.js.map +0 -1
  172. package/dist/src/core/defaults.d.ts +0 -11
  173. package/dist/src/core/defaults.js +0 -11
  174. package/dist/src/core/defaults.js.map +0 -1
  175. package/dist/src/core/index.d.ts +0 -9
  176. package/dist/src/core/index.js +0 -6
  177. package/dist/src/core/index.js.map +0 -1
  178. package/dist/src/core/resolveNamespace.d.ts +0 -5
  179. package/dist/src/core/resolveNamespace.js +0 -10
  180. package/dist/src/core/resolveNamespace.js.map +0 -1
  181. package/dist/src/core/utils/MessageKeys.d.ts +0 -5
  182. package/dist/src/core/utils/MessageKeys.js +0 -2
  183. package/dist/src/core/utils/MessageKeys.js.map +0 -1
  184. package/dist/src/core/utils/NamespaceKeys.d.ts +0 -5
  185. package/dist/src/core/utils/NamespaceKeys.js +0 -2
  186. package/dist/src/core/utils/NamespaceKeys.js.map +0 -1
  187. package/dist/src/core/utils/NestedKeyOf.d.ts +0 -4
  188. package/dist/src/core/utils/NestedKeyOf.js +0 -2
  189. package/dist/src/core/utils/NestedKeyOf.js.map +0 -1
  190. package/dist/src/core/utils/NestedValueOf.d.ts +0 -2
  191. package/dist/src/core/utils/NestedValueOf.js +0 -2
  192. package/dist/src/core/utils/NestedValueOf.js.map +0 -1
  193. package/dist/src/core/validateMessages.d.ts +0 -3
  194. package/dist/src/core/validateMessages.js +0 -56
  195. package/dist/src/core/validateMessages.js.map +0 -1
  196. package/dist/src/index.d.ts +0 -2
  197. package/dist/src/index.js +0 -3
  198. package/dist/src/index.js.map +0 -1
  199. package/dist/src/react/IntlContext.d.ts +0 -13
  200. package/dist/src/react/IntlContext.js +0 -4
  201. package/dist/src/react/IntlContext.js.map +0 -1
  202. package/dist/src/react/IntlProvider.d.ts +0 -7
  203. package/dist/src/react/IntlProvider.js +0 -11
  204. package/dist/src/react/IntlProvider.js.map +0 -1
  205. package/dist/src/react/getInitializedConfig.d.ts +0 -13
  206. package/dist/src/react/getInitializedConfig.js +0 -21
  207. package/dist/src/react/getInitializedConfig.js.map +0 -1
  208. package/dist/src/react/index.d.ts +0 -8
  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.d.ts +0 -6
  212. package/dist/src/react/useFormatter.js +0 -14
  213. package/dist/src/react/useFormatter.js.map +0 -1
  214. package/dist/src/react/useIntl.d.ts +0 -6
  215. package/dist/src/react/useIntl.js +0 -20
  216. package/dist/src/react/useIntl.js.map +0 -1
  217. package/dist/src/react/useIntlContext.d.ts +0 -10
  218. package/dist/src/react/useIntlContext.js +0 -12
  219. package/dist/src/react/useIntlContext.js.map +0 -1
  220. package/dist/src/react/useLocale.d.ts +0 -1
  221. package/dist/src/react/useLocale.js +0 -5
  222. package/dist/src/react/useLocale.js.map +0 -1
  223. package/dist/src/react/useMessages.d.ts +0 -1
  224. package/dist/src/react/useMessages.js +0 -5
  225. package/dist/src/react/useMessages.js.map +0 -1
  226. package/dist/src/react/useNow.d.ts +0 -23
  227. package/dist/src/react/useNow.js +0 -40
  228. package/dist/src/react/useNow.js.map +0 -1
  229. package/dist/src/react/useTimeZone.d.ts +0 -1
  230. package/dist/src/react/useTimeZone.js +0 -5
  231. package/dist/src/react/useTimeZone.js.map +0 -1
  232. package/dist/src/react/useTranslations.d.ts +0 -44
  233. package/dist/src/react/useTranslations.js +0 -21
  234. package/dist/src/react/useTranslations.js.map +0 -1
  235. package/dist/src/react/useTranslationsImpl.d.ts +0 -8
  236. package/dist/src/react/useTranslationsImpl.js +0 -35
  237. package/dist/src/react/useTranslationsImpl.js.map +0 -1
  238. package/src/core/AbstractIntlMessages.tsx +0 -10
  239. package/src/core/DateTimeFormatOptions.tsx +0 -130
  240. package/src/core/Formats.tsx +0 -10
  241. package/src/core/IntlConfig.tsx +0 -59
  242. package/src/core/IntlError.tsx +0 -26
  243. package/src/core/MessageFormatCache.tsx +0 -10
  244. package/src/core/NumberFormatOptions.tsx +0 -3
  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 -191
  250. package/src/core/createIntl.tsx +0 -13
  251. package/src/core/createTranslator.tsx +0 -112
  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/useTimeZone.tsx +0 -5
  272. package/src/react/useTranslations.tsx +0 -103
  273. package/src/react/useTranslationsImpl.tsx +0 -61
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFormatter.esm.js","sources":["../../src/core/createFormatter.tsx"],"sourcesContent":["import DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport NumberFormatOptions from './NumberFormatOptions';\nimport TimeZone from './TimeZone';\nimport {defaultOnError} from './defaults';\n\nconst MINUTE = 60;\nconst HOUR = MINUTE * 60;\nconst DAY = HOUR * 24;\nconst WEEK = DAY * 7;\nconst MONTH = DAY * (365 / 12); // Approximation\nconst YEAR = DAY * 365;\n\nfunction getRelativeTimeFormatConfig(seconds: number) {\n const absValue = Math.abs(seconds);\n let value, unit: Intl.RelativeTimeFormatUnit;\n\n // We have to round the resulting values, as `Intl.RelativeTimeFormat`\n // will include fractions like '2.1 hours ago'.\n\n if (absValue < MINUTE) {\n unit = 'second';\n value = Math.round(seconds);\n } else if (absValue < HOUR) {\n unit = 'minute';\n value = Math.round(seconds / MINUTE);\n } else if (absValue < DAY) {\n unit = 'hour';\n value = Math.round(seconds / HOUR);\n } else if (absValue < WEEK) {\n unit = 'day';\n value = Math.round(seconds / DAY);\n } else if (absValue < MONTH) {\n unit = 'week';\n value = Math.round(seconds / WEEK);\n } else if (absValue < YEAR) {\n unit = 'month';\n value = Math.round(seconds / MONTH);\n } else {\n unit = 'year';\n value = Math.round(seconds / YEAR);\n }\n\n return {value, unit};\n}\n\ntype Props = {\n locale: string;\n timeZone?: TimeZone;\n onError?(error: IntlError): void;\n formats?: Partial<Formats>;\n now?: Date;\n};\n\nexport default function createFormatter({\n formats,\n locale,\n now: globalNow,\n onError = defaultOnError,\n timeZone\n}: Props) {\n function resolveFormatOrOptions<Options>(\n typeFormats: Record<string, Options> | undefined,\n formatOrOptions?: string | Options\n ) {\n let options;\n if (typeof formatOrOptions === 'string') {\n const formatName = formatOrOptions;\n options = typeFormats?.[formatName];\n\n if (!options) {\n const error = new IntlError(\n IntlErrorCode.MISSING_FORMAT,\n process.env.NODE_ENV !== 'production'\n ? `Format \\`${formatName}\\` is not available. You can configure it on the provider or provide custom options.`\n : undefined\n );\n onError(error);\n throw error;\n }\n } else {\n options = formatOrOptions;\n }\n\n return options;\n }\n\n function getFormattedValue<Value, Options>(\n value: Value,\n formatOrOptions: string | Options | undefined,\n typeFormats: Record<string, Options> | undefined,\n formatter: (options?: Options) => string\n ) {\n let options;\n try {\n options = resolveFormatOrOptions(typeFormats, formatOrOptions);\n } catch (error) {\n return String(value);\n }\n\n try {\n return formatter(options);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(value);\n }\n }\n\n function dateTime(\n /** If a number is supplied, this is interpreted as a UTC timestamp. */\n value: Date | number,\n /** If a time zone is supplied, the `value` is converted to that time zone.\n * Otherwise the user time zone will be used. */\n formatOrOptions?: string | DateTimeFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.dateTime,\n (options) => {\n if (timeZone && !options?.timeZone) {\n options = {...options, timeZone};\n }\n\n return new Intl.DateTimeFormat(locale, options).format(value);\n }\n );\n }\n\n function number(\n value: number | bigint,\n formatOrOptions?: string | NumberFormatOptions\n ) {\n return getFormattedValue(\n value,\n formatOrOptions,\n formats?.number,\n (options) => new Intl.NumberFormat(locale, options).format(value)\n );\n }\n\n function relativeTime(\n /** The date time that needs to be formatted. */\n date: number | Date,\n /** The reference point in time to which `date` will be formatted in relation to. */\n now?: number | Date\n ) {\n try {\n if (!now) {\n if (globalNow) {\n now = globalNow;\n } else {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `The \\`now\\` parameter wasn't provided and there was no global fallback configured on the provider.`\n : undefined\n );\n }\n }\n\n const dateDate = date instanceof Date ? date : new Date(date);\n const nowDate = now instanceof Date ? now : new Date(now);\n\n const seconds = (dateDate.getTime() - nowDate.getTime()) / 1000;\n const {unit, value} = getRelativeTimeFormatConfig(seconds);\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto'\n }).format(value, unit);\n } catch (error) {\n onError(\n new IntlError(IntlErrorCode.FORMATTING_ERROR, (error as Error).message)\n );\n return String(date);\n }\n }\n\n function list(\n value: Iterable<string>,\n formatOrOptions?: string | Intl.ListFormatOptions\n ) {\n return getFormattedValue(value, formatOrOptions, formats?.list, (options) =>\n new Intl.ListFormat(locale, options).format(value)\n );\n }\n\n return {dateTime, number, relativeTime, list};\n}\n"],"names":["MINUTE","HOUR","DAY","WEEK","MONTH","YEAR","getRelativeTimeFormatConfig","seconds","absValue","Math","abs","value","unit","round","createFormatter","_ref","formats","locale","globalNow","now","_ref$onError","onError","defaultOnError","timeZone","resolveFormatOrOptions","typeFormats","formatOrOptions","options","formatName","error","IntlError","IntlErrorCode","MISSING_FORMAT","process","env","NODE_ENV","undefined","getFormattedValue","formatter","String","FORMATTING_ERROR","message","dateTime","_options","_extends","Intl","DateTimeFormat","format","number","NumberFormat","relativeTime","date","Error","dateDate","Date","nowDate","getTime","_getRelativeTimeForma","RelativeTimeFormat","numeric","list","ListFormat"],"mappings":";;;;AAOA,IAAMA,MAAM,GAAG,EAAE,CAAA;AACjB,IAAMC,IAAI,GAAGD,MAAM,GAAG,EAAE,CAAA;AACxB,IAAME,GAAG,GAAGD,IAAI,GAAG,EAAE,CAAA;AACrB,IAAME,IAAI,GAAGD,GAAG,GAAG,CAAC,CAAA;AACpB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B,MAAA,OAAO,IAAIkC,IAAI,CAACa,kBAAkB,CAACzC,MAAM,EAAE;AACzC0C,QAAAA,OAAO,EAAE,MAAA;AACV,OAAA,CAAC,CAACZ,MAAM,CAACpC,KAAK,EAAEC,IAAI,CAAC,CAAA;KACvB,CAAC,OAAOiB,KAAK,EAAE;AACdR,MAAAA,OAAO,CACL,IAAIS,SAAS,CAACC,aAAa,CAACS,gBAAgB,EAAGX,KAAe,CAACY,OAAO,CAAC,CACxE,CAAA;MACD,OAAOF,MAAM,CAACY,IAAI,CAAC,CAAA;AACpB,KAAA;AACH,GAAA;AAEA,EAAA,SAASS,IAAIA,CACXjD,KAAuB,EACvBe,eAAiD,EAAA;AAEjD,IAAA,OAAOW,iBAAiB,CAAC1B,KAAK,EAAEe,eAAe,EAAEV,OAAO,IAAA,IAAA,GAAA,KAAA,CAAA,GAAPA,OAAO,CAAE4C,IAAI,EAAE,UAACjC,OAAO,EAAA;AAAA,MAAA,OACtE,IAAIkB,IAAI,CAACgB,UAAU,CAAC5C,MAAM,EAAEU,OAAO,CAAC,CAACoB,MAAM,CAACpC,KAAK,CAAC,CAAA;KACnD,CAAA,CAAA;AACH,GAAA;EAEA,OAAO;AAAC+B,IAAAA,QAAQ,EAARA,QAAQ;AAAEM,IAAAA,MAAM,EAANA,MAAM;AAAEE,IAAAA,YAAY,EAAZA,YAAY;AAAEU,IAAAA,IAAI,EAAJA,IAAAA;GAAK,CAAA;AAC/C;;;;"}
@@ -0,0 +1,14 @@
1
+ import createFormatter from './createFormatter.esm.js';
2
+
3
+ /** @deprecated Switch to `createFormatter` */
4
+ function createIntl() {
5
+ var formatter = createFormatter.apply(void 0, arguments);
6
+ return {
7
+ formatDateTime: formatter.dateTime,
8
+ formatNumber: formatter.number,
9
+ formatRelativeTime: formatter.relativeTime
10
+ };
11
+ }
12
+
13
+ export { createIntl as default };
14
+ //# sourceMappingURL=createIntl.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createIntl.esm.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import createFormatter from './createFormatter';\n\n/** @deprecated Switch to `createFormatter` */\nexport default function createIntl(\n ...args: Parameters<typeof createFormatter>\n) {\n const formatter = createFormatter(...args);\n return {\n formatDateTime: formatter.dateTime,\n formatNumber: formatter.number,\n formatRelativeTime: formatter.relativeTime\n };\n}\n"],"names":["createIntl","formatter","createFormatter","apply","arguments","formatDateTime","dateTime","formatNumber","number","formatRelativeTime","relativeTime"],"mappings":";;AAEA;AACc,SAAUA,UAAUA,GACW;AAE3C,EAAA,IAAMC,SAAS,GAAGC,eAAe,CAAAC,KAAA,CAAA,KAAA,CAAA,EAAAC,SAAQ,CAAC,CAAA;EAC1C,OAAO;IACLC,cAAc,EAAEJ,SAAS,CAACK,QAAQ;IAClCC,YAAY,EAAEN,SAAS,CAACO,MAAM;IAC9BC,kBAAkB,EAAER,SAAS,CAACS,YAAAA;GAC/B,CAAA;AACH;;;;"}
@@ -1,7 +1,6 @@
1
1
  import Formats from './Formats';
2
2
  import IntlConfig from './IntlConfig';
3
- import TranslationValues from './TranslationValues';
4
- import { CoreRichTranslationValues } from './createTranslatorImpl';
3
+ import TranslationValues, { RichTranslationValuesPlain } from './TranslationValues';
5
4
  import MessageKeys from './utils/MessageKeys';
6
5
  import NamespaceKeys from './utils/NamespaceKeys';
7
6
  import NestedKeyOf from './utils/NestedKeyOf';
@@ -35,7 +34,7 @@ export default function createTranslator<NestedKey extends NamespaceKeys<IntlMes
35
34
  '!': IntlMessages;
36
35
  }, [
37
36
  NestedKey
38
- ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: CoreRichTranslationValues, formats?: Partial<Formats>): string;
37
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValuesPlain, formats?: Partial<Formats>): string;
39
38
  raw<TargetKey extends MessageKeys<NestedValueOf<{
40
39
  '!': IntlMessages;
41
40
  }, [
@@ -0,0 +1,37 @@
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
+ import createTranslatorImpl from './createTranslatorImpl.esm.js';
3
+ import { defaultGetMessageFallback, defaultOnError } from './defaults.esm.js';
4
+
5
+ var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
6
+ /**
7
+ * Translates messages from the given namespace by using the ICU syntax.
8
+ * See https://formatjs.io/docs/core-concepts/icu-syntax.
9
+ *
10
+ * If no namespace is provided, all available messages are returned.
11
+ * The namespace can also indicate nesting by using a dot
12
+ * (e.g. `namespace.Component`).
13
+ */
14
+ function createTranslator(_ref) {
15
+ var _ref$getMessageFallba = _ref.getMessageFallback,
16
+ getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
17
+ messages = _ref.messages,
18
+ namespace = _ref.namespace,
19
+ _ref$onError = _ref.onError,
20
+ onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
21
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
22
+ // We have to wrap the actual function so the type inference for the optional
23
+ // namespace works correctly. See https://stackoverflow.com/a/71529575/343045
24
+ // The prefix ("!") is arbitrary.
25
+ return createTranslatorImpl(_extends({}, rest, {
26
+ onError: onError,
27
+ getMessageFallback: getMessageFallback,
28
+ messages: {
29
+ '!': messages
30
+ },
31
+ // @ts-ignore
32
+ namespace: namespace ? "!." + namespace : '!'
33
+ }), '!');
34
+ }
35
+
36
+ export { createTranslator as default };
37
+ //# sourceMappingURL=createTranslator.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTranslator.esm.js","sources":["../../src/core/createTranslator.tsx"],"sourcesContent":["import Formats from './Formats';\nimport IntlConfig from './IntlConfig';\nimport TranslationValues, {\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createTranslatorImpl from './createTranslatorImpl';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NamespaceKeys from './utils/NamespaceKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\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 createTranslator<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>({\n getMessageFallback = defaultGetMessageFallback,\n messages,\n namespace,\n onError = defaultOnError,\n ...rest\n}: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {\n messages: NonNullable<IntlConfig<IntlMessages>['messages']>;\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?: RichTranslationValuesPlain,\n formats?: Partial<Formats>\n ): string;\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 // We have to wrap the actual function 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 createTranslatorImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {\n ...rest,\n onError,\n getMessageFallback,\n messages: {'!': messages},\n // @ts-ignore\n namespace: namespace ? `!.${namespace}` : '!'\n },\n '!'\n );\n}\n"],"names":["createTranslator","_ref","_ref$getMessageFallba","getMessageFallback","defaultGetMessageFallback","messages","namespace","_ref$onError","onError","defaultOnError","rest","_objectWithoutPropertiesLoose","_excluded","createTranslatorImpl","_extends"],"mappings":";;;;;AAYA;;;;;;;AAOG;AACqB,SAAAA,gBAAgBA,CAAAC,IAAA,EAcvC;AAAA,EAAA,IAAAC,qBAAA,GAAAD,IAAA,CARCE,kBAAkB;AAAlBA,IAAAA,kBAAkB,GAAAD,qBAAA,KAAGE,KAAAA,CAAAA,GAAAA,yBAAyB,GAAAF,qBAAA;IAC9CG,QAAQ,GAAAJ,IAAA,CAARI,QAAQ;IACRC,SAAS,GAAAL,IAAA,CAATK,SAAS;IAAAC,YAAA,GAAAN,IAAA,CACTO,OAAO;AAAPA,IAAAA,OAAO,GAAAD,YAAA,KAAGE,KAAAA,CAAAA,GAAAA,cAAc,GAAAF,YAAA;AACrBG,IAAAA,IAAI,GAAAC,6BAAA,CAAAV,IAAA,EAAAW,SAAA,CAAA,CAAA;AAgEP;AACA;AACA;AACA,EAAA,OAAOC,oBAAoB,CAAAC,QAAA,CAAA,EAAA,EAKpBJ,IAAI,EAAA;AACPF,IAAAA,OAAO,EAAPA,OAAO;AACPL,IAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBE,IAAAA,QAAQ,EAAE;AAAC,MAAA,GAAG,EAAEA,QAAAA;KAAS;AACzB;AACAC,IAAAA,SAAS,EAAEA,SAAS,GAAQA,IAAAA,GAAAA,SAAS,GAAK,GAAA;AAAG,GAAA,CAAA,EAE/C,GAAG,CACJ,CAAA;AACH;;;;"}
@@ -1,14 +1,13 @@
1
1
  import AbstractIntlMessages from './AbstractIntlMessages';
2
2
  import { InitializedIntlConfig } from './IntlConfig';
3
- import { TranslationValue } from './TranslationValues';
3
+ import { RichTranslationValuesPlain } from './TranslationValues';
4
4
  import NestedKeyOf from './utils/NestedKeyOf';
5
- export type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
6
5
  export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
7
6
  namespace: string;
8
7
  messages: Messages;
9
8
  };
10
9
  export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ getMessageFallback, messages, namespace, onError, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
11
10
  (key: import("./utils/MessageKeys").default<import("./utils/NestedValueOf").default<Messages, NestedKey>, NestedKeyOf<import("./utils/NestedValueOf").default<Messages, NestedKey>>>, values?: import("./TranslationValues").default | undefined, formats?: Partial<import("./Formats").default> | undefined): string;
12
- rich(key: string, values: CoreRichTranslationValues, formats?: Partial<import("./Formats").default> | undefined): string;
11
+ rich(key: string, values: RichTranslationValuesPlain, formats?: Partial<import("./Formats").default> | undefined): string;
13
12
  raw: (key: string) => any;
14
13
  };
@@ -0,0 +1,50 @@
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
+ import IntlError, { IntlErrorCode } from './IntlError.esm.js';
3
+ import createBaseTranslator from './createBaseTranslator.esm.js';
4
+ import resolveNamespace from './resolveNamespace.esm.js';
5
+
6
+ var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
7
+ function createTranslatorImpl(_ref, namespacePrefix) {
8
+ var getMessageFallback = _ref.getMessageFallback,
9
+ messages = _ref.messages,
10
+ namespace = _ref.namespace,
11
+ onError = _ref.onError,
12
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
13
+ // The `namespacePrefix` is part of the type system.
14
+ // See the comment in the function invocation.
15
+ messages = messages[namespacePrefix];
16
+ namespace = resolveNamespace(namespace, namespacePrefix);
17
+ var translator = createBaseTranslator(_extends({}, rest, {
18
+ onError: onError,
19
+ getMessageFallback: getMessageFallback,
20
+ messages: messages,
21
+ namespace: namespace
22
+ }));
23
+ var originalRich = translator.rich;
24
+ function base() {
25
+ return translator.apply(void 0, arguments);
26
+ }
27
+ // Augment `t.rich` to return plain strings
28
+ base.rich = function (key, /** Key value pairs for values to interpolate into the message. */
29
+ values, formats) {
30
+ // `chunks` is returned as a string when no React element
31
+ // is used, therefore it's safe to cast this type.
32
+ var result = originalRich(key, values, formats);
33
+ // When only string chunks are provided to the parser, only strings should be returned here.
34
+ if (typeof result !== 'string') {
35
+ var error = new IntlError(IntlErrorCode.FORMATTING_ERROR, process.env.NODE_ENV !== 'production' ? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})" : undefined);
36
+ onError(error);
37
+ return getMessageFallback({
38
+ error: error,
39
+ key: key,
40
+ namespace: namespace
41
+ });
42
+ }
43
+ return result;
44
+ };
45
+ base.raw = translator.raw;
46
+ return base;
47
+ }
48
+
49
+ export { createTranslatorImpl as default };
50
+ //# sourceMappingURL=createTranslatorImpl.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTranslatorImpl.esm.js","sources":["../../src/core/createTranslatorImpl.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {\n RichTranslationValues,\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createBaseTranslator from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messages,\n namespace\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: RichTranslationValuesPlain,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n"],"names":["createTranslatorImpl","_ref","namespacePrefix","getMessageFallback","messages","namespace","onError","rest","_objectWithoutPropertiesLoose","_excluded","resolveNamespace","translator","createBaseTranslator","_extends","originalRich","rich","base","apply","arguments","key","values","formats","result","error","IntlError","IntlErrorCode","FORMATTING_ERROR","process","env","NODE_ENV","undefined","raw"],"mappings":";;;;;;AAmBc,SAAUA,oBAAoBA,CAAAC,IAAA,EAW1CC,eAAuB,EAAA;AAAA,EAAA,IANrBC,kBAAkB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AAA,OAAOpB,kBAAkB,CAAC;AAACoB,QAAAA,KAAK,EAALA,KAAK;AAAEJ,QAAAA,GAAG,EAAHA,GAAG;AAAEd,QAAAA,SAAS,EAATA,SAAAA;AAAU,OAAA,CAAC,CAAA;AACnD,KAAA;AAED,IAAA,OAAOiB,MAAM,CAAA;GACd,CAAA;AAEDN,EAAAA,IAAI,CAACe,GAAG,GAAGpB,UAAU,CAACoB,GAAG,CAAA;AAEzB,EAAA,OAAOf,IAAI,CAAA;AACb;;;;"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Contains defaults that are used for all entry points into the core.
3
+ * See also `InitializedIntlConfiguration`.
4
+ */
5
+ function defaultGetMessageFallback(props) {
6
+ return [props.namespace, props.key].filter(function (part) {
7
+ return part != null;
8
+ }).join('.');
9
+ }
10
+ function defaultOnError(error) {
11
+ console.error(error);
12
+ }
13
+
14
+ export { defaultGetMessageFallback, defaultOnError };
15
+ //# sourceMappingURL=defaults.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.esm.js","sources":["../../src/core/defaults.tsx"],"sourcesContent":["import IntlError from './IntlError';\n\n/**\n * Contains defaults that are used for all entry points into the core.\n * See also `InitializedIntlConfiguration`.\n */\n\nexport function defaultGetMessageFallback(props: {\n error: IntlError;\n key: string;\n namespace?: string;\n}) {\n return [props.namespace, props.key].filter((part) => part != null).join('.');\n}\n\nexport function defaultOnError(error: IntlError) {\n console.error(error);\n}\n"],"names":["defaultGetMessageFallback","props","namespace","key","filter","part","join","defaultOnError","error","console"],"mappings":"AAEA;;;AAGG;AAEG,SAAUA,yBAAyBA,CAACC,KAIzC,EAAA;AACC,EAAA,OAAO,CAACA,KAAK,CAACC,SAAS,EAAED,KAAK,CAACE,GAAG,CAAC,CAACC,MAAM,CAAC,UAACC,IAAI,EAAA;IAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,GAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9E,CAAA;AAEM,SAAUC,cAAcA,CAACC,KAAgB,EAAA;AAC7CC,EAAAA,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC,CAAA;AACtB;;;;"}
@@ -1,9 +1,16 @@
1
1
  export type { default as AbstractIntlMessages } from './AbstractIntlMessages';
2
- export type { default as TranslationValues, RichTranslationValues } from './TranslationValues';
2
+ export type { default as TranslationValues, RichTranslationValues, RichTranslationValuesPlain } from './TranslationValues';
3
3
  export type { default as Formats } from './Formats';
4
+ export type { default as IntlConfig } from './IntlConfig';
4
5
  export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
5
6
  export type { default as NumberFormatOptions } from './NumberFormatOptions';
6
7
  export { default as IntlError, IntlErrorCode } from './IntlError';
7
8
  export { default as createTranslator } from './createTranslator';
9
+ export { default as createBaseTranslator } from './createBaseTranslator';
8
10
  export { default as createFormatter } from './createFormatter';
11
+ export { default as initializeConfig } from './initializeConfig';
12
+ export { default as MessageKeys } from './utils/MessageKeys';
13
+ export { default as NamespaceKeys } from './utils/NamespaceKeys';
14
+ export { default as NestedKeyOf } from './utils/NestedKeyOf';
15
+ export { default as NestedValueOf } from './utils/NestedValueOf';
9
16
  export { default as createIntl } from './createIntl';
@@ -0,0 +1,13 @@
1
+ import IntlConfig from './IntlConfig';
2
+ /**
3
+ * Enhances the incoming props with defaults.
4
+ */
5
+ export default function initializeConfig<Props extends Omit<IntlConfig, 'children'>>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
6
+ messages: import("./AbstractIntlMessages").default | undefined;
7
+ onError: (error: import("./IntlError").default) => void;
8
+ getMessageFallback: (info: {
9
+ error: import("./IntlError").default;
10
+ key: string;
11
+ namespace?: string | undefined;
12
+ }) => string;
13
+ };
@@ -0,0 +1,29 @@
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
2
+ import { defaultOnError, defaultGetMessageFallback } from './defaults.esm.js';
3
+ import validateMessages from './validateMessages.esm.js';
4
+
5
+ var _excluded = ["getMessageFallback", "messages", "onError"];
6
+ /**
7
+ * Enhances the incoming props with defaults.
8
+ */
9
+ function initializeConfig(_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 { initializeConfig as default };
29
+ //# sourceMappingURL=initializeConfig.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initializeConfig.esm.js","sources":["../../src/core/initializeConfig.tsx"],"sourcesContent":["import IntlConfig from './IntlConfig';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport validateMessages from './validateMessages';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function initializeConfig<\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":["initializeConfig","_ref","getMessageFallback","messages","onError","rest","_objectWithoutPropertiesLoose","_excluded","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages","_extends"],"mappings":";;;;;AAIA;;AAEG;AACqB,SAAAA,gBAAgBA,CAAAC,IAAA,EAIiB;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;;;;"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * For the strictly typed messages to work we have to wrap the namespace into
3
+ * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
+ */
5
+ function resolveNamespace(namespace, namespacePrefix) {
6
+ return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
7
+ }
8
+
9
+ export { resolveNamespace as default };
10
+ //# sourceMappingURL=resolveNamespace.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveNamespace.esm.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAgBA,CACtCC,SAAiB,EACjBC,eAAuB,EAAA;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAe,GAChCC,SAAS,GACTF,SAAS,CAACG,KAAK,CAAC,CAACF,eAAe,GAAG,GAAG,EAAEG,MAAM,CAAC,CAAA;AACrD;;;;"}
@@ -1,37 +1,28 @@
1
- import { extends as _extends } from '../_virtual/use-intl.esm.js';
2
- import IntlMessageFormat from 'intl-messageformat';
1
+ import IntlError, { IntlErrorCode } from './use-intl.esm.js';
3
2
 
4
- function setTimeZoneInFormats(formats, timeZone) {
5
- if (!formats) return formats;
6
- // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
7
- // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
8
- return Object.keys(formats).reduce(function (acc, key) {
9
- acc[key] = _extends({
10
- timeZone: timeZone
11
- }, formats[key]);
12
- return acc;
13
- }, {});
14
- }
15
- /**
16
- * `intl-messageformat` uses separate keys for `date` and `time`, but there's
17
- * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
18
- * include both a time and a date in a value, therefore the separation doesn't
19
- * seem so useful. We offer a single `dateTime` namespace instead, but we have
20
- * to convert the format before `intl-messageformat` can be used.
21
- */
22
- function convertFormatsToIntlMessageFormat(formats, timeZone) {
23
- var formatsWithTimeZone = timeZone ? _extends({}, formats, {
24
- dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)
25
- }) : formats;
26
- var mfDateDefaults = IntlMessageFormat.formats.date;
27
- var defaultDateFormats = timeZone ? setTimeZoneInFormats(mfDateDefaults, timeZone) : mfDateDefaults;
28
- var mfTimeDefaults = IntlMessageFormat.formats.time;
29
- var defaultTimeFormats = timeZone ? setTimeZoneInFormats(mfTimeDefaults, timeZone) : mfTimeDefaults;
30
- return _extends({}, formatsWithTimeZone, {
31
- date: _extends({}, defaultDateFormats, formatsWithTimeZone == null ? void 0 : formatsWithTimeZone.dateTime),
32
- time: _extends({}, defaultTimeFormats, formatsWithTimeZone == null ? void 0 : formatsWithTimeZone.dateTime)
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
+ }
33
17
  });
34
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
+ }
35
26
 
36
- export { convertFormatsToIntlMessageFormat as default };
27
+ export { validateMessages as default };
37
28
  //# sourceMappingURL=use-intl.esm10.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-intl.esm10.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat, {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: TimeZone\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n const mfDateDefaults = IntlMessageFormat.formats.date as Formats['dateTime'];\n const defaultDateFormats = timeZone\n ? setTimeZoneInFormats(mfDateDefaults, timeZone)\n : mfDateDefaults;\n\n const mfTimeDefaults = IntlMessageFormat.formats.time as Formats['dateTime'];\n const defaultTimeFormats = timeZone\n ? setTimeZoneInFormats(mfTimeDefaults, timeZone)\n : mfTimeDefaults;\n\n return {\n ...formatsWithTimeZone,\n date: {\n ...defaultDateFormats,\n ...formatsWithTimeZone?.dateTime\n },\n time: {\n ...defaultTimeFormats,\n ...formatsWithTimeZone?.dateTime\n }\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","_extends","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","mfDateDefaults","IntlMessageFormat","date","defaultDateFormats","mfTimeDefaults","time","defaultTimeFormats"],"mappings":";;;AAMA,SAASA,oBAAoBA,CAC3BC,OAA0D,EAC1DC,QAAkB,EAAA;AAElB,EAAA,IAAI,CAACD,OAAO,EAAE,OAAOA,OAAO,CAAA;AAE5B;AACA;AACA,EAAA,OAAOE,MAAM,CAACC,IAAI,CAACH,OAAO,CAAC,CAACI,MAAM,CAChC,UAACC,GAA0C,EAAEC,GAAG,EAAI;AAClDD,IAAAA,GAAG,CAACC,GAAG,CAAC,GAAAC,QAAA,CAAA;AACNN,MAAAA,QAAQ,EAARA,QAAAA;AAAQ,KAAA,EACLD,OAAO,CAACM,GAAG,CAAC,CAChB,CAAA;AACD,IAAA,OAAOD,GAAG,CAAA;GACX,EACD,EAAE,CACH,CAAA;AACH,CAAA;AAEA;;;;;;AAMG;AACW,SAAUG,iCAAiCA,CACvDR,OAAyB,EACzBC,QAAmB,EAAA;AAEnB,EAAA,IAAMQ,mBAAmB,GAAGR,QAAQ,GAAAM,QAAA,KAC5BP,OAAO,EAAA;AAAEU,IAAAA,QAAQ,EAAEX,oBAAoB,CAACC,OAAO,CAACU,QAAQ,EAAET,QAAQ,CAAA;AAAC,GAAA,CAAA,GACvED,OAAO,CAAA;AAEX,EAAA,IAAMW,cAAc,GAAGC,iBAAiB,CAACZ,OAAO,CAACa,IAA2B,CAAA;EAC5E,IAAMC,kBAAkB,GAAGb,QAAQ,GAC/BF,oBAAoB,CAACY,cAAc,EAAEV,QAAQ,CAAC,GAC9CU,cAAc,CAAA;AAElB,EAAA,IAAMI,cAAc,GAAGH,iBAAiB,CAACZ,OAAO,CAACgB,IAA2B,CAAA;EAC5E,IAAMC,kBAAkB,GAAGhB,QAAQ,GAC/BF,oBAAoB,CAACgB,cAAc,EAAEd,QAAQ,CAAC,GAC9Cc,cAAc,CAAA;EAElB,OAAAR,QAAA,KACKE,mBAAmB,EAAA;IACtBI,IAAI,EAAAN,QAAA,CAAA,EAAA,EACCO,kBAAkB,EAClBL,mBAAmB,IAAnBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAAQ,CACjC;IACDM,IAAI,EAAAT,QAAA,CACCU,EAAAA,EAAAA,kBAAkB,EAClBR,mBAAmB,IAAA,IAAA,GAAA,KAAA,CAAA,GAAnBA,mBAAmB,CAAEC,QAAQ,CAAA;AACjC,GAAA,CAAA,CAAA;AAEL;;;;"}
1
+ {"version":3,"file":"use-intl.esm10.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;;;;"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * For the strictly typed messages to work we have to wrap the namespace into
3
+ * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
4
+ */
5
+ function resolveNamespace(namespace, namespacePrefix) {
6
+ return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
7
+ }
8
+
9
+ export { resolveNamespace as default };
10
+ //# sourceMappingURL=use-intl.esm11.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-intl.esm11.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAgBA,CACtCC,SAAiB,EACjBC,eAAuB,EAAA;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAe,GAChCC,SAAS,GACTF,SAAS,CAACG,KAAK,CAAC,CAACF,eAAe,GAAG,GAAG,EAAEG,MAAM,CAAC,CAAA;AACrD;;;;"}