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/dist/core.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { _formatCutoff, _formatMessageICU, _formatMessageString, } from './formatting/format';
|
|
2
|
+
import { _isValidLocale, _standardizeLocale } from './locales/isValidLocale';
|
|
3
|
+
import { _resolveCanonicalLocale } from './locales/resolveCanonicalLocale';
|
|
4
|
+
export { LocaleConfig, } from './LocaleConfig';
|
|
5
|
+
/**
|
|
6
|
+
* Core formatting and locale helpers.
|
|
7
|
+
*
|
|
8
|
+
* This entry point exposes deterministic locale and formatting primitives. It
|
|
9
|
+
* does not export the GT service client, project credentials, network
|
|
10
|
+
* translation methods, file APIs, or other server/service concerns from the
|
|
11
|
+
* root `generaltranslation` facade.
|
|
12
|
+
*
|
|
13
|
+
* This entry point is intended for framework and shared packages that need
|
|
14
|
+
* locale metadata or formatting behavior without pulling in the full
|
|
15
|
+
* translation API surface.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Formats a string with cutoff behavior, applying a terminator when the string exceeds the maximum character limit.
|
|
19
|
+
*
|
|
20
|
+
* This standalone function provides cutoff formatting functionality without requiring a GT instance.
|
|
21
|
+
* The locales parameter is required for proper terminator selection based on the target language.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} value - The string value to format with cutoff behavior.
|
|
24
|
+
* @param {Object} [options] - Configuration options for cutoff formatting.
|
|
25
|
+
* @param {string | string[]} [options.locales] - The locales to use for terminator selection.
|
|
26
|
+
* @param {number} [options.maxChars] - The maximum number of characters to display.
|
|
27
|
+
* - Undefined values are treated as no cutoff.
|
|
28
|
+
* - Negative values follow .slice() behavior and terminator will be added before the value.
|
|
29
|
+
* - 0 will result in an empty string.
|
|
30
|
+
* - If cutoff results in an empty string, no terminator is added.
|
|
31
|
+
* @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
|
|
32
|
+
* @param {string} [options.terminator] - Optional override the terminator to use.
|
|
33
|
+
* @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
|
|
34
|
+
* - If no terminator is provided, then separator is ignored.
|
|
35
|
+
* @returns {string} The formatted string with terminator applied if cutoff occurs.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* formatCutoff('Hello, world!', { locales: 'en-US', maxChars: 8 });
|
|
39
|
+
* // Returns: 'Hello, …'
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* formatCutoff('Hello, world!', { locales: 'en-US', maxChars: -3 });
|
|
43
|
+
* // Returns: '…d!'
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* formatCutoff('Very long text that needs cutting', {
|
|
47
|
+
* locales: 'en-US',
|
|
48
|
+
* maxChars: 15,
|
|
49
|
+
* style: 'ellipsis',
|
|
50
|
+
* separator: ' '
|
|
51
|
+
* });
|
|
52
|
+
* // Returns: 'Very long tex …'
|
|
53
|
+
*/
|
|
54
|
+
export function formatCutoff(value, options) {
|
|
55
|
+
return _formatCutoff({ value: value, locales: options === null || options === void 0 ? void 0 : options.locales, options: options });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Formats a message according to the specified locales and options.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} message - The message to format.
|
|
61
|
+
* @param {Object} [options] - Configuration options for message formatting.
|
|
62
|
+
* @param {string | string[]} [options.locales] - The locales to use for formatting.
|
|
63
|
+
* @param {FormatVariables} [options.variables] - The variables to use for formatting.
|
|
64
|
+
* @param {StringFormat} [options.dataFormat='ICU'] - The format of the message. When STRING, the message is returned as is.
|
|
65
|
+
* @returns {string} The formatted message.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* formatMessage('Hello {name}', { variables: { name: 'John' } });
|
|
69
|
+
* // Returns: "Hello John"
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* formatMessage('Hello {name}', {
|
|
73
|
+
* locales: ['fr'],
|
|
74
|
+
* variables: { name: 'John' }
|
|
75
|
+
* });
|
|
76
|
+
*/
|
|
77
|
+
export function formatMessage(message, options) {
|
|
78
|
+
switch (options === null || options === void 0 ? void 0 : options.dataFormat) {
|
|
79
|
+
case 'STRING':
|
|
80
|
+
return _formatMessageString(message);
|
|
81
|
+
default:
|
|
82
|
+
return _formatMessageICU(message, options === null || options === void 0 ? void 0 : options.locales, options === null || options === void 0 ? void 0 : options.variables);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks if a given BCP 47 locale code is valid.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} locale - The BCP 47 locale code to validate.
|
|
89
|
+
* @param {CustomMapping} [customMapping] - The custom mapping to use for validation.
|
|
90
|
+
* @returns {boolean} True if the BCP 47 code is valid, false otherwise.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* isValidLocale('en-US');
|
|
94
|
+
* // Returns: true
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* isValidLocale('en_US');
|
|
98
|
+
* // Returns: false
|
|
99
|
+
*/
|
|
100
|
+
export function isValidLocale(locale, customMapping) {
|
|
101
|
+
return _isValidLocale(locale, customMapping);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Resolves the canonical locale for a given locale.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} locale - The locale to resolve the canonical locale for.
|
|
107
|
+
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the canonical locale.
|
|
108
|
+
* @returns {string} The canonical locale, or the input locale when no canonical mapping exists.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* resolveCanonicalLocale('en-US');
|
|
112
|
+
* // Returns: 'en-US'
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* resolveCanonicalLocale('en', { en: 'en-US' });
|
|
116
|
+
* // Returns: 'en-US'
|
|
117
|
+
*/
|
|
118
|
+
export function resolveCanonicalLocale(locale, customMapping) {
|
|
119
|
+
return _resolveCanonicalLocale(locale, customMapping);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Standardizes a BCP 47 locale code to ensure correct formatting.
|
|
123
|
+
*
|
|
124
|
+
* @param {string} locale - The BCP 47 locale code to standardize.
|
|
125
|
+
* @returns {string} The standardized BCP 47 locale code, or the input string if it cannot be standardized.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* standardizeLocale('en-us');
|
|
129
|
+
* // Returns: 'en-US'
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* standardizeLocale('not a locale');
|
|
133
|
+
* // Returns: 'not a locale'
|
|
134
|
+
*/
|
|
135
|
+
export function standardizeLocale(locale) {
|
|
136
|
+
return _standardizeLocale(locale);
|
|
137
|
+
}
|
package/dist/core.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as standardizeLocale, i as resolveCanonicalLocale, n as formatMessage, o as LocaleConfig, r as isValidLocale, t as formatCutoff } from "./core-
|
|
1
|
+
import { a as standardizeLocale, i as resolveCanonicalLocale, n as formatMessage, o as LocaleConfig, r as isValidLocale, t as formatCutoff } from "./core-isLphYAZ.mjs";
|
|
2
2
|
export { LocaleConfig, formatCutoff, formatMessage, isValidLocale, resolveCanonicalLocale, standardizeLocale };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an indexed ICU string, condenses any select to an argument
|
|
3
|
+
* indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
|
|
4
|
+
* @param {string} icuString - The ICU string to condense.
|
|
5
|
+
* @returns {string} The condensed ICU string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function condenseVars(icuString: string): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TYPE, } from '@formatjs/icu-messageformat-parser/types.js';
|
|
2
|
+
import { printAST } from '@formatjs/icu-messageformat-parser/printer.js';
|
|
3
|
+
import { traverseIcu } from './utils/traverseIcu';
|
|
4
|
+
import { VAR_IDENTIFIER } from './utils/constants';
|
|
5
|
+
import { isGTIndexedSelectElement } from './utils/traverseHelpers';
|
|
6
|
+
/**
|
|
7
|
+
* Given an indexed ICU string, condenses any select to an argument
|
|
8
|
+
* indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
|
|
9
|
+
* @param {string} icuString - The ICU string to condense.
|
|
10
|
+
* @returns {string} The condensed ICU string.
|
|
11
|
+
*/
|
|
12
|
+
export function condenseVars(icuString) {
|
|
13
|
+
// Check if the string contains _gt_
|
|
14
|
+
if (!icuString.includes(VAR_IDENTIFIER)) {
|
|
15
|
+
return icuString;
|
|
16
|
+
}
|
|
17
|
+
// Replace with argument
|
|
18
|
+
function visitor(child) {
|
|
19
|
+
child.type = TYPE.argument;
|
|
20
|
+
Reflect.deleteProperty(child, 'options');
|
|
21
|
+
}
|
|
22
|
+
var ast = traverseIcu({
|
|
23
|
+
icuString: icuString,
|
|
24
|
+
shouldVisit: isGTIndexedSelectElement,
|
|
25
|
+
visitor: visitor,
|
|
26
|
+
options: { recurseIntoVisited: false },
|
|
27
|
+
});
|
|
28
|
+
// Serialize
|
|
29
|
+
return printAST(ast);
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* function nonDerivableFunction() {
|
|
6
|
+
* return Math.random();
|
|
7
|
+
* }
|
|
8
|
+
*
|
|
9
|
+
* function derivableFunction() {
|
|
10
|
+
* if (condition) {
|
|
11
|
+
* return declareVar(nonDerivableFunction())
|
|
12
|
+
* }
|
|
13
|
+
* return 'John Doe';
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* const gt = useGT();
|
|
17
|
+
* gt(`My name is ${derive(derivableFunction())}`);
|
|
18
|
+
*
|
|
19
|
+
* @param {string | number | boolean | null | undefined} variable - The variable to sanitize.
|
|
20
|
+
* @param {Object} [options] - The options for the sanitization.
|
|
21
|
+
* @param {string} [options.$name] - The name of the variable.
|
|
22
|
+
* @returns {string} The sanitized value.
|
|
23
|
+
*/
|
|
24
|
+
export declare function declareVar(variable: string | number | boolean | null | undefined, options?: {
|
|
25
|
+
$name?: string;
|
|
26
|
+
}): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';
|
|
2
|
+
import { sanitizeVar } from './utils/sanitizeVar';
|
|
3
|
+
/**
|
|
4
|
+
* Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* function nonDerivableFunction() {
|
|
8
|
+
* return Math.random();
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* function derivableFunction() {
|
|
12
|
+
* if (condition) {
|
|
13
|
+
* return declareVar(nonDerivableFunction())
|
|
14
|
+
* }
|
|
15
|
+
* return 'John Doe';
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const gt = useGT();
|
|
19
|
+
* gt(`My name is ${derive(derivableFunction())}`);
|
|
20
|
+
*
|
|
21
|
+
* @param {string | number | boolean | null | undefined} variable - The variable to sanitize.
|
|
22
|
+
* @param {Object} [options] - The options for the sanitization.
|
|
23
|
+
* @param {string} [options.$name] - The name of the variable.
|
|
24
|
+
* @returns {string} The sanitized value.
|
|
25
|
+
*/
|
|
26
|
+
export function declareVar(variable, options) {
|
|
27
|
+
// Variable section.
|
|
28
|
+
var sanitizedVariable = sanitizeVar(String(variable !== null && variable !== void 0 ? variable : ''));
|
|
29
|
+
var variableSection = " other {".concat(sanitizedVariable, "}");
|
|
30
|
+
// Name section.
|
|
31
|
+
var nameSection = '';
|
|
32
|
+
if (options === null || options === void 0 ? void 0 : options.$name) {
|
|
33
|
+
var sanitizedName = sanitizeVar(options.$name);
|
|
34
|
+
nameSection = " ".concat(VAR_NAME_IDENTIFIER, " {").concat(sanitizedName, "}");
|
|
35
|
+
}
|
|
36
|
+
// interpolate
|
|
37
|
+
return "{".concat(VAR_IDENTIFIER, ", select,").concat(variableSection).concat(nameSection, "}");
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()
|
|
3
|
+
* @example
|
|
4
|
+
* const encodedIcu = "Hi" + declareVar("Brian") + ", my name is {name}"
|
|
5
|
+
* // 'Hi {_gt_, select, other {Brian}}, my name is {name}'
|
|
6
|
+
* decodeVars(encodedIcu)
|
|
7
|
+
* // 'Hi Brian, my name is {name}'
|
|
8
|
+
*/
|
|
9
|
+
export declare function decodeVars(icuString: string): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { traverseIcu } from './utils/traverseIcu';
|
|
2
|
+
import { VAR_IDENTIFIER } from './utils/constants';
|
|
3
|
+
import { isGTUnindexedSelectElement } from './utils/traverseHelpers';
|
|
4
|
+
/**
|
|
5
|
+
* Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()
|
|
6
|
+
* @example
|
|
7
|
+
* const encodedIcu = "Hi" + declareVar("Brian") + ", my name is {name}"
|
|
8
|
+
* // 'Hi {_gt_, select, other {Brian}}, my name is {name}'
|
|
9
|
+
* decodeVars(encodedIcu)
|
|
10
|
+
* // 'Hi Brian, my name is {name}'
|
|
11
|
+
*/
|
|
12
|
+
export function decodeVars(icuString) {
|
|
13
|
+
// Check if the string contains _gt_
|
|
14
|
+
if (!icuString.includes(VAR_IDENTIFIER)) {
|
|
15
|
+
return icuString;
|
|
16
|
+
}
|
|
17
|
+
// Record the location of the variable
|
|
18
|
+
var variableLocations = [];
|
|
19
|
+
function visitor(child) {
|
|
20
|
+
var _a, _b, _c, _d;
|
|
21
|
+
variableLocations.push({
|
|
22
|
+
start: (_b = (_a = child.location) === null || _a === void 0 ? void 0 : _a.start.offset) !== null && _b !== void 0 ? _b : 0,
|
|
23
|
+
end: (_d = (_c = child.location) === null || _c === void 0 ? void 0 : _c.end.offset) !== null && _d !== void 0 ? _d : 0,
|
|
24
|
+
value: child.options.other.value.length > 0
|
|
25
|
+
? child.options.other.value[0].value
|
|
26
|
+
: '',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Find all variable identifiers.
|
|
30
|
+
traverseIcu({
|
|
31
|
+
icuString: icuString,
|
|
32
|
+
shouldVisit: isGTUnindexedSelectElement,
|
|
33
|
+
visitor: visitor,
|
|
34
|
+
options: {
|
|
35
|
+
recurseIntoVisited: false,
|
|
36
|
+
captureLocation: true,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
// Construct output string
|
|
40
|
+
var previousIndex = 0;
|
|
41
|
+
var outputList = [];
|
|
42
|
+
for (var i = 0; i < variableLocations.length; i++) {
|
|
43
|
+
outputList.push(icuString.slice(previousIndex, variableLocations[i].start));
|
|
44
|
+
outputList.push(variableLocations[i].value);
|
|
45
|
+
previousIndex = variableLocations[i].end;
|
|
46
|
+
}
|
|
47
|
+
if (previousIndex < icuString.length) {
|
|
48
|
+
outputList.push(icuString.slice(previousIndex));
|
|
49
|
+
}
|
|
50
|
+
var outputString = outputList.join('');
|
|
51
|
+
return outputString;
|
|
52
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks content as derivable by the GT compiler and CLI.
|
|
3
|
+
*
|
|
4
|
+
* Use `derive()` when a translation string or context needs content that is
|
|
5
|
+
* computed from source code, but should still be discovered during extraction
|
|
6
|
+
* instead of treated as a runtime interpolation variable. The CLI attempts to
|
|
7
|
+
* resolve the derivable expression into every possible static value and
|
|
8
|
+
* includes those values in the source content that gets translated.
|
|
9
|
+
*
|
|
10
|
+
* `derive()` returns its argument unchanged at runtime.
|
|
11
|
+
*
|
|
12
|
+
* Run `gt validate` after adding or changing `derive()` calls to verify that
|
|
13
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
14
|
+
* building.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```jsx
|
|
18
|
+
* function getSubject() {
|
|
19
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
20
|
+
* }
|
|
21
|
+
* ...
|
|
22
|
+
* gt(`My name is ${derive(getSubject())}`);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
|
|
26
|
+
* @returns {T} The same content, unchanged at runtime.
|
|
27
|
+
*/
|
|
28
|
+
export declare function derive<T extends string | boolean | number | null | undefined>(content: T): T;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use derive() instead.
|
|
31
|
+
*
|
|
32
|
+
* Marks content as derivable by the GT compiler and CLI.
|
|
33
|
+
*
|
|
34
|
+
* Use `derive()` instead of `declareStatic()` for new code. This alias is kept
|
|
35
|
+
* for backwards compatibility and returns its argument unchanged at runtime.
|
|
36
|
+
*
|
|
37
|
+
* Run `gt validate` after adding or changing derived content to verify that
|
|
38
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
39
|
+
* building.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```jsx
|
|
43
|
+
* function getSubject() {
|
|
44
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
45
|
+
* }
|
|
46
|
+
* ...
|
|
47
|
+
* gt(`My name is ${declareStatic(getSubject())}`);
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
|
|
51
|
+
* @returns {T} The same content, unchanged at runtime.
|
|
52
|
+
*/
|
|
53
|
+
export declare const declareStatic: typeof derive;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks content as derivable by the GT compiler and CLI.
|
|
3
|
+
*
|
|
4
|
+
* Use `derive()` when a translation string or context needs content that is
|
|
5
|
+
* computed from source code, but should still be discovered during extraction
|
|
6
|
+
* instead of treated as a runtime interpolation variable. The CLI attempts to
|
|
7
|
+
* resolve the derivable expression into every possible static value and
|
|
8
|
+
* includes those values in the source content that gets translated.
|
|
9
|
+
*
|
|
10
|
+
* `derive()` returns its argument unchanged at runtime.
|
|
11
|
+
*
|
|
12
|
+
* Run `gt validate` after adding or changing `derive()` calls to verify that
|
|
13
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
14
|
+
* building.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```jsx
|
|
18
|
+
* function getSubject() {
|
|
19
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
20
|
+
* }
|
|
21
|
+
* ...
|
|
22
|
+
* gt(`My name is ${derive(getSubject())}`);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
|
|
26
|
+
* @returns {T} The same content, unchanged at runtime.
|
|
27
|
+
*/
|
|
28
|
+
export function derive(content) {
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use derive() instead.
|
|
33
|
+
*
|
|
34
|
+
* Marks content as derivable by the GT compiler and CLI.
|
|
35
|
+
*
|
|
36
|
+
* Use `derive()` instead of `declareStatic()` for new code. This alias is kept
|
|
37
|
+
* for backwards compatibility and returns its argument unchanged at runtime.
|
|
38
|
+
*
|
|
39
|
+
* Run `gt validate` after adding or changing derived content to verify that
|
|
40
|
+
* each derivable expression can be resolved by the CLI before translating or
|
|
41
|
+
* building.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```jsx
|
|
45
|
+
* function getSubject() {
|
|
46
|
+
* return (Math.random() > 0.5) ? "Alice" : "Brian";
|
|
47
|
+
* }
|
|
48
|
+
* ...
|
|
49
|
+
* gt(`My name is ${declareStatic(getSubject())}`);
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.
|
|
53
|
+
* @returns {T} The same content, unchanged at runtime.
|
|
54
|
+
*/
|
|
55
|
+
export var declareStatic = derive;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values
|
|
3
|
+
*
|
|
4
|
+
* extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }
|
|
5
|
+
*
|
|
6
|
+
* @param {string} icuString - The ICU string to extract variables from.
|
|
7
|
+
* @returns {Record<string, string>} A mapping of the variable to the value.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractVars(icuString: string): Record<string, string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { VAR_IDENTIFIER } from './utils/constants';
|
|
2
|
+
import { isGTUnindexedSelectElement } from './utils/traverseHelpers';
|
|
3
|
+
import { traverseIcu } from './utils/traverseIcu';
|
|
4
|
+
/**
|
|
5
|
+
* Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values
|
|
6
|
+
*
|
|
7
|
+
* extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }
|
|
8
|
+
*
|
|
9
|
+
* @param {string} icuString - The ICU string to extract variables from.
|
|
10
|
+
* @returns {Record<string, string>} A mapping of the variable to the value.
|
|
11
|
+
*/
|
|
12
|
+
export function extractVars(icuString) {
|
|
13
|
+
// Check if the string contains _gt_
|
|
14
|
+
if (!icuString.includes(VAR_IDENTIFIER)) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
// Extract all the _gt_# variables
|
|
18
|
+
var index = 1;
|
|
19
|
+
var variables = {};
|
|
20
|
+
function visitor(child) {
|
|
21
|
+
var _a;
|
|
22
|
+
variables[child.value + index] = child.options.other.value.length
|
|
23
|
+
? (_a = child.options.other.value[0]) === null || _a === void 0 ? void 0 : _a.value
|
|
24
|
+
: '';
|
|
25
|
+
index += 1;
|
|
26
|
+
}
|
|
27
|
+
traverseIcu({
|
|
28
|
+
icuString: icuString,
|
|
29
|
+
shouldVisit: isGTUnindexedSelectElement,
|
|
30
|
+
visitor: visitor,
|
|
31
|
+
options: { recurseIntoVisited: false },
|
|
32
|
+
});
|
|
33
|
+
return variables;
|
|
34
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IcuMessage } from '../types-dir/jsx/content';
|
|
2
|
+
/**
|
|
3
|
+
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
4
|
+
* indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'
|
|
5
|
+
*/
|
|
6
|
+
export declare function indexVars(icuString: IcuMessage): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { VAR_IDENTIFIER } from './utils/constants';
|
|
2
|
+
import { traverseIcu } from './utils/traverseIcu';
|
|
3
|
+
import { isGTUnindexedSelectElement } from './utils/traverseHelpers';
|
|
4
|
+
/**
|
|
5
|
+
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
6
|
+
* indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'
|
|
7
|
+
*/
|
|
8
|
+
export function indexVars(icuString) {
|
|
9
|
+
// Check if the string contains _gt_
|
|
10
|
+
if (!icuString.includes(VAR_IDENTIFIER)) {
|
|
11
|
+
return icuString;
|
|
12
|
+
}
|
|
13
|
+
// Record the location of the variable
|
|
14
|
+
var variableLocations = [];
|
|
15
|
+
function visitor(child) {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17
|
+
variableLocations.push({
|
|
18
|
+
start: (_b = (_a = child.location) === null || _a === void 0 ? void 0 : _a.start.offset) !== null && _b !== void 0 ? _b : 0,
|
|
19
|
+
end: (_d = (_c = child.location) === null || _c === void 0 ? void 0 : _c.end.offset) !== null && _d !== void 0 ? _d : 0,
|
|
20
|
+
otherStart: (_f = (_e = child.options.other.location) === null || _e === void 0 ? void 0 : _e.start.offset) !== null && _f !== void 0 ? _f : 0,
|
|
21
|
+
otherEnd: (_h = (_g = child.options.other.location) === null || _g === void 0 ? void 0 : _g.end.offset) !== null && _h !== void 0 ? _h : 0,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// Find all variable identifiers.
|
|
25
|
+
traverseIcu({
|
|
26
|
+
icuString: icuString,
|
|
27
|
+
shouldVisit: isGTUnindexedSelectElement,
|
|
28
|
+
visitor: visitor,
|
|
29
|
+
options: { recurseIntoVisited: false, captureLocation: true },
|
|
30
|
+
});
|
|
31
|
+
// Index each variable and collapse the other option.
|
|
32
|
+
var result = [];
|
|
33
|
+
var current = 0;
|
|
34
|
+
for (var i = 0; i < variableLocations.length; i++) {
|
|
35
|
+
var _a = variableLocations[i], start = _a.start, end = _a.end, otherStart = _a.otherStart, otherEnd = _a.otherEnd;
|
|
36
|
+
// Before the variable
|
|
37
|
+
result.push(icuString.slice(current, start));
|
|
38
|
+
// Replace the variable with the new identifier (+1 is for the curly brace)
|
|
39
|
+
result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));
|
|
40
|
+
// Add the new identifier.
|
|
41
|
+
result.push(String(i + 1));
|
|
42
|
+
// After the variable
|
|
43
|
+
result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));
|
|
44
|
+
// Before the other option
|
|
45
|
+
result.push('{}');
|
|
46
|
+
// The other option
|
|
47
|
+
result.push(icuString.slice(otherEnd, end));
|
|
48
|
+
current = end;
|
|
49
|
+
}
|
|
50
|
+
result.push(icuString.slice(current, icuString.length));
|
|
51
|
+
return result.join('');
|
|
52
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes string by escaping ICU syntax
|
|
3
|
+
*
|
|
4
|
+
* Sanitize arbitrary string so it does not break the following ICU message syntax:
|
|
5
|
+
* {_gt_, select, other {string_here}}
|
|
6
|
+
*
|
|
7
|
+
* Escapes ICU special characters by:
|
|
8
|
+
* 1. Doubling all single quotes (U+0027 ')
|
|
9
|
+
* 2. Adding a single quote before the first special character ({}<>)
|
|
10
|
+
* 3. Adding a single quote after the last special character ({}<>)
|
|
11
|
+
*/
|
|
12
|
+
export declare function sanitizeVar(string: string): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes string by escaping ICU syntax
|
|
3
|
+
*
|
|
4
|
+
* Sanitize arbitrary string so it does not break the following ICU message syntax:
|
|
5
|
+
* {_gt_, select, other {string_here}}
|
|
6
|
+
*
|
|
7
|
+
* Escapes ICU special characters by:
|
|
8
|
+
* 1. Doubling all single quotes (U+0027 ')
|
|
9
|
+
* 2. Adding a single quote before the first special character ({}<>)
|
|
10
|
+
* 3. Adding a single quote after the last special character ({}<>)
|
|
11
|
+
*/
|
|
12
|
+
export function sanitizeVar(string) {
|
|
13
|
+
// First, double all single quotes (both ASCII and Unicode).
|
|
14
|
+
var result = string.replace(/'/g, "''");
|
|
15
|
+
// Find first and last positions of special characters
|
|
16
|
+
var specialChars = /[{}<>]/;
|
|
17
|
+
var firstSpecialIndex = result.search(specialChars);
|
|
18
|
+
if (firstSpecialIndex === -1) {
|
|
19
|
+
// No special characters; return with just doubled quotes.
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
// Find last special character position
|
|
23
|
+
var lastSpecialIndex = -1;
|
|
24
|
+
for (var i = result.length - 1; i >= 0; i--) {
|
|
25
|
+
if (specialChars.test(result[i])) {
|
|
26
|
+
lastSpecialIndex = i;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Insert quotes around the special character region.
|
|
31
|
+
result =
|
|
32
|
+
result.slice(0, firstSpecialIndex) +
|
|
33
|
+
"'" +
|
|
34
|
+
result.slice(firstSpecialIndex, lastSpecialIndex + 1) +
|
|
35
|
+
"'" +
|
|
36
|
+
result.slice(lastSpecialIndex + 1);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';
|
|
2
|
+
import { type MessageFormatElement } from '@formatjs/icu-messageformat-parser/types.js';
|
|
3
|
+
export declare function isGTIndexedSelectElement(child: MessageFormatElement): child is GTIndexedSelectElement;
|
|
4
|
+
export declare function isGTUnindexedSelectElement(child: MessageFormatElement): child is GTUnindexedSelectElement;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GT_INDEXED_IDENTIFIER_REGEX, GT_UNINDEXED_IDENTIFIER_REGEX, } from './regex';
|
|
2
|
+
import { TYPE, } from '@formatjs/icu-messageformat-parser/types.js';
|
|
3
|
+
// Visit any _gt_# select
|
|
4
|
+
export function isGTIndexedSelectElement(child) {
|
|
5
|
+
var _a;
|
|
6
|
+
return (child.type === TYPE.select &&
|
|
7
|
+
GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&
|
|
8
|
+
!!child.options.other &&
|
|
9
|
+
(child.options.other.value.length === 0 ||
|
|
10
|
+
(child.options.other.value.length > 0 &&
|
|
11
|
+
((_a = child.options.other.value[0]) === null || _a === void 0 ? void 0 : _a.type) === TYPE.literal)));
|
|
12
|
+
}
|
|
13
|
+
// Visit any _gt_ select
|
|
14
|
+
export function isGTUnindexedSelectElement(child) {
|
|
15
|
+
var _a;
|
|
16
|
+
return (child.type === TYPE.select &&
|
|
17
|
+
GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&
|
|
18
|
+
!!child.options.other &&
|
|
19
|
+
(child.options.other.value.length === 0 ||
|
|
20
|
+
(child.options.other.value.length > 0 &&
|
|
21
|
+
((_a = child.options.other.value[0]) === null || _a === void 0 ? void 0 : _a.type) === TYPE.literal)));
|
|
22
|
+
}
|