generaltranslation 8.2.13 → 8.2.14

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 (127) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{ApiError-IYfaOR30.mjs → ApiError-0DxxIHLp.mjs} +1 -1
  3. package/dist/{ApiError-CZ45tkW6.cjs.map → ApiError-0DxxIHLp.mjs.map} +1 -1
  4. package/dist/{ApiError-CZ45tkW6.cjs → ApiError-D-IBuHj6.cjs} +1 -1
  5. package/dist/{ApiError-IYfaOR30.mjs.map → ApiError-D-IBuHj6.cjs.map} +1 -1
  6. package/dist/LocaleConfig.d.ts +1 -59
  7. package/dist/LocaleConfig.js +1 -225
  8. package/dist/{base64-2fu94Klt.cjs → base64-C6BHySOc.cjs} +17 -1
  9. package/dist/base64-C6BHySOc.cjs.map +1 -0
  10. package/dist/{base64-DH0STixb.mjs → base64-CWITCfhU.mjs} +6 -2
  11. package/dist/base64-CWITCfhU.mjs.map +1 -0
  12. package/dist/core.cjs +9 -8
  13. package/dist/core.d.cts +1 -2
  14. package/dist/core.d.mts +1 -2
  15. package/dist/core.d.ts +1 -128
  16. package/dist/core.js +1 -137
  17. package/dist/core.mjs +2 -2
  18. package/dist/derive/indexVars.d.ts +1 -1
  19. package/dist/errors.cjs +1 -1
  20. package/dist/errors.mjs +1 -1
  21. package/dist/id/types.d.ts +1 -1
  22. package/dist/{id-CyiXsQrY.cjs → id-C2orn1MA.cjs} +2 -2
  23. package/dist/{id-CyiXsQrY.cjs.map → id-C2orn1MA.cjs.map} +1 -1
  24. package/dist/{id-DbD7K-HL.mjs → id-DEaFhGqX.mjs} +2 -2
  25. package/dist/{id-DbD7K-HL.mjs.map → id-DEaFhGqX.mjs.map} +1 -1
  26. package/dist/id.cjs +1 -1
  27. package/dist/id.d.cts +1 -1
  28. package/dist/id.d.mts +1 -1
  29. package/dist/id.mjs +1 -1
  30. package/dist/index.cjs +368 -385
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +4 -242
  33. package/dist/index.d.mts +4 -242
  34. package/dist/index.d.ts +5 -238
  35. package/dist/index.js +3 -322
  36. package/dist/index.mjs +215 -352
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/internal.cjs +6 -6
  39. package/dist/internal.cjs.map +1 -1
  40. package/dist/internal.d.cts +6 -5
  41. package/dist/internal.d.mts +6 -5
  42. package/dist/internal.mjs +4 -4
  43. package/dist/internal.mjs.map +1 -1
  44. package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
  45. package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
  46. package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
  47. package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
  48. package/dist/locales/getPluralForm.js +2 -2
  49. package/dist/logging/logger.d.ts +0 -3
  50. package/dist/logging/logger.js +0 -3
  51. package/dist/{types-AHtYZIP-.d.mts → types-73XFwmhH.d.mts} +7 -106
  52. package/dist/{types-Bf8_Apq_.d.cts → types-YrrGRHBP.d.cts} +7 -106
  53. package/dist/types-dir/api/enqueueEntries.d.ts +1 -1
  54. package/dist/types-dir/api/enqueueFiles.d.ts +1 -1
  55. package/dist/types-dir/api/fetchTranslations.d.ts +1 -1
  56. package/dist/types-dir/api/file.d.ts +1 -1
  57. package/dist/types-dir/api/translate.d.ts +1 -1
  58. package/dist/types-dir/api/uploadFiles.d.ts +1 -1
  59. package/dist/types.cjs +7 -16
  60. package/dist/types.d.cts +2 -2
  61. package/dist/types.d.mts +2 -2
  62. package/dist/types.d.ts +10 -12
  63. package/dist/types.js +1 -2
  64. package/dist/types.mjs +1 -15
  65. package/package.json +3 -2
  66. package/dist/IntlCache-CAW8tKhd.cjs +0 -212
  67. package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
  68. package/dist/IntlCache-WZk0rKvj.mjs +0 -195
  69. package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
  70. package/dist/base64-2fu94Klt.cjs.map +0 -1
  71. package/dist/base64-DH0STixb.mjs.map +0 -1
  72. package/dist/cache/IntlCache.d.ts +0 -26
  73. package/dist/cache/IntlCache.js +0 -84
  74. package/dist/cache/types.d.ts +0 -32
  75. package/dist/cache/types.js +0 -1
  76. package/dist/core-7RP541eY.cjs +0 -1677
  77. package/dist/core-7RP541eY.cjs.map +0 -1
  78. package/dist/core-I9pWGafA.d.mts +0 -209
  79. package/dist/core-TLJoDpJP.d.cts +0 -209
  80. package/dist/core-isLphYAZ.mjs +0 -1498
  81. package/dist/core-isLphYAZ.mjs.map +0 -1
  82. package/dist/errors/formattingErrors.d.ts +0 -1
  83. package/dist/errors/formattingErrors.js +0 -3
  84. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
  85. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +0 -147
  86. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
  87. package/dist/formatting/custom-formats/CutoffFormat/constants.js +0 -30
  88. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
  89. package/dist/formatting/custom-formats/CutoffFormat/types.js +0 -2
  90. package/dist/formatting/format.d.ts +0 -1
  91. package/dist/formatting/format.js +0 -257
  92. package/dist/locales/customLocaleMapping.d.ts +0 -11
  93. package/dist/locales/customLocaleMapping.js +0 -23
  94. package/dist/locales/determineLocale.d.ts +0 -1
  95. package/dist/locales/determineLocale.js +0 -72
  96. package/dist/locales/getLocaleDirection.d.ts +0 -1
  97. package/dist/locales/getLocaleDirection.js +0 -89
  98. package/dist/locales/getLocaleEmoji.d.ts +0 -2
  99. package/dist/locales/getLocaleEmoji.js +0 -319
  100. package/dist/locales/getLocaleName.d.ts +0 -1
  101. package/dist/locales/getLocaleName.js +0 -45
  102. package/dist/locales/getLocaleProperties.d.ts +0 -32
  103. package/dist/locales/getLocaleProperties.js +0 -220
  104. package/dist/locales/getRegionProperties.d.ts +0 -7
  105. package/dist/locales/getRegionProperties.js +0 -61
  106. package/dist/locales/isSameDialect.d.ts +0 -1
  107. package/dist/locales/isSameDialect.js +0 -41
  108. package/dist/locales/isSameLanguage.d.ts +0 -1
  109. package/dist/locales/isSameLanguage.js +0 -20
  110. package/dist/locales/isSupersetLocale.d.ts +0 -1
  111. package/dist/locales/isSupersetLocale.js +0 -22
  112. package/dist/locales/isValidLocale.d.ts +0 -1
  113. package/dist/locales/isValidLocale.js +0 -75
  114. package/dist/locales/requiresTranslation.d.ts +0 -1
  115. package/dist/locales/requiresTranslation.js +0 -32
  116. package/dist/locales/resolveAliasLocale.d.ts +0 -8
  117. package/dist/locales/resolveAliasLocale.js +0 -21
  118. package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
  119. package/dist/locales/resolveCanonicalLocale.js +0 -13
  120. package/dist/logging/warnings.d.ts +0 -2
  121. package/dist/logging/warnings.js +0 -2
  122. package/dist/types-dir/jsx/content.d.ts +0 -61
  123. package/dist/types-dir/jsx/content.js +0 -11
  124. package/dist/types-dir/jsx/variables.d.ts +0 -9
  125. package/dist/types-dir/jsx/variables.js +0 -1
  126. package/dist/types.cjs.map +0 -1
  127. package/dist/types.mjs.map +0 -1
@@ -1,195 +0,0 @@
1
- //#region src/settings/settings.ts
2
- const libraryDefaultLocale = "en";
3
- const defaultTimeout = 6e4;
4
- //#endregion
5
- //#region src/errors/formattingErrors.ts
6
- const createInvalidCutoffStyleError = (style) => `generaltranslation Formatting Error: Invalid cutoff style: ${style}.`;
7
- const DEFAULT_TERMINATOR_KEY = "DEFAULT_TERMINATOR_KEY";
8
- const TERMINATOR_MAP = {
9
- ellipsis: {
10
- fr: {
11
- terminator: "…",
12
- separator: " "
13
- },
14
- zh: {
15
- terminator: "……",
16
- separator: void 0
17
- },
18
- ja: {
19
- terminator: "……",
20
- separator: void 0
21
- },
22
- [DEFAULT_TERMINATOR_KEY]: {
23
- terminator: "…",
24
- separator: void 0
25
- }
26
- },
27
- none: { [DEFAULT_TERMINATOR_KEY]: {
28
- terminator: void 0,
29
- separator: void 0
30
- } }
31
- };
32
- //#endregion
33
- //#region src/formatting/custom-formats/CutoffFormat/CutoffFormat.ts
34
- var CutoffFormatConstructor = class {
35
- /**
36
- * Constructor
37
- * @param {Intl.LocalesArgument} locales - The locales to use for formatting.
38
- * @param {CutoffFormatOptions} options - The options for formatting.
39
- * @param {number} [options.maxChars] - The maximum number of characters to display.
40
- * - Undefined values are treated as no cutoff.
41
- * - Negative values follow .slice() behavior and terminator will be added before the value.
42
- * - 0 will result in an empty string.
43
- * - If cutoff results in an empty string, no terminator is added.
44
- * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
45
- * @param {string} [options.terminator] - Optional override the terminator to use.
46
- * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
47
- * - If no terminator is provided, then separator is ignored.
48
- *
49
- * @example
50
- * const format = new CutoffFormat('en', { maxChars: 5 });
51
- * format.format('Hello, world!'); // 'Hello...'
52
- *
53
- * const format = new CutoffFormat('en', { maxChars: -3 });
54
- * format.format('Hello, world!'); // '...ld!'
55
- */
56
- constructor(locales, options = {}) {
57
- try {
58
- const localesList = !locales ? ["en"] : Array.isArray(locales) ? locales.map((l) => String(l)) : [String(locales)];
59
- const canonicalLocales = Intl.getCanonicalLocales(localesList);
60
- this.locale = canonicalLocales.length ? canonicalLocales[0] : "en";
61
- } catch {
62
- this.locale = "en";
63
- }
64
- if (!TERMINATOR_MAP[options.style ?? "ellipsis"]) throw new Error(createInvalidCutoffStyleError(options.style ?? "ellipsis"));
65
- let style;
66
- let presetTerminatorOptions;
67
- if (options.maxChars !== void 0) {
68
- style = options.style ?? "ellipsis";
69
- const languageCode = new Intl.Locale(this.locale).language;
70
- presetTerminatorOptions = TERMINATOR_MAP[style][languageCode] || TERMINATOR_MAP[style]["DEFAULT_TERMINATOR_KEY"];
71
- }
72
- let terminator = options.terminator ?? presetTerminatorOptions?.terminator;
73
- let separator = terminator != null ? options.separator ?? presetTerminatorOptions?.separator : void 0;
74
- this.additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);
75
- if (options.maxChars !== void 0 && Math.abs(options.maxChars) < this.additionLength) {
76
- terminator = void 0;
77
- separator = void 0;
78
- }
79
- this.options = {
80
- maxChars: options.maxChars,
81
- style,
82
- terminator,
83
- separator
84
- };
85
- }
86
- /**
87
- * Format a value according to the cutoff options, returning a formatted string.
88
- *
89
- * @param {string} value - The string value to format with cutoff behavior.
90
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
91
- *
92
- * @example
93
- * const formatter = new CutoffFormatConstructor('en', { maxChars: 8, style: 'ellipsis' });
94
- * formatter.format('Hello, world!'); // Returns 'Hello, w...'
95
- */
96
- format(value) {
97
- return this.formatToParts(value).join("");
98
- }
99
- /**
100
- * Format a value to parts according to the cutoff options, returning an array of string parts.
101
- * This method breaks down the formatted result into individual components for more granular control.
102
- *
103
- * @param {string} value - The string value to format with cutoff behavior.
104
- * @returns {PrependedCutoffParts | PostpendedCutoffParts} An array of string parts representing the formatted result.
105
- * - For positive maxChars: [cutoffValue, separator?, terminator?]
106
- * - For negative maxChars: [terminator?, separator?, cutoffValue]
107
- * - For no cutoff: [originalValue]
108
- *
109
- * @example
110
- * const formatter = new CutoffFormatConstructor('en', { maxChars: 5, style: 'ellipsis' });
111
- * formatter.formatToParts('Hello, world!'); // Returns ['Hello', '...']
112
- */
113
- formatToParts(value) {
114
- const { maxChars, terminator, separator } = this.options;
115
- const adjustedChars = maxChars === void 0 || Math.abs(maxChars) >= value.length ? maxChars : maxChars >= 0 ? Math.max(0, maxChars - this.additionLength) : Math.min(0, maxChars + this.additionLength);
116
- const slicedValue = adjustedChars !== void 0 && adjustedChars > -1 ? value.slice(0, adjustedChars) : value.slice(adjustedChars);
117
- if (maxChars == null || adjustedChars == null || adjustedChars === 0 || terminator == null || value.length <= Math.abs(maxChars)) return [slicedValue];
118
- if (adjustedChars > 0) return separator != null ? [
119
- slicedValue,
120
- separator,
121
- terminator
122
- ] : [slicedValue, terminator];
123
- else return separator != null ? [
124
- terminator,
125
- separator,
126
- slicedValue
127
- ] : [terminator, slicedValue];
128
- }
129
- /**
130
- * Get the resolved options
131
- * @returns {ResolvedCutoffFormatOptions} The resolved options.
132
- */
133
- resolvedOptions() {
134
- return this.options;
135
- }
136
- };
137
- //#endregion
138
- //#region src/cache/IntlCache.ts
139
- /**
140
- * Object mapping constructor names to their respective constructor functions
141
- * Includes all native Intl constructors plus custom ones like CutoffFormat
142
- */
143
- const CustomIntl = {
144
- Collator: Intl.Collator,
145
- DateTimeFormat: Intl.DateTimeFormat,
146
- DisplayNames: Intl.DisplayNames,
147
- ListFormat: Intl.ListFormat,
148
- Locale: Intl.Locale,
149
- NumberFormat: Intl.NumberFormat,
150
- PluralRules: Intl.PluralRules,
151
- RelativeTimeFormat: Intl.RelativeTimeFormat,
152
- Segmenter: Intl.Segmenter,
153
- CutoffFormat: CutoffFormatConstructor
154
- };
155
- /**
156
- * Cache for Intl and custom format instances to avoid repeated instantiation
157
- * Uses a two-level structure: constructor name -> cache key -> instance.
158
- */
159
- var IntlCache = class {
160
- constructor() {
161
- this.cache = {};
162
- }
163
- /**
164
- * Generates a consistent cache key from locales and options.
165
- * Handles all LocalesArgument types (string, Locale, array, undefined).
166
- */
167
- _generateKey(locales, options = {}) {
168
- return `${!locales ? "undefined" : Array.isArray(locales) ? locales.map((l) => String(l)).join(",") : String(locales)}:${options ? JSON.stringify(options, Object.keys(options).sort()) : "{}"}`;
169
- }
170
- /**
171
- * Gets a cached Intl instance or creates a new one if not found
172
- * @param constructor The name of the Intl constructor to use.
173
- * @param args Constructor arguments (locales, options).
174
- * @returns Cached or newly created Intl instance.
175
- */
176
- get(constructor, ...args) {
177
- const [locales = "en", options = {}] = args;
178
- const key = this._generateKey(locales, options);
179
- let intlObject = this.cache[constructor]?.[key];
180
- if (intlObject === void 0) {
181
- intlObject = new CustomIntl[constructor](...args);
182
- if (!this.cache[constructor]) this.cache[constructor] = {};
183
- this.cache[constructor][key] = intlObject;
184
- }
185
- return intlObject;
186
- }
187
- };
188
- /**
189
- * Global instance of the Intl cache for use throughout the application
190
- */
191
- const intlCache = new IntlCache();
192
- //#endregion
193
- export { defaultTimeout as n, libraryDefaultLocale as r, intlCache as t };
194
-
195
- //# sourceMappingURL=IntlCache-WZk0rKvj.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntlCache-WZk0rKvj.mjs","names":[],"sources":["../src/settings/settings.ts","../src/errors/formattingErrors.ts","../src/formatting/custom-formats/CutoffFormat/constants.ts","../src/formatting/custom-formats/CutoffFormat/CutoffFormat.ts","../src/cache/IntlCache.ts"],"sourcesContent":["export const libraryDefaultLocale = 'en' as const;\nexport const defaultTimeout = 60000;\n","export const createInvalidCutoffStyleError = (style: string) =>\n `generaltranslation Formatting Error: Invalid cutoff style: ${style}.`;\n","import { CutoffFormatStyle, ResolvedTerminatorOptions } from './types';\n\nexport const DEFAULT_CUTOFF_FORMAT_STYLE: CutoffFormatStyle = 'ellipsis';\n\nexport const DEFAULT_TERMINATOR_KEY = 'DEFAULT_TERMINATOR_KEY';\n\nexport const TERMINATOR_MAP: Record<\n CutoffFormatStyle,\n Record<string | typeof DEFAULT_TERMINATOR_KEY, ResolvedTerminatorOptions>\n> = {\n ellipsis: {\n fr: {\n terminator: '…',\n separator: '\\u202F',\n },\n zh: {\n terminator: '……',\n separator: undefined,\n },\n ja: {\n terminator: '……',\n separator: undefined,\n },\n [DEFAULT_TERMINATOR_KEY]: {\n terminator: '…',\n separator: undefined,\n },\n },\n none: {\n [DEFAULT_TERMINATOR_KEY]: {\n terminator: undefined,\n separator: undefined,\n },\n },\n};\n","import { createInvalidCutoffStyleError } from '../../../errors/formattingErrors';\nimport { libraryDefaultLocale } from '../../../settings/settings';\nimport {\n DEFAULT_CUTOFF_FORMAT_STYLE,\n DEFAULT_TERMINATOR_KEY,\n TERMINATOR_MAP,\n} from './constants';\nimport {\n CutoffFormat,\n CutoffFormatOptions,\n CutoffFormatStyle,\n PostpendedCutoffParts,\n PrependedCutoffParts,\n ResolvedCutoffFormatOptions,\n ResolvedTerminatorOptions,\n} from './types';\n\nexport class CutoffFormatConstructor implements CutoffFormat {\n private locale: string;\n private options: ResolvedCutoffFormatOptions;\n private additionLength: number;\n /**\n * Constructor\n * @param {Intl.LocalesArgument} locales - The locales to use for formatting.\n * @param {CutoffFormatOptions} options - The options for formatting.\n * @param {number} [options.maxChars] - The maximum number of characters to display.\n * - Undefined values are treated as no cutoff.\n * - Negative values follow .slice() behavior and terminator will be added before the value.\n * - 0 will result in an empty string.\n * - If cutoff results in an empty string, no terminator is added.\n * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.\n * @param {string} [options.terminator] - Optional override the terminator to use.\n * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.\n * - If no terminator is provided, then separator is ignored.\n *\n * @example\n * const format = new CutoffFormat('en', { maxChars: 5 });\n * format.format('Hello, world!'); // 'Hello...'\n *\n * const format = new CutoffFormat('en', { maxChars: -3 });\n * format.format('Hello, world!'); // '...ld!'\n */\n constructor(\n locales: Intl.LocalesArgument,\n options: CutoffFormatOptions = {}\n ) {\n // Determine locale (this replicates Intl.NumberFormat behavior including silent failure)\n try {\n // Normalize locales to string\n const localesList = !locales\n ? [libraryDefaultLocale]\n : Array.isArray(locales)\n ? locales.map((l) => String(l))\n : [String(locales)];\n const canonicalLocales = Intl.getCanonicalLocales(localesList);\n this.locale = canonicalLocales.length\n ? canonicalLocales[0]\n : libraryDefaultLocale;\n } catch {\n this.locale = libraryDefaultLocale;\n }\n\n // Follows Intl.NumberFormat behavior of throwing an error when currency is invalid\n if (!TERMINATOR_MAP[options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE]) {\n throw new Error(\n createInvalidCutoffStyleError(\n options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE\n )\n );\n }\n\n // Resolve terminator options.\n let style: CutoffFormatStyle | undefined;\n let presetTerminatorOptions: ResolvedTerminatorOptions | undefined;\n if (options.maxChars !== undefined) {\n style = options.style ?? DEFAULT_CUTOFF_FORMAT_STYLE;\n // TODO: need more sophisticated locale negotiation if we want to add support for region/script/etc.-specific terminators in the future\n const languageCode = new Intl.Locale(this.locale).language;\n presetTerminatorOptions =\n TERMINATOR_MAP[style][languageCode] ||\n TERMINATOR_MAP[style][DEFAULT_TERMINATOR_KEY];\n }\n let terminator: ResolvedTerminatorOptions['terminator'] =\n options.terminator ?? presetTerminatorOptions?.terminator;\n let separator: ResolvedTerminatorOptions['separator'] =\n terminator != null\n ? (options.separator ?? presetTerminatorOptions?.separator)\n : undefined;\n // // Remove terminator and separator if maxChars does have enough space\n this.additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);\n if (\n options.maxChars !== undefined &&\n Math.abs(options.maxChars) < this.additionLength\n ) {\n terminator = undefined;\n separator = undefined;\n }\n\n this.options = {\n maxChars: options.maxChars,\n style,\n terminator,\n separator,\n };\n }\n\n /**\n * Format a value according to the cutoff options, returning a formatted string.\n *\n * @param {string} value - The string value to format with cutoff behavior.\n * @returns {string} The formatted string with terminator applied if cutoff occurs.\n *\n * @example\n * const formatter = new CutoffFormatConstructor('en', { maxChars: 8, style: 'ellipsis' });\n * formatter.format('Hello, world!'); // Returns 'Hello, w...'\n */\n format(value: string): string {\n return this.formatToParts(value).join('');\n }\n\n /**\n * Format a value to parts according to the cutoff options, returning an array of string parts.\n * This method breaks down the formatted result into individual components for more granular control.\n *\n * @param {string} value - The string value to format with cutoff behavior.\n * @returns {PrependedCutoffParts | PostpendedCutoffParts} An array of string parts representing the formatted result.\n * - For positive maxChars: [cutoffValue, separator?, terminator?]\n * - For negative maxChars: [terminator?, separator?, cutoffValue]\n * - For no cutoff: [originalValue]\n *\n * @example\n * const formatter = new CutoffFormatConstructor('en', { maxChars: 5, style: 'ellipsis' });\n * formatter.formatToParts('Hello, world!'); // Returns ['Hello', '...']\n */\n formatToParts(value: string): PrependedCutoffParts | PostpendedCutoffParts {\n const { maxChars, terminator, separator } = this.options;\n\n // Slice our value\n // const additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);\n const adjustedChars =\n maxChars === undefined || Math.abs(maxChars) >= value.length\n ? maxChars\n : maxChars >= 0\n ? Math.max(0, maxChars - this.additionLength)\n : Math.min(0, maxChars + this.additionLength);\n const slicedValue =\n adjustedChars !== undefined && adjustedChars > -1\n ? value.slice(0, adjustedChars)\n : value.slice(adjustedChars);\n\n // No cutoff, no terminator -> value only\n if (\n maxChars == null ||\n adjustedChars == null ||\n adjustedChars === 0 ||\n terminator == null ||\n value.length <= Math.abs(maxChars)\n ) {\n return [slicedValue];\n }\n\n // Postpended cutoff.\n if (adjustedChars > 0) {\n return separator != null\n ? [slicedValue, separator, terminator]\n : [slicedValue, terminator];\n }\n // Prepended cutoff.\n else {\n return separator != null\n ? [terminator, separator, slicedValue]\n : [terminator, slicedValue];\n }\n }\n\n /**\n * Get the resolved options\n * @returns {ResolvedCutoffFormatOptions} The resolved options.\n */\n resolvedOptions(): ResolvedCutoffFormatOptions {\n return this.options;\n }\n}\n","import { libraryDefaultLocale } from '../settings/settings';\nimport { CutoffFormatConstructor } from '../formatting/custom-formats/CutoffFormat/CutoffFormat';\nimport {\n ConstructorType,\n CustomIntlConstructors,\n CustomIntlType,\n IntlCacheObject,\n} from './types';\n\n/**\n * Object mapping constructor names to their respective constructor functions\n * Includes all native Intl constructors plus custom ones like CutoffFormat\n */\nconst CustomIntl: CustomIntlType = {\n Collator: Intl.Collator,\n DateTimeFormat: Intl.DateTimeFormat,\n DisplayNames: Intl.DisplayNames,\n ListFormat: Intl.ListFormat,\n Locale: Intl.Locale,\n NumberFormat: Intl.NumberFormat,\n PluralRules: Intl.PluralRules,\n RelativeTimeFormat: Intl.RelativeTimeFormat,\n Segmenter: Intl.Segmenter,\n CutoffFormat: CutoffFormatConstructor,\n};\n\n/**\n * Cache for Intl and custom format instances to avoid repeated instantiation\n * Uses a two-level structure: constructor name -> cache key -> instance.\n */\nclass IntlCache {\n private cache: IntlCacheObject;\n\n constructor() {\n this.cache = {};\n }\n\n /**\n * Generates a consistent cache key from locales and options.\n * Handles all LocalesArgument types (string, Locale, array, undefined).\n */\n private _generateKey(locales: Intl.LocalesArgument, options = {}) {\n // Normalize locales to string representation\n const localeKey = !locales\n ? 'undefined'\n : Array.isArray(locales)\n ? locales.map((l) => String(l)).join(',')\n : String(locales);\n\n // Sort option keys to ensure consistent key generation regardless of property order\n const sortedOptions = options\n ? JSON.stringify(options, Object.keys(options).sort())\n : '{}';\n return `${localeKey}:${sortedOptions}`;\n }\n\n /**\n * Gets a cached Intl instance or creates a new one if not found\n * @param constructor The name of the Intl constructor to use.\n * @param args Constructor arguments (locales, options).\n * @returns Cached or newly created Intl instance.\n */\n get<K extends keyof CustomIntlConstructors>(\n constructor: K,\n ...args: ConstructorParameters<CustomIntlConstructors[K]>\n ): InstanceType<ConstructorType<K>> {\n const [locales = libraryDefaultLocale, options = {}] = args;\n const key = this._generateKey(locales, options);\n let intlObject = this.cache[constructor]?.[key];\n\n if (intlObject === undefined) {\n // Create new instance and cache it\n intlObject = new CustomIntl[constructor](...args);\n if (!this.cache[constructor]) this.cache[constructor] = {};\n this.cache[constructor][key] = intlObject;\n }\n\n return intlObject;\n }\n}\n\n/**\n * Global instance of the Intl cache for use throughout the application\n */\nexport const intlCache = new IntlCache();\n"],"mappings":";AAAA,MAAa,uBAAuB;AACpC,MAAa,iBAAiB;;;ACD9B,MAAa,iCAAiC,UAC5C,8DAA8D,MAAM;ACGtE,MAAa,yBAAyB;AAEtC,MAAa,iBAGT;CACF,UAAU;EACR,IAAI;GACF,YAAY;GACZ,WAAW;GACZ;EACD,IAAI;GACF,YAAY;GACZ,WAAW,KAAA;GACZ;EACD,IAAI;GACF,YAAY;GACZ,WAAW,KAAA;GACZ;GACA,yBAAyB;GACxB,YAAY;GACZ,WAAW,KAAA;GACZ;EACF;CACD,MAAM,GACH,yBAAyB;EACxB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AAa,KAAK,MAAM,eAAe;AAE3C,MAAI,eAAe,KAAA,GAAW;AAE5B,gBAAa,IAAI,WAAW,aAAa,GAAG,KAAK;AACjD,OAAI,CAAC,KAAK,MAAM,aAAc,MAAK,MAAM,eAAe,EAAE;AAC1D,QAAK,MAAM,aAAa,OAAO;;AAGjC,SAAO;;;;;;AAOX,MAAa,YAAY,IAAI,WAAW"}
@@ -1 +0,0 @@
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,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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"}
@@ -1,26 +0,0 @@
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 {};
@@ -1,84 +0,0 @@
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();
@@ -1,32 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
- export {};