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
@@ -0,0 +1,207 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { isOldJsxChildren, isNewVariableObject, isOldVariableObject, } from './typeChecking';
13
+ /**
14
+ * Convert request data from old format to new format
15
+ */
16
+ export function getNewJsxChild(child) {
17
+ // string (end case)
18
+ if (typeof child === 'string') {
19
+ return child;
20
+ }
21
+ // VariableObject
22
+ if (isOldVariableObject(child)) {
23
+ return getNewVariableObject(child);
24
+ }
25
+ // JsxElement
26
+ return getNewJsxElement(child);
27
+ }
28
+ export function getNewJsxChildren(children) {
29
+ // string (end case)
30
+ if (typeof children === 'string') {
31
+ return children;
32
+ }
33
+ // Array
34
+ if (Array.isArray(children)) {
35
+ return children.map(getNewJsxChild);
36
+ }
37
+ // Object
38
+ return getNewJsxChild(children);
39
+ }
40
+ export function getNewJsxElement(element) {
41
+ var _a;
42
+ // string (end case)
43
+ if (typeof element === 'string') {
44
+ return element;
45
+ }
46
+ // type
47
+ var t = undefined;
48
+ if (element.type != null) {
49
+ t = element.type;
50
+ }
51
+ // children
52
+ var c = undefined;
53
+ if (((_a = element.props) === null || _a === void 0 ? void 0 : _a.children) != null) {
54
+ c = getNewJsxChildren(element.props.children);
55
+ }
56
+ return __assign(__assign(__assign({}, (t && { t: t })), (c && { c: c })), { d: getNewGTProp(element.props['data-_gt']), i: element.props['data-_gt'].id });
57
+ }
58
+ export function getNewBranchType(branch) {
59
+ if (branch === 'branch') {
60
+ return 'b';
61
+ }
62
+ return 'p';
63
+ }
64
+ export function getNewVariableType(variable) {
65
+ switch (variable) {
66
+ case 'number':
67
+ return 'n';
68
+ case 'variable':
69
+ return 'v';
70
+ case 'datetime':
71
+ return 'd';
72
+ case 'currency':
73
+ return 'c';
74
+ default:
75
+ return 'v';
76
+ }
77
+ }
78
+ export function getNewVariableObject(variable) {
79
+ // variable type
80
+ var v = undefined;
81
+ if (variable.variable != null) {
82
+ v = getNewVariableType(variable.variable);
83
+ }
84
+ // variable id
85
+ var i = undefined;
86
+ if (variable.id != null) {
87
+ i = variable.id;
88
+ }
89
+ return __assign(__assign({ k: variable.key }, (v && { v: v })), (i && { i: i }));
90
+ }
91
+ export function getNewGTProp(dataGT) {
92
+ // branches
93
+ var b = undefined;
94
+ if (dataGT.branches) {
95
+ b = Object.fromEntries(Object.entries(dataGT.branches).map(function (_a) {
96
+ var key = _a[0], value = _a[1];
97
+ return [
98
+ key,
99
+ getNewJsxChildren(value),
100
+ ];
101
+ }));
102
+ }
103
+ // transformation
104
+ var t;
105
+ if (dataGT.transformation) {
106
+ t = getNewBranchType(dataGT.transformation);
107
+ }
108
+ return __assign(__assign({}, (b && { b: b })), (t && { t: t }));
109
+ }
110
+ /**
111
+ * Convert response data from current format to old format
112
+ */
113
+ export function getOldJsxChild(child) {
114
+ // string (end case)
115
+ if (typeof child === 'string') {
116
+ return child;
117
+ }
118
+ // VariableObject
119
+ if (isNewVariableObject(child)) {
120
+ return getOldVariableObject(child);
121
+ }
122
+ // JsxElement
123
+ return getOldJsxElement(child);
124
+ }
125
+ export function getOldJsxChildren(children) {
126
+ // if children is already old, return it
127
+ if (isOldJsxChildren(children)) {
128
+ return children;
129
+ }
130
+ // string (end case)
131
+ if (typeof children === 'string') {
132
+ return children;
133
+ }
134
+ // Array
135
+ if (Array.isArray(children)) {
136
+ return children.map(getOldJsxChild);
137
+ }
138
+ // Object
139
+ return getOldJsxChild(children);
140
+ }
141
+ export function getOldJsxElement(element) {
142
+ // type (can assume that type will exist here)
143
+ var type = element.t;
144
+ // children
145
+ var children = undefined;
146
+ if (element.c != null) {
147
+ children = getOldJsxChildren(element.c);
148
+ }
149
+ // data-_gt (can assume id will exist here)
150
+ var dataGT = getOldGTProp(element.d || {}, element.i);
151
+ return {
152
+ type: type,
153
+ props: { children: children, 'data-_gt': dataGT },
154
+ };
155
+ }
156
+ export function getOldBranchType(branch) {
157
+ if (branch === 'b') {
158
+ return 'branch';
159
+ }
160
+ return 'plural';
161
+ }
162
+ export function getOldVariableType(variable) {
163
+ switch (variable) {
164
+ case 'n':
165
+ return 'number';
166
+ case 'v':
167
+ return 'variable';
168
+ case 'd':
169
+ return 'datetime';
170
+ case 'c':
171
+ return 'currency';
172
+ default:
173
+ return 'variable';
174
+ }
175
+ }
176
+ export function getOldVariableObject(variable) {
177
+ // variable type
178
+ var v = undefined;
179
+ if (variable.v != null) {
180
+ v = getOldVariableType(variable.v);
181
+ }
182
+ // variable id
183
+ var i = undefined;
184
+ if (variable.i != null) {
185
+ i = variable.i;
186
+ }
187
+ return __assign(__assign({ key: variable.k }, (v && { variable: v })), (i && { id: i }));
188
+ }
189
+ export function getOldGTProp(dataGT, i) {
190
+ // transformation
191
+ var transformation = undefined;
192
+ if (dataGT.t != null) {
193
+ transformation = getOldBranchType(dataGT.t);
194
+ }
195
+ // branches
196
+ var branches = undefined;
197
+ if (dataGT.b != null) {
198
+ branches = Object.fromEntries(Object.entries(dataGT.b).map(function (_a) {
199
+ var key = _a[0], value = _a[1];
200
+ return [
201
+ key,
202
+ getOldJsxChildren(value),
203
+ ];
204
+ }));
205
+ }
206
+ return __assign(__assign({ id: i }, (transformation && { transformation: transformation })), (branches && { branches: branches }));
207
+ }
@@ -0,0 +1,23 @@
1
+ import { OldJsxChildren } from './oldTypes';
2
+ /**
3
+ * Calculates a unique hash for a given string using SHA-256.
4
+ *
5
+ * @param {string} string - The string to be hashed.
6
+ * @returns {string} The resulting hash as a hexadecimal string.
7
+ */
8
+ export declare function oldHashString(string: string): string;
9
+ /**
10
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
11
+ *
12
+ * @param {any} childrenAsObjects - The children objects to be hashed.
13
+ * @param {string} context - The context for the children.
14
+ * @param {string} id - The ID for the JSX children object.
15
+ * @param {function} hashFunction - Custom hash function.
16
+ * @returns {string} - The unique hash of the children.
17
+ */
18
+ export declare function oldHashJsxChildren({ source, context, id, dataFormat, }: {
19
+ source: OldJsxChildren;
20
+ context?: string;
21
+ id?: string;
22
+ dataFormat: string;
23
+ }, hashFunction?: (string: string) => string): string;
@@ -0,0 +1,79 @@
1
+ // Functions provided to other GT libraries
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ import { stableStringify as stringify } from '../utils/stableStringify';
14
+ import { sha256 } from '@noble/hashes/sha2.js';
15
+ import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
16
+ // ----- FUNCTIONS ----- //
17
+ /**
18
+ * Calculates a unique hash for a given string using SHA-256.
19
+ *
20
+ * @param {string} string - The string to be hashed.
21
+ * @returns {string} The resulting hash as a hexadecimal string.
22
+ */
23
+ export function oldHashString(string) {
24
+ return bytesToHex(sha256(utf8ToBytes(string)));
25
+ }
26
+ /**
27
+ * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
28
+ *
29
+ * @param {any} childrenAsObjects - The children objects to be hashed.
30
+ * @param {string} context - The context for the children.
31
+ * @param {string} id - The ID for the JSX children object.
32
+ * @param {function} hashFunction - Custom hash function.
33
+ * @returns {string} - The unique hash of the children.
34
+ */
35
+ export function oldHashJsxChildren(_a, hashFunction) {
36
+ var source = _a.source, context = _a.context, id = _a.id, dataFormat = _a.dataFormat;
37
+ if (hashFunction === void 0) { hashFunction = oldHashString; }
38
+ var unhashedKey = stringify(__assign(__assign(__assign({ source: sanitizeJsxChildren(source) }, (id && { id: id })), (context && { context: context })), (dataFormat && { dataFormat: dataFormat })));
39
+ return hashFunction(unhashedKey);
40
+ }
41
+ var sanitizeChild = function (child) {
42
+ var _a, _b, _c, _d;
43
+ if (child && typeof child === 'object') {
44
+ if ('props' in child) {
45
+ var newChild = {};
46
+ var dataGt = (_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a['data-_gt'];
47
+ if (dataGt === null || dataGt === void 0 ? void 0 : dataGt.branches) {
48
+ // The only thing that prevents sanitizeJsx from being stable is
49
+ // the order of the keys in the branches object.
50
+ // We don't sort them because stable-stringify sorts them anyways
51
+ newChild.branches = Object.fromEntries(Object.entries(dataGt.branches).map(function (_a) {
52
+ var key = _a[0], value = _a[1];
53
+ return [
54
+ key,
55
+ sanitizeJsxChildren(value),
56
+ ];
57
+ }));
58
+ }
59
+ if ((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.children) {
60
+ newChild.children = sanitizeJsxChildren(child.props.children);
61
+ }
62
+ if ((_d = (_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c['data-_gt']) === null || _d === void 0 ? void 0 : _d.transformation) {
63
+ newChild.transformation = child.props['data-_gt'].transformation;
64
+ }
65
+ return newChild;
66
+ }
67
+ if ('key' in child) {
68
+ return __assign({ key: child.key }, (child.variable && {
69
+ variable: child.variable,
70
+ }));
71
+ }
72
+ }
73
+ return child;
74
+ };
75
+ function sanitizeJsxChildren(childrenAsObjects) {
76
+ return Array.isArray(childrenAsObjects)
77
+ ? childrenAsObjects.map(sanitizeChild)
78
+ : sanitizeChild(childrenAsObjects);
79
+ }
@@ -0,0 +1,21 @@
1
+ export type OldBranchType = 'branch' | 'plural';
2
+ export type OldGTProp = {
3
+ id: number;
4
+ transformation?: OldBranchType;
5
+ branches?: Record<string, OldJsxChildren>;
6
+ };
7
+ export type OldJsxElement = {
8
+ type: string;
9
+ props: {
10
+ children?: OldJsxChildren;
11
+ 'data-_gt': OldGTProp;
12
+ };
13
+ };
14
+ export type OldVariableType = 'number' | 'variable' | 'datetime' | 'currency';
15
+ export type OldVariableObject = {
16
+ variable?: OldVariableType;
17
+ key: string;
18
+ id?: number;
19
+ };
20
+ export type OldJsxChild = OldJsxElement | OldVariableObject | string;
21
+ export type OldJsxChildren = OldJsxChild | OldJsxChild[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { JsxChild, JsxChildren } from '../types';
2
+ import { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes.js';
3
+ import { Variable as VariableObject } from '../types';
4
+ /**
5
+ * Checks if a JSX child is an old variable object format
6
+ * @param child - The JSX child to check.
7
+ * @returns True if the child is an old variable object (has 'key' property)
8
+ */
9
+ export declare function isOldVariableObject(child: OldJsxChild | JsxChild): child is OldVariableObject;
10
+ /**
11
+ * Checks if a JSX child is a new variable object format
12
+ * @param child - The JSX child to check.
13
+ * @returns True if the child is a new variable object (has 'k' property)
14
+ */
15
+ export declare function isNewVariableObject(child: OldJsxChild | JsxChild): child is VariableObject;
16
+ /**
17
+ * Checks if JSX children follow the old format
18
+ * @param children - The JSX children to check (can be string, array, or single child)
19
+ * @returns True if all children are in the old format.
20
+ */
21
+ export declare function isOldJsxChildren(children: OldJsxChildren | JsxChildren): children is OldJsxChildren;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Checks if a JSX child is an old variable object format
3
+ * @param child - The JSX child to check.
4
+ * @returns True if the child is an old variable object (has 'key' property)
5
+ */
6
+ export function isOldVariableObject(child) {
7
+ return typeof child === 'object' && child != null && 'key' in child;
8
+ }
9
+ /**
10
+ * Checks if a JSX child is a new variable object format
11
+ * @param child - The JSX child to check.
12
+ * @returns True if the child is a new variable object (has 'k' property)
13
+ */
14
+ export function isNewVariableObject(child) {
15
+ return typeof child === 'object' && child != null && 'k' in child;
16
+ }
17
+ /**
18
+ * Checks if a JSX child is an old JSX element format
19
+ * @param child - The JSX child to check.
20
+ * @returns True if the child is an old JSX element (has 'type' and 'props' properties)
21
+ */
22
+ function isOldJsxElement(child) {
23
+ return (typeof child === 'object' &&
24
+ child != null &&
25
+ 'type' in child &&
26
+ 'props' in child);
27
+ }
28
+ /**
29
+ * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)
30
+ * @param child - The JSX child to check.
31
+ * @returns True if the child is in the old format.
32
+ */
33
+ function isOldJsxChild(child) {
34
+ // string
35
+ if (typeof child === 'string') {
36
+ return true;
37
+ }
38
+ // variable object
39
+ if (isOldVariableObject(child)) {
40
+ return true;
41
+ }
42
+ // element
43
+ return isOldJsxElement(child);
44
+ }
45
+ /**
46
+ * Checks if JSX children follow the old format
47
+ * @param children - The JSX children to check (can be string, array, or single child)
48
+ * @returns True if all children are in the old format.
49
+ */
50
+ export function isOldJsxChildren(children) {
51
+ // string
52
+ if (typeof children === 'string') {
53
+ return true;
54
+ }
55
+ // array
56
+ if (Array.isArray(children)) {
57
+ return !children.some(function (child) { return !isOldJsxChild(child); });
58
+ }
59
+ // object
60
+ return isOldJsxChild(children);
61
+ }
@@ -20,8 +20,8 @@ const SUPPORTED_TRANSFORMATIONS = {
20
20
  };
21
21
  /**
22
22
  * This function checks if a file format transformation is supported during translation
23
- * @param from - The source file format
24
- * @param to - The target file format
23
+ * @param from - The source file format.
24
+ * @param to - The target file format.
25
25
  * @returns True if the transformation is supported, false otherwise
26
26
  */
27
27
  function isSupportedFileFormatTransform(from, to) {
@@ -108,4 +108,4 @@ Object.defineProperty(exports, "validateFileFormatTransforms", {
108
108
  }
109
109
  });
110
110
 
111
- //# sourceMappingURL=base64-CUcEPEC5.cjs.map
111
+ //# sourceMappingURL=base64-2fu94Klt.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64-2fu94Klt.cjs","names":[],"sources":["../src/settings/settingsUrls.ts","../src/utils/isSupportedFileFormatTransform.ts","../src/translate/utils/validateFileFormatTransform.ts","../src/utils/base64.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api2.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime2.gtx.dev' as const;\n","import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","import type { FileFormat } from '../../types-dir/api/file';\nimport { isSupportedFileFormatTransform } from '../../utils/isSupportedFileFormatTransform';\n\nexport type FileFormatTransformInput = {\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n fileName?: string;\n fileId?: string;\n};\n\n/**\n * Returns a user-facing validation error when a requested file format transform\n * is missing source format context or is not currently supported.\n */\nexport function getFileFormatTransformError(\n file: FileFormatTransformInput\n): string | undefined {\n if (!file.transformFormat) return undefined;\n const fileLabel = file.fileName ?? file.fileId ?? 'unknown file';\n if (!file.fileFormat) {\n return `fileFormat is required when transformFormat is provided for ${fileLabel}`;\n }\n if (!isSupportedFileFormatTransform(file.fileFormat, file.transformFormat)) {\n return `Unsupported file format transform: ${file.fileFormat} -> ${file.transformFormat}`;\n }\n return undefined;\n}\n\n/**\n * Validates file format transforms before sending upload/enqueue requests.\n */\nexport function validateFileFormatTransforms(\n files: FileFormatTransformInput[]\n): void {\n for (const file of files) {\n const error = getFileFormatTransformError(file);\n if (error) throw new Error(error);\n }\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n"],"mappings":";AAAA,MAAa,kBAAkB;AAC/B,MAAa,iBAAiB;AAC9B,MAAa,uBAAuB;;;ACApC,MAAM,4BAA4B;CAChC,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,OAAO;CACd,IAAI,CAAC,KAAK;CAEV,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,qBAAqB,CAAC,sBAAsB;CAC7C;;;;;;;AAQD,SAAgB,+BACd,MACA,IACS;AAET,QAD4C,0BAA0B,OACpD,SAAS,GAAG,IAAI;;;;;;;;ACfpC,SAAgB,4BACd,MACoB;AACpB,KAAI,CAAC,KAAK,gBAAiB,QAAO,KAAA;CAClC,MAAM,YAAY,KAAK,YAAY,KAAK,UAAU;AAClD,KAAI,CAAC,KAAK,WACR,QAAO,+DAA+D;AAExE,KAAI,CAAC,+BAA+B,KAAK,YAAY,KAAK,gBAAgB,CACxE,QAAO,sCAAsC,KAAK,WAAW,MAAM,KAAK;;;;;AAQ5E,SAAgB,6BACd,OACM;AACN,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,4BAA4B,KAAK;AAC/C,MAAI,MAAO,OAAM,IAAI,MAAM,MAAM;;;;;ACnCrC,SAAgB,OAAO,MAAsB;AAC3C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,MAAM,OAAO,CAAC,SAAS,SAAS;CAGrD,MAAM,QAAQ,IAAI,aAAa,CAAC,OAAO,KAAK;CAC5C,IAAI,SAAS;AACb,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,WAAU,OAAO,aAAa,MAAM,GAAG;AAEzC,QAAO,KAAK,OAAO;;AAIrB,SAAgB,OAAO,QAAwB;AAC7C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,QAAQ,SAAS,CAAC,SAAS,OAAO;CAGvD,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,QAAQ,IAAI,WAAW,OAAO,OAAO;AAC3C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,OAAM,KAAK,OAAO,WAAW,EAAE;AAEjC,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM"}
@@ -20,8 +20,8 @@ const SUPPORTED_TRANSFORMATIONS = {
20
20
  };
21
21
  /**
22
22
  * This function checks if a file format transformation is supported during translation
23
- * @param from - The source file format
24
- * @param to - The target file format
23
+ * @param from - The source file format.
24
+ * @param to - The target file format.
25
25
  * @returns True if the transformation is supported, false otherwise
26
26
  */
27
27
  function isSupportedFileFormatTransform(from, to) {
@@ -67,4 +67,4 @@ function decode(base64) {
67
67
  //#endregion
68
68
  export { defaultBaseUrl as a, isSupportedFileFormatTransform as i, encode as n, defaultCacheUrl as o, validateFileFormatTransforms as r, defaultRuntimeApiUrl as s, decode as t };
69
69
 
70
- //# sourceMappingURL=base64-C1sogiix.mjs.map
70
+ //# sourceMappingURL=base64-DH0STixb.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64-DH0STixb.mjs","names":[],"sources":["../src/settings/settingsUrls.ts","../src/utils/isSupportedFileFormatTransform.ts","../src/translate/utils/validateFileFormatTransform.ts","../src/utils/base64.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api2.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime2.gtx.dev' as const;\n","import type { FileFormat } from '../types-dir/api/file';\n\nconst SUPPORTED_TRANSFORMATIONS = {\n GTJSON: ['GTJSON'],\n JSON: ['JSON'],\n PO: ['PO'],\n // POT templates can produce translated PO catalog files.\n POT: ['POT', 'PO'],\n YAML: ['YAML'],\n MDX: ['MDX'],\n MD: ['MD'],\n TS: ['TS'],\n JS: ['JS'],\n HTML: ['HTML'],\n TXT: ['TXT'],\n TWILIO_CONTENT_JSON: ['TWILIO_CONTENT_JSON'],\n} as const satisfies Record<FileFormat, FileFormat[]>;\n\n/**\n * This function checks if a file format transformation is supported during translation\n * @param from - The source file format.\n * @param to - The target file format.\n * @returns True if the transformation is supported, false otherwise\n */\nexport function isSupportedFileFormatTransform(\n from: FileFormat,\n to: FileFormat\n): boolean {\n const toFormats: FileFormat[] | undefined = SUPPORTED_TRANSFORMATIONS[from];\n return toFormats?.includes(to) ?? false;\n}\n","import type { FileFormat } from '../../types-dir/api/file';\nimport { isSupportedFileFormatTransform } from '../../utils/isSupportedFileFormatTransform';\n\nexport type FileFormatTransformInput = {\n fileFormat?: FileFormat;\n transformFormat?: FileFormat;\n fileName?: string;\n fileId?: string;\n};\n\n/**\n * Returns a user-facing validation error when a requested file format transform\n * is missing source format context or is not currently supported.\n */\nexport function getFileFormatTransformError(\n file: FileFormatTransformInput\n): string | undefined {\n if (!file.transformFormat) return undefined;\n const fileLabel = file.fileName ?? file.fileId ?? 'unknown file';\n if (!file.fileFormat) {\n return `fileFormat is required when transformFormat is provided for ${fileLabel}`;\n }\n if (!isSupportedFileFormatTransform(file.fileFormat, file.transformFormat)) {\n return `Unsupported file format transform: ${file.fileFormat} -> ${file.transformFormat}`;\n }\n return undefined;\n}\n\n/**\n * Validates file format transforms before sending upload/enqueue requests.\n */\nexport function validateFileFormatTransforms(\n files: FileFormatTransformInput[]\n): void {\n for (const file of files) {\n const error = getFileFormatTransformError(file);\n if (error) throw new Error(error);\n }\n}\n","// Encode a string to base64\nexport function encode(data: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(data, 'utf8').toString('base64');\n }\n // Browser path.\n const bytes = new TextEncoder().encode(data);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n\n// Decode a base64 string to a string\nexport function decode(base64: string): string {\n if (typeof Buffer !== 'undefined') {\n // Node.js path.\n return Buffer.from(base64, 'base64').toString('utf8');\n }\n // Browser path.\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n"],"mappings":";AAAA,MAAa,kBAAkB;AAC/B,MAAa,iBAAiB;AAC9B,MAAa,uBAAuB;;;ACApC,MAAM,4BAA4B;CAChC,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,OAAO;CACd,IAAI,CAAC,KAAK;CAEV,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,IAAI,CAAC,KAAK;CACV,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,MAAM;CACZ,qBAAqB,CAAC,sBAAsB;CAC7C;;;;;;;AAQD,SAAgB,+BACd,MACA,IACS;AAET,QAD4C,0BAA0B,OACpD,SAAS,GAAG,IAAI;;;;;;;;ACfpC,SAAgB,4BACd,MACoB;AACpB,KAAI,CAAC,KAAK,gBAAiB,QAAO,KAAA;CAClC,MAAM,YAAY,KAAK,YAAY,KAAK,UAAU;AAClD,KAAI,CAAC,KAAK,WACR,QAAO,+DAA+D;AAExE,KAAI,CAAC,+BAA+B,KAAK,YAAY,KAAK,gBAAgB,CACxE,QAAO,sCAAsC,KAAK,WAAW,MAAM,KAAK;;;;;AAQ5E,SAAgB,6BACd,OACM;AACN,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,4BAA4B,KAAK;AAC/C,MAAI,MAAO,OAAM,IAAI,MAAM,MAAM;;;;;ACnCrC,SAAgB,OAAO,MAAsB;AAC3C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,MAAM,OAAO,CAAC,SAAS,SAAS;CAGrD,MAAM,QAAQ,IAAI,aAAa,CAAC,OAAO,KAAK;CAC5C,IAAI,SAAS;AACb,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,WAAU,OAAO,aAAa,MAAM,GAAG;AAEzC,QAAO,KAAK,OAAO;;AAIrB,SAAgB,OAAO,QAAwB;AAC7C,KAAI,OAAO,WAAW,YAEpB,QAAO,OAAO,KAAK,QAAQ,SAAS,CAAC,SAAS,OAAO;CAGvD,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,QAAQ,IAAI,WAAW,OAAO,OAAO;AAC3C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,OAAM,KAAK,OAAO,WAAW,EAAE;AAEjC,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM"}
@@ -0,0 +1,26 @@
1
+ import { ConstructorType, CustomIntlConstructors } from './types';
2
+ /**
3
+ * Cache for Intl and custom format instances to avoid repeated instantiation
4
+ * Uses a two-level structure: constructor name -> cache key -> instance.
5
+ */
6
+ declare class IntlCache {
7
+ private cache;
8
+ constructor();
9
+ /**
10
+ * Generates a consistent cache key from locales and options.
11
+ * Handles all LocalesArgument types (string, Locale, array, undefined).
12
+ */
13
+ private _generateKey;
14
+ /**
15
+ * Gets a cached Intl instance or creates a new one if not found
16
+ * @param constructor The name of the Intl constructor to use.
17
+ * @param args Constructor arguments (locales, options).
18
+ * @returns Cached or newly created Intl instance.
19
+ */
20
+ get<K extends keyof CustomIntlConstructors>(constructor: K, ...args: ConstructorParameters<CustomIntlConstructors[K]>): InstanceType<ConstructorType<K>>;
21
+ }
22
+ /**
23
+ * Global instance of the Intl cache for use throughout the application
24
+ */
25
+ export declare const intlCache: IntlCache;
26
+ export {};
@@ -0,0 +1,84 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { libraryDefaultLocale } from '../settings/settings';
11
+ import { CutoffFormatConstructor } from '../formatting/custom-formats/CutoffFormat/CutoffFormat';
12
+ /**
13
+ * Object mapping constructor names to their respective constructor functions
14
+ * Includes all native Intl constructors plus custom ones like CutoffFormat
15
+ */
16
+ var CustomIntl = {
17
+ Collator: Intl.Collator,
18
+ DateTimeFormat: Intl.DateTimeFormat,
19
+ DisplayNames: Intl.DisplayNames,
20
+ ListFormat: Intl.ListFormat,
21
+ Locale: Intl.Locale,
22
+ NumberFormat: Intl.NumberFormat,
23
+ PluralRules: Intl.PluralRules,
24
+ RelativeTimeFormat: Intl.RelativeTimeFormat,
25
+ Segmenter: Intl.Segmenter,
26
+ CutoffFormat: CutoffFormatConstructor,
27
+ };
28
+ /**
29
+ * Cache for Intl and custom format instances to avoid repeated instantiation
30
+ * Uses a two-level structure: constructor name -> cache key -> instance.
31
+ */
32
+ var IntlCache = /** @class */ (function () {
33
+ function IntlCache() {
34
+ this.cache = {};
35
+ }
36
+ /**
37
+ * Generates a consistent cache key from locales and options.
38
+ * Handles all LocalesArgument types (string, Locale, array, undefined).
39
+ */
40
+ IntlCache.prototype._generateKey = function (locales, options) {
41
+ if (options === void 0) { options = {}; }
42
+ // Normalize locales to string representation
43
+ var localeKey = !locales
44
+ ? 'undefined'
45
+ : Array.isArray(locales)
46
+ ? locales.map(function (l) { return String(l); }).join(',')
47
+ : String(locales);
48
+ // Sort option keys to ensure consistent key generation regardless of property order
49
+ var sortedOptions = options
50
+ ? JSON.stringify(options, Object.keys(options).sort())
51
+ : '{}';
52
+ return "".concat(localeKey, ":").concat(sortedOptions);
53
+ };
54
+ /**
55
+ * Gets a cached Intl instance or creates a new one if not found
56
+ * @param constructor The name of the Intl constructor to use.
57
+ * @param args Constructor arguments (locales, options).
58
+ * @returns Cached or newly created Intl instance.
59
+ */
60
+ IntlCache.prototype.get = function (constructor) {
61
+ var _a;
62
+ var _b;
63
+ var args = [];
64
+ for (var _i = 1; _i < arguments.length; _i++) {
65
+ args[_i - 1] = arguments[_i];
66
+ }
67
+ var _c = args[0], locales = _c === void 0 ? libraryDefaultLocale : _c, _d = args[1], options = _d === void 0 ? {} : _d;
68
+ var key = this._generateKey(locales, options);
69
+ var intlObject = (_b = this.cache[constructor]) === null || _b === void 0 ? void 0 : _b[key];
70
+ if (intlObject === undefined) {
71
+ // Create new instance and cache it
72
+ intlObject = new ((_a = CustomIntl[constructor]).bind.apply(_a, __spreadArray([void 0], args, false)))();
73
+ if (!this.cache[constructor])
74
+ this.cache[constructor] = {};
75
+ this.cache[constructor][key] = intlObject;
76
+ }
77
+ return intlObject;
78
+ };
79
+ return IntlCache;
80
+ }());
81
+ /**
82
+ * Global instance of the Intl cache for use throughout the application
83
+ */
84
+ export var intlCache = new IntlCache();
@@ -0,0 +1,32 @@
1
+ import { CutoffFormatConstructor } from '../formatting/custom-formats/CutoffFormat/CutoffFormat';
2
+ /**
3
+ * Extracts only the constructor functions from the Intl namespace,
4
+ * filtering out static methods like getCanonicalLocales and supportedValuesOf
5
+ */
6
+ type IntlConstructors = {
7
+ [K in keyof typeof Intl as (typeof Intl)[K] extends new (...args: any[]) => any ? K : never]: (typeof Intl)[K];
8
+ };
9
+ /**
10
+ * Extended interface that includes all native Intl constructors plus custom ones
11
+ */
12
+ export interface CustomIntlConstructors extends IntlConstructors {
13
+ CutoffFormat: typeof CutoffFormatConstructor;
14
+ }
15
+ /**
16
+ * Helper type to represent a constructor function for a given Intl constructor key
17
+ */
18
+ export type ConstructorType<K extends keyof CustomIntlConstructors> = new (...args: ConstructorParameters<CustomIntlConstructors[K]>) => InstanceType<CustomIntlConstructors[K]>;
19
+ /**
20
+ * Type for the cache object structure - each constructor gets its own Record
21
+ * mapping cache keys to instances of that specific constructor type
22
+ */
23
+ export type IntlCacheObject = {
24
+ [K in keyof CustomIntlConstructors]?: Record<string, InstanceType<ConstructorType<K>>>;
25
+ };
26
+ /**
27
+ * Type for the CustomIntl object that maps constructor names to constructor functions
28
+ */
29
+ export type CustomIntlType = {
30
+ [K in keyof CustomIntlConstructors]: ConstructorType<K>;
31
+ };
32
+ export {};
@@ -0,0 +1 @@
1
+ export {};