react-intlayer 8.4.3 → 8.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/dist/cjs/IntlayerNode.cjs +17 -1
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -1
  3. package/dist/cjs/UI/ContentSelector.cjs +96 -1
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -1
  6. package/dist/cjs/client/IntlayerProvider.cjs +92 -1
  7. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
  8. package/dist/cjs/client/format/index.cjs +20 -1
  9. package/dist/cjs/client/format/useCompact.cjs +29 -1
  10. package/dist/cjs/client/format/useCompact.cjs.map +1 -1
  11. package/dist/cjs/client/format/useCurrency.cjs +43 -1
  12. package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
  13. package/dist/cjs/client/format/useDate.cjs +45 -1
  14. package/dist/cjs/client/format/useDate.cjs.map +1 -1
  15. package/dist/cjs/client/format/useIntl.cjs +45 -1
  16. package/dist/cjs/client/format/useIntl.cjs.map +1 -1
  17. package/dist/cjs/client/format/useList.cjs +40 -1
  18. package/dist/cjs/client/format/useList.cjs.map +1 -1
  19. package/dist/cjs/client/format/useNumber.cjs +41 -1
  20. package/dist/cjs/client/format/useNumber.cjs.map +1 -1
  21. package/dist/cjs/client/format/usePercentage.cjs +37 -1
  22. package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
  23. package/dist/cjs/client/format/useRelativeTime.cjs +37 -1
  24. package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
  25. package/dist/cjs/client/format/useUnit.cjs +36 -1
  26. package/dist/cjs/client/format/useUnit.cjs.map +1 -1
  27. package/dist/cjs/client/index.cjs +34 -1
  28. package/dist/cjs/client/t.cjs +40 -1
  29. package/dist/cjs/client/t.cjs.map +1 -1
  30. package/dist/cjs/client/useDictionary.cjs +27 -1
  31. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  32. package/dist/cjs/client/useDictionaryAsync.cjs +24 -1
  33. package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
  34. package/dist/cjs/client/useDictionaryDynamic.cjs +25 -1
  35. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
  36. package/dist/cjs/client/useI18n.cjs +45 -1
  37. package/dist/cjs/client/useI18n.cjs.map +1 -1
  38. package/dist/cjs/client/useIntlayer.cjs +42 -1
  39. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  40. package/dist/cjs/client/useLoadDynamic.cjs +27 -1
  41. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
  42. package/dist/cjs/client/useLocale.cjs +60 -1
  43. package/dist/cjs/client/useLocale.cjs.map +1 -1
  44. package/dist/cjs/client/useLocaleBase.cjs +26 -1
  45. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  46. package/dist/cjs/client/useLocaleStorage.cjs +62 -1
  47. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
  48. package/dist/cjs/client/useRewriteURL.cjs +42 -1
  49. package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
  50. package/dist/cjs/client/useTraduction.cjs +35 -1
  51. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  52. package/dist/cjs/editor/ContentSelector.cjs +18 -1
  53. package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
  54. package/dist/cjs/editor/EditorProvider.cjs +11 -1
  55. package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
  56. package/dist/cjs/editor/useEditor.cjs +39 -1
  57. package/dist/cjs/editor/useEditor.cjs.map +1 -1
  58. package/dist/cjs/getDictionary.cjs +10 -1
  59. package/dist/cjs/getDictionary.cjs.map +1 -1
  60. package/dist/cjs/getIntlayer.cjs +10 -1
  61. package/dist/cjs/getIntlayer.cjs.map +1 -1
  62. package/dist/cjs/html/HTMLProvider.cjs +18 -1
  63. package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
  64. package/dist/cjs/html/HTMLRenderer.cjs +60 -1
  65. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
  66. package/dist/cjs/html/HTMLRendererPlugin.cjs +23 -1
  67. package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
  68. package/dist/cjs/html/index.cjs +12 -1
  69. package/dist/cjs/index.cjs +52 -1
  70. package/dist/cjs/markdown/MarkdownProvider.cjs +80 -1
  71. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
  72. package/dist/cjs/markdown/MarkdownRenderer.cjs +201 -1
  73. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
  74. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +17 -1
  75. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
  76. package/dist/cjs/markdown/index.cjs +24 -1
  77. package/dist/cjs/markdown/processor.cjs +66 -1
  78. package/dist/cjs/markdown/processor.cjs.map +1 -1
  79. package/dist/cjs/markdown/runtime.cjs +43 -1
  80. package/dist/cjs/markdown/runtime.cjs.map +1 -1
  81. package/dist/cjs/plugins.cjs +200 -1
  82. package/dist/cjs/plugins.cjs.map +1 -1
  83. package/dist/cjs/reactElement/renderReactElement.cjs +52 -1
  84. package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
  85. package/dist/cjs/server/IntlayerServerProvider.cjs +34 -1
  86. package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
  87. package/dist/cjs/server/format/index.cjs +18 -1
  88. package/dist/cjs/server/format/useCompact.cjs +27 -1
  89. package/dist/cjs/server/format/useCompact.cjs.map +1 -1
  90. package/dist/cjs/server/format/useCurrency.cjs +38 -1
  91. package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
  92. package/dist/cjs/server/format/useDate.cjs +43 -1
  93. package/dist/cjs/server/format/useDate.cjs.map +1 -1
  94. package/dist/cjs/server/format/useIntl.cjs +44 -1
  95. package/dist/cjs/server/format/useIntl.cjs.map +1 -1
  96. package/dist/cjs/server/format/useList.cjs +35 -1
  97. package/dist/cjs/server/format/useList.cjs.map +1 -1
  98. package/dist/cjs/server/format/useNumber.cjs +39 -1
  99. package/dist/cjs/server/format/useNumber.cjs.map +1 -1
  100. package/dist/cjs/server/format/usePercentage.cjs +35 -1
  101. package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
  102. package/dist/cjs/server/format/useRelativeTime.cjs +35 -1
  103. package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
  104. package/dist/cjs/server/format/useUnit.cjs +34 -1
  105. package/dist/cjs/server/format/useUnit.cjs.map +1 -1
  106. package/dist/cjs/server/index.cjs +24 -1
  107. package/dist/cjs/server/serverContext.cjs +58 -1
  108. package/dist/cjs/server/serverContext.cjs.map +1 -1
  109. package/dist/cjs/server/t.cjs +35 -1
  110. package/dist/cjs/server/t.cjs.map +1 -1
  111. package/dist/cjs/server/useDictionary.cjs +17 -1
  112. package/dist/cjs/server/useDictionary.cjs.map +1 -1
  113. package/dist/cjs/server/useDictionaryAsync.cjs +21 -1
  114. package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
  115. package/dist/cjs/server/useDictionaryDynamic.cjs +22 -1
  116. package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
  117. package/dist/cjs/server/useI18n.cjs +38 -1
  118. package/dist/cjs/server/useI18n.cjs.map +1 -1
  119. package/dist/cjs/server/useIntlayer.cjs +17 -1
  120. package/dist/cjs/server/useIntlayer.cjs.map +1 -1
  121. package/dist/cjs/server/useLoadDynamic.cjs +14 -1
  122. package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
  123. package/dist/cjs/server/useLocale.cjs +24 -1
  124. package/dist/cjs/server/useLocale.cjs.map +1 -1
  125. package/dist/esm/IntlayerNode.mjs +15 -1
  126. package/dist/esm/IntlayerNode.mjs.map +1 -1
  127. package/dist/esm/UI/ContentSelector.mjs +94 -1
  128. package/dist/esm/UI/ContentSelector.mjs.map +1 -1
  129. package/dist/esm/client/IntlayerProvider.mjs +86 -1
  130. package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
  131. package/dist/esm/client/format/index.mjs +11 -1
  132. package/dist/esm/client/format/useCompact.mjs +27 -1
  133. package/dist/esm/client/format/useCompact.mjs.map +1 -1
  134. package/dist/esm/client/format/useCurrency.mjs +41 -1
  135. package/dist/esm/client/format/useCurrency.mjs.map +1 -1
  136. package/dist/esm/client/format/useDate.mjs +43 -1
  137. package/dist/esm/client/format/useDate.mjs.map +1 -1
  138. package/dist/esm/client/format/useIntl.mjs +43 -1
  139. package/dist/esm/client/format/useIntl.mjs.map +1 -1
  140. package/dist/esm/client/format/useList.mjs +38 -1
  141. package/dist/esm/client/format/useList.mjs.map +1 -1
  142. package/dist/esm/client/format/useNumber.mjs +39 -1
  143. package/dist/esm/client/format/useNumber.mjs.map +1 -1
  144. package/dist/esm/client/format/usePercentage.mjs +35 -1
  145. package/dist/esm/client/format/usePercentage.mjs.map +1 -1
  146. package/dist/esm/client/format/useRelativeTime.mjs +35 -1
  147. package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
  148. package/dist/esm/client/format/useUnit.mjs +34 -1
  149. package/dist/esm/client/format/useUnit.mjs.map +1 -1
  150. package/dist/esm/client/index.mjs +14 -1
  151. package/dist/esm/client/t.mjs +38 -1
  152. package/dist/esm/client/t.mjs.map +1 -1
  153. package/dist/esm/client/useDictionary.mjs +25 -1
  154. package/dist/esm/client/useDictionary.mjs.map +1 -1
  155. package/dist/esm/client/useDictionaryAsync.mjs +21 -1
  156. package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
  157. package/dist/esm/client/useDictionaryDynamic.mjs +22 -1
  158. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
  159. package/dist/esm/client/useI18n.mjs +43 -1
  160. package/dist/esm/client/useI18n.mjs.map +1 -1
  161. package/dist/esm/client/useIntlayer.mjs +40 -1
  162. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  163. package/dist/esm/client/useLoadDynamic.mjs +25 -1
  164. package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
  165. package/dist/esm/client/useLocale.mjs +57 -1
  166. package/dist/esm/client/useLocale.mjs.map +1 -1
  167. package/dist/esm/client/useLocaleBase.mjs +23 -1
  168. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  169. package/dist/esm/client/useLocaleStorage.mjs +55 -1
  170. package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
  171. package/dist/esm/client/useRewriteURL.mjs +39 -1
  172. package/dist/esm/client/useRewriteURL.mjs.map +1 -1
  173. package/dist/esm/client/useTraduction.mjs +33 -1
  174. package/dist/esm/client/useTraduction.mjs.map +1 -1
  175. package/dist/esm/editor/ContentSelector.mjs +16 -1
  176. package/dist/esm/editor/ContentSelector.mjs.map +1 -1
  177. package/dist/esm/editor/EditorProvider.mjs +10 -1
  178. package/dist/esm/editor/EditorProvider.mjs.map +1 -1
  179. package/dist/esm/editor/useEditor.mjs +37 -1
  180. package/dist/esm/editor/useEditor.mjs.map +1 -1
  181. package/dist/esm/getDictionary.mjs +8 -1
  182. package/dist/esm/getDictionary.mjs.map +1 -1
  183. package/dist/esm/getIntlayer.mjs +8 -1
  184. package/dist/esm/getIntlayer.mjs.map +1 -1
  185. package/dist/esm/html/HTMLProvider.mjs +15 -1
  186. package/dist/esm/html/HTMLProvider.mjs.map +1 -1
  187. package/dist/esm/html/HTMLRenderer.mjs +55 -1
  188. package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
  189. package/dist/esm/html/HTMLRendererPlugin.mjs +21 -1
  190. package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
  191. package/dist/esm/html/index.mjs +5 -1
  192. package/dist/esm/index.mjs +21 -1
  193. package/dist/esm/markdown/MarkdownProvider.mjs +77 -1
  194. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
  195. package/dist/esm/markdown/MarkdownRenderer.mjs +197 -1
  196. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
  197. package/dist/esm/markdown/MarkdownRendererPlugin.mjs +16 -1
  198. package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
  199. package/dist/esm/markdown/index.mjs +7 -1
  200. package/dist/esm/markdown/processor.mjs +58 -1
  201. package/dist/esm/markdown/processor.mjs.map +1 -1
  202. package/dist/esm/markdown/runtime.mjs +39 -1
  203. package/dist/esm/markdown/runtime.mjs.map +1 -1
  204. package/dist/esm/plugins.mjs +190 -1
  205. package/dist/esm/plugins.mjs.map +1 -1
  206. package/dist/esm/reactElement/renderReactElement.mjs +50 -1
  207. package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
  208. package/dist/esm/server/IntlayerServerProvider.mjs +28 -1
  209. package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
  210. package/dist/esm/server/format/index.mjs +10 -1
  211. package/dist/esm/server/format/useCompact.mjs +25 -1
  212. package/dist/esm/server/format/useCompact.mjs.map +1 -1
  213. package/dist/esm/server/format/useCurrency.mjs +36 -1
  214. package/dist/esm/server/format/useCurrency.mjs.map +1 -1
  215. package/dist/esm/server/format/useDate.mjs +41 -1
  216. package/dist/esm/server/format/useDate.mjs.map +1 -1
  217. package/dist/esm/server/format/useIntl.mjs +41 -1
  218. package/dist/esm/server/format/useIntl.mjs.map +1 -1
  219. package/dist/esm/server/format/useList.mjs +33 -1
  220. package/dist/esm/server/format/useList.mjs.map +1 -1
  221. package/dist/esm/server/format/useNumber.mjs +37 -1
  222. package/dist/esm/server/format/useNumber.mjs.map +1 -1
  223. package/dist/esm/server/format/usePercentage.mjs +33 -1
  224. package/dist/esm/server/format/usePercentage.mjs.map +1 -1
  225. package/dist/esm/server/format/useRelativeTime.mjs +33 -1
  226. package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
  227. package/dist/esm/server/format/useUnit.mjs +32 -1
  228. package/dist/esm/server/format/useUnit.mjs.map +1 -1
  229. package/dist/esm/server/index.mjs +12 -1
  230. package/dist/esm/server/serverContext.mjs +54 -1
  231. package/dist/esm/server/serverContext.mjs.map +1 -1
  232. package/dist/esm/server/t.mjs +33 -1
  233. package/dist/esm/server/t.mjs.map +1 -1
  234. package/dist/esm/server/useDictionary.mjs +16 -1
  235. package/dist/esm/server/useDictionary.mjs.map +1 -1
  236. package/dist/esm/server/useDictionaryAsync.mjs +18 -1
  237. package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
  238. package/dist/esm/server/useDictionaryDynamic.mjs +19 -1
  239. package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
  240. package/dist/esm/server/useI18n.mjs +37 -1
  241. package/dist/esm/server/useI18n.mjs.map +1 -1
  242. package/dist/esm/server/useIntlayer.mjs +16 -1
  243. package/dist/esm/server/useIntlayer.mjs.map +1 -1
  244. package/dist/esm/server/useLoadDynamic.mjs +11 -1
  245. package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
  246. package/dist/esm/server/useLocale.mjs +21 -1
  247. package/dist/esm/server/useLocale.mjs.map +1 -1
  248. package/dist/types/html/HTMLRenderer.d.ts +1 -1
  249. package/dist/types/plugins.d.ts +4 -3
  250. package/dist/types/plugins.d.ts.map +1 -1
  251. package/package.json +9 -9
@@ -1,2 +1,42 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{date as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useDate};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { date } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/useDate.ts
6
+ /**
7
+ * React client hook that provides a localized date/time formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @returns {(date: Date | string | number, options?: DateProps) => string}
11
+ * A function to format dates or timestamps into localized date/time strings.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatDate = useDate();
16
+ *
17
+ * formatDate(new Date("2025-01-01"));
18
+ * // "Jan 1, 2025"
19
+ *
20
+ * formatDate("2025-01-01T15:30:00Z", {
21
+ * dateStyle: "full",
22
+ * timeStyle: "short",
23
+ * });
24
+ * // "Wednesday, January 1, 2025 at 3:30 PM"
25
+ *
26
+ * formatDate(1735689600000, { locale: "fr-FR", dateStyle: "long" });
27
+ * // "1 janvier 2025"
28
+ * ```
29
+ *
30
+ * @see createDate
31
+ */
32
+ const useDate = () => {
33
+ const locale = getServerContext(IntlayerServerContext);
34
+ return (...args) => date(args[0], {
35
+ ...args[1],
36
+ locale: args[1]?.locale ?? locale
37
+ });
38
+ };
39
+
40
+ //#endregion
41
+ export { useDate };
2
42
  //# sourceMappingURL=useDate.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/server/format/useDate.ts"],"sourcesContent":["import { date } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"+KA+BA,MAAa,MAAgB,CAC3B,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAK,EAAK,GAAI,CACZ,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/server/format/useDate.ts"],"sourcesContent":["import { date } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1,2 +1,42 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import n from"@intlayer/config/built";import{bindIntl as r}from"@intlayer/core/formatters";const i=i=>{let a=e(t);return r(i??a??n?.internationalization?.defaultLocale)};export{i as useIntl};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import configuration from "@intlayer/config/built";
4
+ import { bindIntl } from "@intlayer/core/formatters";
5
+
6
+ //#region src/server/format/useIntl.ts
7
+ /**
8
+ * React client hook that provides a locale-bound `Intl` object.
9
+ *
10
+ * It acts exactly like the native `Intl` object, but acts as a proxy to:
11
+ * 1. Inject the current locale automatically if none is provided.
12
+ * 2. Use the performance-optimized `CachedIntl` under the hood.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const intl = useIntl(); // uses context locale
17
+ *
18
+ * // Standard API, but no need to pass 'en-US' as the first argument
19
+ * const formatted = new intl.NumberFormat({
20
+ * style: 'currency',
21
+ * currency: 'USD'
22
+ * }).format(123.45);
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const intl = useIntl();
28
+ *
29
+ * // You can still override the locale if needed
30
+ * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());
31
+ * // or
32
+ * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());
33
+ * ```
34
+ */
35
+ const useIntl = (locale) => {
36
+ const currentLocale = getServerContext(IntlayerServerContext);
37
+ return bindIntl(locale ?? currentLocale ?? configuration?.internationalization?.defaultLocale);
38
+ };
39
+
40
+ //#endregion
41
+ export { useIntl };
2
42
  //# sourceMappingURL=useIntl.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues): WrappedIntl => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ??\n currentLocale ??\n configuration?.internationalization?.defaultLocale\n );\n};\n"],"mappings":"yNAkCA,MAAa,EAAW,GAAwC,CAC9D,IAAM,EAAgB,EAAgC,EAAsB,CAE5E,OAAO,EACL,GACE,GACA,GAAe,sBAAsB,cACxC"}
1
+ {"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/server/format/useIntl.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues): WrappedIntl => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return bindIntl(\n locale ??\n currentLocale ??\n configuration?.internationalization?.defaultLocale\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,WAAW,WAAwC;CAC9D,MAAM,gBAAgB,iBAAgC,sBAAsB;AAE5E,QAAO,SACL,UACE,iBACA,eAAe,sBAAsB,cACxC"}
@@ -1,2 +1,34 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{list as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useList};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { list } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/useList.ts
6
+ /**
7
+ * React server hook that provides a list formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const formatList = useList();
13
+ *
14
+ * formatList(['apple', 'banana', 'orange']);
15
+ * // "apple, banana, and orange"
16
+ *
17
+ * formatList(['red', 'green', 'blue'], { type: 'disjunction' });
18
+ * // "red, green, or blue"
19
+ *
20
+ * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });
21
+ * // "1, 2 und 3"
22
+ * ```
23
+ */
24
+ const useList = () => {
25
+ const locale = getServerContext(IntlayerServerContext);
26
+ return (...args) => list(args[0], {
27
+ ...args[1],
28
+ locale: args[1]?.locale ?? locale
29
+ });
30
+ };
31
+
32
+ //#endregion
33
+ export { useList };
2
34
  //# sourceMappingURL=useList.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/server/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React server hook that provides a list formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"+KAuBA,MAAa,MAAgB,CAC3B,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAK,EAAK,GAAI,CACZ,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/server/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React server hook that provides a list formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1,2 +1,38 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{number as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useNumber};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { number } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/useNumber.ts
6
+ /**
7
+ * React client hook that provides a localized number formatter.
8
+ *
9
+ * Uses the current locale from {@link useLocaleBase} and returns
10
+ * a function that can be used to format numbers consistently
11
+ * according to the user's locale.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatNumber = useNumber();
16
+ *
17
+ * formatNumber(12345);
18
+ * // e.g. "12,345" (en-US)
19
+ * // e.g. "12 345" (fr-FR)
20
+ *
21
+ * formatNumber(0.75, { style: "percent" });
22
+ * // e.g. "75%"
23
+ * ```
24
+ *
25
+ * @returns {(value: string | number, options?: import("../createNumber").NumberProps) => string}
26
+ * A number formatting function bound to the active locale.
27
+ */
28
+ const useNumber = () => {
29
+ const locale = getServerContext(IntlayerServerContext);
30
+ return (...args) => number(args[0], {
31
+ ...args[1],
32
+ locale: args[1]?.locale ?? locale
33
+ });
34
+ };
35
+
36
+ //#endregion
37
+ export { useNumber };
2
38
  //# sourceMappingURL=useNumber.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/server/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"iLA2BA,MAAa,MAAkB,CAC7B,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAO,EAAK,GAAI,CACd,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/server/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,kBAAkB;CAC7B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,OAAO,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1,2 +1,34 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{percentage as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as usePercentage};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { percentage } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/usePercentage.ts
6
+ /**
7
+ * React hook to provide a percentage formatter function
8
+ * based on the current application locale.
9
+ *
10
+ * This hook retrieves the active locale using {@link useLocaleBase}
11
+ * and memoizes a `createPercentage` instance for that locale.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatPercentage = usePercentage();
16
+ *
17
+ * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });
18
+ * // "87.5%" (depending on locale)
19
+ * ```
20
+ *
21
+ * @returns {(value: string | number, options?: Omit<PercentageOptions, "value">) => string}
22
+ * A function that formats numbers or numeric strings into localized percentages.
23
+ */
24
+ const usePercentage = () => {
25
+ const locale = getServerContext(IntlayerServerContext);
26
+ return (...args) => percentage(args[0], {
27
+ ...args[1],
28
+ locale: args[1]?.locale ?? locale
29
+ });
30
+ };
31
+
32
+ //#endregion
33
+ export { usePercentage };
2
34
  //# sourceMappingURL=usePercentage.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/server/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"qLAuBA,MAAa,MAAsB,CACjC,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAW,EAAK,GAAI,CAClB,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/server/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,sBAAsB;CACjC,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,WAAW,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1,2 +1,34 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{relativeTime as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],e[1]??new Date,{...e[2],locale:e[2]?.locale??r})};export{r as useRelativeTime};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { relativeTime } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/useRelativeTime.ts
6
+ /**
7
+ * Client-side React hook for accessing a localized relative time formatter.
8
+ *
9
+ * This hook:
10
+ * - Reads the current locale from {@link useLocaleBase}.
11
+ * - Creates a new relative time formatter with {@link createRelativeTime}.
12
+ * - Returns a function that can format time differences into localized strings.
13
+ *
14
+ * Example:
15
+ * ```tsx
16
+ * const relativeTime = useRelativeTime();
17
+ * const formatted = relativeTime(new Date("2024-08-01"), new Date());
18
+ * // e.g., "2 weeks ago"
19
+ * ```
20
+ *
21
+ * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function
22
+ * bound to the current client locale.
23
+ */
24
+ const useRelativeTime = () => {
25
+ const locale = getServerContext(IntlayerServerContext);
26
+ return (...args) => relativeTime(args[0], args[1] ?? /* @__PURE__ */ new Date(), {
27
+ ...args[2],
28
+ locale: args[2]?.locale ?? locale
29
+ });
30
+ };
31
+
32
+ //#endregion
33
+ export { useRelativeTime };
2
34
  //# sourceMappingURL=useRelativeTime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/server/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1] ?? new Date(), {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n });\n};\n"],"mappings":"uLAuBA,MAAa,MAAwB,CACnC,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAa,EAAK,GAAI,EAAK,IAAM,IAAI,KAAQ,CAC3C,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/server/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1] ?? new Date(), {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,wBAAwB;CACnC,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,aAAa,KAAK,IAAI,KAAK,sBAAM,IAAI,MAAM,EAAE;EAC3C,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1,2 +1,33 @@
1
- import{getServerContext as e}from"../serverContext.mjs";import{IntlayerServerContext as t}from"../IntlayerServerProvider.mjs";import{units as n}from"@intlayer/core/formatters";const r=()=>{let r=e(t);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useUnit};
1
+ import { getServerContext } from "../serverContext.mjs";
2
+ import { IntlayerServerContext } from "../IntlayerServerProvider.mjs";
3
+ import { units } from "@intlayer/core/formatters";
4
+
5
+ //#region src/server/format/useUnit.ts
6
+ /**
7
+ * React hook that provides a unit formatting function
8
+ * based on the current locale from {@link useLocaleBase}.
9
+ *
10
+ * This hook wraps {@link createUnit} to return a formatter
11
+ * that can convert values into human-readable localized units
12
+ * (e.g., "10 km", "5 lbs").
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const formatUnit = useUnit();
17
+ * const distance = formatUnit(10, { unit: "kilometer" });
18
+ * // "10 km" (depending on locale)
19
+ * ```
20
+ *
21
+ * @returns {Function} A unit formatting function that accepts a value and optional formatting options.
22
+ */
23
+ const useUnit = () => {
24
+ const locale = getServerContext(IntlayerServerContext);
25
+ return (...args) => units(args[0], {
26
+ ...args[1],
27
+ locale: args[1]?.locale ?? locale
28
+ });
29
+ };
30
+
31
+ //#endregion
32
+ export { useUnit };
2
33
  //# sourceMappingURL=useUnit.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/server/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"gLAsBA,MAAa,MAAgB,CAC3B,IAAM,EAAS,EAAgC,EAAsB,CAErE,OAAQ,GAAG,IACT,EAAM,EAAK,GAAI,CACb,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
1
+ {"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/server/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAgC,sBAAsB;AAErE,SAAQ,GAAG,SACT,MAAM,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1 +1,12 @@
1
- import{IntlayerServerContext as e,IntlayerServerProvider as t,locale as n}from"./IntlayerServerProvider.mjs";import{t as r}from"./t.mjs";import{useI18n as i}from"./useI18n.mjs";import{useIntlayer as a}from"./useIntlayer.mjs";import{useDictionary as o}from"./useDictionary.mjs";import{useDictionaryAsync as s}from"./useDictionaryAsync.mjs";import{useLocale as c}from"./useLocale.mjs";import{useLoadDynamic as l}from"./useLoadDynamic.mjs";import{useDictionaryDynamic as u}from"./useDictionaryDynamic.mjs";import{useIntl as d}from"./format/useIntl.mjs";export{e as IntlayerServer,t as IntlayerServerProvider,n as locale,r as t,o as useDictionary,s as useDictionaryAsync,u as useDictionaryDynamic,i as useI18n,d as useIntl,a as useIntlayer,l as useLoadDynamic,c as useLocale};
1
+ import { IntlayerServerContext, IntlayerServerProvider, locale } from "./IntlayerServerProvider.mjs";
2
+ import { t } from "./t.mjs";
3
+ import { useI18n } from "./useI18n.mjs";
4
+ import { useIntlayer } from "./useIntlayer.mjs";
5
+ import { useDictionary } from "./useDictionary.mjs";
6
+ import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
7
+ import { useLocale } from "./useLocale.mjs";
8
+ import { useLoadDynamic } from "./useLoadDynamic.mjs";
9
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
10
+ import { useIntl } from "./format/useIntl.mjs";
11
+
12
+ export { IntlayerServerContext as IntlayerServer, IntlayerServerProvider, locale, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale };
@@ -1,2 +1,55 @@
1
- import e from"react";const t=()=>()=>({value:void 0}),n=n=>{i();let r=(e.cache??t)(()=>({value:void 0})),a=({children:e,value:t})=>(r().value=t,e),o=a;return o.Provider=a,o.Consumer=e=>{let t=r();return e.children(t?t.value:n)},o._storage=r,o._defaultValue=n,o},r=({_storage:e,_defaultValue:t})=>{let n=e();return n?n.value:t},i=()=>{if(typeof window<`u`)throw Error(`createServerContext only works in Server Components`)};export{n as createServerContext,r as getServerContext};
1
+ import react from "react";
2
+
3
+ //#region src/server/serverContext.tsx
4
+ /**
5
+ * Creates a new datastore for a given server context.
6
+ * Attempts to closely mimic the `createContext` API.
7
+ *
8
+ * @example
9
+ * const IntlayerServer = createServerContext<string | null>(null);
10
+ *
11
+ * <IntlayerServer value={locale}>
12
+ * {children}
13
+ * </IntlayerServer>
14
+ */
15
+ const cacheFallback = () => () => ({ value: void 0 });
16
+ const createServerContext = (defaultValue) => {
17
+ throwInClient();
18
+ const getCache = (react.cache ?? cacheFallback)(() => ({ value: void 0 }));
19
+ const Provider = ({ children, value }) => {
20
+ getCache().value = value;
21
+ return children;
22
+ };
23
+ const ServerContext = Provider;
24
+ ServerContext.Provider = Provider;
25
+ ServerContext.Consumer = (props) => {
26
+ const store = getCache();
27
+ return props.children(store ? store.value : defaultValue);
28
+ };
29
+ ServerContext._storage = getCache;
30
+ ServerContext._defaultValue = defaultValue;
31
+ return ServerContext;
32
+ };
33
+ /**
34
+ * Fetches a value present in a given server context.
35
+ * Attempts to closely mimic the `useContext` API.
36
+ *
37
+ * @example
38
+ * getServerContext(IntlayerServer);
39
+ */
40
+ const getServerContext = ({ _storage, _defaultValue }) => {
41
+ const store = _storage();
42
+ if (!store) return _defaultValue;
43
+ return store.value;
44
+ };
45
+ /**
46
+ * Throws if called within a client component environment.
47
+ * Useful to help prevent mistakes.
48
+ */
49
+ const throwInClient = () => {
50
+ if (typeof window !== "undefined") throw new Error(`createServerContext only works in Server Components`);
51
+ };
52
+
53
+ //#endregion
54
+ export { createServerContext, getServerContext };
2
55
  //# sourceMappingURL=serverContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"serverContext.mjs","names":[],"sources":["../../../src/server/serverContext.tsx"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer value={locale}>\n * {children}\n * </IntlayerServer>\n */\nimport react, { type FC, type PropsWithChildren, type ReactNode } from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T,>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n const Provider: FC<PropsWithChildren<{ value?: T }>> = ({\n children,\n value,\n }) => {\n getCache().value = value;\n return children;\n };\n\n const ServerContext = Provider as ServerContext<T>;\n ServerContext.Provider = Provider;\n ServerContext.Consumer = (props) => {\n const store = getCache();\n return props.children(store ? store.value : defaultValue);\n };\n ServerContext._storage = getCache;\n ServerContext._defaultValue = defaultValue;\n\n return ServerContext;\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T,>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = FC<PropsWithChildren<{ value?: T }>> & {\n Provider: FC<PropsWithChildren<{ value?: T }>>;\n Consumer: FC<\n PropsWithChildren<{ children: (context: T | undefined) => ReactNode }>\n >;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): undefined | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":"qBAeA,MAAM,WAA6B,CAAE,MAAO,IAAA,GAAW,EAE1C,EAA2B,GAAuC,CAC7E,GAAe,CAKf,IAAM,GAFQ,EAAM,OAAuB,QAEb,CAC5B,MAAO,IAAA,GACR,EAAE,CAEG,GAAkD,CACtD,WACA,YAEA,GAAU,CAAC,MAAQ,EACZ,GAGH,EAAgB,EAStB,MARA,GAAc,SAAW,EACzB,EAAc,SAAY,GAAU,CAClC,IAAM,EAAQ,GAAU,CACxB,OAAO,EAAM,SAAS,EAAQ,EAAM,MAAQ,EAAa,EAE3D,EAAc,SAAW,EACzB,EAAc,cAAgB,EAEvB,GAUI,GAAwB,CACnC,WACA,mBACsB,CAEtB,IAAM,EAAQ,GAAU,CAExB,OADK,EACE,EAAM,MADM,GAiBf,MAAyC,CAE7C,GAAI,OAAO,OAAW,IACpB,MAAU,MAAM,sDAAsD"}
1
+ {"version":3,"file":"serverContext.mjs","names":[],"sources":["../../../src/server/serverContext.tsx"],"sourcesContent":["/**\n * Creates a new datastore for a given server context.\n * Attempts to closely mimic the `createContext` API.\n *\n * @example\n * const IntlayerServer = createServerContext<string | null>(null);\n *\n * <IntlayerServer value={locale}>\n * {children}\n * </IntlayerServer>\n */\nimport react, { type FC, type PropsWithChildren, type ReactNode } from 'react';\n\ntype CacheType<T> = () => { value: T | undefined };\n\nconst cacheFallback = () => () => ({ value: undefined });\n\nexport const createServerContext = <T,>(defaultValue?: T): ServerContext<T> => {\n throwInClient();\n\n /** @ts-ignore remove error Property 'cache' does not exist on type 'typeof React'. */\n const cache = react.cache<CacheType<T>> ?? cacheFallback;\n\n const getCache = cache(() => ({\n value: undefined,\n }));\n\n const Provider: FC<PropsWithChildren<{ value?: T }>> = ({\n children,\n value,\n }) => {\n getCache().value = value;\n return children;\n };\n\n const ServerContext = Provider as ServerContext<T>;\n ServerContext.Provider = Provider;\n ServerContext.Consumer = (props) => {\n const store = getCache();\n return props.children(store ? store.value : defaultValue);\n };\n ServerContext._storage = getCache;\n ServerContext._defaultValue = defaultValue;\n\n return ServerContext;\n};\n\n/**\n * Fetches a value present in a given server context.\n * Attempts to closely mimic the `useContext` API.\n *\n * @example\n * getServerContext(IntlayerServer);\n */\nexport const getServerContext = <T,>({\n _storage,\n _defaultValue,\n}: ServerContext<T>) => {\n // throwInClient();\n const store = _storage();\n if (!store) return _defaultValue;\n return store.value;\n};\n\ntype ServerContext<T> = FC<PropsWithChildren<{ value?: T }>> & {\n Provider: FC<PropsWithChildren<{ value?: T }>>;\n Consumer: FC<\n PropsWithChildren<{ children: (context: T | undefined) => ReactNode }>\n >;\n _storage: () => { value: T | undefined };\n _defaultValue: T | undefined;\n};\n\n/**\n * Throws if called within a client component environment.\n * Useful to help prevent mistakes.\n */\nconst throwInClient = (): undefined | never => {\n // If window.document is defined we're in a client component\n if (typeof window !== 'undefined') {\n throw new Error(`createServerContext only works in Server Components`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAM,6BAA6B,EAAE,OAAO,QAAW;AAEvD,MAAa,uBAA2B,iBAAuC;AAC7E,gBAAe;CAKf,MAAM,YAFQ,MAAM,SAAuB,sBAEb,EAC5B,OAAO,QACR,EAAE;CAEH,MAAM,YAAkD,EACtD,UACA,YACI;AACJ,YAAU,CAAC,QAAQ;AACnB,SAAO;;CAGT,MAAM,gBAAgB;AACtB,eAAc,WAAW;AACzB,eAAc,YAAY,UAAU;EAClC,MAAM,QAAQ,UAAU;AACxB,SAAO,MAAM,SAAS,QAAQ,MAAM,QAAQ,aAAa;;AAE3D,eAAc,WAAW;AACzB,eAAc,gBAAgB;AAE9B,QAAO;;;;;;;;;AAUT,MAAa,oBAAwB,EACnC,UACA,oBACsB;CAEtB,MAAM,QAAQ,UAAU;AACxB,KAAI,CAAC,MAAO,QAAO;AACnB,QAAO,MAAM;;;;;;AAgBf,MAAM,sBAAyC;AAE7C,KAAI,OAAO,WAAW,YACpB,OAAM,IAAI,MAAM,sDAAsD"}
@@ -1,2 +1,34 @@
1
- import{getServerContext as e}from"./serverContext.mjs";import{IntlayerServerContext as t}from"./IntlayerServerProvider.mjs";import{getTranslation as n}from"@intlayer/core/interpreter";const r=(r,i)=>{let a=e(t);return n(r,i??a)};export{r as t};
1
+ import { getServerContext } from "./serverContext.mjs";
2
+ import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
3
+ import { getTranslation } from "@intlayer/core/interpreter";
4
+
5
+ //#region src/server/t.ts
6
+ /**
7
+ * On the server side, hook to get the translation content based on the locale
8
+ *
9
+ * If not locale found, it will return the content related to the default locale.
10
+ *
11
+ * Return either the content editor, or the content itself depending on the configuration.
12
+ *
13
+ * Usage:
14
+ *
15
+ * ```ts
16
+ * const content = t<string>({
17
+ * en: 'Hello',
18
+ * fr: 'Bonjour',
19
+ * }, 'fr');
20
+ * // 'Bonjour'
21
+ * ```
22
+ *
23
+ * Using TypeScript:
24
+ * - this function will require each locale to be defined if defined in the project configuration.
25
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
26
+ */
27
+ const t = (multilangContent, locale) => {
28
+ const currentLocale = getServerContext(IntlayerServerContext);
29
+ return getTranslation(multilangContent, locale ?? currentLocale);
30
+ };
31
+
32
+ //#endregion
33
+ export { t };
2
34
  //# sourceMappingURL=t.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"t.mjs","names":[],"sources":["../../../src/server/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { DeclaredLocales, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = t<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const t = <Content = string, L extends LocalesValues = DeclaredLocales>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: L\n) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n const localeTarget = locale ?? (currentLocale as LocalesValues);\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"wLA0BA,MAAa,GACX,EACA,IACG,CACH,IAAM,EAAgB,EAAgC,EAAsB,CAG5E,OAAO,EAAwB,EAFV,GAAW,EAE8B"}
1
+ {"version":3,"file":"t.mjs","names":[],"sources":["../../../src/server/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { DeclaredLocales, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, hook to get the translation content based on the locale\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = t<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const t = <Content = string, L extends LocalesValues = DeclaredLocales>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: L\n) => {\n const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n const localeTarget = locale ?? (currentLocale as LocalesValues);\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,KACX,kBACA,WACG;CACH,MAAM,gBAAgB,iBAAgC,sBAAsB;AAG5E,QAAO,eAAwB,kBAFV,UAAW,cAE8B"}
@@ -1,2 +1,17 @@
1
- import{getDictionary as e}from"../getDictionary.mjs";import{getServerContext as t}from"./serverContext.mjs";import{IntlayerServerContext as n}from"./IntlayerServerProvider.mjs";const r=(r,i,a)=>e(r,i??t(n)??a);export{r as useDictionary};
1
+ import { getDictionary } from "../getDictionary.mjs";
2
+ import { getServerContext } from "./serverContext.mjs";
3
+ import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
4
+
5
+ //#region src/server/useDictionary.ts
6
+ /**
7
+ * On the server side, Hook that transform a dictionary and return the content
8
+ *
9
+ * If the locale is not provided, it will use the locale from the server context
10
+ */
11
+ const useDictionary = (dictionary, locale, fallbackLocale) => {
12
+ return getDictionary(dictionary, locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale);
13
+ };
14
+
15
+ //#endregion
16
+ export { useDictionary };
2
17
  //# sourceMappingURL=useDictionary.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"iLAcA,MAAa,GAIX,EACA,EACA,IAOO,EAAoB,EAJzB,GACA,EAAgC,EAAsB,EACtD,EAEuD"}
1
+ {"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAa,iBAIX,YACA,QACA,mBACG;AAMH,QAAO,cAAoB,YAJzB,UACA,iBAAgC,sBAAsB,IACtD,eAEuD"}
@@ -1,2 +1,19 @@
1
- import{getServerContext as e}from"./serverContext.mjs";import{IntlayerServerContext as t}from"./IntlayerServerProvider.mjs";import{useDictionary as n}from"./useDictionary.mjs";import r from"@intlayer/config/built";const i=async(i,a,o)=>{let s=a??e(t)??o??r?.internationalization.defaultLocale;return n(await i[s]?.(),s)};export{i as useDictionaryAsync};
1
+ import { getServerContext } from "./serverContext.mjs";
2
+ import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
3
+ import { useDictionary } from "./useDictionary.mjs";
4
+ import configuration from "@intlayer/config/built";
5
+
6
+ //#region src/server/useDictionaryAsync.ts
7
+ /**
8
+ * On the server side, Hook that transform a dictionary and return the content
9
+ *
10
+ * If the locale is not provided, it will use the locale from the server context
11
+ */
12
+ const useDictionaryAsync = async (dictionaryPromise, locale, fallbackLocale) => {
13
+ const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale ?? configuration?.internationalization.defaultLocale;
14
+ return useDictionary(await dictionaryPromise[localeTarget]?.(), localeTarget);
15
+ };
16
+
17
+ //#endregion
18
+ export { useDictionaryAsync };
2
19
  //# sourceMappingURL=useDictionaryAsync.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"sNAgBA,MAAa,EAAqB,MAIhC,EACA,EACA,IACG,CACH,IAAM,EACJ,GACA,EAAgC,EAAsB,EACtD,GACA,GAAe,qBAAqB,cAItC,OAAO,EAFY,MAAO,EAA0B,MAAiB,CAE9B,EAAkB"}
1
+ {"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAIhC,mBACA,QACA,mBACG;CACH,MAAM,eACJ,UACA,iBAAgC,sBAAsB,IACtD,kBACA,eAAe,qBAAqB;AAItC,QAAO,cAFY,MAAO,kBAA0B,iBAAiB,EAE9B,aAAkB"}
@@ -1,2 +1,20 @@
1
- import{getServerContext as e}from"./serverContext.mjs";import{IntlayerServerContext as t}from"./IntlayerServerProvider.mjs";import{useDictionary as n}from"./useDictionary.mjs";import{useLoadDynamic as r}from"./useLoadDynamic.mjs";import i from"@intlayer/config/built";const a=(a,o,s,c)=>{let l=s??e(t)??c??i?.internationalization.defaultLocale;return n(r(`${String(o)}.${l}`,a[l]?.()),l)};export{a as useDictionaryDynamic};
1
+ import { getServerContext } from "./serverContext.mjs";
2
+ import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
3
+ import { useDictionary } from "./useDictionary.mjs";
4
+ import { useLoadDynamic } from "./useLoadDynamic.mjs";
5
+ import configuration from "@intlayer/config/built";
6
+
7
+ //#region src/server/useDictionaryDynamic.ts
8
+ /**
9
+ * On the server side, Hook that transform a dictionary and return the content
10
+ *
11
+ * If the locale is not provided, it will use the locale from the server context
12
+ */
13
+ const useDictionaryDynamic = (dictionaryPromise, key, locale, fallbackLocale) => {
14
+ const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale ?? configuration?.internationalization.defaultLocale;
15
+ return useDictionary(useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
16
+ };
17
+
18
+ //#endregion
19
+ export { useDictionaryDynamic };
2
20
  //# sourceMappingURL=useDictionaryDynamic.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":"4QAiBA,MAAa,GAIX,EACA,EACA,EACA,IACG,CACH,IAAM,EACJ,GACA,EAAgC,EAAsB,EACtD,GACA,GAAe,qBAAqB,cAOtC,OAAO,EALY,EACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEsC,EAAkB"}
1
+ {"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAa,wBAIX,mBACA,KACA,QACA,mBACG;CACH,MAAM,eACJ,UACA,iBAAgC,sBAAsB,IACtD,kBACA,eAAe,qBAAqB;AAOtC,QAAO,cALY,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBACjB,kBAA0B,iBAAiB,CAC7C,EAEsC,aAAkB"}