generaltranslation 8.2.13 → 8.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{ApiError-IYfaOR30.mjs → ApiError-0DxxIHLp.mjs} +1 -1
  3. package/dist/{ApiError-CZ45tkW6.cjs.map → ApiError-0DxxIHLp.mjs.map} +1 -1
  4. package/dist/{ApiError-CZ45tkW6.cjs → ApiError-D-IBuHj6.cjs} +1 -1
  5. package/dist/{ApiError-IYfaOR30.mjs.map → ApiError-D-IBuHj6.cjs.map} +1 -1
  6. package/dist/LocaleConfig.d.ts +1 -59
  7. package/dist/LocaleConfig.js +1 -225
  8. package/dist/{base64-2fu94Klt.cjs → base64-C6BHySOc.cjs} +17 -1
  9. package/dist/base64-C6BHySOc.cjs.map +1 -0
  10. package/dist/{base64-DH0STixb.mjs → base64-CWITCfhU.mjs} +6 -2
  11. package/dist/base64-CWITCfhU.mjs.map +1 -0
  12. package/dist/core.cjs +9 -8
  13. package/dist/core.d.cts +1 -2
  14. package/dist/core.d.mts +1 -2
  15. package/dist/core.d.ts +1 -128
  16. package/dist/core.js +1 -137
  17. package/dist/core.mjs +2 -2
  18. package/dist/derive/indexVars.d.ts +1 -1
  19. package/dist/errors.cjs +1 -1
  20. package/dist/errors.mjs +1 -1
  21. package/dist/id/types.d.ts +1 -1
  22. package/dist/{id-CyiXsQrY.cjs → id-C2orn1MA.cjs} +2 -2
  23. package/dist/{id-CyiXsQrY.cjs.map → id-C2orn1MA.cjs.map} +1 -1
  24. package/dist/{id-DbD7K-HL.mjs → id-DEaFhGqX.mjs} +2 -2
  25. package/dist/{id-DbD7K-HL.mjs.map → id-DEaFhGqX.mjs.map} +1 -1
  26. package/dist/id.cjs +1 -1
  27. package/dist/id.d.cts +1 -1
  28. package/dist/id.d.mts +1 -1
  29. package/dist/id.mjs +1 -1
  30. package/dist/index.cjs +368 -385
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +4 -242
  33. package/dist/index.d.mts +4 -242
  34. package/dist/index.d.ts +5 -238
  35. package/dist/index.js +3 -322
  36. package/dist/index.mjs +215 -352
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/internal.cjs +6 -6
  39. package/dist/internal.cjs.map +1 -1
  40. package/dist/internal.d.cts +6 -5
  41. package/dist/internal.d.mts +6 -5
  42. package/dist/internal.mjs +4 -4
  43. package/dist/internal.mjs.map +1 -1
  44. package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
  45. package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
  46. package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
  47. package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
  48. package/dist/locales/getPluralForm.js +2 -2
  49. package/dist/logging/logger.d.ts +0 -3
  50. package/dist/logging/logger.js +0 -3
  51. package/dist/{types-AHtYZIP-.d.mts → types-73XFwmhH.d.mts} +7 -106
  52. package/dist/{types-Bf8_Apq_.d.cts → types-YrrGRHBP.d.cts} +7 -106
  53. package/dist/types-dir/api/enqueueEntries.d.ts +1 -1
  54. package/dist/types-dir/api/enqueueFiles.d.ts +1 -1
  55. package/dist/types-dir/api/fetchTranslations.d.ts +1 -1
  56. package/dist/types-dir/api/file.d.ts +1 -1
  57. package/dist/types-dir/api/translate.d.ts +1 -1
  58. package/dist/types-dir/api/uploadFiles.d.ts +1 -1
  59. package/dist/types.cjs +7 -16
  60. package/dist/types.d.cts +2 -2
  61. package/dist/types.d.mts +2 -2
  62. package/dist/types.d.ts +10 -12
  63. package/dist/types.js +1 -2
  64. package/dist/types.mjs +1 -15
  65. package/package.json +3 -2
  66. package/dist/IntlCache-CAW8tKhd.cjs +0 -212
  67. package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
  68. package/dist/IntlCache-WZk0rKvj.mjs +0 -195
  69. package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
  70. package/dist/base64-2fu94Klt.cjs.map +0 -1
  71. package/dist/base64-DH0STixb.mjs.map +0 -1
  72. package/dist/cache/IntlCache.d.ts +0 -26
  73. package/dist/cache/IntlCache.js +0 -84
  74. package/dist/cache/types.d.ts +0 -32
  75. package/dist/cache/types.js +0 -1
  76. package/dist/core-7RP541eY.cjs +0 -1677
  77. package/dist/core-7RP541eY.cjs.map +0 -1
  78. package/dist/core-I9pWGafA.d.mts +0 -209
  79. package/dist/core-TLJoDpJP.d.cts +0 -209
  80. package/dist/core-isLphYAZ.mjs +0 -1498
  81. package/dist/core-isLphYAZ.mjs.map +0 -1
  82. package/dist/errors/formattingErrors.d.ts +0 -1
  83. package/dist/errors/formattingErrors.js +0 -3
  84. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
  85. package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +0 -147
  86. package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
  87. package/dist/formatting/custom-formats/CutoffFormat/constants.js +0 -30
  88. package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
  89. package/dist/formatting/custom-formats/CutoffFormat/types.js +0 -2
  90. package/dist/formatting/format.d.ts +0 -1
  91. package/dist/formatting/format.js +0 -257
  92. package/dist/locales/customLocaleMapping.d.ts +0 -11
  93. package/dist/locales/customLocaleMapping.js +0 -23
  94. package/dist/locales/determineLocale.d.ts +0 -1
  95. package/dist/locales/determineLocale.js +0 -72
  96. package/dist/locales/getLocaleDirection.d.ts +0 -1
  97. package/dist/locales/getLocaleDirection.js +0 -89
  98. package/dist/locales/getLocaleEmoji.d.ts +0 -2
  99. package/dist/locales/getLocaleEmoji.js +0 -319
  100. package/dist/locales/getLocaleName.d.ts +0 -1
  101. package/dist/locales/getLocaleName.js +0 -45
  102. package/dist/locales/getLocaleProperties.d.ts +0 -32
  103. package/dist/locales/getLocaleProperties.js +0 -220
  104. package/dist/locales/getRegionProperties.d.ts +0 -7
  105. package/dist/locales/getRegionProperties.js +0 -61
  106. package/dist/locales/isSameDialect.d.ts +0 -1
  107. package/dist/locales/isSameDialect.js +0 -41
  108. package/dist/locales/isSameLanguage.d.ts +0 -1
  109. package/dist/locales/isSameLanguage.js +0 -20
  110. package/dist/locales/isSupersetLocale.d.ts +0 -1
  111. package/dist/locales/isSupersetLocale.js +0 -22
  112. package/dist/locales/isValidLocale.d.ts +0 -1
  113. package/dist/locales/isValidLocale.js +0 -75
  114. package/dist/locales/requiresTranslation.d.ts +0 -1
  115. package/dist/locales/requiresTranslation.js +0 -32
  116. package/dist/locales/resolveAliasLocale.d.ts +0 -8
  117. package/dist/locales/resolveAliasLocale.js +0 -21
  118. package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
  119. package/dist/locales/resolveCanonicalLocale.js +0 -13
  120. package/dist/logging/warnings.d.ts +0 -2
  121. package/dist/logging/warnings.js +0 -2
  122. package/dist/types-dir/jsx/content.d.ts +0 -61
  123. package/dist/types-dir/jsx/content.js +0 -11
  124. package/dist/types-dir/jsx/variables.d.ts +0 -9
  125. package/dist/types-dir/jsx/variables.js +0 -1
  126. package/dist/types.cjs.map +0 -1
  127. package/dist/types.mjs.map +0 -1
@@ -1,104 +1,5 @@
1
- //#region src/locales/customLocaleMapping.d.ts
2
- type CustomMapping = Record<string, string | Partial<LocaleProperties>>;
3
- //#endregion
4
- //#region src/locales/getLocaleProperties.d.ts
5
- type LocaleProperties = {
6
- code: string;
7
- name: string;
8
- nativeName: string;
9
- languageCode: string;
10
- languageName: string;
11
- nativeLanguageName: string;
12
- nameWithRegionCode: string;
13
- nativeNameWithRegionCode: string;
14
- regionCode: string;
15
- regionName: string;
16
- nativeRegionName: string;
17
- scriptCode: string;
18
- scriptName: string;
19
- nativeScriptName: string;
20
- maximizedCode: string;
21
- maximizedName: string;
22
- nativeMaximizedName: string;
23
- minimizedCode: string;
24
- minimizedName: string;
25
- nativeMinimizedName: string;
26
- emoji: string;
27
- };
28
- //#endregion
29
- //#region src/types-dir/jsx/variables.d.ts
30
- type VariableType = 'v' | 'n' | 'd' | 'c' | 'rt';
31
- /**
32
- * Variables are used to store the variable name and type.
33
- */
34
- type Variable = {
35
- k: string;
36
- i?: number;
37
- v?: VariableType;
38
- };
39
- //#endregion
40
- //#region src/types-dir/jsx/content.d.ts
41
- /**
42
- * Map of data-_gt properties to their corresponding React props
43
- */
44
- declare const HTML_CONTENT_PROPS: {
45
- readonly pl: "placeholder";
46
- readonly ti: "title";
47
- readonly alt: "alt";
48
- readonly arl: "aria-label";
49
- readonly arb: "aria-labelledby";
50
- readonly ard: "aria-describedby";
51
- };
52
- type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>;
53
- type HtmlContentPropValuesRecord = Partial<Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>>;
54
- /**
55
- * GTProp is an internal property used to contain data for translating and rendering elements.
56
- * note, transformations are only read on the server side if they are 'plural' or 'branch'
57
- */
58
- type GTProp = {
59
- b?: Record<string, JsxChildren>;
60
- t?: 'p' | 'b';
61
- } & HtmlContentPropKeysRecord;
62
- type JsxElement = {
63
- t?: string;
64
- i?: number;
65
- d?: GTProp;
66
- c?: JsxChildren;
67
- };
68
- type JsxChild = string | JsxElement | Variable;
69
- /**
70
- * The format of the string content
71
- */
72
- type StringFormat = 'ICU' | 'I18NEXT' | 'STRING';
73
- /**
74
- * The format of the content.
75
- */
76
- type DataFormat = 'JSX' | StringFormat;
77
- /**
78
- * String format content.
79
- */
80
- type StringContent = IcuMessage | StringMessage | I18nextMessage;
81
- /**
82
- * A content type representing JSX, ICU, and I18next messages.
83
- */
84
- type Content = JsxChildren | StringContent;
85
- /**
86
- * A content type representing JSX elements.
87
- */
88
- type JsxChildren = JsxChild | JsxChild[];
89
- /**
90
- * A content type representing ICU messages.
91
- */
92
- type IcuMessage = string;
93
- /**
94
- * A content type representing I18next messages.
95
- */
96
- type I18nextMessage = string;
97
- /**
98
- * A content type representing plain strings.
99
- */
100
- type StringMessage = string;
101
- //#endregion
1
+ import { Content, Content as Content$1, CustomMapping as CustomMapping$1, CustomRegionMapping as CustomRegionMapping$1, CutoffFormatOptions as CutoffFormatOptions$1, DataFormat, DataFormat as DataFormat$1, GTProp, HTML_CONTENT_PROPS, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, I18nextMessage as I18nextMessage$1, IcuMessage, IcuMessage as IcuMessage$1, JsxChild, JsxChildren, JsxChildren as JsxChildren$1, JsxElement, LocaleProperties as LocaleProperties$1, StringContent, StringFormat as StringFormat$1, StringMessage, StringMessage as StringMessage$1, Variable, Variable as Variable$1, VariableType } from "@generaltranslation/format/types";
2
+
102
3
  //#region src/types-dir/api/entry.d.ts
103
4
  /**
104
5
  * ActionType is the type of action to perform on the request.
@@ -119,7 +20,7 @@ type EntryMetadata = {
119
20
  hash?: string;
120
21
  context?: string;
121
22
  maxChars?: number;
122
- dataFormat?: DataFormat;
23
+ dataFormat?: DataFormat$1;
123
24
  actionType?: ActionType;
124
25
  };
125
26
  type RuntimeTranslateManyOptions = {
@@ -135,7 +36,7 @@ type TranslateOptions = RuntimeTranslateManyOptions & {
135
36
  * Can be a plain string or an object with source and entry metadata fields.
136
37
  */
137
38
  type TranslateManyEntry = string | {
138
- source: Content;
39
+ source: Content$1;
139
40
  metadata?: EntryMetadata;
140
41
  };
141
42
  //#endregion
@@ -682,7 +583,7 @@ type Metadata = {
682
583
  filePaths?: string[];
683
584
  [key: string]: unknown;
684
585
  };
685
- type FormatVariables = Record<string, string | number | boolean | null | undefined | Date>;
586
+ type FormatVariables$1 = Record<string, string | number | boolean | null | undefined | Date>;
686
587
  /**
687
588
  * @deprecated This type is deprecated and will be removed in a future version.
688
589
  */
@@ -763,5 +664,5 @@ type TranslationRequestConfig = {
763
664
  apiKey?: string;
764
665
  };
765
666
  //#endregion
766
- export { FileReference as $, BranchDataResult as A, StringContent as At, FileUpload as B, ProcessMovesOptions as C, HtmlContentPropKeysRecord as Ct, FileDataQuery as D, JsxChild as Dt, OrphanedFile as E, IcuMessage as Et, DownloadFileOptions as F, LocaleProperties as Ft, FetchTranslationsOptions as G, UploadFilesResponse as H, PublishFileEntry as I, CustomMapping as It, DownloadFileBatchOptions as J, FetchTranslationsResult as K, PublishFilesResult as L, TranslationError as M, StringMessage as Mt, TranslationResult as N, Variable as Nt, FileDataResult as O, JsxChildren as Ot, TranslationResultReference as P, VariableType as Pt, FileFormat as Q, EnqueueEntriesOptions as R, MoveResult as S, HTML_CONTENT_PROPS as St, GetOrphanedFilesResult as T, I18nextMessage as Tt, CreateTagOptions as U, UploadFilesOptions as V, CreateTagResult as W, DownloadFileBatchResult as X, DownloadFileBatchRequest as Y, DownloadedFile as Z, AwaitJobsResult as _, TranslateManyEntry as _t, Metadata as a, CheckFileTranslationsOptions as at, JobStatus as b, DataFormat as bt, Update as c, FileTranslationQuery as ct, Transformation as d, JsonValue as dt, FileReferenceIds as et, TransformationPrefix as f, TranslationStatusResult as ft, AwaitJobsOptions as g, RuntimeTranslateManyOptions as gt, SubmitUserEditDiffsPayload as h, EntryMetadata as ht, JsxTranslationResult as i, Updates as it, TranslateManyResult as j, StringFormat as jt, BranchQuery as k, JsxElement as kt, _Content as l, JsonObject as lt, SubmitUserEditDiff as m, ActionType as mt, FormatVariables as n, EnqueueFilesOptions as nt, Request as o, FileQuery as ot, VariableTransformationSuffix as p, HashMetadata as pt, RetrievedTranslations as q, IcuTranslationResult as r, EnqueueFilesResult as rt, TranslationRequestConfig as s, FileQueryResult as st, ContentTranslationResult as t, FileToUpload as tt, InjectionType as u, JsonPrimitive as ut, JobResult as v, TranslateOptions as vt, ProcessMovesResponse as w, HtmlContentPropValuesRecord as wt, MoveMapping as x, GTProp as xt, CheckJobStatusResult as y, Content as yt, EnqueueEntriesResult as z };
767
- //# sourceMappingURL=types-Bf8_Apq_.d.cts.map
667
+ export { TranslationResult as $, InjectionType as A, JsonPrimitive as At, JobStatus as B, StringFormat$1 as C, EnqueueFilesResult as Ct, Variable$1 as D, FileQueryResult as Dt, Update as E, FileQuery as Et, SubmitUserEditDiffsPayload as F, EntryMetadata as Ft, GetOrphanedFilesResult as G, MoveResult as H, AwaitJobsOptions as I, RuntimeTranslateManyOptions as It, FileDataResult as J, OrphanedFile as K, AwaitJobsResult as L, TranslateManyEntry as Lt, TransformationPrefix as M, TranslationStatusResult as Mt, VariableTransformationSuffix as N, HashMetadata as Nt, VariableType as O, FileTranslationQuery as Ot, SubmitUserEditDiff as P, ActionType as Pt, TranslationError as Q, JobResult as R, TranslateOptions as Rt, StringContent as S, EnqueueFilesOptions as St, TranslationRequestConfig as T, CheckFileTranslationsOptions as Tt, ProcessMovesOptions as U, MoveMapping as V, ProcessMovesResponse as W, BranchDataResult as X, BranchQuery as Y, TranslateManyResult as Z, JsxElement as _, DownloadedFile as _t, CutoffFormatOptions$1 as a, EnqueueEntriesResult as at, Metadata as b, FileReferenceIds as bt, GTProp as c, UploadFilesResponse as ct, HtmlContentPropValuesRecord as d, FetchTranslationsOptions as dt, TranslationResultReference as et, I18nextMessage$1 as f, FetchTranslationsResult as ft, JsxChildren$1 as g, DownloadFileBatchResult as gt, JsxChild as h, DownloadFileBatchRequest as ht, CustomRegionMapping$1 as i, EnqueueEntriesOptions as it, Transformation as j, JsonValue as jt, _Content as k, JsonObject as kt, HTML_CONTENT_PROPS as l, CreateTagOptions as lt, IcuTranslationResult as m, DownloadFileBatchOptions as mt, ContentTranslationResult as n, PublishFileEntry as nt, DataFormat$1 as o, FileUpload as ot, IcuMessage$1 as p, RetrievedTranslations as pt, FileDataQuery as q, CustomMapping$1 as r, PublishFilesResult as rt, FormatVariables$1 as s, UploadFilesOptions as st, Content$1 as t, DownloadFileOptions as tt, HtmlContentPropKeysRecord as u, CreateTagResult as ut, JsxTranslationResult as v, FileFormat as vt, StringMessage$1 as w, Updates as wt, Request as x, FileToUpload as xt, LocaleProperties$1 as y, FileReference as yt, CheckJobStatusResult as z };
668
+ //# sourceMappingURL=types-YrrGRHBP.d.cts.map
@@ -1,4 +1,4 @@
1
- import { DataFormat } from '../jsx/content';
1
+ import type { DataFormat } from '@generaltranslation/format/types';
2
2
  export type { Updates } from './enqueueFiles';
3
3
  export type EnqueueEntriesOptions = {
4
4
  timeout?: number;
@@ -1,4 +1,4 @@
1
- import { DataFormat, JsxChildren } from '../jsx/content';
1
+ import type { DataFormat, JsxChildren } from '@generaltranslation/format/types';
2
2
  type UpdateMetadata = {
3
3
  id?: string;
4
4
  hash?: string;
@@ -1,4 +1,4 @@
1
- import type { Content } from '../jsx/content';
1
+ import type { Content } from '@generaltranslation/format/types';
2
2
  export type FetchTranslationsOptions = {
3
3
  timeout?: number;
4
4
  };
@@ -1,4 +1,4 @@
1
- import { DataFormat } from '../jsx/content';
1
+ import type { DataFormat } from '@generaltranslation/format/types';
2
2
  import { Updates } from './enqueueFiles';
3
3
  import type { JsonObject } from './json';
4
4
  export type FileFormat = 'GTJSON' | 'JSON' | 'PO' | 'POT' | 'YAML' | 'MDX' | 'MD' | 'TS' | 'JS' | 'HTML' | 'TXT' | 'TWILIO_CONTENT_JSON';
@@ -1,4 +1,4 @@
1
- import { I18nextMessage, IcuMessage, JsxChildren, StringMessage } from '../jsx/content';
1
+ import { I18nextMessage, IcuMessage, JsxChildren, StringMessage } from '@generaltranslation/format/types';
2
2
  /**
3
3
  * TranslationResultReference is used to store the reference for a translation result.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { DataFormat } from '../jsx/content';
1
+ import type { DataFormat } from '@generaltranslation/format/types';
2
2
  import { FileFormat, FileReference, type FormatMetadata } from './file';
3
3
  /**
4
4
  * Metadata stored alongside GTJSON file entries.
package/dist/types.cjs CHANGED
@@ -1,17 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/types-dir/jsx/content.ts
3
- /**
4
- * Map of data-_gt properties to their corresponding React props
5
- */
6
- const HTML_CONTENT_PROPS = {
7
- pl: "placeholder",
8
- ti: "title",
9
- alt: "alt",
10
- arl: "aria-label",
11
- arb: "aria-labelledby",
12
- ard: "aria-describedby"
13
- };
14
- //#endregion
15
- exports.HTML_CONTENT_PROPS = HTML_CONTENT_PROPS;
16
-
17
- //# sourceMappingURL=types.cjs.map
2
+ let _generaltranslation_format_types = require("@generaltranslation/format/types");
3
+ Object.defineProperty(exports, "HTML_CONTENT_PROPS", {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _generaltranslation_format_types.HTML_CONTENT_PROPS;
7
+ }
8
+ });
package/dist/types.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as FileReference, A as BranchDataResult, At as StringContent, B as FileUpload, C as ProcessMovesOptions, Ct as HtmlContentPropKeysRecord, D as FileDataQuery, Dt as JsxChild, E as OrphanedFile, Et as IcuMessage, F as DownloadFileOptions, Ft as LocaleProperties, G as FetchTranslationsOptions, I as PublishFileEntry, It as CustomMapping, J as DownloadFileBatchOptions, K as FetchTranslationsResult, L as PublishFilesResult, M as TranslationError, Mt as StringMessage, N as TranslationResult, Nt as Variable, O as FileDataResult, Ot as JsxChildren, P as TranslationResultReference, Pt as VariableType, Q as FileFormat, R as EnqueueEntriesOptions, S as MoveResult, St as HTML_CONTENT_PROPS, T as GetOrphanedFilesResult, Tt as I18nextMessage, U as CreateTagOptions, W as CreateTagResult, X as DownloadFileBatchResult, Z as DownloadedFile, _ as AwaitJobsResult, _t as TranslateManyEntry, a as Metadata, at as CheckFileTranslationsOptions, b as JobStatus, bt as DataFormat, c as Update, ct as FileTranslationQuery, d as Transformation, dt as JsonValue, f as TransformationPrefix, ft as TranslationStatusResult, g as AwaitJobsOptions, h as SubmitUserEditDiffsPayload, ht as EntryMetadata, i as JsxTranslationResult, it as Updates, j as TranslateManyResult, jt as StringFormat, k as BranchQuery, kt as JsxElement, l as _Content, lt as JsonObject, m as SubmitUserEditDiff, mt as ActionType, n as FormatVariables, nt as EnqueueFilesOptions, o as Request, p as VariableTransformationSuffix, pt as HashMetadata, q as RetrievedTranslations, r as IcuTranslationResult, rt as EnqueueFilesResult, s as TranslationRequestConfig, t as ContentTranslationResult, tt as FileToUpload, u as InjectionType, ut as JsonPrimitive, v as JobResult, w as ProcessMovesResponse, wt as HtmlContentPropValuesRecord, x as MoveMapping, xt as GTProp, y as CheckJobStatusResult, yt as Content, z as EnqueueEntriesResult } from "./types-Bf8_Apq_.cjs";
2
- export { AwaitJobsOptions, AwaitJobsResult, BranchDataResult, BranchQuery, CheckFileTranslationsOptions, CheckJobStatusResult, Content, ContentTranslationResult, CreateTagOptions, CreateTagResult, CustomMapping, DataFormat, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, DownloadedFile, EnqueueEntriesOptions, EnqueueEntriesResult, EnqueueFilesOptions, EnqueueFilesResult, ActionType as EntryActionType, EntryMetadata, FetchTranslationsOptions, FetchTranslationsResult, FileDataQuery, FileDataResult, FileFormat, FileReference, FileToUpload, FileTranslationQuery, FileUpload, FormatVariables, GTProp, GetOrphanedFilesResult, HTML_CONTENT_PROPS, HashMetadata, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, IcuTranslationResult, InjectionType, JobResult, JobStatus, JsonObject, JsonPrimitive, JsonValue, JsxChild, JsxChildren, JsxElement, JsxTranslationResult, LocaleProperties, Metadata, MoveMapping, MoveResult, OrphanedFile, ProcessMovesOptions, ProcessMovesResponse, PublishFileEntry, PublishFilesResult, Request, RetrievedTranslations, StringContent, StringFormat, StringMessage, SubmitUserEditDiff, SubmitUserEditDiffsPayload, Transformation, TransformationPrefix, TranslateManyEntry, TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslationResultReference, TranslationStatusResult, Update, Updates, Variable, VariableTransformationSuffix, VariableType, _Content };
1
+ import { $ as TranslationResult, A as InjectionType, At as JsonPrimitive, B as JobStatus, C as StringFormat, Ct as EnqueueFilesResult, D as Variable, E as Update, F as SubmitUserEditDiffsPayload, Ft as EntryMetadata, G as GetOrphanedFilesResult, H as MoveResult, I as AwaitJobsOptions, J as FileDataResult, K as OrphanedFile, L as AwaitJobsResult, Lt as TranslateManyEntry, M as TransformationPrefix, Mt as TranslationStatusResult, N as VariableTransformationSuffix, Nt as HashMetadata, O as VariableType, Ot as FileTranslationQuery, P as SubmitUserEditDiff, Pt as ActionType, Q as TranslationError, R as JobResult, S as StringContent, St as EnqueueFilesOptions, T as TranslationRequestConfig, Tt as CheckFileTranslationsOptions, U as ProcessMovesOptions, V as MoveMapping, W as ProcessMovesResponse, X as BranchDataResult, Y as BranchQuery, Z as TranslateManyResult, _ as JsxElement, _t as DownloadedFile, a as CutoffFormatOptions, at as EnqueueEntriesResult, b as Metadata, c as GTProp, d as HtmlContentPropValuesRecord, dt as FetchTranslationsOptions, et as TranslationResultReference, f as I18nextMessage, ft as FetchTranslationsResult, g as JsxChildren, gt as DownloadFileBatchResult, h as JsxChild, i as CustomRegionMapping, it as EnqueueEntriesOptions, j as Transformation, jt as JsonValue, k as _Content, kt as JsonObject, l as HTML_CONTENT_PROPS, lt as CreateTagOptions, m as IcuTranslationResult, mt as DownloadFileBatchOptions, n as ContentTranslationResult, nt as PublishFileEntry, o as DataFormat, ot as FileUpload, p as IcuMessage, pt as RetrievedTranslations, q as FileDataQuery, r as CustomMapping, rt as PublishFilesResult, s as FormatVariables, t as Content, tt as DownloadFileOptions, u as HtmlContentPropKeysRecord, ut as CreateTagResult, v as JsxTranslationResult, vt as FileFormat, w as StringMessage, wt as Updates, x as Request, xt as FileToUpload, y as LocaleProperties, yt as FileReference, z as CheckJobStatusResult } from "./types-YrrGRHBP.cjs";
2
+ export { AwaitJobsOptions, AwaitJobsResult, BranchDataResult, BranchQuery, CheckFileTranslationsOptions, CheckJobStatusResult, Content, ContentTranslationResult, CreateTagOptions, CreateTagResult, CustomMapping, CustomRegionMapping, CutoffFormatOptions, DataFormat, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, DownloadedFile, EnqueueEntriesOptions, EnqueueEntriesResult, EnqueueFilesOptions, EnqueueFilesResult, ActionType as EntryActionType, EntryMetadata, FetchTranslationsOptions, FetchTranslationsResult, FileDataQuery, FileDataResult, FileFormat, FileReference, FileToUpload, FileTranslationQuery, FileUpload, FormatVariables, GTProp, GetOrphanedFilesResult, HTML_CONTENT_PROPS, HashMetadata, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, IcuTranslationResult, InjectionType, JobResult, JobStatus, JsonObject, JsonPrimitive, JsonValue, JsxChild, JsxChildren, JsxElement, JsxTranslationResult, LocaleProperties, Metadata, MoveMapping, MoveResult, OrphanedFile, ProcessMovesOptions, ProcessMovesResponse, PublishFileEntry, PublishFilesResult, Request, RetrievedTranslations, StringContent, StringFormat, StringMessage, SubmitUserEditDiff, SubmitUserEditDiffsPayload, Transformation, TransformationPrefix, TranslateManyEntry, TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslationResultReference, TranslationStatusResult, Update, Updates, Variable, VariableTransformationSuffix, VariableType, _Content };
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as FileReference, A as BranchDataResult, At as StringContent, B as FileUpload, C as ProcessMovesOptions, Ct as HtmlContentPropKeysRecord, D as FileDataQuery, Dt as JsxChild, E as OrphanedFile, Et as IcuMessage, F as DownloadFileOptions, Ft as LocaleProperties, G as FetchTranslationsOptions, I as PublishFileEntry, It as CustomMapping, J as DownloadFileBatchOptions, K as FetchTranslationsResult, L as PublishFilesResult, M as TranslationError, Mt as StringMessage, N as TranslationResult, Nt as Variable, O as FileDataResult, Ot as JsxChildren, P as TranslationResultReference, Pt as VariableType, Q as FileFormat, R as EnqueueEntriesOptions, S as MoveResult, St as HTML_CONTENT_PROPS, T as GetOrphanedFilesResult, Tt as I18nextMessage, U as CreateTagOptions, W as CreateTagResult, X as DownloadFileBatchResult, Z as DownloadedFile, _ as AwaitJobsResult, _t as TranslateManyEntry, a as Metadata, at as CheckFileTranslationsOptions, b as JobStatus, bt as DataFormat, c as Update, ct as FileTranslationQuery, d as Transformation, dt as JsonValue, f as TransformationPrefix, ft as TranslationStatusResult, g as AwaitJobsOptions, h as SubmitUserEditDiffsPayload, ht as EntryMetadata, i as JsxTranslationResult, it as Updates, j as TranslateManyResult, jt as StringFormat, k as BranchQuery, kt as JsxElement, l as _Content, lt as JsonObject, m as SubmitUserEditDiff, mt as ActionType, n as FormatVariables, nt as EnqueueFilesOptions, o as Request, p as VariableTransformationSuffix, pt as HashMetadata, q as RetrievedTranslations, r as IcuTranslationResult, rt as EnqueueFilesResult, s as TranslationRequestConfig, t as ContentTranslationResult, tt as FileToUpload, u as InjectionType, ut as JsonPrimitive, v as JobResult, w as ProcessMovesResponse, wt as HtmlContentPropValuesRecord, x as MoveMapping, xt as GTProp, y as CheckJobStatusResult, yt as Content, z as EnqueueEntriesResult } from "./types-AHtYZIP-.mjs";
2
- export { AwaitJobsOptions, AwaitJobsResult, BranchDataResult, BranchQuery, CheckFileTranslationsOptions, CheckJobStatusResult, Content, ContentTranslationResult, CreateTagOptions, CreateTagResult, CustomMapping, DataFormat, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, DownloadedFile, EnqueueEntriesOptions, EnqueueEntriesResult, EnqueueFilesOptions, EnqueueFilesResult, ActionType as EntryActionType, EntryMetadata, FetchTranslationsOptions, FetchTranslationsResult, FileDataQuery, FileDataResult, FileFormat, FileReference, FileToUpload, FileTranslationQuery, FileUpload, FormatVariables, GTProp, GetOrphanedFilesResult, HTML_CONTENT_PROPS, HashMetadata, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, IcuTranslationResult, InjectionType, JobResult, JobStatus, JsonObject, JsonPrimitive, JsonValue, JsxChild, JsxChildren, JsxElement, JsxTranslationResult, LocaleProperties, Metadata, MoveMapping, MoveResult, OrphanedFile, ProcessMovesOptions, ProcessMovesResponse, PublishFileEntry, PublishFilesResult, Request, RetrievedTranslations, StringContent, StringFormat, StringMessage, SubmitUserEditDiff, SubmitUserEditDiffsPayload, Transformation, TransformationPrefix, TranslateManyEntry, TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslationResultReference, TranslationStatusResult, Update, Updates, Variable, VariableTransformationSuffix, VariableType, _Content };
1
+ import { $ as TranslationResult, A as InjectionType, At as JsonPrimitive, B as JobStatus, C as StringFormat, Ct as EnqueueFilesResult, D as Variable, E as Update, F as SubmitUserEditDiffsPayload, Ft as EntryMetadata, G as GetOrphanedFilesResult, H as MoveResult, I as AwaitJobsOptions, J as FileDataResult, K as OrphanedFile, L as AwaitJobsResult, Lt as TranslateManyEntry, M as TransformationPrefix, Mt as TranslationStatusResult, N as VariableTransformationSuffix, Nt as HashMetadata, O as VariableType, Ot as FileTranslationQuery, P as SubmitUserEditDiff, Pt as ActionType, Q as TranslationError, R as JobResult, S as StringContent, St as EnqueueFilesOptions, T as TranslationRequestConfig, Tt as CheckFileTranslationsOptions, U as ProcessMovesOptions, V as MoveMapping, W as ProcessMovesResponse, X as BranchDataResult, Y as BranchQuery, Z as TranslateManyResult, _ as JsxElement, _t as DownloadedFile, a as CutoffFormatOptions, at as EnqueueEntriesResult, b as Metadata, c as GTProp, d as HtmlContentPropValuesRecord, dt as FetchTranslationsOptions, et as TranslationResultReference, f as I18nextMessage, ft as FetchTranslationsResult, g as JsxChildren, gt as DownloadFileBatchResult, h as JsxChild, i as CustomRegionMapping, it as EnqueueEntriesOptions, j as Transformation, jt as JsonValue, k as _Content, kt as JsonObject, l as HTML_CONTENT_PROPS, lt as CreateTagOptions, m as IcuTranslationResult, mt as DownloadFileBatchOptions, n as ContentTranslationResult, nt as PublishFileEntry, o as DataFormat, ot as FileUpload, p as IcuMessage, pt as RetrievedTranslations, q as FileDataQuery, r as CustomMapping, rt as PublishFilesResult, s as FormatVariables, t as Content, tt as DownloadFileOptions, u as HtmlContentPropKeysRecord, ut as CreateTagResult, v as JsxTranslationResult, vt as FileFormat, w as StringMessage, wt as Updates, x as Request, xt as FileToUpload, y as LocaleProperties, yt as FileReference, z as CheckJobStatusResult } from "./types-73XFwmhH.mjs";
2
+ export { AwaitJobsOptions, AwaitJobsResult, BranchDataResult, BranchQuery, CheckFileTranslationsOptions, CheckJobStatusResult, Content, ContentTranslationResult, CreateTagOptions, CreateTagResult, CustomMapping, CustomRegionMapping, CutoffFormatOptions, DataFormat, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, DownloadedFile, EnqueueEntriesOptions, EnqueueEntriesResult, EnqueueFilesOptions, EnqueueFilesResult, ActionType as EntryActionType, EntryMetadata, FetchTranslationsOptions, FetchTranslationsResult, FileDataQuery, FileDataResult, FileFormat, FileReference, FileToUpload, FileTranslationQuery, FileUpload, FormatVariables, GTProp, GetOrphanedFilesResult, HTML_CONTENT_PROPS, HashMetadata, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, IcuTranslationResult, InjectionType, JobResult, JobStatus, JsonObject, JsonPrimitive, JsonValue, JsxChild, JsxChildren, JsxElement, JsxTranslationResult, LocaleProperties, Metadata, MoveMapping, MoveResult, OrphanedFile, ProcessMovesOptions, ProcessMovesResponse, PublishFileEntry, PublishFilesResult, Request, RetrievedTranslations, StringContent, StringFormat, StringMessage, SubmitUserEditDiff, SubmitUserEditDiffsPayload, Transformation, TransformationPrefix, TranslateManyEntry, TranslateManyResult, TranslationError, TranslationRequestConfig, TranslationResult, TranslationResultReference, TranslationStatusResult, Update, Updates, Variable, VariableTransformationSuffix, VariableType, _Content };
package/dist/types.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- import type { LocaleProperties } from './locales/getLocaleProperties';
2
- import type { Variable, VariableType } from './types-dir/jsx/variables';
3
- import { type IcuMessage, type I18nextMessage, type StringMessage, type StringContent, type JsxChildren, type JsxChild, type JsxElement, type GTProp, type HtmlContentPropKeysRecord, type HtmlContentPropValuesRecord, HTML_CONTENT_PROPS, type DataFormat, type Content, type StringFormat } from './types-dir/jsx/content';
4
- import type { ActionType, EntryMetadata, TranslateManyEntry } from './types-dir/api/entry';
5
- import type { HashMetadata } from './id/types';
1
+ import type { DataFormat as FormatDataFormat, JsxChildren as FormatJsxChildren, Variable as FormatVariable } from '@generaltranslation/format/types';
2
+ export { HTML_CONTENT_PROPS } from '@generaltranslation/format/types';
3
+ export type { Content, CustomMapping, CustomRegionMapping, CutoffFormatOptions, DataFormat, GTProp, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, I18nextMessage, IcuMessage, JsxChild, JsxChildren, JsxElement, LocaleProperties, StringContent, StringFormat, StringMessage, Variable, VariableType, } from '@generaltranslation/format/types';
4
+ export type { ActionType as EntryActionType, EntryMetadata, TranslateManyEntry, } from './types-dir/api/entry';
5
+ export type { HashMetadata } from './id/types';
6
6
  export type { TranslationStatusResult } from './types-dir/api/translationStatus';
7
7
  export type { JsonObject, JsonPrimitive, JsonValue, } from './types-dir/api/json';
8
- export { IcuMessage, StringMessage, I18nextMessage, StringContent, JsxChildren, JsxChild, JsxElement, GTProp, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, HTML_CONTENT_PROPS, Variable, VariableType, LocaleProperties, DataFormat, ActionType as EntryActionType, EntryMetadata, TranslateManyEntry, Content, StringFormat, HashMetadata, };
9
8
  export type { FileTranslationQuery, CheckFileTranslationsOptions, } from './types-dir/api/checkFileTranslations';
10
9
  export type { DownloadFileBatchOptions, DownloadFileBatchResult, } from './types-dir/api/downloadFileBatch';
11
10
  export type { FetchTranslationsOptions, FetchTranslationsResult, RetrievedTranslations, } from './types-dir/api/fetchTranslations';
@@ -32,7 +31,7 @@ export type { SubmitUserEditDiff, SubmitUserEditDiffsPayload, } from './translat
32
31
  /**
33
32
  * @deprecated Use {@link Content} instead.
34
33
  */
35
- export type _Content = string | Array<string | Variable>;
34
+ export type _Content = string | Array<string | FormatVariable>;
36
35
  export type { Transformation, TransformationPrefix, VariableTransformationSuffix, InjectionType, } from './types-dir/transformations';
37
36
  export type Metadata = {
38
37
  maxChars?: number;
@@ -40,7 +39,7 @@ export type Metadata = {
40
39
  id?: string;
41
40
  hash?: string;
42
41
  format?: string;
43
- dataFormat?: DataFormat;
42
+ dataFormat?: FormatDataFormat;
44
43
  sourceLocale?: string;
45
44
  actionType?: 'standard' | 'fast' | string;
46
45
  filePaths?: string[];
@@ -59,7 +58,7 @@ export type Update = {
59
58
  } | {
60
59
  type: 'jsx';
61
60
  data: {
62
- source: JsxChildren;
61
+ source: FormatJsxChildren;
63
62
  metadata: Metadata;
64
63
  };
65
64
  };
@@ -76,7 +75,7 @@ export type Request = {
76
75
  } | {
77
76
  type: 'jsx';
78
77
  data: {
79
- source: JsxChildren;
78
+ source: FormatJsxChildren;
80
79
  targetLocale: string;
81
80
  metadata: Metadata;
82
81
  };
@@ -107,14 +106,13 @@ export type IcuTranslationResult = {
107
106
  * @deprecated Use {@link TranslationResult} instead.
108
107
  */
109
108
  export type JsxTranslationResult = {
110
- translation: JsxChildren;
109
+ translation: FormatJsxChildren;
111
110
  locale: string;
112
111
  reference?: {
113
112
  id: string;
114
113
  key: string;
115
114
  };
116
115
  };
117
- export type { CustomMapping } from './locales/customLocaleMapping';
118
116
  /**
119
117
  * TranslationRequestConfig is used to configure the translation request.
120
118
  *
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- import { HTML_CONTENT_PROPS, } from './types-dir/jsx/content';
2
- export { HTML_CONTENT_PROPS, };
1
+ export { HTML_CONTENT_PROPS } from '@generaltranslation/format/types';
package/dist/types.mjs CHANGED
@@ -1,16 +1,2 @@
1
- //#region src/types-dir/jsx/content.ts
2
- /**
3
- * Map of data-_gt properties to their corresponding React props
4
- */
5
- const HTML_CONTENT_PROPS = {
6
- pl: "placeholder",
7
- ti: "title",
8
- alt: "alt",
9
- arl: "aria-label",
10
- arb: "aria-labelledby",
11
- ard: "aria-describedby"
12
- };
13
- //#endregion
1
+ import { HTML_CONTENT_PROPS } from "@generaltranslation/format/types";
14
2
  export { HTML_CONTENT_PROPS };
15
-
16
- //# sourceMappingURL=types.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "8.2.13",
3
+ "version": "8.2.14",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -32,6 +32,7 @@
32
32
  "homepage": "https://generaltranslation.com/",
33
33
  "devDependencies": {
34
34
  "@types/node": "^22.13.5",
35
+ "intl-messageformat": "^10.7.16",
35
36
  "tsdown": "^0.21.10",
36
37
  "typescript": "^5.9.2"
37
38
  },
@@ -41,7 +42,7 @@
41
42
  "dependencies": {
42
43
  "@formatjs/icu-messageformat-parser": "^2.11.4",
43
44
  "@noble/hashes": "^2.2.0",
44
- "intl-messageformat": "^10.7.16"
45
+ "@generaltranslation/format": "0.1.0"
45
46
  },
46
47
  "exports": {
47
48
  ".": {
@@ -1,212 +0,0 @@
1
- //#region src/settings/settings.ts
2
- const libraryDefaultLocale = "en";
3
- const defaultTimeout = 6e4;
4
- //#endregion
5
- //#region src/errors/formattingErrors.ts
6
- const createInvalidCutoffStyleError = (style) => `generaltranslation Formatting Error: Invalid cutoff style: ${style}.`;
7
- const DEFAULT_TERMINATOR_KEY = "DEFAULT_TERMINATOR_KEY";
8
- const TERMINATOR_MAP = {
9
- ellipsis: {
10
- fr: {
11
- terminator: "…",
12
- separator: " "
13
- },
14
- zh: {
15
- terminator: "……",
16
- separator: void 0
17
- },
18
- ja: {
19
- terminator: "……",
20
- separator: void 0
21
- },
22
- [DEFAULT_TERMINATOR_KEY]: {
23
- terminator: "…",
24
- separator: void 0
25
- }
26
- },
27
- none: { [DEFAULT_TERMINATOR_KEY]: {
28
- terminator: void 0,
29
- separator: void 0
30
- } }
31
- };
32
- //#endregion
33
- //#region src/formatting/custom-formats/CutoffFormat/CutoffFormat.ts
34
- var CutoffFormatConstructor = class {
35
- /**
36
- * Constructor
37
- * @param {Intl.LocalesArgument} locales - The locales to use for formatting.
38
- * @param {CutoffFormatOptions} options - The options for formatting.
39
- * @param {number} [options.maxChars] - The maximum number of characters to display.
40
- * - Undefined values are treated as no cutoff.
41
- * - Negative values follow .slice() behavior and terminator will be added before the value.
42
- * - 0 will result in an empty string.
43
- * - If cutoff results in an empty string, no terminator is added.
44
- * @param {CutoffFormatStyle} [options.style='ellipsis'] - The style of the terminator.
45
- * @param {string} [options.terminator] - Optional override the terminator to use.
46
- * @param {string} [options.separator] - Optional override the separator to use between the terminator and the value.
47
- * - If no terminator is provided, then separator is ignored.
48
- *
49
- * @example
50
- * const format = new CutoffFormat('en', { maxChars: 5 });
51
- * format.format('Hello, world!'); // 'Hello...'
52
- *
53
- * const format = new CutoffFormat('en', { maxChars: -3 });
54
- * format.format('Hello, world!'); // '...ld!'
55
- */
56
- constructor(locales, options = {}) {
57
- try {
58
- const localesList = !locales ? ["en"] : Array.isArray(locales) ? locales.map((l) => String(l)) : [String(locales)];
59
- const canonicalLocales = Intl.getCanonicalLocales(localesList);
60
- this.locale = canonicalLocales.length ? canonicalLocales[0] : "en";
61
- } catch {
62
- this.locale = "en";
63
- }
64
- if (!TERMINATOR_MAP[options.style ?? "ellipsis"]) throw new Error(createInvalidCutoffStyleError(options.style ?? "ellipsis"));
65
- let style;
66
- let presetTerminatorOptions;
67
- if (options.maxChars !== void 0) {
68
- style = options.style ?? "ellipsis";
69
- const languageCode = new Intl.Locale(this.locale).language;
70
- presetTerminatorOptions = TERMINATOR_MAP[style][languageCode] || TERMINATOR_MAP[style]["DEFAULT_TERMINATOR_KEY"];
71
- }
72
- let terminator = options.terminator ?? presetTerminatorOptions?.terminator;
73
- let separator = terminator != null ? options.separator ?? presetTerminatorOptions?.separator : void 0;
74
- this.additionLength = (terminator?.length ?? 0) + (separator?.length ?? 0);
75
- if (options.maxChars !== void 0 && Math.abs(options.maxChars) < this.additionLength) {
76
- terminator = void 0;
77
- separator = void 0;
78
- }
79
- this.options = {
80
- maxChars: options.maxChars,
81
- style,
82
- terminator,
83
- separator
84
- };
85
- }
86
- /**
87
- * Format a value according to the cutoff options, returning a formatted string.
88
- *
89
- * @param {string} value - The string value to format with cutoff behavior.
90
- * @returns {string} The formatted string with terminator applied if cutoff occurs.
91
- *
92
- * @example
93
- * const formatter = new CutoffFormatConstructor('en', { maxChars: 8, style: 'ellipsis' });
94
- * formatter.format('Hello, world!'); // Returns 'Hello, w...'
95
- */
96
- format(value) {
97
- return this.formatToParts(value).join("");
98
- }
99
- /**
100
- * Format a value to parts according to the cutoff options, returning an array of string parts.
101
- * This method breaks down the formatted result into individual components for more granular control.
102
- *
103
- * @param {string} value - The string value to format with cutoff behavior.
104
- * @returns {PrependedCutoffParts | PostpendedCutoffParts} An array of string parts representing the formatted result.
105
- * - For positive maxChars: [cutoffValue, separator?, terminator?]
106
- * - For negative maxChars: [terminator?, separator?, cutoffValue]
107
- * - For no cutoff: [originalValue]
108
- *
109
- * @example
110
- * const formatter = new CutoffFormatConstructor('en', { maxChars: 5, style: 'ellipsis' });
111
- * formatter.formatToParts('Hello, world!'); // Returns ['Hello', '...']
112
- */
113
- formatToParts(value) {
114
- const { maxChars, terminator, separator } = this.options;
115
- const adjustedChars = maxChars === void 0 || Math.abs(maxChars) >= value.length ? maxChars : maxChars >= 0 ? Math.max(0, maxChars - this.additionLength) : Math.min(0, maxChars + this.additionLength);
116
- const slicedValue = adjustedChars !== void 0 && adjustedChars > -1 ? value.slice(0, adjustedChars) : value.slice(adjustedChars);
117
- if (maxChars == null || adjustedChars == null || adjustedChars === 0 || terminator == null || value.length <= Math.abs(maxChars)) return [slicedValue];
118
- if (adjustedChars > 0) return separator != null ? [
119
- slicedValue,
120
- separator,
121
- terminator
122
- ] : [slicedValue, terminator];
123
- else return separator != null ? [
124
- terminator,
125
- separator,
126
- slicedValue
127
- ] : [terminator, slicedValue];
128
- }
129
- /**
130
- * Get the resolved options
131
- * @returns {ResolvedCutoffFormatOptions} The resolved options.
132
- */
133
- resolvedOptions() {
134
- return this.options;
135
- }
136
- };
137
- //#endregion
138
- //#region src/cache/IntlCache.ts
139
- /**
140
- * Object mapping constructor names to their respective constructor functions
141
- * Includes all native Intl constructors plus custom ones like CutoffFormat
142
- */
143
- const CustomIntl = {
144
- Collator: Intl.Collator,
145
- DateTimeFormat: Intl.DateTimeFormat,
146
- DisplayNames: Intl.DisplayNames,
147
- ListFormat: Intl.ListFormat,
148
- Locale: Intl.Locale,
149
- NumberFormat: Intl.NumberFormat,
150
- PluralRules: Intl.PluralRules,
151
- RelativeTimeFormat: Intl.RelativeTimeFormat,
152
- Segmenter: Intl.Segmenter,
153
- CutoffFormat: CutoffFormatConstructor
154
- };
155
- /**
156
- * Cache for Intl and custom format instances to avoid repeated instantiation
157
- * Uses a two-level structure: constructor name -> cache key -> instance.
158
- */
159
- var IntlCache = class {
160
- constructor() {
161
- this.cache = {};
162
- }
163
- /**
164
- * Generates a consistent cache key from locales and options.
165
- * Handles all LocalesArgument types (string, Locale, array, undefined).
166
- */
167
- _generateKey(locales, options = {}) {
168
- return `${!locales ? "undefined" : Array.isArray(locales) ? locales.map((l) => String(l)).join(",") : String(locales)}:${options ? JSON.stringify(options, Object.keys(options).sort()) : "{}"}`;
169
- }
170
- /**
171
- * Gets a cached Intl instance or creates a new one if not found
172
- * @param constructor The name of the Intl constructor to use.
173
- * @param args Constructor arguments (locales, options).
174
- * @returns Cached or newly created Intl instance.
175
- */
176
- get(constructor, ...args) {
177
- const [locales = "en", options = {}] = args;
178
- const key = this._generateKey(locales, options);
179
- let intlObject = this.cache[constructor]?.[key];
180
- if (intlObject === void 0) {
181
- intlObject = new CustomIntl[constructor](...args);
182
- if (!this.cache[constructor]) this.cache[constructor] = {};
183
- this.cache[constructor][key] = intlObject;
184
- }
185
- return intlObject;
186
- }
187
- };
188
- /**
189
- * Global instance of the Intl cache for use throughout the application
190
- */
191
- const intlCache = new IntlCache();
192
- //#endregion
193
- Object.defineProperty(exports, "defaultTimeout", {
194
- enumerable: true,
195
- get: function() {
196
- return defaultTimeout;
197
- }
198
- });
199
- Object.defineProperty(exports, "intlCache", {
200
- enumerable: true,
201
- get: function() {
202
- return intlCache;
203
- }
204
- });
205
- Object.defineProperty(exports, "libraryDefaultLocale", {
206
- enumerable: true,
207
- get: function() {
208
- return libraryDefaultLocale;
209
- }
210
- });
211
-
212
- //# sourceMappingURL=IntlCache-CAW8tKhd.cjs.map
@@ -1 +0,0 @@
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":"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"}