generaltranslation 8.2.12 → 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 +8 -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/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-CST4J4WU.cjs → core-7RP541eY.cjs} +2 -2
- package/dist/core-7RP541eY.cjs.map +1 -0
- package/dist/{core-D-E8qhLn.d.cts → core-I9pWGafA.d.mts} +2 -2
- package/dist/{core-CGhlXrrK.d.mts → core-TLJoDpJP.d.cts} +2 -2
- package/dist/{core-7RJsqw6c.mjs → core-isLphYAZ.mjs} +2 -2
- 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.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/id.d.ts +3 -0
- package/dist/id.js +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +1019 -0
- package/dist/index.js +1664 -0
- package/dist/index.mjs +1 -1
- package/dist/internal.cjs +1 -1
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.mts +2 -2
- package/dist/internal.d.ts +19 -0
- package/dist/internal.js +17 -0
- package/dist/internal.mjs +1 -1
- 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-BsGsgJWF.d.mts → types-AHtYZIP-.d.mts} +34 -11
- package/dist/{types-V5rqd1WR.d.cts → types-Bf8_Apq_.d.cts} +34 -11
- 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.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/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 +3 -3
- package/dist/core-7RJsqw6c.mjs.map +0 -1
- package/dist/core-CST4J4WU.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## 8.2.12
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -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;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { isOldJsxChildren, isNewVariableObject, isOldVariableObject, } from './typeChecking';
|
|
13
|
+
/**
|
|
14
|
+
* Convert request data from old format to new format
|
|
15
|
+
*/
|
|
16
|
+
export function getNewJsxChild(child) {
|
|
17
|
+
// string (end case)
|
|
18
|
+
if (typeof child === 'string') {
|
|
19
|
+
return child;
|
|
20
|
+
}
|
|
21
|
+
// VariableObject
|
|
22
|
+
if (isOldVariableObject(child)) {
|
|
23
|
+
return getNewVariableObject(child);
|
|
24
|
+
}
|
|
25
|
+
// JsxElement
|
|
26
|
+
return getNewJsxElement(child);
|
|
27
|
+
}
|
|
28
|
+
export function getNewJsxChildren(children) {
|
|
29
|
+
// string (end case)
|
|
30
|
+
if (typeof children === 'string') {
|
|
31
|
+
return children;
|
|
32
|
+
}
|
|
33
|
+
// Array
|
|
34
|
+
if (Array.isArray(children)) {
|
|
35
|
+
return children.map(getNewJsxChild);
|
|
36
|
+
}
|
|
37
|
+
// Object
|
|
38
|
+
return getNewJsxChild(children);
|
|
39
|
+
}
|
|
40
|
+
export function getNewJsxElement(element) {
|
|
41
|
+
var _a;
|
|
42
|
+
// string (end case)
|
|
43
|
+
if (typeof element === 'string') {
|
|
44
|
+
return element;
|
|
45
|
+
}
|
|
46
|
+
// type
|
|
47
|
+
var t = undefined;
|
|
48
|
+
if (element.type != null) {
|
|
49
|
+
t = element.type;
|
|
50
|
+
}
|
|
51
|
+
// children
|
|
52
|
+
var c = undefined;
|
|
53
|
+
if (((_a = element.props) === null || _a === void 0 ? void 0 : _a.children) != null) {
|
|
54
|
+
c = getNewJsxChildren(element.props.children);
|
|
55
|
+
}
|
|
56
|
+
return __assign(__assign(__assign({}, (t && { t: t })), (c && { c: c })), { d: getNewGTProp(element.props['data-_gt']), i: element.props['data-_gt'].id });
|
|
57
|
+
}
|
|
58
|
+
export function getNewBranchType(branch) {
|
|
59
|
+
if (branch === 'branch') {
|
|
60
|
+
return 'b';
|
|
61
|
+
}
|
|
62
|
+
return 'p';
|
|
63
|
+
}
|
|
64
|
+
export function getNewVariableType(variable) {
|
|
65
|
+
switch (variable) {
|
|
66
|
+
case 'number':
|
|
67
|
+
return 'n';
|
|
68
|
+
case 'variable':
|
|
69
|
+
return 'v';
|
|
70
|
+
case 'datetime':
|
|
71
|
+
return 'd';
|
|
72
|
+
case 'currency':
|
|
73
|
+
return 'c';
|
|
74
|
+
default:
|
|
75
|
+
return 'v';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function getNewVariableObject(variable) {
|
|
79
|
+
// variable type
|
|
80
|
+
var v = undefined;
|
|
81
|
+
if (variable.variable != null) {
|
|
82
|
+
v = getNewVariableType(variable.variable);
|
|
83
|
+
}
|
|
84
|
+
// variable id
|
|
85
|
+
var i = undefined;
|
|
86
|
+
if (variable.id != null) {
|
|
87
|
+
i = variable.id;
|
|
88
|
+
}
|
|
89
|
+
return __assign(__assign({ k: variable.key }, (v && { v: v })), (i && { i: i }));
|
|
90
|
+
}
|
|
91
|
+
export function getNewGTProp(dataGT) {
|
|
92
|
+
// branches
|
|
93
|
+
var b = undefined;
|
|
94
|
+
if (dataGT.branches) {
|
|
95
|
+
b = Object.fromEntries(Object.entries(dataGT.branches).map(function (_a) {
|
|
96
|
+
var key = _a[0], value = _a[1];
|
|
97
|
+
return [
|
|
98
|
+
key,
|
|
99
|
+
getNewJsxChildren(value),
|
|
100
|
+
];
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
// transformation
|
|
104
|
+
var t;
|
|
105
|
+
if (dataGT.transformation) {
|
|
106
|
+
t = getNewBranchType(dataGT.transformation);
|
|
107
|
+
}
|
|
108
|
+
return __assign(__assign({}, (b && { b: b })), (t && { t: t }));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Convert response data from current format to old format
|
|
112
|
+
*/
|
|
113
|
+
export function getOldJsxChild(child) {
|
|
114
|
+
// string (end case)
|
|
115
|
+
if (typeof child === 'string') {
|
|
116
|
+
return child;
|
|
117
|
+
}
|
|
118
|
+
// VariableObject
|
|
119
|
+
if (isNewVariableObject(child)) {
|
|
120
|
+
return getOldVariableObject(child);
|
|
121
|
+
}
|
|
122
|
+
// JsxElement
|
|
123
|
+
return getOldJsxElement(child);
|
|
124
|
+
}
|
|
125
|
+
export function getOldJsxChildren(children) {
|
|
126
|
+
// if children is already old, return it
|
|
127
|
+
if (isOldJsxChildren(children)) {
|
|
128
|
+
return children;
|
|
129
|
+
}
|
|
130
|
+
// string (end case)
|
|
131
|
+
if (typeof children === 'string') {
|
|
132
|
+
return children;
|
|
133
|
+
}
|
|
134
|
+
// Array
|
|
135
|
+
if (Array.isArray(children)) {
|
|
136
|
+
return children.map(getOldJsxChild);
|
|
137
|
+
}
|
|
138
|
+
// Object
|
|
139
|
+
return getOldJsxChild(children);
|
|
140
|
+
}
|
|
141
|
+
export function getOldJsxElement(element) {
|
|
142
|
+
// type (can assume that type will exist here)
|
|
143
|
+
var type = element.t;
|
|
144
|
+
// children
|
|
145
|
+
var children = undefined;
|
|
146
|
+
if (element.c != null) {
|
|
147
|
+
children = getOldJsxChildren(element.c);
|
|
148
|
+
}
|
|
149
|
+
// data-_gt (can assume id will exist here)
|
|
150
|
+
var dataGT = getOldGTProp(element.d || {}, element.i);
|
|
151
|
+
return {
|
|
152
|
+
type: type,
|
|
153
|
+
props: { children: children, 'data-_gt': dataGT },
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export function getOldBranchType(branch) {
|
|
157
|
+
if (branch === 'b') {
|
|
158
|
+
return 'branch';
|
|
159
|
+
}
|
|
160
|
+
return 'plural';
|
|
161
|
+
}
|
|
162
|
+
export function getOldVariableType(variable) {
|
|
163
|
+
switch (variable) {
|
|
164
|
+
case 'n':
|
|
165
|
+
return 'number';
|
|
166
|
+
case 'v':
|
|
167
|
+
return 'variable';
|
|
168
|
+
case 'd':
|
|
169
|
+
return 'datetime';
|
|
170
|
+
case 'c':
|
|
171
|
+
return 'currency';
|
|
172
|
+
default:
|
|
173
|
+
return 'variable';
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export function getOldVariableObject(variable) {
|
|
177
|
+
// variable type
|
|
178
|
+
var v = undefined;
|
|
179
|
+
if (variable.v != null) {
|
|
180
|
+
v = getOldVariableType(variable.v);
|
|
181
|
+
}
|
|
182
|
+
// variable id
|
|
183
|
+
var i = undefined;
|
|
184
|
+
if (variable.i != null) {
|
|
185
|
+
i = variable.i;
|
|
186
|
+
}
|
|
187
|
+
return __assign(__assign({ key: variable.k }, (v && { variable: v })), (i && { id: i }));
|
|
188
|
+
}
|
|
189
|
+
export function getOldGTProp(dataGT, i) {
|
|
190
|
+
// transformation
|
|
191
|
+
var transformation = undefined;
|
|
192
|
+
if (dataGT.t != null) {
|
|
193
|
+
transformation = getOldBranchType(dataGT.t);
|
|
194
|
+
}
|
|
195
|
+
// branches
|
|
196
|
+
var branches = undefined;
|
|
197
|
+
if (dataGT.b != null) {
|
|
198
|
+
branches = Object.fromEntries(Object.entries(dataGT.b).map(function (_a) {
|
|
199
|
+
var key = _a[0], value = _a[1];
|
|
200
|
+
return [
|
|
201
|
+
key,
|
|
202
|
+
getOldJsxChildren(value),
|
|
203
|
+
];
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
return __assign(__assign({ id: i }, (transformation && { transformation: transformation })), (branches && { branches: branches }));
|
|
207
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OldJsxChildren } from './oldTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Calculates a unique hash for a given string using SHA-256.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} string - The string to be hashed.
|
|
6
|
+
* @returns {string} The resulting hash as a hexadecimal string.
|
|
7
|
+
*/
|
|
8
|
+
export declare function oldHashString(string: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
|
|
11
|
+
*
|
|
12
|
+
* @param {any} childrenAsObjects - The children objects to be hashed.
|
|
13
|
+
* @param {string} context - The context for the children.
|
|
14
|
+
* @param {string} id - The ID for the JSX children object.
|
|
15
|
+
* @param {function} hashFunction - Custom hash function.
|
|
16
|
+
* @returns {string} - The unique hash of the children.
|
|
17
|
+
*/
|
|
18
|
+
export declare function oldHashJsxChildren({ source, context, id, dataFormat, }: {
|
|
19
|
+
source: OldJsxChildren;
|
|
20
|
+
context?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
dataFormat: string;
|
|
23
|
+
}, hashFunction?: (string: string) => string): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Functions provided to other GT libraries
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
import { stableStringify as stringify } from '../utils/stableStringify';
|
|
14
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
15
|
+
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
|
|
16
|
+
// ----- FUNCTIONS ----- //
|
|
17
|
+
/**
|
|
18
|
+
* Calculates a unique hash for a given string using SHA-256.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} string - The string to be hashed.
|
|
21
|
+
* @returns {string} The resulting hash as a hexadecimal string.
|
|
22
|
+
*/
|
|
23
|
+
export function oldHashString(string) {
|
|
24
|
+
return bytesToHex(sha256(utf8ToBytes(string)));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.
|
|
28
|
+
*
|
|
29
|
+
* @param {any} childrenAsObjects - The children objects to be hashed.
|
|
30
|
+
* @param {string} context - The context for the children.
|
|
31
|
+
* @param {string} id - The ID for the JSX children object.
|
|
32
|
+
* @param {function} hashFunction - Custom hash function.
|
|
33
|
+
* @returns {string} - The unique hash of the children.
|
|
34
|
+
*/
|
|
35
|
+
export function oldHashJsxChildren(_a, hashFunction) {
|
|
36
|
+
var source = _a.source, context = _a.context, id = _a.id, dataFormat = _a.dataFormat;
|
|
37
|
+
if (hashFunction === void 0) { hashFunction = oldHashString; }
|
|
38
|
+
var unhashedKey = stringify(__assign(__assign(__assign({ source: sanitizeJsxChildren(source) }, (id && { id: id })), (context && { context: context })), (dataFormat && { dataFormat: dataFormat })));
|
|
39
|
+
return hashFunction(unhashedKey);
|
|
40
|
+
}
|
|
41
|
+
var sanitizeChild = function (child) {
|
|
42
|
+
var _a, _b, _c, _d;
|
|
43
|
+
if (child && typeof child === 'object') {
|
|
44
|
+
if ('props' in child) {
|
|
45
|
+
var newChild = {};
|
|
46
|
+
var dataGt = (_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a['data-_gt'];
|
|
47
|
+
if (dataGt === null || dataGt === void 0 ? void 0 : dataGt.branches) {
|
|
48
|
+
// The only thing that prevents sanitizeJsx from being stable is
|
|
49
|
+
// the order of the keys in the branches object.
|
|
50
|
+
// We don't sort them because stable-stringify sorts them anyways
|
|
51
|
+
newChild.branches = Object.fromEntries(Object.entries(dataGt.branches).map(function (_a) {
|
|
52
|
+
var key = _a[0], value = _a[1];
|
|
53
|
+
return [
|
|
54
|
+
key,
|
|
55
|
+
sanitizeJsxChildren(value),
|
|
56
|
+
];
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
if ((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.children) {
|
|
60
|
+
newChild.children = sanitizeJsxChildren(child.props.children);
|
|
61
|
+
}
|
|
62
|
+
if ((_d = (_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c['data-_gt']) === null || _d === void 0 ? void 0 : _d.transformation) {
|
|
63
|
+
newChild.transformation = child.props['data-_gt'].transformation;
|
|
64
|
+
}
|
|
65
|
+
return newChild;
|
|
66
|
+
}
|
|
67
|
+
if ('key' in child) {
|
|
68
|
+
return __assign({ key: child.key }, (child.variable && {
|
|
69
|
+
variable: child.variable,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return child;
|
|
74
|
+
};
|
|
75
|
+
function sanitizeJsxChildren(childrenAsObjects) {
|
|
76
|
+
return Array.isArray(childrenAsObjects)
|
|
77
|
+
? childrenAsObjects.map(sanitizeChild)
|
|
78
|
+
: sanitizeChild(childrenAsObjects);
|
|
79
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type OldBranchType = 'branch' | 'plural';
|
|
2
|
+
export type OldGTProp = {
|
|
3
|
+
id: number;
|
|
4
|
+
transformation?: OldBranchType;
|
|
5
|
+
branches?: Record<string, OldJsxChildren>;
|
|
6
|
+
};
|
|
7
|
+
export type OldJsxElement = {
|
|
8
|
+
type: string;
|
|
9
|
+
props: {
|
|
10
|
+
children?: OldJsxChildren;
|
|
11
|
+
'data-_gt': OldGTProp;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type OldVariableType = 'number' | 'variable' | 'datetime' | 'currency';
|
|
15
|
+
export type OldVariableObject = {
|
|
16
|
+
variable?: OldVariableType;
|
|
17
|
+
key: string;
|
|
18
|
+
id?: number;
|
|
19
|
+
};
|
|
20
|
+
export type OldJsxChild = OldJsxElement | OldVariableObject | string;
|
|
21
|
+
export type OldJsxChildren = OldJsxChild | OldJsxChild[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JsxChild, JsxChildren } from '../types';
|
|
2
|
+
import { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes.js';
|
|
3
|
+
import { Variable as VariableObject } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a JSX child is an old variable object format
|
|
6
|
+
* @param child - The JSX child to check.
|
|
7
|
+
* @returns True if the child is an old variable object (has 'key' property)
|
|
8
|
+
*/
|
|
9
|
+
export declare function isOldVariableObject(child: OldJsxChild | JsxChild): child is OldVariableObject;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a JSX child is a new variable object format
|
|
12
|
+
* @param child - The JSX child to check.
|
|
13
|
+
* @returns True if the child is a new variable object (has 'k' property)
|
|
14
|
+
*/
|
|
15
|
+
export declare function isNewVariableObject(child: OldJsxChild | JsxChild): child is VariableObject;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if JSX children follow the old format
|
|
18
|
+
* @param children - The JSX children to check (can be string, array, or single child)
|
|
19
|
+
* @returns True if all children are in the old format.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isOldJsxChildren(children: OldJsxChildren | JsxChildren): children is OldJsxChildren;
|