generaltranslation 8.2.11 → 8.2.13

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 (264) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{IntlCache-k2qfrDqB.cjs → IntlCache-CAW8tKhd.cjs} +12 -12
  3. package/dist/IntlCache-CAW8tKhd.cjs.map +1 -0
  4. package/dist/{IntlCache-Ccg_cQPR.mjs → IntlCache-WZk0rKvj.mjs} +12 -12
  5. package/dist/IntlCache-WZk0rKvj.mjs.map +1 -0
  6. package/dist/LocaleConfig.d.ts +59 -0
  7. package/dist/LocaleConfig.js +225 -0
  8. package/dist/backwards-compatability/dataConversion.d.ts +23 -0
  9. package/dist/backwards-compatability/dataConversion.js +207 -0
  10. package/dist/backwards-compatability/oldHashJsxChildren.d.ts +23 -0
  11. package/dist/backwards-compatability/oldHashJsxChildren.js +79 -0
  12. package/dist/backwards-compatability/oldTypes.d.ts +21 -0
  13. package/dist/backwards-compatability/oldTypes.js +1 -0
  14. package/dist/backwards-compatability/typeChecking.d.ts +21 -0
  15. package/dist/backwards-compatability/typeChecking.js +61 -0
  16. package/dist/{base64-CUcEPEC5.cjs → base64-2fu94Klt.cjs} +3 -3
  17. package/dist/base64-2fu94Klt.cjs.map +1 -0
  18. package/dist/{base64-C1sogiix.mjs → base64-DH0STixb.mjs} +3 -3
  19. package/dist/base64-DH0STixb.mjs.map +1 -0
  20. package/dist/cache/IntlCache.d.ts +26 -0
  21. package/dist/cache/IntlCache.js +84 -0
  22. package/dist/cache/types.d.ts +32 -0
  23. package/dist/cache/types.js +1 -0
  24. package/dist/{core-3SOQ5ND6.cjs → core-7RP541eY.cjs} +18 -20
  25. package/dist/core-7RP541eY.cjs.map +1 -0
  26. package/dist/{core-6rY3oy32.d.cts → core-I9pWGafA.d.mts} +8 -8
  27. package/dist/{core-BYVWty_t.d.mts → core-TLJoDpJP.d.cts} +8 -8
  28. package/dist/{core-Bx0m6GOp.mjs → core-isLphYAZ.mjs} +18 -20
  29. package/dist/core-isLphYAZ.mjs.map +1 -0
  30. package/dist/core.cjs +1 -1
  31. package/dist/core.d.cts +1 -1
  32. package/dist/core.d.mts +1 -1
  33. package/dist/core.d.ts +128 -0
  34. package/dist/core.js +137 -0
  35. package/dist/core.mjs +1 -1
  36. package/dist/derive/condenseVars.d.ts +7 -0
  37. package/dist/derive/condenseVars.js +30 -0
  38. package/dist/derive/declareVar.d.ts +26 -0
  39. package/dist/derive/declareVar.js +38 -0
  40. package/dist/derive/decodeVars.d.ts +9 -0
  41. package/dist/derive/decodeVars.js +52 -0
  42. package/dist/derive/derive.d.ts +53 -0
  43. package/dist/derive/derive.js +55 -0
  44. package/dist/derive/extractVars.d.ts +9 -0
  45. package/dist/derive/extractVars.js +34 -0
  46. package/dist/derive/index.d.ts +7 -0
  47. package/dist/derive/index.js +7 -0
  48. package/dist/derive/indexVars.d.ts +6 -0
  49. package/dist/derive/indexVars.js +52 -0
  50. package/dist/derive/utils/constants.d.ts +2 -0
  51. package/dist/derive/utils/constants.js +2 -0
  52. package/dist/derive/utils/regex.d.ts +2 -0
  53. package/dist/derive/utils/regex.js +4 -0
  54. package/dist/derive/utils/sanitizeVar.d.ts +12 -0
  55. package/dist/derive/utils/sanitizeVar.js +38 -0
  56. package/dist/derive/utils/traverseHelpers.d.ts +4 -0
  57. package/dist/derive/utils/traverseHelpers.js +22 -0
  58. package/dist/derive/utils/traverseIcu.d.ts +20 -0
  59. package/dist/derive/utils/traverseIcu.js +49 -0
  60. package/dist/derive/utils/types.d.ts +23 -0
  61. package/dist/derive/utils/types.js +1 -0
  62. package/dist/errors/ApiError.d.ts +7 -0
  63. package/dist/errors/ApiError.js +33 -0
  64. package/dist/errors/formattingErrors.d.ts +1 -0
  65. package/dist/errors/formattingErrors.js +3 -0
  66. package/dist/errors.d.ts +1 -0
  67. package/dist/errors.js +1 -0
  68. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +59 -0
  69. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +147 -0
  70. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +4 -0
  71. package/dist/formatting/custom-formats/CutoffFormat/constants.js +30 -0
  72. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +48 -0
  73. package/dist/formatting/custom-formats/CutoffFormat/types.js +2 -0
  74. package/dist/formatting/format.d.ts +1 -0
  75. package/dist/formatting/format.js +257 -0
  76. package/dist/id/hashSource.d.ts +25 -0
  77. package/dist/id/hashSource.js +98 -0
  78. package/dist/id/hashTemplate.d.ts +4 -0
  79. package/dist/id/hashTemplate.js +6 -0
  80. package/dist/id/types.d.ts +7 -0
  81. package/dist/id/types.js +1 -0
  82. package/dist/{id-COlX5v3V.cjs → id-CyiXsQrY.cjs} +9 -9
  83. package/dist/id-CyiXsQrY.cjs.map +1 -0
  84. package/dist/{id-BmOyfaug.mjs → id-DbD7K-HL.mjs} +9 -9
  85. package/dist/id-DbD7K-HL.mjs.map +1 -0
  86. package/dist/id.cjs +1 -1
  87. package/dist/id.d.cts +9 -9
  88. package/dist/id.d.mts +9 -9
  89. package/dist/id.d.ts +3 -0
  90. package/dist/id.js +3 -0
  91. package/dist/id.mjs +1 -1
  92. package/dist/index.cjs +140 -140
  93. package/dist/index.cjs.map +1 -1
  94. package/dist/index.d.cts +88 -88
  95. package/dist/index.d.mts +88 -88
  96. package/dist/index.d.ts +1019 -0
  97. package/dist/index.js +1664 -0
  98. package/dist/index.mjs +140 -140
  99. package/dist/index.mjs.map +1 -1
  100. package/dist/internal.cjs +41 -26
  101. package/dist/internal.cjs.map +1 -1
  102. package/dist/internal.d.cts +38 -23
  103. package/dist/internal.d.mts +38 -23
  104. package/dist/internal.d.ts +19 -0
  105. package/dist/internal.js +17 -0
  106. package/dist/internal.mjs +41 -26
  107. package/dist/internal.mjs.map +1 -1
  108. package/dist/locales/customLocaleMapping.d.ts +11 -0
  109. package/dist/locales/customLocaleMapping.js +23 -0
  110. package/dist/locales/determineLocale.d.ts +1 -0
  111. package/dist/locales/determineLocale.js +72 -0
  112. package/dist/locales/getLocaleDirection.d.ts +1 -0
  113. package/dist/locales/getLocaleDirection.js +89 -0
  114. package/dist/locales/getLocaleEmoji.d.ts +2 -0
  115. package/dist/locales/getLocaleEmoji.js +319 -0
  116. package/dist/locales/getLocaleName.d.ts +1 -0
  117. package/dist/locales/getLocaleName.js +45 -0
  118. package/dist/locales/getLocaleProperties.d.ts +32 -0
  119. package/dist/locales/getLocaleProperties.js +220 -0
  120. package/dist/locales/getPluralForm.d.ts +9 -0
  121. package/dist/locales/getPluralForm.js +63 -0
  122. package/dist/locales/getRegionProperties.d.ts +7 -0
  123. package/dist/locales/getRegionProperties.js +61 -0
  124. package/dist/locales/isSameDialect.d.ts +1 -0
  125. package/dist/locales/isSameDialect.js +41 -0
  126. package/dist/locales/isSameLanguage.d.ts +1 -0
  127. package/dist/locales/isSameLanguage.js +20 -0
  128. package/dist/locales/isSupersetLocale.d.ts +1 -0
  129. package/dist/locales/isSupersetLocale.js +22 -0
  130. package/dist/locales/isValidLocale.d.ts +1 -0
  131. package/dist/locales/isValidLocale.js +75 -0
  132. package/dist/locales/requiresTranslation.d.ts +1 -0
  133. package/dist/locales/requiresTranslation.js +32 -0
  134. package/dist/locales/resolveAliasLocale.d.ts +8 -0
  135. package/dist/locales/resolveAliasLocale.js +21 -0
  136. package/dist/locales/resolveCanonicalLocale.d.ts +8 -0
  137. package/dist/locales/resolveCanonicalLocale.js +13 -0
  138. package/dist/logging/errors.d.ts +10 -0
  139. package/dist/logging/errors.js +29 -0
  140. package/dist/logging/logger.d.ts +121 -0
  141. package/dist/logging/logger.js +259 -0
  142. package/dist/logging/warnings.d.ts +2 -0
  143. package/dist/logging/warnings.js +2 -0
  144. package/dist/projects/getProjectData.d.ts +1 -0
  145. package/dist/projects/getProjectData.js +87 -0
  146. package/dist/settings/plurals.d.ts +3 -0
  147. package/dist/settings/plurals.js +14 -0
  148. package/dist/settings/settings.d.ts +2 -0
  149. package/dist/settings/settings.js +2 -0
  150. package/dist/settings/settingsUrls.d.ts +3 -0
  151. package/dist/settings/settingsUrls.js +3 -0
  152. package/dist/translate/api.d.ts +1 -0
  153. package/dist/translate/api.js +1 -0
  154. package/dist/translate/awaitJobs.d.ts +19 -0
  155. package/dist/translate/awaitJobs.js +112 -0
  156. package/dist/translate/checkJobStatus.d.ts +8 -0
  157. package/dist/translate/checkJobStatus.js +55 -0
  158. package/dist/translate/createBranch.d.ts +10 -0
  159. package/dist/translate/createBranch.js +53 -0
  160. package/dist/translate/createTag.d.ts +19 -0
  161. package/dist/translate/createTag.js +67 -0
  162. package/dist/translate/downloadFileBatch.d.ts +1 -0
  163. package/dist/translate/downloadFileBatch.js +77 -0
  164. package/dist/translate/enqueueFiles.d.ts +8 -0
  165. package/dist/translate/enqueueFiles.js +96 -0
  166. package/dist/translate/getOrphanedFiles.d.ts +8 -0
  167. package/dist/translate/getOrphanedFiles.js +97 -0
  168. package/dist/translate/processFileMoves.d.ts +25 -0
  169. package/dist/translate/processFileMoves.js +90 -0
  170. package/dist/translate/publishFiles.d.ts +17 -0
  171. package/dist/translate/publishFiles.js +56 -0
  172. package/dist/translate/queryBranchData.d.ts +3 -0
  173. package/dist/translate/queryBranchData.js +53 -0
  174. package/dist/translate/queryFileData.d.ts +42 -0
  175. package/dist/translate/queryFileData.js +71 -0
  176. package/dist/translate/querySourceFile.d.ts +1 -0
  177. package/dist/translate/querySourceFile.js +67 -0
  178. package/dist/translate/setupProject.d.ts +11 -0
  179. package/dist/translate/setupProject.js +63 -0
  180. package/dist/translate/submitUserEditDiffs.d.ts +12 -0
  181. package/dist/translate/submitUserEditDiffs.js +68 -0
  182. package/dist/translate/translateMany.d.ts +1 -0
  183. package/dist/translate/translateMany.js +103 -0
  184. package/dist/translate/uploadSourceFiles.d.ts +1 -0
  185. package/dist/translate/uploadSourceFiles.js +87 -0
  186. package/dist/translate/uploadTranslations.d.ts +1 -0
  187. package/dist/translate/uploadTranslations.js +101 -0
  188. package/dist/translate/utils/apiRequest.d.ts +1 -0
  189. package/dist/translate/utils/apiRequest.js +130 -0
  190. package/dist/translate/utils/batch.d.ts +52 -0
  191. package/dist/translate/utils/batch.js +126 -0
  192. package/dist/translate/utils/fetchWithTimeout.d.ts +1 -0
  193. package/dist/translate/utils/fetchWithTimeout.js +93 -0
  194. package/dist/translate/utils/generateRequestHeaders.d.ts +2 -0
  195. package/dist/translate/utils/generateRequestHeaders.js +26 -0
  196. package/dist/translate/utils/handleFetchError.d.ts +1 -0
  197. package/dist/translate/utils/handleFetchError.js +12 -0
  198. package/dist/translate/utils/validateFileFormatTransform.d.ts +16 -0
  199. package/dist/translate/utils/validateFileFormatTransform.js +29 -0
  200. package/dist/translate/utils/validateResponse.d.ts +1 -0
  201. package/dist/translate/utils/validateResponse.js +72 -0
  202. package/dist/{types-Cy8q2XZX.d.mts → types-AHtYZIP-.d.mts} +63 -40
  203. package/dist/{types-NKhpChvT.d.cts → types-Bf8_Apq_.d.cts} +63 -40
  204. package/dist/types-dir/api/branch.d.ts +10 -0
  205. package/dist/types-dir/api/branch.js +1 -0
  206. package/dist/types-dir/api/checkFileTranslations.d.ts +37 -0
  207. package/dist/types-dir/api/checkFileTranslations.js +1 -0
  208. package/dist/types-dir/api/downloadFile.d.ts +3 -0
  209. package/dist/types-dir/api/downloadFile.js +1 -0
  210. package/dist/types-dir/api/downloadFileBatch.d.ts +35 -0
  211. package/dist/types-dir/api/downloadFileBatch.js +1 -0
  212. package/dist/types-dir/api/enqueueEntries.d.ts +21 -0
  213. package/dist/types-dir/api/enqueueEntries.js +1 -0
  214. package/dist/types-dir/api/enqueueFiles.d.ts +70 -0
  215. package/dist/types-dir/api/enqueueFiles.js +1 -0
  216. package/dist/types-dir/api/entry.d.ts +39 -0
  217. package/dist/types-dir/api/entry.js +1 -0
  218. package/dist/types-dir/api/fetchTranslations.d.ts +12 -0
  219. package/dist/types-dir/api/fetchTranslations.js +1 -0
  220. package/dist/types-dir/api/file.d.ts +57 -0
  221. package/dist/types-dir/api/file.js +1 -0
  222. package/dist/types-dir/api/json.d.ts +5 -0
  223. package/dist/types-dir/api/json.js +1 -0
  224. package/dist/types-dir/api/project.d.ts +7 -0
  225. package/dist/types-dir/api/project.js +1 -0
  226. package/dist/types-dir/api/translate.d.ts +34 -0
  227. package/dist/types-dir/api/translate.js +1 -0
  228. package/dist/types-dir/api/translateMany.d.ts +5 -0
  229. package/dist/types-dir/api/translateMany.js +1 -0
  230. package/dist/types-dir/api/translationStatus.d.ts +9 -0
  231. package/dist/types-dir/api/translationStatus.js +1 -0
  232. package/dist/types-dir/api/uploadFiles.d.ts +44 -0
  233. package/dist/types-dir/api/uploadFiles.js +1 -0
  234. package/dist/types-dir/jsx/content.d.ts +61 -0
  235. package/dist/types-dir/jsx/content.js +11 -0
  236. package/dist/types-dir/jsx/variables.d.ts +9 -0
  237. package/dist/types-dir/jsx/variables.js +1 -0
  238. package/dist/types-dir/transformations.d.ts +8 -0
  239. package/dist/types-dir/transformations.js +1 -0
  240. package/dist/types.cjs.map +1 -1
  241. package/dist/types.d.cts +2 -2
  242. package/dist/types.d.mts +2 -2
  243. package/dist/types.d.ts +129 -0
  244. package/dist/types.js +2 -0
  245. package/dist/types.mjs.map +1 -1
  246. package/dist/utils/base64.d.ts +2 -0
  247. package/dist/utils/base64.js +28 -0
  248. package/dist/utils/isSupportedFileFormatTransform.d.ts +8 -0
  249. package/dist/utils/isSupportedFileFormatTransform.js +26 -0
  250. package/dist/utils/isVariable.d.ts +2 -0
  251. package/dist/utils/isVariable.js +22 -0
  252. package/dist/utils/minify.d.ts +2 -0
  253. package/dist/utils/minify.js +10 -0
  254. package/dist/utils/stableStringify.d.ts +1 -0
  255. package/dist/utils/stableStringify.js +40 -0
  256. package/package.json +5 -6
  257. package/dist/IntlCache-Ccg_cQPR.mjs.map +0 -1
  258. package/dist/IntlCache-k2qfrDqB.cjs.map +0 -1
  259. package/dist/base64-C1sogiix.mjs.map +0 -1
  260. package/dist/base64-CUcEPEC5.cjs.map +0 -1
  261. package/dist/core-3SOQ5ND6.cjs.map +0 -1
  262. package/dist/core-Bx0m6GOp.mjs.map +0 -1
  263. package/dist/id-BmOyfaug.mjs.map +0 -1
  264. package/dist/id-COlX5v3V.cjs.map +0 -1
package/dist/internal.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_IntlCache = require("./IntlCache-k2qfrDqB.cjs");
3
- const require_base64 = require("./base64-CUcEPEC5.cjs");
2
+ const require_IntlCache = require("./IntlCache-CAW8tKhd.cjs");
3
+ const require_base64 = require("./base64-2fu94Klt.cjs");
4
4
  const require_isVariable = require("./isVariable-B08mggBy.cjs");
5
5
  let _formatjs_icu_messageformat_parser = require("@formatjs/icu-messageformat-parser");
6
6
  let _formatjs_icu_messageformat_parser_types_js = require("@formatjs/icu-messageformat-parser/types.js");
@@ -26,7 +26,7 @@ function isAcceptedPluralForm(form) {
26
26
  * Given a number and a list of allowed plural forms, return the plural form that best fits the number.
27
27
  *
28
28
  * @param {number} n - The number to determine the plural form for.
29
- * @param {locales[]} forms - The allowed plural forms.
29
+ * @param {PluralType[]} forms - The allowed plural forms.
30
30
  * @returns {PluralType} The determined plural form, or an empty string if none fit.
31
31
  */
32
32
  function _getPluralForm(n, forms = pluralForms, locales = ["en"]) {
@@ -73,7 +73,7 @@ function minifyVariableType(variableType) {
73
73
  * @param icu - The ICU string to traverse
74
74
  * @param shouldVisit - A function that returns true if the element should be visited
75
75
  * @param visitor - A function that is called for each element that matches the type T
76
- * @returns The modified AST of the ICU string
76
+ * @returns The modified AST of the ICU string.
77
77
  *
78
78
  * @note This function is a heavy operation, use sparingly
79
79
  */
@@ -211,9 +211,19 @@ function declareVar(variable, options) {
211
211
  //#endregion
212
212
  //#region src/derive/derive.ts
213
213
  /**
214
- * derive() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.
214
+ * Marks content as derivable by the GT compiler and CLI.
215
215
  *
216
- * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.
216
+ * Use `derive()` when a translation string or context needs content that is
217
+ * computed from source code, but should still be discovered during extraction
218
+ * instead of treated as a runtime interpolation variable. The CLI attempts to
219
+ * resolve the derivable expression into every possible static value and
220
+ * includes those values in the source content that gets translated.
221
+ *
222
+ * `derive()` returns its argument unchanged at runtime.
223
+ *
224
+ * Run `gt validate` after adding or changing `derive()` calls to verify that
225
+ * each derivable expression can be resolved by the CLI before translating or
226
+ * building.
217
227
  *
218
228
  * @example
219
229
  * ```jsx
@@ -224,8 +234,8 @@ function declareVar(variable, options) {
224
234
  * gt(`My name is ${derive(getSubject())}`);
225
235
  * ```
226
236
  *
227
- * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.
228
- * @returns content
237
+ * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
238
+ * @returns {T} The same content, unchanged at runtime.
229
239
  */
230
240
  function derive(content) {
231
241
  return content;
@@ -233,9 +243,14 @@ function derive(content) {
233
243
  /**
234
244
  * @deprecated Use derive() instead.
235
245
  *
236
- * declareStatic() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.
246
+ * Marks content as derivable by the GT compiler and CLI.
247
+ *
248
+ * Use `derive()` instead of `declareStatic()` for new code. This alias is kept
249
+ * for backwards compatibility and returns its argument unchanged at runtime.
237
250
  *
238
- * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.
251
+ * Run `gt validate` after adding or changing derived content to verify that
252
+ * each derivable expression can be resolved by the CLI before translating or
253
+ * building.
239
254
  *
240
255
  * @example
241
256
  * ```jsx
@@ -246,8 +261,8 @@ function derive(content) {
246
261
  * gt(`My name is ${declareStatic(getSubject())}`);
247
262
  * ```
248
263
  *
249
- * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.
250
- * @returns content
264
+ * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
265
+ * @returns {T} The same content, unchanged at runtime.
251
266
  */
252
267
  const declareStatic = derive;
253
268
  //#endregion
@@ -329,7 +344,7 @@ function condenseVars(icuString) {
329
344
  if (!icuString.includes("_gt_")) return icuString;
330
345
  function visitor(child) {
331
346
  child.type = _formatjs_icu_messageformat_parser_types_js.TYPE.argument;
332
- delete child.options;
347
+ Reflect.deleteProperty(child, "options");
333
348
  }
334
349
  return (0, _formatjs_icu_messageformat_parser_printer_js.printAST)(traverseIcu({
335
350
  icuString,
@@ -342,7 +357,7 @@ function condenseVars(icuString) {
342
357
  //#region src/backwards-compatability/typeChecking.ts
343
358
  /**
344
359
  * Checks if a JSX child is an old variable object format
345
- * @param child - The JSX child to check
360
+ * @param child - The JSX child to check.
346
361
  * @returns True if the child is an old variable object (has 'key' property)
347
362
  */
348
363
  function isOldVariableObject(child) {
@@ -350,7 +365,7 @@ function isOldVariableObject(child) {
350
365
  }
351
366
  /**
352
367
  * Checks if a JSX child is a new variable object format
353
- * @param child - The JSX child to check
368
+ * @param child - The JSX child to check.
354
369
  * @returns True if the child is a new variable object (has 'k' property)
355
370
  */
356
371
  function isNewVariableObject(child) {
@@ -358,7 +373,7 @@ function isNewVariableObject(child) {
358
373
  }
359
374
  /**
360
375
  * Checks if a JSX child is an old JSX element format
361
- * @param child - The JSX child to check
376
+ * @param child - The JSX child to check.
362
377
  * @returns True if the child is an old JSX element (has 'type' and 'props' properties)
363
378
  */
364
379
  function isOldJsxElement(child) {
@@ -366,8 +381,8 @@ function isOldJsxElement(child) {
366
381
  }
367
382
  /**
368
383
  * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)
369
- * @param child - The JSX child to check
370
- * @returns True if the child is in the old format
384
+ * @param child - The JSX child to check.
385
+ * @returns True if the child is in the old format.
371
386
  */
372
387
  function isOldJsxChild(child) {
373
388
  if (typeof child === "string") return true;
@@ -377,7 +392,7 @@ function isOldJsxChild(child) {
377
392
  /**
378
393
  * Checks if JSX children follow the old format
379
394
  * @param children - The JSX children to check (can be string, array, or single child)
380
- * @returns True if all children are in the old format
395
+ * @returns True if all children are in the old format.
381
396
  */
382
397
  function isOldJsxChildren(children) {
383
398
  if (typeof children === "string") return true;
@@ -447,7 +462,7 @@ function getNewGTProp(dataGT) {
447
462
  };
448
463
  }
449
464
  /**
450
- * Convert response data from old format to new format
465
+ * Convert response data from current format to old format
451
466
  */
452
467
  function getOldJsxChild(child) {
453
468
  if (typeof child === "string") return child;
@@ -511,10 +526,10 @@ function getOldGTProp(dataGT, i) {
511
526
  //#endregion
512
527
  //#region src/backwards-compatability/oldHashJsxChildren.ts
513
528
  /**
514
- * Calculates a unique hash for a given string using sha256.
529
+ * Calculates a unique hash for a given string using SHA-256.
515
530
  *
516
531
  * @param {string} string - The string to be hashed.
517
- * @returns {string} - The resulting hash as a hexadecimal string.
532
+ * @returns {string} The resulting hash as a hexadecimal string.
518
533
  */
519
534
  function oldHashString(string) {
520
535
  return require_isVariable.bytesToHex(require_isVariable.sha256(require_isVariable.utf8ToBytes(string)));
@@ -523,10 +538,10 @@ function oldHashString(string) {
523
538
  * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
524
539
  *
525
540
  * @param {any} childrenAsObjects - The children objects to be hashed.
526
- * @param {string} context - The context for the children
527
- * @param {string} id - The id for the JSX Children object
528
- * @param {function} hashFunction custom hash function
529
- * @returns {string} - The unique has of the children.
541
+ * @param {string} context - The context for the children.
542
+ * @param {string} id - The ID for the JSX children object.
543
+ * @param {function} hashFunction - Custom hash function.
544
+ * @returns {string} - The unique hash of the children.
530
545
  */
531
546
  function oldHashJsxChildren({ source, context, id, dataFormat }, hashFunction = oldHashString) {
532
547
  return hashFunction(require_isVariable.stableStringify({
@@ -1 +1 @@
1
- {"version":3,"file":"internal.cjs","names":["intlCache","TYPE","TYPE","TYPE","bytesToHex","sha256","utf8ToBytes","stringify"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts","../src/backwards-compatability/typeChecking.ts","../src/backwards-compatability/dataConversion.ts","../src/backwards-compatability/oldHashJsxChildren.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { intlCache } from '../cache/IntlCache';\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {locales[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: PluralType[] = pluralForms as any,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = intlCache.get('PluralRules', locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n MessageFormatElement,\n parse,\n ParserOptions,\n TYPE,\n} from '@formatjs/icu-messageformat-parser';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport {\n type MessageFormatElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode)\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters, return with just doubled quotes\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // variable section\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // name section\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * derive() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.\n *\n * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.\n * @returns content\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n\n/**\n * @deprecated Use derive() instead.\n *\n * declareStatic() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.\n *\n * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${declareStatic(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.\n * @returns content\n */\nexport const declareStatic = derive;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { IcuMessage } from '../types-dir/jsx/content';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import {\n type ArgumentElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\nimport { printAST } from '@formatjs/icu-messageformat-parser/printer.js';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n delete (child as any).options;\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n","import { JsxChild, JsxChildren } from '../types';\nimport {\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n} from './oldTypes.js';\nimport { Variable as VariableObject } from '../types';\n\n/**\n * Checks if a JSX child is an old variable object format\n * @param child - The JSX child to check\n * @returns True if the child is an old variable object (has 'key' property)\n */\nexport function isOldVariableObject(\n child: OldJsxChild | JsxChild\n): child is OldVariableObject {\n return typeof child === 'object' && child != null && 'key' in child;\n}\n\n/**\n * Checks if a JSX child is a new variable object format\n * @param child - The JSX child to check\n * @returns True if the child is a new variable object (has 'k' property)\n */\nexport function isNewVariableObject(\n child: OldJsxChild | JsxChild\n): child is VariableObject {\n return typeof child === 'object' && child != null && 'k' in child;\n}\n\n/**\n * Checks if a JSX child is an old JSX element format\n * @param child - The JSX child to check\n * @returns True if the child is an old JSX element (has 'type' and 'props' properties)\n */\nfunction isOldJsxElement(\n child: OldJsxChild | JsxChild\n): child is OldJsxElement {\n return (\n typeof child === 'object' &&\n child != null &&\n 'type' in child &&\n 'props' in child\n );\n}\n\n/**\n * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)\n * @param child - The JSX child to check\n * @returns True if the child is in the old format\n */\nfunction isOldJsxChild(child: OldJsxChild | JsxChild): child is OldJsxChild {\n // string\n if (typeof child === 'string') {\n return true;\n }\n\n // variable object\n if (isOldVariableObject(child)) {\n return true;\n }\n\n // element\n return isOldJsxElement(child);\n}\n\n/**\n * Checks if JSX children follow the old format\n * @param children - The JSX children to check (can be string, array, or single child)\n * @returns True if all children are in the old format\n */\nexport function isOldJsxChildren(\n children: OldJsxChildren | JsxChildren\n): children is OldJsxChildren {\n // string\n if (typeof children === 'string') {\n return true;\n }\n\n // array\n if (Array.isArray(children)) {\n return !children.some((child) => !isOldJsxChild(child));\n }\n\n // object\n return isOldJsxChild(children);\n}\n","import { Variable as VariableObject, VariableType } from '../types';\nimport {\n OldBranchType,\n OldGTProp,\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n OldVariableType,\n} from './oldTypes.js';\nimport { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';\nimport {\n isOldJsxChildren,\n isNewVariableObject,\n isOldVariableObject,\n} from './typeChecking';\n\n/**\n * Convert request data from old format to new format\n */\n\nexport function getNewJsxChild(child: OldJsxChild): JsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isOldVariableObject(child)) {\n return getNewVariableObject(child);\n }\n\n // JsxElement\n return getNewJsxElement(child);\n}\n\nexport function getNewJsxChildren(children: OldJsxChildren): JsxChildren {\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getNewJsxChild);\n }\n\n // Object\n return getNewJsxChild(children);\n}\n\nexport function getNewJsxElement(element: OldJsxElement): JsxElement {\n // string (end case)\n if (typeof element === 'string') {\n return element;\n }\n\n // type\n let t: string | undefined = undefined;\n if (element.type != null) {\n t = element.type;\n }\n // children\n let c: JsxChildren | undefined = undefined;\n if (element.props?.children != null) {\n c = getNewJsxChildren(element.props.children);\n }\n return {\n ...(t && { t }),\n ...(c && { c }),\n d: getNewGTProp(element.props['data-_gt']),\n i: element.props['data-_gt'].id,\n };\n}\n\nexport function getNewBranchType(branch: OldBranchType): 'b' | 'p' {\n if (branch === 'branch') {\n return 'b';\n }\n return 'p';\n}\n\nexport function getNewVariableType(variable: OldVariableType): VariableType {\n switch (variable) {\n case 'number':\n return 'n';\n case 'variable':\n return 'v';\n case 'datetime':\n return 'd';\n case 'currency':\n return 'c';\n default:\n return 'v';\n }\n}\n\nexport function getNewVariableObject(\n variable: OldVariableObject\n): VariableObject {\n // variable type\n let v: VariableType | undefined = undefined;\n if (variable.variable != null) {\n v = getNewVariableType(variable.variable);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.id != null) {\n i = variable.id;\n }\n return {\n k: variable.key,\n ...(v && { v }),\n ...(i && { i }),\n };\n}\n\nexport function getNewGTProp(dataGT: OldGTProp): GTProp {\n // branches\n let b: Record<string, JsxChildren> | undefined = undefined;\n if (dataGT.branches) {\n b = Object.fromEntries(\n Object.entries(dataGT.branches).map(([key, value]) => [\n key,\n getNewJsxChildren(value),\n ])\n );\n }\n // transformation\n let t: 'b' | 'p' | undefined;\n if (dataGT.transformation) {\n t = getNewBranchType(dataGT.transformation);\n }\n return { ...(b && { b }), ...(t && { t }) };\n}\n\n/**\n * Convert response data from old format to new format\n */\n\nexport function getOldJsxChild(child: JsxChild): OldJsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isNewVariableObject(child)) {\n return getOldVariableObject(child);\n }\n\n // JsxElement\n return getOldJsxElement(child);\n}\n\nexport function getOldJsxChildren(\n children: JsxChildren | OldJsxChildren\n): OldJsxChildren {\n // if children is already old, return it\n if (isOldJsxChildren(children)) {\n return children;\n }\n\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getOldJsxChild);\n }\n\n // Object\n return getOldJsxChild(children);\n}\n\nexport function getOldJsxElement(element: JsxElement): OldJsxElement {\n // type (can assume that type will exist here)\n const type: string = element.t as string;\n // children\n let children: OldJsxChildren | undefined = undefined;\n if (element.c != null) {\n children = getOldJsxChildren(element.c);\n }\n // data-_gt (can assume id will exist here)\n const dataGT: OldGTProp = getOldGTProp(element.d || {}, element.i as number);\n return {\n type,\n props: { children, 'data-_gt': dataGT },\n };\n}\n\nexport function getOldBranchType(branch: 'b' | 'p'): OldBranchType {\n if (branch === 'b') {\n return 'branch';\n }\n return 'plural';\n}\n\nexport function getOldVariableType(variable: VariableType): OldVariableType {\n switch (variable) {\n case 'n':\n return 'number';\n case 'v':\n return 'variable';\n case 'd':\n return 'datetime';\n case 'c':\n return 'currency';\n default:\n return 'variable';\n }\n}\n\nexport function getOldVariableObject(\n variable: VariableObject\n): OldVariableObject {\n // variable type\n let v: OldVariableType | undefined = undefined;\n if (variable.v != null) {\n v = getOldVariableType(variable.v);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.i != null) {\n i = variable.i;\n }\n return {\n key: variable.k,\n ...(v && { variable: v }),\n ...(i && { id: i }),\n };\n}\n\nexport function getOldGTProp(dataGT: GTProp, i: number): OldGTProp {\n // transformation\n let transformation: OldBranchType | undefined = undefined;\n if (dataGT.t != null) {\n transformation = getOldBranchType(dataGT.t);\n }\n // branches\n let branches: Record<string, OldJsxChildren> | undefined = undefined;\n if (dataGT.b != null) {\n branches = Object.fromEntries(\n Object.entries(dataGT.b).map(([key, value]) => [\n key,\n getOldJsxChildren(value),\n ])\n );\n }\n return {\n id: i,\n ...(transformation && { transformation }),\n ...(branches && { branches }),\n };\n}\n","// Functions provided to other GT libraries\n\nimport { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using sha256.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} - The resulting hash as a hexadecimal string.\n */\nexport function oldHashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string)));\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} context - The context for the children\n * @param {string} id - The id for the JSX Children object\n * @param {function} hashFunction custom hash function\n * @returns {string} - The unique has of the children.\n */\nexport function oldHashJsxChildren(\n {\n source,\n context,\n id,\n dataFormat,\n }: {\n source: OldJsxChildren;\n context?: string;\n id?: string;\n dataFormat: string;\n },\n hashFunction: (string: string) => string = oldHashString\n): string {\n const unhashedKey = stringify({\n source: sanitizeJsxChildren(source),\n ...(id && { id }),\n ...(context && { context }),\n ...(dataFormat && { dataFormat }),\n });\n return hashFunction(unhashedKey);\n}\n\ntype SanitizedVariable = Omit<OldVariableObject, 'id'>;\n\ntype SanitizedElement = {\n branches?: {\n [k: string]: SanitizedChildren;\n };\n children?: SanitizedChildren;\n transformation?: string;\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\nconst sanitizeChild = (child: OldJsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n if ('props' in child) {\n const newChild: SanitizedChild = {};\n const dataGt = child?.props?.['data-_gt'];\n if (dataGt?.branches) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.branches = Object.fromEntries(\n Object.entries(dataGt.branches).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as OldJsxChildren),\n ])\n );\n }\n if (child?.props?.children) {\n newChild.children = sanitizeJsxChildren(child.props.children);\n }\n if (child?.props?.['data-_gt']?.transformation) {\n newChild.transformation = child.props['data-_gt'].transformation;\n }\n return newChild;\n }\n if ('key' in child) {\n return {\n key: child.key,\n ...(child.variable && {\n variable: child.variable,\n }),\n };\n }\n }\n return child as string;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: OldJsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA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AAM,SAAS,OAAO,QAAQ;AAC9B,OAAI,QAAQ,SAIV,UAAS,WAAW,OAAO,YACzB,OAAO,QAAQ,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,WAAW,CACpD,KACA,oBAAoB,MAAwB,CAC7C,CAAC,CACH;AAEH,OAAI,OAAO,OAAO,SAChB,UAAS,WAAW,oBAAoB,MAAM,MAAM,SAAS;AAE/D,OAAI,OAAO,QAAQ,aAAa,eAC9B,UAAS,iBAAiB,MAAM,MAAM,YAAY;AAEpD,UAAO;;AAET,MAAI,SAAS,MACX,QAAO;GACL,KAAK,MAAM;GACX,GAAI,MAAM,YAAY,EACpB,UAAU,MAAM,UACjB;GACF;;AAGL,QAAO;;AAGT,SAAS,oBACP,mBACmB;AACnB,QAAO,MAAM,QAAQ,kBAAkB,GACnC,kBAAkB,IAAI,cAAc,GACpC,cAAc,kBAAkB"}
1
+ {"version":3,"file":"internal.cjs","names":["intlCache","TYPE","TYPE","TYPE","bytesToHex","sha256","utf8ToBytes","stringify"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts","../src/backwards-compatability/typeChecking.ts","../src/backwards-compatability/dataConversion.ts","../src/backwards-compatability/oldHashJsxChildren.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { intlCache } from '../cache/IntlCache';\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = intlCache.get('PluralRules', locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n MessageFormatElement,\n parse,\n ParserOptions,\n TYPE,\n} from '@formatjs/icu-messageformat-parser';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport {\n type MessageFormatElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n\n/**\n * @deprecated Use derive() instead.\n *\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` instead of `declareStatic()` for new code. This alias is kept\n * for backwards compatibility and returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing derived content to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${declareStatic(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport const declareStatic = derive;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { IcuMessage } from '../types-dir/jsx/content';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import {\n type ArgumentElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\nimport { printAST } from '@formatjs/icu-messageformat-parser/printer.js';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n","import { JsxChild, JsxChildren } from '../types';\nimport {\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n} from './oldTypes.js';\nimport { Variable as VariableObject } from '../types';\n\n/**\n * Checks if a JSX child is an old variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is an old variable object (has 'key' property)\n */\nexport function isOldVariableObject(\n child: OldJsxChild | JsxChild\n): child is OldVariableObject {\n return typeof child === 'object' && child != null && 'key' in child;\n}\n\n/**\n * Checks if a JSX child is a new variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is a new variable object (has 'k' property)\n */\nexport function isNewVariableObject(\n child: OldJsxChild | JsxChild\n): child is VariableObject {\n return typeof child === 'object' && child != null && 'k' in child;\n}\n\n/**\n * Checks if a JSX child is an old JSX element format\n * @param child - The JSX child to check.\n * @returns True if the child is an old JSX element (has 'type' and 'props' properties)\n */\nfunction isOldJsxElement(\n child: OldJsxChild | JsxChild\n): child is OldJsxElement {\n return (\n typeof child === 'object' &&\n child != null &&\n 'type' in child &&\n 'props' in child\n );\n}\n\n/**\n * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)\n * @param child - The JSX child to check.\n * @returns True if the child is in the old format.\n */\nfunction isOldJsxChild(child: OldJsxChild | JsxChild): child is OldJsxChild {\n // string\n if (typeof child === 'string') {\n return true;\n }\n\n // variable object\n if (isOldVariableObject(child)) {\n return true;\n }\n\n // element\n return isOldJsxElement(child);\n}\n\n/**\n * Checks if JSX children follow the old format\n * @param children - The JSX children to check (can be string, array, or single child)\n * @returns True if all children are in the old format.\n */\nexport function isOldJsxChildren(\n children: OldJsxChildren | JsxChildren\n): children is OldJsxChildren {\n // string\n if (typeof children === 'string') {\n return true;\n }\n\n // array\n if (Array.isArray(children)) {\n return !children.some((child) => !isOldJsxChild(child));\n }\n\n // object\n return isOldJsxChild(children);\n}\n","import { Variable as VariableObject, VariableType } from '../types';\nimport {\n OldBranchType,\n OldGTProp,\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n OldVariableType,\n} from './oldTypes.js';\nimport { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';\nimport {\n isOldJsxChildren,\n isNewVariableObject,\n isOldVariableObject,\n} from './typeChecking';\n\n/**\n * Convert request data from old format to new format\n */\n\nexport function getNewJsxChild(child: OldJsxChild): JsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isOldVariableObject(child)) {\n return getNewVariableObject(child);\n }\n\n // JsxElement\n return getNewJsxElement(child);\n}\n\nexport function getNewJsxChildren(children: OldJsxChildren): JsxChildren {\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getNewJsxChild);\n }\n\n // Object\n return getNewJsxChild(children);\n}\n\nexport function getNewJsxElement(element: OldJsxElement): JsxElement {\n // string (end case)\n if (typeof element === 'string') {\n return element;\n }\n\n // type\n let t: string | undefined = undefined;\n if (element.type != null) {\n t = element.type;\n }\n // children\n let c: JsxChildren | undefined = undefined;\n if (element.props?.children != null) {\n c = getNewJsxChildren(element.props.children);\n }\n return {\n ...(t && { t }),\n ...(c && { c }),\n d: getNewGTProp(element.props['data-_gt']),\n i: element.props['data-_gt'].id,\n };\n}\n\nexport function getNewBranchType(branch: OldBranchType): 'b' | 'p' {\n if (branch === 'branch') {\n return 'b';\n }\n return 'p';\n}\n\nexport function getNewVariableType(variable: OldVariableType): VariableType {\n switch (variable) {\n case 'number':\n return 'n';\n case 'variable':\n return 'v';\n case 'datetime':\n return 'd';\n case 'currency':\n return 'c';\n default:\n return 'v';\n }\n}\n\nexport function getNewVariableObject(\n variable: OldVariableObject\n): VariableObject {\n // variable type\n let v: VariableType | undefined = undefined;\n if (variable.variable != null) {\n v = getNewVariableType(variable.variable);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.id != null) {\n i = variable.id;\n }\n return {\n k: variable.key,\n ...(v && { v }),\n ...(i && { i }),\n };\n}\n\nexport function getNewGTProp(dataGT: OldGTProp): GTProp {\n // branches\n let b: Record<string, JsxChildren> | undefined = undefined;\n if (dataGT.branches) {\n b = Object.fromEntries(\n Object.entries(dataGT.branches).map(([key, value]) => [\n key,\n getNewJsxChildren(value),\n ])\n );\n }\n // transformation\n let t: 'b' | 'p' | undefined;\n if (dataGT.transformation) {\n t = getNewBranchType(dataGT.transformation);\n }\n return { ...(b && { b }), ...(t && { t }) };\n}\n\n/**\n * Convert response data from current format to old format\n */\n\nexport function getOldJsxChild(child: JsxChild): OldJsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isNewVariableObject(child)) {\n return getOldVariableObject(child);\n }\n\n // JsxElement\n return getOldJsxElement(child);\n}\n\nexport function getOldJsxChildren(\n children: JsxChildren | OldJsxChildren\n): OldJsxChildren {\n // if children is already old, return it\n if (isOldJsxChildren(children)) {\n return children;\n }\n\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getOldJsxChild);\n }\n\n // Object\n return getOldJsxChild(children);\n}\n\nexport function getOldJsxElement(element: JsxElement): OldJsxElement {\n // type (can assume that type will exist here)\n const type: string = element.t as string;\n // children\n let children: OldJsxChildren | undefined = undefined;\n if (element.c != null) {\n children = getOldJsxChildren(element.c);\n }\n // data-_gt (can assume id will exist here)\n const dataGT: OldGTProp = getOldGTProp(element.d || {}, element.i as number);\n return {\n type,\n props: { children, 'data-_gt': dataGT },\n };\n}\n\nexport function getOldBranchType(branch: 'b' | 'p'): OldBranchType {\n if (branch === 'b') {\n return 'branch';\n }\n return 'plural';\n}\n\nexport function getOldVariableType(variable: VariableType): OldVariableType {\n switch (variable) {\n case 'n':\n return 'number';\n case 'v':\n return 'variable';\n case 'd':\n return 'datetime';\n case 'c':\n return 'currency';\n default:\n return 'variable';\n }\n}\n\nexport function getOldVariableObject(\n variable: VariableObject\n): OldVariableObject {\n // variable type\n let v: OldVariableType | undefined = undefined;\n if (variable.v != null) {\n v = getOldVariableType(variable.v);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.i != null) {\n i = variable.i;\n }\n return {\n key: variable.k,\n ...(v && { variable: v }),\n ...(i && { id: i }),\n };\n}\n\nexport function getOldGTProp(dataGT: GTProp, i: number): OldGTProp {\n // transformation\n let transformation: OldBranchType | undefined = undefined;\n if (dataGT.t != null) {\n transformation = getOldBranchType(dataGT.t);\n }\n // branches\n let branches: Record<string, OldJsxChildren> | undefined = undefined;\n if (dataGT.b != null) {\n branches = Object.fromEntries(\n Object.entries(dataGT.b).map(([key, value]) => [\n key,\n getOldJsxChildren(value),\n ])\n );\n }\n return {\n id: i,\n ...(transformation && { transformation }),\n ...(branches && { branches }),\n };\n}\n","// Functions provided to other GT libraries\n\nimport { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using SHA-256.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} The resulting hash as a hexadecimal string.\n */\nexport function oldHashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string)));\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} context - The context for the children.\n * @param {string} id - The ID for the JSX children object.\n * @param {function} hashFunction - Custom hash function.\n * @returns {string} - The unique hash of the children.\n */\nexport function oldHashJsxChildren(\n {\n source,\n context,\n id,\n dataFormat,\n }: {\n source: OldJsxChildren;\n context?: string;\n id?: string;\n dataFormat: string;\n },\n hashFunction: (string: string) => string = oldHashString\n): string {\n const unhashedKey = stringify({\n source: sanitizeJsxChildren(source),\n ...(id && { id }),\n ...(context && { context }),\n ...(dataFormat && { dataFormat }),\n });\n return hashFunction(unhashedKey);\n}\n\ntype SanitizedVariable = Omit<OldVariableObject, 'id'>;\n\ntype SanitizedElement = {\n branches?: {\n [k: string]: SanitizedChildren;\n };\n children?: SanitizedChildren;\n transformation?: string;\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\nconst sanitizeChild = (child: OldJsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n if ('props' in child) {\n const newChild: SanitizedChild = {};\n const dataGt = child?.props?.['data-_gt'];\n if (dataGt?.branches) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.branches = Object.fromEntries(\n Object.entries(dataGt.branches).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as OldJsxChildren),\n ])\n );\n }\n if (child?.props?.children) {\n newChild.children = sanitizeJsxChildren(child.props.children);\n }\n if (child?.props?.['data-_gt']?.transformation) {\n newChild.transformation = child.props['data-_gt'].transformation;\n }\n return newChild;\n }\n if ('key' in child) {\n return {\n key: child.key,\n ...(child.variable && {\n variable: child.variable,\n }),\n };\n }\n }\n return child as string;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: OldJsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACFnE,SAAwB,eACtB,GACA,QAA+B,aAC/B,UAAoB,CAAA,KAAsB,EACzB;CAEjB,MAAM,wBADcA,kBAAAA,UAAU,IAAI,eAAe,QACR,CAAC,OAAO,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OAAO,OAAO,SAChB,UAAS,WAAW,oBAAoB,MAAM,MAAM,SAAS;AAE/D,OAAI,OAAO,QAAQ,aAAa,eAC9B,UAAS,iBAAiB,MAAM,MAAM,YAAY;AAEpD,UAAO;;AAET,MAAI,SAAS,MACX,QAAO;GACL,KAAK,MAAM;GACX,GAAI,MAAM,YAAY,EACpB,UAAU,MAAM,UACjB;GACF;;AAGL,QAAO;;AAGT,SAAS,oBACP,mBACmB;AACnB,QAAO,MAAM,QAAQ,kBAAkB,GACnC,kBAAkB,IAAI,cAAc,GACpC,cAAc,kBAAkB"}
@@ -1,4 +1,4 @@
1
- import { At as Variable, Ct as IcuMessage, Et as JsxElement, Mt as LocaleProperties, Q as FileFormat, Tt as JsxChildren, jt as VariableType, l as _Content, p as VariableTransformationSuffix, pt as RuntimeTranslateManyOptions, vt as GTProp, wt as JsxChild } from "./types-NKhpChvT.cjs";
1
+ import { Dt as JsxChild, Et as IcuMessage, Ft as LocaleProperties, Nt as Variable, Ot as JsxChildren, Pt as VariableType, Q as FileFormat, gt as RuntimeTranslateManyOptions, kt as JsxElement, l as _Content, p as VariableTransformationSuffix, xt as GTProp } from "./types-Bf8_Apq_.cjs";
2
2
 
3
3
  //#region src/settings/settingsUrls.d.ts
4
4
  declare const defaultCacheUrl: "https://cdn.gtx.dev";
@@ -19,10 +19,10 @@ declare function isAcceptedPluralForm(form: string): form is PluralType;
19
19
  * Given a number and a list of allowed plural forms, return the plural form that best fits the number.
20
20
  *
21
21
  * @param {number} n - The number to determine the plural form for.
22
- * @param {locales[]} forms - The allowed plural forms.
22
+ * @param {PluralType[]} forms - The allowed plural forms.
23
23
  * @returns {PluralType} The determined plural form, or an empty string if none fit.
24
24
  */
25
- declare function _getPluralForm(n: number, forms?: PluralType[], locales?: string[]): PluralType | '';
25
+ declare function _getPluralForm(n: number, forms?: readonly PluralType[], locales?: string[]): PluralType | '';
26
26
  //#endregion
27
27
  //#region src/utils/isVariable.d.ts
28
28
  declare function isVariable(obj: unknown): obj is Variable;
@@ -37,8 +37,8 @@ declare function decode(base64: string): string;
37
37
  //#region src/utils/isSupportedFileFormatTransform.d.ts
38
38
  /**
39
39
  * This function checks if a file format transformation is supported during translation
40
- * @param from - The source file format
41
- * @param to - The target file format
40
+ * @param from - The source file format.
41
+ * @param to - The target file format.
42
42
  * @returns True if the transformation is supported, false otherwise
43
43
  */
44
44
  declare function isSupportedFileFormatTransform(from: FileFormat, to: FileFormat): boolean;
@@ -96,9 +96,19 @@ declare function declareVar(variable: string | number | boolean | null | undefin
96
96
  //#endregion
97
97
  //#region src/derive/derive.d.ts
98
98
  /**
99
- * derive() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.
99
+ * Marks content as derivable by the GT compiler and CLI.
100
100
  *
101
- * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.
101
+ * Use `derive()` when a translation string or context needs content that is
102
+ * computed from source code, but should still be discovered during extraction
103
+ * instead of treated as a runtime interpolation variable. The CLI attempts to
104
+ * resolve the derivable expression into every possible static value and
105
+ * includes those values in the source content that gets translated.
106
+ *
107
+ * `derive()` returns its argument unchanged at runtime.
108
+ *
109
+ * Run `gt validate` after adding or changing `derive()` calls to verify that
110
+ * each derivable expression can be resolved by the CLI before translating or
111
+ * building.
102
112
  *
103
113
  * @example
104
114
  * ```jsx
@@ -109,16 +119,21 @@ declare function declareVar(variable: string | number | boolean | null | undefin
109
119
  * gt(`My name is ${derive(getSubject())}`);
110
120
  * ```
111
121
  *
112
- * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.
113
- * @returns content
122
+ * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
123
+ * @returns {T} The same content, unchanged at runtime.
114
124
  */
115
125
  declare function derive<T extends string | boolean | number | null | undefined>(content: T): T;
116
126
  /**
117
127
  * @deprecated Use derive() instead.
118
128
  *
119
- * declareStatic() is a powerful but dangerous function which marks its argument as derivable (statically analyzable) for the compiler and CLI tool.
129
+ * Marks content as derivable by the GT compiler and CLI.
130
+ *
131
+ * Use `derive()` instead of `declareStatic()` for new code. This alias is kept
132
+ * for backwards compatibility and returns its argument unchanged at runtime.
120
133
  *
121
- * This function is dangerous because it can cause the compiler and CLI tool to throw an error if the argument is not derivable.
134
+ * Run `gt validate` after adding or changing derived content to verify that
135
+ * each derivable expression can be resolved by the CLI before translating or
136
+ * building.
122
137
  *
123
138
  * @example
124
139
  * ```jsx
@@ -129,8 +144,8 @@ declare function derive<T extends string | boolean | number | null | undefined>(
129
144
  * gt(`My name is ${declareStatic(getSubject())}`);
130
145
  * ```
131
146
  *
132
- * @param {T extends string | boolean | number | null | undefined} content - Content to mark as derivable.
133
- * @returns content
147
+ * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
148
+ * @returns {T} The same content, unchanged at runtime.
134
149
  */
135
150
  declare const declareStatic: typeof derive;
136
151
  //#endregion
@@ -200,7 +215,7 @@ declare function getNewVariableType(variable: OldVariableType): VariableType;
200
215
  declare function getNewVariableObject(variable: OldVariableObject): Variable;
201
216
  declare function getNewGTProp(dataGT: OldGTProp): GTProp;
202
217
  /**
203
- * Convert response data from old format to new format
218
+ * Convert response data from current format to old format
204
219
  */
205
220
  declare function getOldJsxChild(child: JsxChild): OldJsxChild;
206
221
  declare function getOldJsxChildren(children: JsxChildren | OldJsxChildren): OldJsxChildren;
@@ -213,39 +228,39 @@ declare function getOldGTProp(dataGT: GTProp, i: number): OldGTProp;
213
228
  //#region src/backwards-compatability/typeChecking.d.ts
214
229
  /**
215
230
  * Checks if a JSX child is an old variable object format
216
- * @param child - The JSX child to check
231
+ * @param child - The JSX child to check.
217
232
  * @returns True if the child is an old variable object (has 'key' property)
218
233
  */
219
234
  declare function isOldVariableObject(child: OldJsxChild | JsxChild): child is OldVariableObject;
220
235
  /**
221
236
  * Checks if a JSX child is a new variable object format
222
- * @param child - The JSX child to check
237
+ * @param child - The JSX child to check.
223
238
  * @returns True if the child is a new variable object (has 'k' property)
224
239
  */
225
240
  declare function isNewVariableObject(child: OldJsxChild | JsxChild): child is Variable;
226
241
  /**
227
242
  * Checks if JSX children follow the old format
228
243
  * @param children - The JSX children to check (can be string, array, or single child)
229
- * @returns True if all children are in the old format
244
+ * @returns True if all children are in the old format.
230
245
  */
231
246
  declare function isOldJsxChildren(children: OldJsxChildren | JsxChildren): children is OldJsxChildren;
232
247
  //#endregion
233
248
  //#region src/backwards-compatability/oldHashJsxChildren.d.ts
234
249
  /**
235
- * Calculates a unique hash for a given string using sha256.
250
+ * Calculates a unique hash for a given string using SHA-256.
236
251
  *
237
252
  * @param {string} string - The string to be hashed.
238
- * @returns {string} - The resulting hash as a hexadecimal string.
253
+ * @returns {string} The resulting hash as a hexadecimal string.
239
254
  */
240
255
  declare function oldHashString(string: string): string;
241
256
  /**
242
257
  * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
243
258
  *
244
259
  * @param {any} childrenAsObjects - The children objects to be hashed.
245
- * @param {string} context - The context for the children
246
- * @param {string} id - The id for the JSX Children object
247
- * @param {function} hashFunction custom hash function
248
- * @returns {string} - The unique has of the children.
260
+ * @param {string} context - The context for the children.
261
+ * @param {string} id - The ID for the JSX children object.
262
+ * @param {function} hashFunction - Custom hash function.
263
+ * @returns {string} - The unique hash of the children.
249
264
  */
250
265
  declare function oldHashJsxChildren({
251
266
  source,