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.
- package/CHANGELOG.md +15 -0
- package/dist/{IntlCache-k2qfrDqB.cjs → IntlCache-CAW8tKhd.cjs} +12 -12
- package/dist/IntlCache-CAW8tKhd.cjs.map +1 -0
- package/dist/{IntlCache-Ccg_cQPR.mjs → IntlCache-WZk0rKvj.mjs} +12 -12
- package/dist/IntlCache-WZk0rKvj.mjs.map +1 -0
- package/dist/LocaleConfig.d.ts +59 -0
- package/dist/LocaleConfig.js +225 -0
- package/dist/backwards-compatability/dataConversion.d.ts +23 -0
- package/dist/backwards-compatability/dataConversion.js +207 -0
- package/dist/backwards-compatability/oldHashJsxChildren.d.ts +23 -0
- package/dist/backwards-compatability/oldHashJsxChildren.js +79 -0
- package/dist/backwards-compatability/oldTypes.d.ts +21 -0
- package/dist/backwards-compatability/oldTypes.js +1 -0
- package/dist/backwards-compatability/typeChecking.d.ts +21 -0
- package/dist/backwards-compatability/typeChecking.js +61 -0
- package/dist/{base64-CUcEPEC5.cjs → base64-2fu94Klt.cjs} +3 -3
- package/dist/base64-2fu94Klt.cjs.map +1 -0
- package/dist/{base64-C1sogiix.mjs → base64-DH0STixb.mjs} +3 -3
- package/dist/base64-DH0STixb.mjs.map +1 -0
- package/dist/cache/IntlCache.d.ts +26 -0
- package/dist/cache/IntlCache.js +84 -0
- package/dist/cache/types.d.ts +32 -0
- package/dist/cache/types.js +1 -0
- package/dist/{core-3SOQ5ND6.cjs → core-7RP541eY.cjs} +18 -20
- package/dist/core-7RP541eY.cjs.map +1 -0
- package/dist/{core-6rY3oy32.d.cts → core-I9pWGafA.d.mts} +8 -8
- package/dist/{core-BYVWty_t.d.mts → core-TLJoDpJP.d.cts} +8 -8
- package/dist/{core-Bx0m6GOp.mjs → core-isLphYAZ.mjs} +18 -20
- package/dist/core-isLphYAZ.mjs.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.mts +1 -1
- package/dist/core.d.ts +128 -0
- package/dist/core.js +137 -0
- package/dist/core.mjs +1 -1
- package/dist/derive/condenseVars.d.ts +7 -0
- package/dist/derive/condenseVars.js +30 -0
- package/dist/derive/declareVar.d.ts +26 -0
- package/dist/derive/declareVar.js +38 -0
- package/dist/derive/decodeVars.d.ts +9 -0
- package/dist/derive/decodeVars.js +52 -0
- package/dist/derive/derive.d.ts +53 -0
- package/dist/derive/derive.js +55 -0
- package/dist/derive/extractVars.d.ts +9 -0
- package/dist/derive/extractVars.js +34 -0
- package/dist/derive/index.d.ts +7 -0
- package/dist/derive/index.js +7 -0
- package/dist/derive/indexVars.d.ts +6 -0
- package/dist/derive/indexVars.js +52 -0
- package/dist/derive/utils/constants.d.ts +2 -0
- package/dist/derive/utils/constants.js +2 -0
- package/dist/derive/utils/regex.d.ts +2 -0
- package/dist/derive/utils/regex.js +4 -0
- package/dist/derive/utils/sanitizeVar.d.ts +12 -0
- package/dist/derive/utils/sanitizeVar.js +38 -0
- package/dist/derive/utils/traverseHelpers.d.ts +4 -0
- package/dist/derive/utils/traverseHelpers.js +22 -0
- package/dist/derive/utils/traverseIcu.d.ts +20 -0
- package/dist/derive/utils/traverseIcu.js +49 -0
- package/dist/derive/utils/types.d.ts +23 -0
- package/dist/derive/utils/types.js +1 -0
- package/dist/errors/ApiError.d.ts +7 -0
- package/dist/errors/ApiError.js +33 -0
- package/dist/errors/formattingErrors.d.ts +1 -0
- package/dist/errors/formattingErrors.js +3 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +1 -0
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +59 -0
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +147 -0
- package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +4 -0
- package/dist/formatting/custom-formats/CutoffFormat/constants.js +30 -0
- package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +48 -0
- package/dist/formatting/custom-formats/CutoffFormat/types.js +2 -0
- package/dist/formatting/format.d.ts +1 -0
- package/dist/formatting/format.js +257 -0
- package/dist/id/hashSource.d.ts +25 -0
- package/dist/id/hashSource.js +98 -0
- package/dist/id/hashTemplate.d.ts +4 -0
- package/dist/id/hashTemplate.js +6 -0
- package/dist/id/types.d.ts +7 -0
- package/dist/id/types.js +1 -0
- package/dist/{id-COlX5v3V.cjs → id-CyiXsQrY.cjs} +9 -9
- package/dist/id-CyiXsQrY.cjs.map +1 -0
- package/dist/{id-BmOyfaug.mjs → id-DbD7K-HL.mjs} +9 -9
- package/dist/id-DbD7K-HL.mjs.map +1 -0
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +9 -9
- package/dist/id.d.mts +9 -9
- package/dist/id.d.ts +3 -0
- package/dist/id.js +3 -0
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +140 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -88
- package/dist/index.d.mts +88 -88
- package/dist/index.d.ts +1019 -0
- package/dist/index.js +1664 -0
- package/dist/index.mjs +140 -140
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +41 -26
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +38 -23
- package/dist/internal.d.mts +38 -23
- package/dist/internal.d.ts +19 -0
- package/dist/internal.js +17 -0
- package/dist/internal.mjs +41 -26
- package/dist/internal.mjs.map +1 -1
- package/dist/locales/customLocaleMapping.d.ts +11 -0
- package/dist/locales/customLocaleMapping.js +23 -0
- package/dist/locales/determineLocale.d.ts +1 -0
- package/dist/locales/determineLocale.js +72 -0
- package/dist/locales/getLocaleDirection.d.ts +1 -0
- package/dist/locales/getLocaleDirection.js +89 -0
- package/dist/locales/getLocaleEmoji.d.ts +2 -0
- package/dist/locales/getLocaleEmoji.js +319 -0
- package/dist/locales/getLocaleName.d.ts +1 -0
- package/dist/locales/getLocaleName.js +45 -0
- package/dist/locales/getLocaleProperties.d.ts +32 -0
- package/dist/locales/getLocaleProperties.js +220 -0
- package/dist/locales/getPluralForm.d.ts +9 -0
- package/dist/locales/getPluralForm.js +63 -0
- package/dist/locales/getRegionProperties.d.ts +7 -0
- package/dist/locales/getRegionProperties.js +61 -0
- package/dist/locales/isSameDialect.d.ts +1 -0
- package/dist/locales/isSameDialect.js +41 -0
- package/dist/locales/isSameLanguage.d.ts +1 -0
- package/dist/locales/isSameLanguage.js +20 -0
- package/dist/locales/isSupersetLocale.d.ts +1 -0
- package/dist/locales/isSupersetLocale.js +22 -0
- package/dist/locales/isValidLocale.d.ts +1 -0
- package/dist/locales/isValidLocale.js +75 -0
- package/dist/locales/requiresTranslation.d.ts +1 -0
- package/dist/locales/requiresTranslation.js +32 -0
- package/dist/locales/resolveAliasLocale.d.ts +8 -0
- package/dist/locales/resolveAliasLocale.js +21 -0
- package/dist/locales/resolveCanonicalLocale.d.ts +8 -0
- package/dist/locales/resolveCanonicalLocale.js +13 -0
- package/dist/logging/errors.d.ts +10 -0
- package/dist/logging/errors.js +29 -0
- package/dist/logging/logger.d.ts +121 -0
- package/dist/logging/logger.js +259 -0
- package/dist/logging/warnings.d.ts +2 -0
- package/dist/logging/warnings.js +2 -0
- package/dist/projects/getProjectData.d.ts +1 -0
- package/dist/projects/getProjectData.js +87 -0
- package/dist/settings/plurals.d.ts +3 -0
- package/dist/settings/plurals.js +14 -0
- package/dist/settings/settings.d.ts +2 -0
- package/dist/settings/settings.js +2 -0
- package/dist/settings/settingsUrls.d.ts +3 -0
- package/dist/settings/settingsUrls.js +3 -0
- package/dist/translate/api.d.ts +1 -0
- package/dist/translate/api.js +1 -0
- package/dist/translate/awaitJobs.d.ts +19 -0
- package/dist/translate/awaitJobs.js +112 -0
- package/dist/translate/checkJobStatus.d.ts +8 -0
- package/dist/translate/checkJobStatus.js +55 -0
- package/dist/translate/createBranch.d.ts +10 -0
- package/dist/translate/createBranch.js +53 -0
- package/dist/translate/createTag.d.ts +19 -0
- package/dist/translate/createTag.js +67 -0
- package/dist/translate/downloadFileBatch.d.ts +1 -0
- package/dist/translate/downloadFileBatch.js +77 -0
- package/dist/translate/enqueueFiles.d.ts +8 -0
- package/dist/translate/enqueueFiles.js +96 -0
- package/dist/translate/getOrphanedFiles.d.ts +8 -0
- package/dist/translate/getOrphanedFiles.js +97 -0
- package/dist/translate/processFileMoves.d.ts +25 -0
- package/dist/translate/processFileMoves.js +90 -0
- package/dist/translate/publishFiles.d.ts +17 -0
- package/dist/translate/publishFiles.js +56 -0
- package/dist/translate/queryBranchData.d.ts +3 -0
- package/dist/translate/queryBranchData.js +53 -0
- package/dist/translate/queryFileData.d.ts +42 -0
- package/dist/translate/queryFileData.js +71 -0
- package/dist/translate/querySourceFile.d.ts +1 -0
- package/dist/translate/querySourceFile.js +67 -0
- package/dist/translate/setupProject.d.ts +11 -0
- package/dist/translate/setupProject.js +63 -0
- package/dist/translate/submitUserEditDiffs.d.ts +12 -0
- package/dist/translate/submitUserEditDiffs.js +68 -0
- package/dist/translate/translateMany.d.ts +1 -0
- package/dist/translate/translateMany.js +103 -0
- package/dist/translate/uploadSourceFiles.d.ts +1 -0
- package/dist/translate/uploadSourceFiles.js +87 -0
- package/dist/translate/uploadTranslations.d.ts +1 -0
- package/dist/translate/uploadTranslations.js +101 -0
- package/dist/translate/utils/apiRequest.d.ts +1 -0
- package/dist/translate/utils/apiRequest.js +130 -0
- package/dist/translate/utils/batch.d.ts +52 -0
- package/dist/translate/utils/batch.js +126 -0
- package/dist/translate/utils/fetchWithTimeout.d.ts +1 -0
- package/dist/translate/utils/fetchWithTimeout.js +93 -0
- package/dist/translate/utils/generateRequestHeaders.d.ts +2 -0
- package/dist/translate/utils/generateRequestHeaders.js +26 -0
- package/dist/translate/utils/handleFetchError.d.ts +1 -0
- package/dist/translate/utils/handleFetchError.js +12 -0
- package/dist/translate/utils/validateFileFormatTransform.d.ts +16 -0
- package/dist/translate/utils/validateFileFormatTransform.js +29 -0
- package/dist/translate/utils/validateResponse.d.ts +1 -0
- package/dist/translate/utils/validateResponse.js +72 -0
- package/dist/{types-Cy8q2XZX.d.mts → types-AHtYZIP-.d.mts} +63 -40
- package/dist/{types-NKhpChvT.d.cts → types-Bf8_Apq_.d.cts} +63 -40
- package/dist/types-dir/api/branch.d.ts +10 -0
- package/dist/types-dir/api/branch.js +1 -0
- package/dist/types-dir/api/checkFileTranslations.d.ts +37 -0
- package/dist/types-dir/api/checkFileTranslations.js +1 -0
- package/dist/types-dir/api/downloadFile.d.ts +3 -0
- package/dist/types-dir/api/downloadFile.js +1 -0
- package/dist/types-dir/api/downloadFileBatch.d.ts +35 -0
- package/dist/types-dir/api/downloadFileBatch.js +1 -0
- package/dist/types-dir/api/enqueueEntries.d.ts +21 -0
- package/dist/types-dir/api/enqueueEntries.js +1 -0
- package/dist/types-dir/api/enqueueFiles.d.ts +70 -0
- package/dist/types-dir/api/enqueueFiles.js +1 -0
- package/dist/types-dir/api/entry.d.ts +39 -0
- package/dist/types-dir/api/entry.js +1 -0
- package/dist/types-dir/api/fetchTranslations.d.ts +12 -0
- package/dist/types-dir/api/fetchTranslations.js +1 -0
- package/dist/types-dir/api/file.d.ts +57 -0
- package/dist/types-dir/api/file.js +1 -0
- package/dist/types-dir/api/json.d.ts +5 -0
- package/dist/types-dir/api/json.js +1 -0
- package/dist/types-dir/api/project.d.ts +7 -0
- package/dist/types-dir/api/project.js +1 -0
- package/dist/types-dir/api/translate.d.ts +34 -0
- package/dist/types-dir/api/translate.js +1 -0
- package/dist/types-dir/api/translateMany.d.ts +5 -0
- package/dist/types-dir/api/translateMany.js +1 -0
- package/dist/types-dir/api/translationStatus.d.ts +9 -0
- package/dist/types-dir/api/translationStatus.js +1 -0
- package/dist/types-dir/api/uploadFiles.d.ts +44 -0
- package/dist/types-dir/api/uploadFiles.js +1 -0
- package/dist/types-dir/jsx/content.d.ts +61 -0
- package/dist/types-dir/jsx/content.js +11 -0
- package/dist/types-dir/jsx/variables.d.ts +9 -0
- package/dist/types-dir/jsx/variables.js +1 -0
- package/dist/types-dir/transformations.d.ts +8 -0
- package/dist/types-dir/transformations.js +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +129 -0
- package/dist/types.js +2 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils/base64.d.ts +2 -0
- package/dist/utils/base64.js +28 -0
- package/dist/utils/isSupportedFileFormatTransform.d.ts +8 -0
- package/dist/utils/isSupportedFileFormatTransform.js +26 -0
- package/dist/utils/isVariable.d.ts +2 -0
- package/dist/utils/isVariable.js +22 -0
- package/dist/utils/minify.d.ts +2 -0
- package/dist/utils/minify.js +10 -0
- package/dist/utils/stableStringify.d.ts +1 -0
- package/dist/utils/stableStringify.js +40 -0
- package/package.json +5 -6
- package/dist/IntlCache-Ccg_cQPR.mjs.map +0 -1
- package/dist/IntlCache-k2qfrDqB.cjs.map +0 -1
- package/dist/base64-C1sogiix.mjs.map +0 -1
- package/dist/base64-CUcEPEC5.cjs.map +0 -1
- package/dist/core-3SOQ5ND6.cjs.map +0 -1
- package/dist/core-Bx0m6GOp.mjs.map +0 -1
- package/dist/id-BmOyfaug.mjs.map +0 -1
- package/dist/id-COlX5v3V.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# generaltranslation
|
|
2
2
|
|
|
3
|
+
## 8.2.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1379](https://github.com/generaltranslation/gt/pull/1379) [`e88fd39`](https://github.com/generaltranslation/gt/commit/e88fd399683868d5af1fe2b0ba2974fe5b17d7a7) Thanks [@bgub](https://github.com/bgub)! - Tighten public and API metadata types, and handle metadata entries without hashes in the CLI.
|
|
8
|
+
|
|
9
|
+
- [#1387](https://github.com/generaltranslation/gt/pull/1387) [`95f852a`](https://github.com/generaltranslation/gt/commit/95f852ae086ac79d2c446f4d3072d8fd18688796) Thanks [@bgub](https://github.com/bgub)! - Reduce explicit any usage in core and Next.js types.
|
|
10
|
+
|
|
11
|
+
## 8.2.12
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#1364](https://github.com/generaltranslation/gt/pull/1364) [`9eae4d9`](https://github.com/generaltranslation/gt/commit/9eae4d93476688b621c739683c8bac64cbf50bf0) Thanks [@pie575](https://github.com/pie575)! - Update Derive docs comments
|
|
16
|
+
|
|
3
17
|
## 8.2.11
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -275,6 +289,7 @@
|
|
|
275
289
|
https://generaltranslation.com/blog/generaltranslation_v8
|
|
276
290
|
|
|
277
291
|
Please update the following packages to the latest version:
|
|
292
|
+
|
|
278
293
|
- generaltranslation: `7.9.1` or later
|
|
279
294
|
- gtx-cli: `2.4.15` or later
|
|
280
295
|
- gt-sanity: `1.0.11` or later
|
|
@@ -34,16 +34,16 @@ const TERMINATOR_MAP = {
|
|
|
34
34
|
var CutoffFormatConstructor = class {
|
|
35
35
|
/**
|
|
36
36
|
* Constructor
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {Intl.LocalesArgument} locales - The locales to use for formatting.
|
|
38
38
|
* @param {CutoffFormatOptions} options - The options for formatting.
|
|
39
|
-
* @param {number} [
|
|
39
|
+
* @param {number} [options.maxChars] - The maximum number of characters to display.
|
|
40
40
|
* - Undefined values are treated as no cutoff.
|
|
41
41
|
* - Negative values follow .slice() behavior and terminator will be added before the value.
|
|
42
42
|
* - 0 will result in an empty string.
|
|
43
43
|
* - If cutoff results in an empty string, no terminator is added.
|
|
44
|
-
* @param {CutoffFormatStyle} [
|
|
45
|
-
* @param {string} [
|
|
46
|
-
* @param {string} [
|
|
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
47
|
* - If no terminator is provided, then separator is ignored.
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
@@ -154,24 +154,24 @@ const CustomIntl = {
|
|
|
154
154
|
};
|
|
155
155
|
/**
|
|
156
156
|
* Cache for Intl and custom format instances to avoid repeated instantiation
|
|
157
|
-
* Uses a two-level structure: constructor name -> cache key -> instance
|
|
157
|
+
* Uses a two-level structure: constructor name -> cache key -> instance.
|
|
158
158
|
*/
|
|
159
159
|
var IntlCache = class {
|
|
160
160
|
constructor() {
|
|
161
161
|
this.cache = {};
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* Generates a consistent cache key from locales and options
|
|
165
|
-
* Handles all LocalesArgument types (string, Locale, array, undefined)
|
|
164
|
+
* Generates a consistent cache key from locales and options.
|
|
165
|
+
* Handles all LocalesArgument types (string, Locale, array, undefined).
|
|
166
166
|
*/
|
|
167
167
|
_generateKey(locales, options = {}) {
|
|
168
168
|
return `${!locales ? "undefined" : Array.isArray(locales) ? locales.map((l) => String(l)).join(",") : String(locales)}:${options ? JSON.stringify(options, Object.keys(options).sort()) : "{}"}`;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
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
|
|
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
175
|
*/
|
|
176
176
|
get(constructor, ...args) {
|
|
177
177
|
const [locales = "en", options = {}] = args;
|
|
@@ -209,4 +209,4 @@ Object.defineProperty(exports, "libraryDefaultLocale", {
|
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
-
//# sourceMappingURL=IntlCache-
|
|
212
|
+
//# sourceMappingURL=IntlCache-CAW8tKhd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlCache-CAW8tKhd.cjs","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,YAAY,KAAA;EACZ,WAAW,KAAA;EACZ,EACF;CACF;;;ACjBD,IAAa,0BAAb,MAA6D;;;;;;;;;;;;;;;;;;;;;;CAyB3D,YACE,SACA,UAA+B,EAAE,EACjC;AAEA,MAAI;GAEF,MAAM,cAAc,CAAC,UACjB,CAAA,KAAsB,GACtB,MAAM,QAAQ,QAAQ,GACpB,QAAQ,KAAK,MAAM,OAAO,EAAE,CAAC,GAC7B,CAAC,OA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P = {
|
|
|
34
34
|
var CutoffFormatConstructor = class {
|
|
35
35
|
/**
|
|
36
36
|
* Constructor
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {Intl.LocalesArgument} locales - The locales to use for formatting.
|
|
38
38
|
* @param {CutoffFormatOptions} options - The options for formatting.
|
|
39
|
-
* @param {number} [
|
|
39
|
+
* @param {number} [options.maxChars] - The maximum number of characters to display.
|
|
40
40
|
* - Undefined values are treated as no cutoff.
|
|
41
41
|
* - Negative values follow .slice() behavior and terminator will be added before the value.
|
|
42
42
|
* - 0 will result in an empty string.
|
|
43
43
|
* - If cutoff results in an empty string, no terminator is added.
|
|
44
|
-
* @param {CutoffFormatStyle} [
|
|
45
|
-
* @param {string} [
|
|
46
|
-
* @param {string} [
|
|
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
47
|
* - If no terminator is provided, then separator is ignored.
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
@@ -154,24 +154,24 @@ const CustomIntl = {
|
|
|
154
154
|
};
|
|
155
155
|
/**
|
|
156
156
|
* Cache for Intl and custom format instances to avoid repeated instantiation
|
|
157
|
-
* Uses a two-level structure: constructor name -> cache key -> instance
|
|
157
|
+
* Uses a two-level structure: constructor name -> cache key -> instance.
|
|
158
158
|
*/
|
|
159
159
|
var IntlCache = class {
|
|
160
160
|
constructor() {
|
|
161
161
|
this.cache = {};
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* Generates a consistent cache key from locales and options
|
|
165
|
-
* Handles all LocalesArgument types (string, Locale, array, undefined)
|
|
164
|
+
* Generates a consistent cache key from locales and options.
|
|
165
|
+
* Handles all LocalesArgument types (string, Locale, array, undefined).
|
|
166
166
|
*/
|
|
167
167
|
_generateKey(locales, options = {}) {
|
|
168
168
|
return `${!locales ? "undefined" : Array.isArray(locales) ? locales.map((l) => String(l)).join(",") : String(locales)}:${options ? JSON.stringify(options, Object.keys(options).sort()) : "{}"}`;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
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
|
|
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
175
|
*/
|
|
176
176
|
get(constructor, ...args) {
|
|
177
177
|
const [locales = "en", options = {}] = args;
|
|
@@ -192,4 +192,4 @@ const intlCache = new IntlCache();
|
|
|
192
192
|
//#endregion
|
|
193
193
|
export { defaultTimeout as n, libraryDefaultLocale as r, intlCache as t };
|
|
194
194
|
|
|
195
|
-
//# sourceMappingURL=IntlCache-
|
|
195
|
+
//# sourceMappingURL=IntlCache-WZk0rKvj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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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AOjB,aAAqB,SAA+B,UAAU,EAAE,EAAE;AAYhE,SAAO,GAVW,CAAC,UACf,cACA,MAAM,QAAQ,QAAQ,GACpB,QAAQ,KAAK,MAAM,OAAO,EAAE,CAAC,CAAC,KAAK,IAAI,GACvC,OAAO,QAAQ,CAMD,GAHE,UAClB,KAAK,UAAU,SAAS,OAAO,KAAK,QAAQ,CAAC,MAAM,CAAC,GACpD;;;;;;;;CAUN,IACE,aACA,GAAG,MAC+B;EAClC,MAAM,CAAC,UAAA,MAAgC,UAAU,EAAE,IAAI;EACvD,MAAM,MAAM,KAAK,aAAa,SAAS,QAAQ;EAC/C,IAAI,aAAa,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"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { CustomMapping, FormatVariables } from './types';
|
|
2
|
+
import { CutoffFormatOptions } from './formatting/custom-formats/CutoffFormat/types';
|
|
3
|
+
import { StringFormat } from './types-dir/jsx/content';
|
|
4
|
+
export type LocaleConfigConstructorParams = {
|
|
5
|
+
defaultLocale?: string;
|
|
6
|
+
locales?: string[];
|
|
7
|
+
customMapping?: CustomMapping;
|
|
8
|
+
};
|
|
9
|
+
type LocalesOption = {
|
|
10
|
+
locales?: string | string[];
|
|
11
|
+
};
|
|
12
|
+
type WithLocales<T = object> = T & LocalesOption;
|
|
13
|
+
/**
|
|
14
|
+
* LocaleConfig contains the locale and formatting primitives exposed through
|
|
15
|
+
* the core entrypoint.
|
|
16
|
+
*
|
|
17
|
+
* It intentionally does not store project IDs, API keys, runtime URLs, or any
|
|
18
|
+
* translation credentials. It only stores locale metadata needed to resolve
|
|
19
|
+
* aliases, choose formatting fallbacks, and format values with Intl.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LocaleConfig {
|
|
22
|
+
readonly defaultLocale: string;
|
|
23
|
+
readonly locales: string[];
|
|
24
|
+
readonly customMapping?: CustomMapping;
|
|
25
|
+
constructor({ defaultLocale, locales, customMapping, }?: LocaleConfigConstructorParams);
|
|
26
|
+
private get translationLocales();
|
|
27
|
+
private resolveCanonicalLocaleList;
|
|
28
|
+
private resolveCanonicalLocaleArgs;
|
|
29
|
+
private toLocaleList;
|
|
30
|
+
private getFormattingLocales;
|
|
31
|
+
formatNum(value: number, targetLocale?: string, options?: WithLocales<Intl.NumberFormatOptions>): string;
|
|
32
|
+
formatDateTime(value: Date, targetLocale?: string, options?: WithLocales<Intl.DateTimeFormatOptions>): string;
|
|
33
|
+
formatCurrency(value: number, currency: string, targetLocale?: string, options?: WithLocales<Intl.NumberFormatOptions>): string;
|
|
34
|
+
formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, targetLocale?: string, options?: WithLocales<Intl.RelativeTimeFormatOptions>): string;
|
|
35
|
+
formatRelativeTimeFromDate(date: Date, targetLocale?: string, options?: WithLocales<Intl.RelativeTimeFormatOptions & {
|
|
36
|
+
baseDate?: Date;
|
|
37
|
+
}>): string;
|
|
38
|
+
formatCutoff(value: string, targetLocale?: string, options?: WithLocales<CutoffFormatOptions>): string;
|
|
39
|
+
formatMessage(message: string, targetLocale?: string, options?: WithLocales<{
|
|
40
|
+
variables?: FormatVariables;
|
|
41
|
+
dataFormat?: StringFormat;
|
|
42
|
+
}>): string;
|
|
43
|
+
formatList(array: Array<string | number>, targetLocale?: string, options?: WithLocales<Intl.ListFormatOptions>): string;
|
|
44
|
+
formatListToParts<T>(array: Array<T>, targetLocale?: string, options?: WithLocales<Intl.ListFormatOptions>): (string | T)[];
|
|
45
|
+
getLocaleName(locale: string): string;
|
|
46
|
+
getLocaleEmoji(locale: string): string;
|
|
47
|
+
getLocaleProperties(locale: string): import("./types").LocaleProperties;
|
|
48
|
+
requiresTranslation(targetLocale: string, sourceLocale?: string, approvedLocales?: string[] | undefined): boolean;
|
|
49
|
+
determineLocale(locales: string | string[], approvedLocales?: string[]): string | undefined;
|
|
50
|
+
getLocaleDirection(locale: string): "ltr" | "rtl";
|
|
51
|
+
isValidLocale(locale: string): boolean;
|
|
52
|
+
resolveCanonicalLocale(locale: string): string;
|
|
53
|
+
resolveAliasLocale(locale: string): string;
|
|
54
|
+
standardizeLocale(locale: string): string;
|
|
55
|
+
isSameDialect(...locales: (string | string[])[]): boolean;
|
|
56
|
+
isSameLanguage(...locales: (string | string[])[]): boolean;
|
|
57
|
+
isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { _formatCurrency, _formatCutoff, _formatDateTime, _formatList, _formatListToParts, _formatMessageICU, _formatMessageString, _formatNum, _formatRelativeTime, _formatRelativeTimeFromDate, } from './formatting/format';
|
|
13
|
+
import _requiresTranslation from './locales/requiresTranslation';
|
|
14
|
+
import _determineLocale from './locales/determineLocale';
|
|
15
|
+
import _isSameLanguage from './locales/isSameLanguage';
|
|
16
|
+
import _getLocaleProperties from './locales/getLocaleProperties';
|
|
17
|
+
import _getLocaleEmoji from './locales/getLocaleEmoji';
|
|
18
|
+
import { _isValidLocale, _standardizeLocale } from './locales/isValidLocale';
|
|
19
|
+
import { _getLocaleName } from './locales/getLocaleName';
|
|
20
|
+
import { _getLocaleDirection } from './locales/getLocaleDirection';
|
|
21
|
+
import { libraryDefaultLocale } from './settings/settings';
|
|
22
|
+
import _isSameDialect from './locales/isSameDialect';
|
|
23
|
+
import _isSupersetLocale from './locales/isSupersetLocale';
|
|
24
|
+
import { _resolveAliasLocale } from './locales/resolveAliasLocale';
|
|
25
|
+
import { _resolveCanonicalLocale } from './locales/resolveCanonicalLocale';
|
|
26
|
+
/**
|
|
27
|
+
* LocaleConfig contains the locale and formatting primitives exposed through
|
|
28
|
+
* the core entrypoint.
|
|
29
|
+
*
|
|
30
|
+
* It intentionally does not store project IDs, API keys, runtime URLs, or any
|
|
31
|
+
* translation credentials. It only stores locale metadata needed to resolve
|
|
32
|
+
* aliases, choose formatting fallbacks, and format values with Intl.
|
|
33
|
+
*/
|
|
34
|
+
var LocaleConfig = /** @class */ (function () {
|
|
35
|
+
function LocaleConfig(_a) {
|
|
36
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.defaultLocale, defaultLocale = _c === void 0 ? libraryDefaultLocale : _c, _d = _b.locales, locales = _d === void 0 ? [] : _d, customMapping = _b.customMapping;
|
|
37
|
+
this.defaultLocale = defaultLocale;
|
|
38
|
+
this.locales = locales;
|
|
39
|
+
this.customMapping = customMapping;
|
|
40
|
+
}
|
|
41
|
+
Object.defineProperty(LocaleConfig.prototype, "translationLocales", {
|
|
42
|
+
get: function () {
|
|
43
|
+
return this.locales.length ? this.locales : undefined;
|
|
44
|
+
},
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
LocaleConfig.prototype.resolveCanonicalLocaleList = function (locales) {
|
|
49
|
+
var _this = this;
|
|
50
|
+
return locales.map(function (locale) { return _this.resolveCanonicalLocale(locale); });
|
|
51
|
+
};
|
|
52
|
+
LocaleConfig.prototype.resolveCanonicalLocaleArgs = function (locales) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
return locales.map(function (locale) {
|
|
55
|
+
return Array.isArray(locale)
|
|
56
|
+
? _this.resolveCanonicalLocaleList(locale)
|
|
57
|
+
: _this.resolveCanonicalLocale(locale);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
LocaleConfig.prototype.toLocaleList = function (locales) {
|
|
61
|
+
return Array.isArray(locales) ? locales : [locales];
|
|
62
|
+
};
|
|
63
|
+
LocaleConfig.prototype.getFormattingLocales = function (targetLocale, locales) {
|
|
64
|
+
var _this = this;
|
|
65
|
+
var localeList = locales !== undefined
|
|
66
|
+
? this.toLocaleList(locales)
|
|
67
|
+
: [targetLocale, this.defaultLocale, libraryDefaultLocale];
|
|
68
|
+
return localeList
|
|
69
|
+
.filter(function (locale) { return !!locale; })
|
|
70
|
+
.map(function (locale) { return _this.resolveCanonicalLocale(locale); });
|
|
71
|
+
};
|
|
72
|
+
LocaleConfig.prototype.formatNum = function (value, targetLocale, options) {
|
|
73
|
+
if (options === void 0) { options = {}; }
|
|
74
|
+
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
75
|
+
return _formatNum({
|
|
76
|
+
value: value,
|
|
77
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
78
|
+
options: intlOptions,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
LocaleConfig.prototype.formatDateTime = function (value, targetLocale, options) {
|
|
82
|
+
if (options === void 0) { options = {}; }
|
|
83
|
+
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
84
|
+
return _formatDateTime({
|
|
85
|
+
value: value,
|
|
86
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
87
|
+
options: intlOptions,
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
LocaleConfig.prototype.formatCurrency = function (value, currency, targetLocale, options) {
|
|
91
|
+
if (options === void 0) { options = {}; }
|
|
92
|
+
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
93
|
+
return _formatCurrency({
|
|
94
|
+
value: value,
|
|
95
|
+
currency: currency,
|
|
96
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
97
|
+
options: intlOptions,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
LocaleConfig.prototype.formatRelativeTime = function (value, unit, targetLocale, options) {
|
|
101
|
+
if (options === void 0) { options = {}; }
|
|
102
|
+
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
103
|
+
return _formatRelativeTime({
|
|
104
|
+
value: value,
|
|
105
|
+
unit: unit,
|
|
106
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
107
|
+
options: intlOptions,
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
LocaleConfig.prototype.formatRelativeTimeFromDate = function (date, targetLocale, options) {
|
|
111
|
+
if (options === void 0) { options = {}; }
|
|
112
|
+
var locales = options.locales, baseDate = options.baseDate, intlOptions = __rest(options, ["locales", "baseDate"]);
|
|
113
|
+
return _formatRelativeTimeFromDate({
|
|
114
|
+
date: date,
|
|
115
|
+
baseDate: baseDate !== null && baseDate !== void 0 ? baseDate : new Date(),
|
|
116
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
117
|
+
options: intlOptions,
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
LocaleConfig.prototype.formatCutoff = function (value, targetLocale, options) {
|
|
121
|
+
if (options === void 0) { options = {}; }
|
|
122
|
+
var locales = options.locales, formatOptions = __rest(options, ["locales"]);
|
|
123
|
+
return _formatCutoff({
|
|
124
|
+
value: value,
|
|
125
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
126
|
+
options: formatOptions,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
LocaleConfig.prototype.formatMessage = function (message, targetLocale, options) {
|
|
130
|
+
if (options === void 0) { options = {}; }
|
|
131
|
+
var locales = options.locales, variables = options.variables, dataFormat = options.dataFormat;
|
|
132
|
+
if (dataFormat === 'STRING')
|
|
133
|
+
return _formatMessageString(message);
|
|
134
|
+
return _formatMessageICU(message, this.getFormattingLocales(targetLocale, locales), variables);
|
|
135
|
+
};
|
|
136
|
+
LocaleConfig.prototype.formatList = function (array, targetLocale, options) {
|
|
137
|
+
if (options === void 0) { options = {}; }
|
|
138
|
+
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
139
|
+
return _formatList({
|
|
140
|
+
value: array,
|
|
141
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
142
|
+
options: intlOptions,
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
LocaleConfig.prototype.formatListToParts = function (array, targetLocale, options) {
|
|
146
|
+
if (options === void 0) { options = {}; }
|
|
147
|
+
var locales = options.locales, intlOptions = __rest(options, ["locales"]);
|
|
148
|
+
return _formatListToParts({
|
|
149
|
+
value: array,
|
|
150
|
+
locales: this.getFormattingLocales(targetLocale, locales),
|
|
151
|
+
options: intlOptions,
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
LocaleConfig.prototype.getLocaleName = function (locale) {
|
|
155
|
+
return _getLocaleName(locale, this.defaultLocale, this.customMapping);
|
|
156
|
+
};
|
|
157
|
+
LocaleConfig.prototype.getLocaleEmoji = function (locale) {
|
|
158
|
+
return _getLocaleEmoji(locale, this.customMapping);
|
|
159
|
+
};
|
|
160
|
+
LocaleConfig.prototype.getLocaleProperties = function (locale) {
|
|
161
|
+
return _getLocaleProperties(locale, this.defaultLocale, this.customMapping);
|
|
162
|
+
};
|
|
163
|
+
LocaleConfig.prototype.requiresTranslation = function (targetLocale, sourceLocale, approvedLocales) {
|
|
164
|
+
if (sourceLocale === void 0) { sourceLocale = this.defaultLocale; }
|
|
165
|
+
if (approvedLocales === void 0) { approvedLocales = this.translationLocales; }
|
|
166
|
+
return _requiresTranslation(this.resolveCanonicalLocale(sourceLocale), this.resolveCanonicalLocale(targetLocale), approvedLocales
|
|
167
|
+
? this.resolveCanonicalLocaleList(approvedLocales)
|
|
168
|
+
: undefined, this.customMapping);
|
|
169
|
+
};
|
|
170
|
+
LocaleConfig.prototype.determineLocale = function (locales, approvedLocales) {
|
|
171
|
+
var _this = this;
|
|
172
|
+
var _a;
|
|
173
|
+
if (approvedLocales === void 0) { approvedLocales = this.locales; }
|
|
174
|
+
var approvedLocalePairs = approvedLocales.map(function (locale) { return ({
|
|
175
|
+
locale: locale,
|
|
176
|
+
canonicalLocale: _this.resolveCanonicalLocale(locale),
|
|
177
|
+
}); });
|
|
178
|
+
var resolvedLocale = _determineLocale(Array.isArray(locales)
|
|
179
|
+
? this.resolveCanonicalLocaleList(locales)
|
|
180
|
+
: this.resolveCanonicalLocale(locales), approvedLocalePairs.map(function (_a) {
|
|
181
|
+
var canonicalLocale = _a.canonicalLocale;
|
|
182
|
+
return canonicalLocale;
|
|
183
|
+
}), this.customMapping);
|
|
184
|
+
if (!resolvedLocale)
|
|
185
|
+
return undefined;
|
|
186
|
+
return (((_a = approvedLocalePairs.find(function (_a) {
|
|
187
|
+
var canonicalLocale = _a.canonicalLocale;
|
|
188
|
+
return canonicalLocale === resolvedLocale;
|
|
189
|
+
})) === null || _a === void 0 ? void 0 : _a.locale) || this.resolveAliasLocale(resolvedLocale));
|
|
190
|
+
};
|
|
191
|
+
LocaleConfig.prototype.getLocaleDirection = function (locale) {
|
|
192
|
+
return _getLocaleDirection(this.resolveCanonicalLocale(locale));
|
|
193
|
+
};
|
|
194
|
+
LocaleConfig.prototype.isValidLocale = function (locale) {
|
|
195
|
+
return _isValidLocale(locale, this.customMapping);
|
|
196
|
+
};
|
|
197
|
+
LocaleConfig.prototype.resolveCanonicalLocale = function (locale) {
|
|
198
|
+
return _resolveCanonicalLocale(locale, this.customMapping);
|
|
199
|
+
};
|
|
200
|
+
LocaleConfig.prototype.resolveAliasLocale = function (locale) {
|
|
201
|
+
return _resolveAliasLocale(locale, this.customMapping);
|
|
202
|
+
};
|
|
203
|
+
LocaleConfig.prototype.standardizeLocale = function (locale) {
|
|
204
|
+
return _standardizeLocale(locale);
|
|
205
|
+
};
|
|
206
|
+
LocaleConfig.prototype.isSameDialect = function () {
|
|
207
|
+
var locales = [];
|
|
208
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
209
|
+
locales[_i] = arguments[_i];
|
|
210
|
+
}
|
|
211
|
+
return _isSameDialect.apply(void 0, this.resolveCanonicalLocaleArgs(locales));
|
|
212
|
+
};
|
|
213
|
+
LocaleConfig.prototype.isSameLanguage = function () {
|
|
214
|
+
var locales = [];
|
|
215
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
216
|
+
locales[_i] = arguments[_i];
|
|
217
|
+
}
|
|
218
|
+
return _isSameLanguage.apply(void 0, this.resolveCanonicalLocaleArgs(locales));
|
|
219
|
+
};
|
|
220
|
+
LocaleConfig.prototype.isSupersetLocale = function (superLocale, subLocale) {
|
|
221
|
+
return _isSupersetLocale(this.resolveCanonicalLocale(superLocale), this.resolveCanonicalLocale(subLocale));
|
|
222
|
+
};
|
|
223
|
+
return LocaleConfig;
|
|
224
|
+
}());
|
|
225
|
+
export { LocaleConfig };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Variable as VariableObject, VariableType } from '../types';
|
|
2
|
+
import { OldBranchType, OldGTProp, OldJsxChild, OldJsxChildren, OldJsxElement, OldVariableObject, OldVariableType } from './oldTypes.js';
|
|
3
|
+
import { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Convert request data from old format to new format
|
|
6
|
+
*/
|
|
7
|
+
export declare function getNewJsxChild(child: OldJsxChild): JsxChild;
|
|
8
|
+
export declare function getNewJsxChildren(children: OldJsxChildren): JsxChildren;
|
|
9
|
+
export declare function getNewJsxElement(element: OldJsxElement): JsxElement;
|
|
10
|
+
export declare function getNewBranchType(branch: OldBranchType): 'b' | 'p';
|
|
11
|
+
export declare function getNewVariableType(variable: OldVariableType): VariableType;
|
|
12
|
+
export declare function getNewVariableObject(variable: OldVariableObject): VariableObject;
|
|
13
|
+
export declare function getNewGTProp(dataGT: OldGTProp): GTProp;
|
|
14
|
+
/**
|
|
15
|
+
* Convert response data from current format to old format
|
|
16
|
+
*/
|
|
17
|
+
export declare function getOldJsxChild(child: JsxChild): OldJsxChild;
|
|
18
|
+
export declare function getOldJsxChildren(children: JsxChildren | OldJsxChildren): OldJsxChildren;
|
|
19
|
+
export declare function getOldJsxElement(element: JsxElement): OldJsxElement;
|
|
20
|
+
export declare function getOldBranchType(branch: 'b' | 'p'): OldBranchType;
|
|
21
|
+
export declare function getOldVariableType(variable: VariableType): OldVariableType;
|
|
22
|
+
export declare function getOldVariableObject(variable: VariableObject): OldVariableObject;
|
|
23
|
+
export declare function getOldGTProp(dataGT: GTProp, i: number): OldGTProp;
|