generaltranslation 8.2.15 → 8.2.16

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # generaltranslation
2
2
 
3
+ ## 8.2.16
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1460](https://github.com/generaltranslation/gt/pull/1460) [`e041312`](https://github.com/generaltranslation/gt/commit/e04131263dd61e469db977bcc196dc1283e773d0) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: escape characters in declareVar() for source locale consumed by condenseVars()
8
+
3
9
  ## 8.2.15
4
10
 
5
11
  ### Patch Changes
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Given an indexed ICU string, condenses any select to an argument
3
+ * Unindexed _gt_ source strings and indexed _gt_# translation strings
4
+ * are mutually exclusive.
3
5
  * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
4
6
  * @param {string} icuString - The ICU string to condense.
5
7
  * @returns {string} The condensed ICU string.
@@ -3,15 +3,18 @@ import { printAST } from '@formatjs/icu-messageformat-parser/printer.js';
3
3
  import { traverseIcu } from './utils/traverseIcu';
4
4
  import { VAR_IDENTIFIER } from './utils/constants';
5
5
  import { isGTIndexedSelectElement } from './utils/traverseHelpers';
6
+ var CONTAINS_INDEXED_GT_REGEX = new RegExp("".concat(VAR_IDENTIFIER, "\\d+"));
6
7
  /**
7
8
  * Given an indexed ICU string, condenses any select to an argument
9
+ * Unindexed _gt_ source strings and indexed _gt_# translation strings
10
+ * are mutually exclusive.
8
11
  * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
9
12
  * @param {string} icuString - The ICU string to condense.
10
13
  * @returns {string} The condensed ICU string.
11
14
  */
12
15
  export function condenseVars(icuString) {
13
- // Check if the string contains _gt_
14
- if (!icuString.includes(VAR_IDENTIFIER)) {
16
+ // Check if the string contains an indexed _gt_ identifier.
17
+ if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) {
15
18
  return icuString;
16
19
  }
17
20
  // Replace with argument
package/dist/internal.cjs CHANGED
@@ -334,14 +334,17 @@ function extractVars(icuString) {
334
334
  }
335
335
  //#endregion
336
336
  //#region src/derive/condenseVars.ts
337
+ const CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\d+`);
337
338
  /**
338
339
  * Given an indexed ICU string, condenses any select to an argument
340
+ * Unindexed _gt_ source strings and indexed _gt_# translation strings
341
+ * are mutually exclusive.
339
342
  * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
340
343
  * @param {string} icuString - The ICU string to condense.
341
344
  * @returns {string} The condensed ICU string.
342
345
  */
343
346
  function condenseVars(icuString) {
344
- if (!icuString.includes("_gt_")) return icuString;
347
+ if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) return icuString;
345
348
  function visitor(child) {
346
349
  child.type = _formatjs_icu_messageformat_parser_types_js.TYPE.argument;
347
350
  Reflect.deleteProperty(child, "options");
@@ -1 +1 @@
1
- {"version":3,"file":"internal.cjs","names":["TYPE","TYPE","TYPE","bytesToHex","sha256","utf8ToBytes","stringify"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts","../src/backwards-compatability/typeChecking.ts","../src/backwards-compatability/dataConversion.ts","../src/backwards-compatability/oldHashJsxChildren.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n MessageFormatElement,\n parse,\n ParserOptions,\n TYPE,\n} from '@formatjs/icu-messageformat-parser';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport {\n type MessageFormatElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n\n/**\n * @deprecated Use derive() instead.\n *\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` instead of `declareStatic()` for new code. This alias is kept\n * for backwards compatibility and returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing derived content to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${declareStatic(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport const declareStatic = derive;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import {\n type ArgumentElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\nimport { printAST } from '@formatjs/icu-messageformat-parser/printer.js';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n","import { JsxChild, JsxChildren } from '../types';\nimport {\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n} from './oldTypes.js';\nimport { Variable as VariableObject } from '../types';\n\n/**\n * Checks if a JSX child is an old variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is an old variable object (has 'key' property)\n */\nexport function isOldVariableObject(\n child: OldJsxChild | JsxChild\n): child is OldVariableObject {\n return typeof child === 'object' && child != null && 'key' in child;\n}\n\n/**\n * Checks if a JSX child is a new variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is a new variable object (has 'k' property)\n */\nexport function isNewVariableObject(\n child: OldJsxChild | JsxChild\n): child is VariableObject {\n return typeof child === 'object' && child != null && 'k' in child;\n}\n\n/**\n * Checks if a JSX child is an old JSX element format\n * @param child - The JSX child to check.\n * @returns True if the child is an old JSX element (has 'type' and 'props' properties)\n */\nfunction isOldJsxElement(\n child: OldJsxChild | JsxChild\n): child is OldJsxElement {\n return (\n typeof child === 'object' &&\n child != null &&\n 'type' in child &&\n 'props' in child\n );\n}\n\n/**\n * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)\n * @param child - The JSX child to check.\n * @returns True if the child is in the old format.\n */\nfunction isOldJsxChild(child: OldJsxChild | JsxChild): child is OldJsxChild {\n // string\n if (typeof child === 'string') {\n return true;\n }\n\n // variable object\n if (isOldVariableObject(child)) {\n return true;\n }\n\n // element\n return isOldJsxElement(child);\n}\n\n/**\n * Checks if JSX children follow the old format\n * @param children - The JSX children to check (can be string, array, or single child)\n * @returns True if all children are in the old format.\n */\nexport function isOldJsxChildren(\n children: OldJsxChildren | JsxChildren\n): children is OldJsxChildren {\n // string\n if (typeof children === 'string') {\n return true;\n }\n\n // array\n if (Array.isArray(children)) {\n return !children.some((child) => !isOldJsxChild(child));\n }\n\n // object\n return isOldJsxChild(children);\n}\n","import { Variable as VariableObject, VariableType } from '../types';\nimport {\n OldBranchType,\n OldGTProp,\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n OldVariableType,\n} from './oldTypes.js';\nimport { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';\nimport {\n isOldJsxChildren,\n isNewVariableObject,\n isOldVariableObject,\n} from './typeChecking';\n\n/**\n * Convert request data from old format to new format\n */\n\nexport function getNewJsxChild(child: OldJsxChild): JsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isOldVariableObject(child)) {\n return getNewVariableObject(child);\n }\n\n // JsxElement\n return getNewJsxElement(child);\n}\n\nexport function getNewJsxChildren(children: OldJsxChildren): JsxChildren {\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getNewJsxChild);\n }\n\n // Object\n return getNewJsxChild(children);\n}\n\nexport function getNewJsxElement(element: OldJsxElement): JsxElement {\n // string (end case)\n if (typeof element === 'string') {\n return element;\n }\n\n // type\n let t: string | undefined = undefined;\n if (element.type != null) {\n t = element.type;\n }\n // children\n let c: JsxChildren | undefined = undefined;\n if (element.props?.children != null) {\n c = getNewJsxChildren(element.props.children);\n }\n return {\n ...(t && { t }),\n ...(c && { c }),\n d: getNewGTProp(element.props['data-_gt']),\n i: element.props['data-_gt'].id,\n };\n}\n\nexport function getNewBranchType(branch: OldBranchType): 'b' | 'p' {\n if (branch === 'branch') {\n return 'b';\n }\n return 'p';\n}\n\nexport function getNewVariableType(variable: OldVariableType): VariableType {\n switch (variable) {\n case 'number':\n return 'n';\n case 'variable':\n return 'v';\n case 'datetime':\n return 'd';\n case 'currency':\n return 'c';\n default:\n return 'v';\n }\n}\n\nexport function getNewVariableObject(\n variable: OldVariableObject\n): VariableObject {\n // variable type\n let v: VariableType | undefined = undefined;\n if (variable.variable != null) {\n v = getNewVariableType(variable.variable);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.id != null) {\n i = variable.id;\n }\n return {\n k: variable.key,\n ...(v && { v }),\n ...(i && { i }),\n };\n}\n\nexport function getNewGTProp(dataGT: OldGTProp): GTProp {\n // branches\n let b: Record<string, JsxChildren> | undefined = undefined;\n if (dataGT.branches) {\n b = Object.fromEntries(\n Object.entries(dataGT.branches).map(([key, value]) => [\n key,\n getNewJsxChildren(value),\n ])\n );\n }\n // transformation\n let t: 'b' | 'p' | undefined;\n if (dataGT.transformation) {\n t = getNewBranchType(dataGT.transformation);\n }\n return { ...(b && { b }), ...(t && { t }) };\n}\n\n/**\n * Convert response data from current format to old format\n */\n\nexport function getOldJsxChild(child: JsxChild): OldJsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isNewVariableObject(child)) {\n return getOldVariableObject(child);\n }\n\n // JsxElement\n return getOldJsxElement(child);\n}\n\nexport function getOldJsxChildren(\n children: JsxChildren | OldJsxChildren\n): OldJsxChildren {\n // if children is already old, return it\n if (isOldJsxChildren(children)) {\n return children;\n }\n\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getOldJsxChild);\n }\n\n // Object\n return getOldJsxChild(children);\n}\n\nexport function getOldJsxElement(element: JsxElement): OldJsxElement {\n // type (can assume that type will exist here)\n const type: string = element.t as string;\n // children\n let children: OldJsxChildren | undefined = undefined;\n if (element.c != null) {\n children = getOldJsxChildren(element.c);\n }\n // data-_gt (can assume id will exist here)\n const dataGT: OldGTProp = getOldGTProp(element.d || {}, element.i as number);\n return {\n type,\n props: { children, 'data-_gt': dataGT },\n };\n}\n\nexport function getOldBranchType(branch: 'b' | 'p'): OldBranchType {\n if (branch === 'b') {\n return 'branch';\n }\n return 'plural';\n}\n\nexport function getOldVariableType(variable: VariableType): OldVariableType {\n switch (variable) {\n case 'n':\n return 'number';\n case 'v':\n return 'variable';\n case 'd':\n return 'datetime';\n case 'c':\n return 'currency';\n default:\n return 'variable';\n }\n}\n\nexport function getOldVariableObject(\n variable: VariableObject\n): OldVariableObject {\n // variable type\n let v: OldVariableType | undefined = undefined;\n if (variable.v != null) {\n v = getOldVariableType(variable.v);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.i != null) {\n i = variable.i;\n }\n return {\n key: variable.k,\n ...(v && { variable: v }),\n ...(i && { id: i }),\n };\n}\n\nexport function getOldGTProp(dataGT: GTProp, i: number): OldGTProp {\n // transformation\n let transformation: OldBranchType | undefined = undefined;\n if (dataGT.t != null) {\n transformation = getOldBranchType(dataGT.t);\n }\n // branches\n let branches: Record<string, OldJsxChildren> | undefined = undefined;\n if (dataGT.b != null) {\n branches = Object.fromEntries(\n Object.entries(dataGT.b).map(([key, value]) => [\n key,\n getOldJsxChildren(value),\n ])\n );\n }\n return {\n id: i,\n ...(transformation && { transformation }),\n ...(branches && { branches }),\n };\n}\n","// Functions provided to other GT libraries\n\nimport { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using SHA-256.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} The resulting hash as a hexadecimal string.\n */\nexport function oldHashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string)));\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} context - The context for the children.\n * @param {string} id - The ID for the JSX children object.\n * @param {function} hashFunction - Custom hash function.\n * @returns {string} - The unique hash of the children.\n */\nexport function oldHashJsxChildren(\n {\n source,\n context,\n id,\n dataFormat,\n }: {\n source: OldJsxChildren;\n context?: string;\n id?: string;\n dataFormat: string;\n },\n hashFunction: (string: string) => string = oldHashString\n): string {\n const unhashedKey = stringify({\n source: sanitizeJsxChildren(source),\n ...(id && { id }),\n ...(context && { context }),\n ...(dataFormat && { dataFormat }),\n });\n return hashFunction(unhashedKey);\n}\n\ntype SanitizedVariable = Omit<OldVariableObject, 'id'>;\n\ntype SanitizedElement = {\n branches?: {\n [k: string]: SanitizedChildren;\n };\n children?: SanitizedChildren;\n transformation?: string;\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\nconst sanitizeChild = (child: OldJsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n if ('props' in child) {\n const newChild: SanitizedChild = {};\n const dataGt = child?.props?.['data-_gt'];\n if (dataGt?.branches) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.branches = Object.fromEntries(\n Object.entries(dataGt.branches).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as OldJsxChildren),\n ])\n );\n }\n if (child?.props?.children) {\n newChild.children = sanitizeJsxChildren(child.props.children);\n }\n if (child?.props?.['data-_gt']?.transformation) {\n newChild.transformation = child.props['data-_gt'].transformation;\n }\n return newChild;\n }\n if ('key' in child) {\n return {\n key: child.key,\n ...(child.variable && {\n variable: child.variable,\n }),\n };\n }\n }\n return child as string;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: OldJsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACDnE,SAAwB,eACtB,GACA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,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,WAAW,CACpD,KACA,oBAAoB,MAAwB,CAC7C,CAAC,CACH;AAEH,OAAI,OAAO,OAAO,SAChB,UAAS,WAAW,oBAAoB,MAAM,MAAM,SAAS;AAE/D,OAAI,OAAO,QAAQ,aAAa,eAC9B,UAAS,iBAAiB,MAAM,MAAM,YAAY;AAEpD,UAAO;;AAET,MAAI,SAAS,MACX,QAAO;GACL,KAAK,MAAM;GACX,GAAI,MAAM,YAAY,EACpB,UAAU,MAAM,UACjB;GACF;;AAGL,QAAO;;AAGT,SAAS,oBACP,mBACmB;AACnB,QAAO,MAAM,QAAQ,kBAAkB,GACnC,kBAAkB,IAAI,cAAc,GACpC,cAAc,kBAAkB"}
1
+ {"version":3,"file":"internal.cjs","names":["TYPE","TYPE","TYPE","bytesToHex","sha256","utf8ToBytes","stringify"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts","../src/backwards-compatability/typeChecking.ts","../src/backwards-compatability/dataConversion.ts","../src/backwards-compatability/oldHashJsxChildren.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n MessageFormatElement,\n parse,\n ParserOptions,\n TYPE,\n} from '@formatjs/icu-messageformat-parser';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport {\n type MessageFormatElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n\n/**\n * @deprecated Use derive() instead.\n *\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` instead of `declareStatic()` for new code. This alias is kept\n * for backwards compatibility and returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing derived content to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${declareStatic(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport const declareStatic = derive;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import {\n type ArgumentElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\nimport { printAST } from '@formatjs/icu-messageformat-parser/printer.js';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\nconst CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\\\d+`);\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * Unindexed _gt_ source strings and indexed _gt_# translation strings\n * are mutually exclusive.\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains an indexed _gt_ identifier.\n if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n","import { JsxChild, JsxChildren } from '../types';\nimport {\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n} from './oldTypes.js';\nimport { Variable as VariableObject } from '../types';\n\n/**\n * Checks if a JSX child is an old variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is an old variable object (has 'key' property)\n */\nexport function isOldVariableObject(\n child: OldJsxChild | JsxChild\n): child is OldVariableObject {\n return typeof child === 'object' && child != null && 'key' in child;\n}\n\n/**\n * Checks if a JSX child is a new variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is a new variable object (has 'k' property)\n */\nexport function isNewVariableObject(\n child: OldJsxChild | JsxChild\n): child is VariableObject {\n return typeof child === 'object' && child != null && 'k' in child;\n}\n\n/**\n * Checks if a JSX child is an old JSX element format\n * @param child - The JSX child to check.\n * @returns True if the child is an old JSX element (has 'type' and 'props' properties)\n */\nfunction isOldJsxElement(\n child: OldJsxChild | JsxChild\n): child is OldJsxElement {\n return (\n typeof child === 'object' &&\n child != null &&\n 'type' in child &&\n 'props' in child\n );\n}\n\n/**\n * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)\n * @param child - The JSX child to check.\n * @returns True if the child is in the old format.\n */\nfunction isOldJsxChild(child: OldJsxChild | JsxChild): child is OldJsxChild {\n // string\n if (typeof child === 'string') {\n return true;\n }\n\n // variable object\n if (isOldVariableObject(child)) {\n return true;\n }\n\n // element\n return isOldJsxElement(child);\n}\n\n/**\n * Checks if JSX children follow the old format\n * @param children - The JSX children to check (can be string, array, or single child)\n * @returns True if all children are in the old format.\n */\nexport function isOldJsxChildren(\n children: OldJsxChildren | JsxChildren\n): children is OldJsxChildren {\n // string\n if (typeof children === 'string') {\n return true;\n }\n\n // array\n if (Array.isArray(children)) {\n return !children.some((child) => !isOldJsxChild(child));\n }\n\n // object\n return isOldJsxChild(children);\n}\n","import { Variable as VariableObject, VariableType } from '../types';\nimport {\n OldBranchType,\n OldGTProp,\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n OldVariableType,\n} from './oldTypes.js';\nimport { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';\nimport {\n isOldJsxChildren,\n isNewVariableObject,\n isOldVariableObject,\n} from './typeChecking';\n\n/**\n * Convert request data from old format to new format\n */\n\nexport function getNewJsxChild(child: OldJsxChild): JsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isOldVariableObject(child)) {\n return getNewVariableObject(child);\n }\n\n // JsxElement\n return getNewJsxElement(child);\n}\n\nexport function getNewJsxChildren(children: OldJsxChildren): JsxChildren {\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getNewJsxChild);\n }\n\n // Object\n return getNewJsxChild(children);\n}\n\nexport function getNewJsxElement(element: OldJsxElement): JsxElement {\n // string (end case)\n if (typeof element === 'string') {\n return element;\n }\n\n // type\n let t: string | undefined = undefined;\n if (element.type != null) {\n t = element.type;\n }\n // children\n let c: JsxChildren | undefined = undefined;\n if (element.props?.children != null) {\n c = getNewJsxChildren(element.props.children);\n }\n return {\n ...(t && { t }),\n ...(c && { c }),\n d: getNewGTProp(element.props['data-_gt']),\n i: element.props['data-_gt'].id,\n };\n}\n\nexport function getNewBranchType(branch: OldBranchType): 'b' | 'p' {\n if (branch === 'branch') {\n return 'b';\n }\n return 'p';\n}\n\nexport function getNewVariableType(variable: OldVariableType): VariableType {\n switch (variable) {\n case 'number':\n return 'n';\n case 'variable':\n return 'v';\n case 'datetime':\n return 'd';\n case 'currency':\n return 'c';\n default:\n return 'v';\n }\n}\n\nexport function getNewVariableObject(\n variable: OldVariableObject\n): VariableObject {\n // variable type\n let v: VariableType | undefined = undefined;\n if (variable.variable != null) {\n v = getNewVariableType(variable.variable);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.id != null) {\n i = variable.id;\n }\n return {\n k: variable.key,\n ...(v && { v }),\n ...(i && { i }),\n };\n}\n\nexport function getNewGTProp(dataGT: OldGTProp): GTProp {\n // branches\n let b: Record<string, JsxChildren> | undefined = undefined;\n if (dataGT.branches) {\n b = Object.fromEntries(\n Object.entries(dataGT.branches).map(([key, value]) => [\n key,\n getNewJsxChildren(value),\n ])\n );\n }\n // transformation\n let t: 'b' | 'p' | undefined;\n if (dataGT.transformation) {\n t = getNewBranchType(dataGT.transformation);\n }\n return { ...(b && { b }), ...(t && { t }) };\n}\n\n/**\n * Convert response data from current format to old format\n */\n\nexport function getOldJsxChild(child: JsxChild): OldJsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isNewVariableObject(child)) {\n return getOldVariableObject(child);\n }\n\n // JsxElement\n return getOldJsxElement(child);\n}\n\nexport function getOldJsxChildren(\n children: JsxChildren | OldJsxChildren\n): OldJsxChildren {\n // if children is already old, return it\n if (isOldJsxChildren(children)) {\n return children;\n }\n\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getOldJsxChild);\n }\n\n // Object\n return getOldJsxChild(children);\n}\n\nexport function getOldJsxElement(element: JsxElement): OldJsxElement {\n // type (can assume that type will exist here)\n const type: string = element.t as string;\n // children\n let children: OldJsxChildren | undefined = undefined;\n if (element.c != null) {\n children = getOldJsxChildren(element.c);\n }\n // data-_gt (can assume id will exist here)\n const dataGT: OldGTProp = getOldGTProp(element.d || {}, element.i as number);\n return {\n type,\n props: { children, 'data-_gt': dataGT },\n };\n}\n\nexport function getOldBranchType(branch: 'b' | 'p'): OldBranchType {\n if (branch === 'b') {\n return 'branch';\n }\n return 'plural';\n}\n\nexport function getOldVariableType(variable: VariableType): OldVariableType {\n switch (variable) {\n case 'n':\n return 'number';\n case 'v':\n return 'variable';\n case 'd':\n return 'datetime';\n case 'c':\n return 'currency';\n default:\n return 'variable';\n }\n}\n\nexport function getOldVariableObject(\n variable: VariableObject\n): OldVariableObject {\n // variable type\n let v: OldVariableType | undefined = undefined;\n if (variable.v != null) {\n v = getOldVariableType(variable.v);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.i != null) {\n i = variable.i;\n }\n return {\n key: variable.k,\n ...(v && { variable: v }),\n ...(i && { id: i }),\n };\n}\n\nexport function getOldGTProp(dataGT: GTProp, i: number): OldGTProp {\n // transformation\n let transformation: OldBranchType | undefined = undefined;\n if (dataGT.t != null) {\n transformation = getOldBranchType(dataGT.t);\n }\n // branches\n let branches: Record<string, OldJsxChildren> | undefined = undefined;\n if (dataGT.b != null) {\n branches = Object.fromEntries(\n Object.entries(dataGT.b).map(([key, value]) => [\n key,\n getOldJsxChildren(value),\n ])\n );\n }\n return {\n id: i,\n ...(transformation && { transformation }),\n ...(branches && { branches }),\n };\n}\n","// Functions provided to other GT libraries\n\nimport { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using SHA-256.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} The resulting hash as a hexadecimal string.\n */\nexport function oldHashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string)));\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} context - The context for the children.\n * @param {string} id - The ID for the JSX children object.\n * @param {function} hashFunction - Custom hash function.\n * @returns {string} - The unique hash of the children.\n */\nexport function oldHashJsxChildren(\n {\n source,\n context,\n id,\n dataFormat,\n }: {\n source: OldJsxChildren;\n context?: string;\n id?: string;\n dataFormat: string;\n },\n hashFunction: (string: string) => string = oldHashString\n): string {\n const unhashedKey = stringify({\n source: sanitizeJsxChildren(source),\n ...(id && { id }),\n ...(context && { context }),\n ...(dataFormat && { dataFormat }),\n });\n return hashFunction(unhashedKey);\n}\n\ntype SanitizedVariable = Omit<OldVariableObject, 'id'>;\n\ntype SanitizedElement = {\n branches?: {\n [k: string]: SanitizedChildren;\n };\n children?: SanitizedChildren;\n transformation?: string;\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\nconst sanitizeChild = (child: OldJsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n if ('props' in child) {\n const newChild: SanitizedChild = {};\n const dataGt = child?.props?.['data-_gt'];\n if (dataGt?.branches) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.branches = Object.fromEntries(\n Object.entries(dataGt.branches).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as OldJsxChildren),\n ])\n );\n }\n if (child?.props?.children) {\n newChild.children = sanitizeJsxChildren(child.props.children);\n }\n if (child?.props?.['data-_gt']?.transformation) {\n newChild.transformation = child.props['data-_gt'].transformation;\n }\n return newChild;\n }\n if ('key' in child) {\n return {\n key: child.key,\n ...(child.variable && {\n variable: child.variable,\n }),\n };\n }\n }\n return child as string;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: OldJsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACDnE,SAAwB,eACtB,GACA,QAA+B,aAC/B,UAAoB,CAAA,KAAsB,EACzB;CAEjB,MAA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AAQ,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,WAAW,CACpD,KACA,oBAAoB,MAAwB,CAC7C,CAAC,CACH;AAEH,OAAI,OAAO,OAAO,SAChB,UAAS,WAAW,oBAAoB,MAAM,MAAM,SAAS;AAE/D,OAAI,OAAO,QAAQ,aAAa,eAC9B,UAAS,iBAAiB,MAAM,MAAM,YAAY;AAEpD,UAAO;;AAET,MAAI,SAAS,MACX,QAAO;GACL,KAAK,MAAM;GACX,GAAI,MAAM,YAAY,EACpB,UAAU,MAAM,UACjB;GACF;;AAGL,QAAO;;AAGT,SAAS,oBACP,mBACmB;AACnB,QAAO,MAAM,QAAQ,kBAAkB,GACnC,kBAAkB,IAAI,cAAc,GACpC,cAAc,kBAAkB"}
@@ -201,6 +201,8 @@ declare function extractVars(icuString: string): Record<string, string>;
201
201
  //#region src/derive/condenseVars.d.ts
202
202
  /**
203
203
  * Given an indexed ICU string, condenses any select to an argument
204
+ * Unindexed _gt_ source strings and indexed _gt_# translation strings
205
+ * are mutually exclusive.
204
206
  * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
205
207
  * @param {string} icuString - The ICU string to condense.
206
208
  * @returns {string} The condensed ICU string.
@@ -201,6 +201,8 @@ declare function extractVars(icuString: string): Record<string, string>;
201
201
  //#region src/derive/condenseVars.d.ts
202
202
  /**
203
203
  * Given an indexed ICU string, condenses any select to an argument
204
+ * Unindexed _gt_ source strings and indexed _gt_# translation strings
205
+ * are mutually exclusive.
204
206
  * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
205
207
  * @param {string} icuString - The ICU string to condense.
206
208
  * @returns {string} The condensed ICU string.
package/dist/internal.mjs CHANGED
@@ -335,14 +335,17 @@ function extractVars(icuString) {
335
335
  }
336
336
  //#endregion
337
337
  //#region src/derive/condenseVars.ts
338
+ const CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\d+`);
338
339
  /**
339
340
  * Given an indexed ICU string, condenses any select to an argument
341
+ * Unindexed _gt_ source strings and indexed _gt_# translation strings
342
+ * are mutually exclusive.
340
343
  * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'
341
344
  * @param {string} icuString - The ICU string to condense.
342
345
  * @returns {string} The condensed ICU string.
343
346
  */
344
347
  function condenseVars(icuString) {
345
- if (!icuString.includes("_gt_")) return icuString;
348
+ if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) return icuString;
346
349
  function visitor(child) {
347
350
  child.type = TYPE$1.argument;
348
351
  Reflect.deleteProperty(child, "options");
@@ -1 +1 @@
1
- {"version":3,"file":"internal.mjs","names":["TYPE","TYPE","stringify"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts","../src/backwards-compatability/typeChecking.ts","../src/backwards-compatability/dataConversion.ts","../src/backwards-compatability/oldHashJsxChildren.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n MessageFormatElement,\n parse,\n ParserOptions,\n TYPE,\n} from '@formatjs/icu-messageformat-parser';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport {\n type MessageFormatElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n\n/**\n * @deprecated Use derive() instead.\n *\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` instead of `declareStatic()` for new code. This alias is kept\n * for backwards compatibility and returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing derived content to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${declareStatic(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport const declareStatic = derive;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import {\n type ArgumentElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\nimport { printAST } from '@formatjs/icu-messageformat-parser/printer.js';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n","import { JsxChild, JsxChildren } from '../types';\nimport {\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n} from './oldTypes.js';\nimport { Variable as VariableObject } from '../types';\n\n/**\n * Checks if a JSX child is an old variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is an old variable object (has 'key' property)\n */\nexport function isOldVariableObject(\n child: OldJsxChild | JsxChild\n): child is OldVariableObject {\n return typeof child === 'object' && child != null && 'key' in child;\n}\n\n/**\n * Checks if a JSX child is a new variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is a new variable object (has 'k' property)\n */\nexport function isNewVariableObject(\n child: OldJsxChild | JsxChild\n): child is VariableObject {\n return typeof child === 'object' && child != null && 'k' in child;\n}\n\n/**\n * Checks if a JSX child is an old JSX element format\n * @param child - The JSX child to check.\n * @returns True if the child is an old JSX element (has 'type' and 'props' properties)\n */\nfunction isOldJsxElement(\n child: OldJsxChild | JsxChild\n): child is OldJsxElement {\n return (\n typeof child === 'object' &&\n child != null &&\n 'type' in child &&\n 'props' in child\n );\n}\n\n/**\n * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)\n * @param child - The JSX child to check.\n * @returns True if the child is in the old format.\n */\nfunction isOldJsxChild(child: OldJsxChild | JsxChild): child is OldJsxChild {\n // string\n if (typeof child === 'string') {\n return true;\n }\n\n // variable object\n if (isOldVariableObject(child)) {\n return true;\n }\n\n // element\n return isOldJsxElement(child);\n}\n\n/**\n * Checks if JSX children follow the old format\n * @param children - The JSX children to check (can be string, array, or single child)\n * @returns True if all children are in the old format.\n */\nexport function isOldJsxChildren(\n children: OldJsxChildren | JsxChildren\n): children is OldJsxChildren {\n // string\n if (typeof children === 'string') {\n return true;\n }\n\n // array\n if (Array.isArray(children)) {\n return !children.some((child) => !isOldJsxChild(child));\n }\n\n // object\n return isOldJsxChild(children);\n}\n","import { Variable as VariableObject, VariableType } from '../types';\nimport {\n OldBranchType,\n OldGTProp,\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n OldVariableType,\n} from './oldTypes.js';\nimport { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';\nimport {\n isOldJsxChildren,\n isNewVariableObject,\n isOldVariableObject,\n} from './typeChecking';\n\n/**\n * Convert request data from old format to new format\n */\n\nexport function getNewJsxChild(child: OldJsxChild): JsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isOldVariableObject(child)) {\n return getNewVariableObject(child);\n }\n\n // JsxElement\n return getNewJsxElement(child);\n}\n\nexport function getNewJsxChildren(children: OldJsxChildren): JsxChildren {\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getNewJsxChild);\n }\n\n // Object\n return getNewJsxChild(children);\n}\n\nexport function getNewJsxElement(element: OldJsxElement): JsxElement {\n // string (end case)\n if (typeof element === 'string') {\n return element;\n }\n\n // type\n let t: string | undefined = undefined;\n if (element.type != null) {\n t = element.type;\n }\n // children\n let c: JsxChildren | undefined = undefined;\n if (element.props?.children != null) {\n c = getNewJsxChildren(element.props.children);\n }\n return {\n ...(t && { t }),\n ...(c && { c }),\n d: getNewGTProp(element.props['data-_gt']),\n i: element.props['data-_gt'].id,\n };\n}\n\nexport function getNewBranchType(branch: OldBranchType): 'b' | 'p' {\n if (branch === 'branch') {\n return 'b';\n }\n return 'p';\n}\n\nexport function getNewVariableType(variable: OldVariableType): VariableType {\n switch (variable) {\n case 'number':\n return 'n';\n case 'variable':\n return 'v';\n case 'datetime':\n return 'd';\n case 'currency':\n return 'c';\n default:\n return 'v';\n }\n}\n\nexport function getNewVariableObject(\n variable: OldVariableObject\n): VariableObject {\n // variable type\n let v: VariableType | undefined = undefined;\n if (variable.variable != null) {\n v = getNewVariableType(variable.variable);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.id != null) {\n i = variable.id;\n }\n return {\n k: variable.key,\n ...(v && { v }),\n ...(i && { i }),\n };\n}\n\nexport function getNewGTProp(dataGT: OldGTProp): GTProp {\n // branches\n let b: Record<string, JsxChildren> | undefined = undefined;\n if (dataGT.branches) {\n b = Object.fromEntries(\n Object.entries(dataGT.branches).map(([key, value]) => [\n key,\n getNewJsxChildren(value),\n ])\n );\n }\n // transformation\n let t: 'b' | 'p' | undefined;\n if (dataGT.transformation) {\n t = getNewBranchType(dataGT.transformation);\n }\n return { ...(b && { b }), ...(t && { t }) };\n}\n\n/**\n * Convert response data from current format to old format\n */\n\nexport function getOldJsxChild(child: JsxChild): OldJsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isNewVariableObject(child)) {\n return getOldVariableObject(child);\n }\n\n // JsxElement\n return getOldJsxElement(child);\n}\n\nexport function getOldJsxChildren(\n children: JsxChildren | OldJsxChildren\n): OldJsxChildren {\n // if children is already old, return it\n if (isOldJsxChildren(children)) {\n return children;\n }\n\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getOldJsxChild);\n }\n\n // Object\n return getOldJsxChild(children);\n}\n\nexport function getOldJsxElement(element: JsxElement): OldJsxElement {\n // type (can assume that type will exist here)\n const type: string = element.t as string;\n // children\n let children: OldJsxChildren | undefined = undefined;\n if (element.c != null) {\n children = getOldJsxChildren(element.c);\n }\n // data-_gt (can assume id will exist here)\n const dataGT: OldGTProp = getOldGTProp(element.d || {}, element.i as number);\n return {\n type,\n props: { children, 'data-_gt': dataGT },\n };\n}\n\nexport function getOldBranchType(branch: 'b' | 'p'): OldBranchType {\n if (branch === 'b') {\n return 'branch';\n }\n return 'plural';\n}\n\nexport function getOldVariableType(variable: VariableType): OldVariableType {\n switch (variable) {\n case 'n':\n return 'number';\n case 'v':\n return 'variable';\n case 'd':\n return 'datetime';\n case 'c':\n return 'currency';\n default:\n return 'variable';\n }\n}\n\nexport function getOldVariableObject(\n variable: VariableObject\n): OldVariableObject {\n // variable type\n let v: OldVariableType | undefined = undefined;\n if (variable.v != null) {\n v = getOldVariableType(variable.v);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.i != null) {\n i = variable.i;\n }\n return {\n key: variable.k,\n ...(v && { variable: v }),\n ...(i && { id: i }),\n };\n}\n\nexport function getOldGTProp(dataGT: GTProp, i: number): OldGTProp {\n // transformation\n let transformation: OldBranchType | undefined = undefined;\n if (dataGT.t != null) {\n transformation = getOldBranchType(dataGT.t);\n }\n // branches\n let branches: Record<string, OldJsxChildren> | undefined = undefined;\n if (dataGT.b != null) {\n branches = Object.fromEntries(\n Object.entries(dataGT.b).map(([key, value]) => [\n key,\n getOldJsxChildren(value),\n ])\n );\n }\n return {\n id: i,\n ...(transformation && { transformation }),\n ...(branches && { branches }),\n };\n}\n","// Functions provided to other GT libraries\n\nimport { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using SHA-256.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} The resulting hash as a hexadecimal string.\n */\nexport function oldHashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string)));\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} context - The context for the children.\n * @param {string} id - The ID for the JSX children object.\n * @param {function} hashFunction - Custom hash function.\n * @returns {string} - The unique hash of the children.\n */\nexport function oldHashJsxChildren(\n {\n source,\n context,\n id,\n dataFormat,\n }: {\n source: OldJsxChildren;\n context?: string;\n id?: string;\n dataFormat: string;\n },\n hashFunction: (string: string) => string = oldHashString\n): string {\n const unhashedKey = stringify({\n source: sanitizeJsxChildren(source),\n ...(id && { id }),\n ...(context && { context }),\n ...(dataFormat && { dataFormat }),\n });\n return hashFunction(unhashedKey);\n}\n\ntype SanitizedVariable = Omit<OldVariableObject, 'id'>;\n\ntype SanitizedElement = {\n branches?: {\n [k: string]: SanitizedChildren;\n };\n children?: SanitizedChildren;\n transformation?: string;\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\nconst sanitizeChild = (child: OldJsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n if ('props' in child) {\n const newChild: SanitizedChild = {};\n const dataGt = child?.props?.['data-_gt'];\n if (dataGt?.branches) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.branches = Object.fromEntries(\n Object.entries(dataGt.branches).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as OldJsxChildren),\n ])\n );\n }\n if (child?.props?.children) {\n newChild.children = sanitizeJsxChildren(child.props.children);\n }\n if (child?.props?.['data-_gt']?.transformation) {\n newChild.transformation = child.props['data-_gt'].transformation;\n }\n return newChild;\n }\n if ('key' in child) {\n return {\n key: child.key,\n ...(child.variable && {\n variable: child.variable,\n }),\n };\n }\n }\n return child as string;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: OldJsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n"],"mappings":";;;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACDnE,SAAwB,eACtB,GACA,QAA+B,aAC/B,UAAoB,CAAA,KAAsB,EACzB;CAEjB,MAAM,wBADc,qBAAqB,QACA,CAAC,OAAO,EAAE;CAEnD,MAAM,OAAO,KAAK,IAAI,EAAE;AAExB,KAAI,SAAS,KAAK,MAAM,SAAS,OAAO,CAAE,QAAO;AAEjD,KAAI,SAAS,GAAG;AACd,MAAI,MAAM,SAAS,WAAW,CAAE,QAAO;AACvC,MAAI,MAAM,SAAS,MAAM,CAAE,QAAO;;AAEpC,KAAI,0BA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AkB"}
1
+ {"version":3,"file":"internal.mjs","names":["TYPE","TYPE","stringify"],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/utils/traverseIcu.ts","../src/derive/utils/constants.ts","../src/derive/utils/regex.ts","../src/derive/utils/traverseHelpers.ts","../src/derive/decodeVars.ts","../src/derive/utils/sanitizeVar.ts","../src/derive/declareVar.ts","../src/derive/derive.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts","../src/backwards-compatability/typeChecking.ts","../src/backwards-compatability/dataConversion.ts","../src/backwards-compatability/oldHashJsxChildren.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n MessageFormatElement,\n parse,\n ParserOptions,\n TYPE,\n} from '@formatjs/icu-messageformat-parser';\n\ntype TraverseIcuOptions = ParserOptions & {\n recurseIntoVisited?: boolean;\n};\n\n/**\n * Given an ICU string, traverse the AST and call the visitor function for each element that matches the type T\n * @param icu - The ICU string to traverse\n * @param shouldVisit - A function that returns true if the element should be visited\n * @param visitor - A function that is called for each element that matches the type T\n * @returns The modified AST of the ICU string.\n *\n * @note This function is a heavy operation, use sparingly\n */\nexport function traverseIcu<T extends MessageFormatElement>({\n icuString,\n shouldVisit,\n visitor,\n options: { recurseIntoVisited = true, ...otherOptions },\n}: {\n icuString: string;\n shouldVisit: (element: MessageFormatElement) => element is T;\n visitor: (element: T) => void;\n options: TraverseIcuOptions;\n}): MessageFormatElement[] {\n const ast = parse(icuString, otherOptions);\n handleChildren(ast);\n return ast;\n\n function handleChildren(children: MessageFormatElement[]): void {\n children.map(handleChild);\n }\n\n function handleChild(child: MessageFormatElement) {\n // handle select var\n let visited = false;\n if (shouldVisit(child)) {\n visitor(child);\n visited = true;\n }\n // recurse on children\n if (!visited || recurseIntoVisited) {\n if (child.type === TYPE.select || child.type === TYPE.plural) {\n Object.values(child.options)\n .map((option) => option.value)\n .map(handleChildren);\n } else if (child.type === TYPE.tag) {\n handleChildren(child.children);\n }\n }\n }\n}\n","export const VAR_IDENTIFIER = '_gt_';\nexport const VAR_NAME_IDENTIFIER = '_gt_var_name';\n","import { VAR_IDENTIFIER } from './constants';\n\n// Regex for _gt_# select\nexport const GT_INDEXED_IDENTIFIER_REGEX = new RegExp(\n `^${VAR_IDENTIFIER}\\\\d+$`\n);\n\nexport const GT_UNINDEXED_IDENTIFIER_REGEX = new RegExp(`^${VAR_IDENTIFIER}$`);\n","import {\n GT_INDEXED_IDENTIFIER_REGEX,\n GT_UNINDEXED_IDENTIFIER_REGEX,\n} from './regex';\nimport { GTIndexedSelectElement, GTUnindexedSelectElement } from './types';\nimport {\n type MessageFormatElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\n\n// Visit any _gt_# select\nexport function isGTIndexedSelectElement(\n child: MessageFormatElement\n): child is GTIndexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_INDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n\n// Visit any _gt_ select\nexport function isGTUnindexedSelectElement(\n child: MessageFormatElement\n): child is GTUnindexedSelectElement {\n return (\n child.type === TYPE.select &&\n GT_UNINDEXED_IDENTIFIER_REGEX.test(child.value) &&\n !!child.options.other &&\n (child.options.other.value.length === 0 ||\n (child.options.other.value.length > 0 &&\n child.options.other.value[0]?.type === TYPE.literal))\n );\n}\n","import { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\n\ntype Location = {\n start: number;\n end: number;\n value: string;\n};\n\n/**\n * Given an encoded ICU string, interpolate only _gt_ variables that have been marked with declareVar()\n * @example\n * const encodedIcu = \"Hi\" + declareVar(\"Brian\") + \", my name is {name}\"\n * // 'Hi {_gt_, select, other {Brian}}, my name is {name}'\n * decodeVars(encodedIcu)\n * // 'Hi Brian, my name is {name}'\n */\nexport function decodeVars(icuString: string): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n value:\n child.options.other.value.length > 0\n ? child.options.other.value[0].value\n : '',\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: {\n recurseIntoVisited: false,\n captureLocation: true,\n },\n });\n\n // Construct output string\n let previousIndex = 0;\n const outputList = [];\n for (let i = 0; i < variableLocations.length; i++) {\n outputList.push(icuString.slice(previousIndex, variableLocations[i].start));\n outputList.push(variableLocations[i].value);\n previousIndex = variableLocations[i].end;\n }\n if (previousIndex < icuString.length) {\n outputList.push(icuString.slice(previousIndex));\n }\n const outputString = outputList.join('');\n\n return outputString;\n}\n","/**\n * Sanitizes string by escaping ICU syntax\n *\n * Sanitize arbitrary string so it does not break the following ICU message syntax:\n * {_gt_, select, other {string_here}}\n *\n * Escapes ICU special characters by:\n * 1. Doubling all single quotes (U+0027 ')\n * 2. Adding a single quote before the first special character ({}<>)\n * 3. Adding a single quote after the last special character ({}<>)\n */\nexport function sanitizeVar(string: string): string {\n // First, double all single quotes (both ASCII and Unicode).\n let result = string.replace(/'/g, \"''\");\n\n // Find first and last positions of special characters\n const specialChars = /[{}<>]/;\n const firstSpecialIndex = result.search(specialChars);\n\n if (firstSpecialIndex === -1) {\n // No special characters; return with just doubled quotes.\n return result;\n }\n\n // Find last special character position\n let lastSpecialIndex = -1;\n for (let i = result.length - 1; i >= 0; i--) {\n if (specialChars.test(result[i])) {\n lastSpecialIndex = i;\n break;\n }\n }\n\n // Insert quotes around the special character region.\n result =\n result.slice(0, firstSpecialIndex) +\n \"'\" +\n result.slice(firstSpecialIndex, lastSpecialIndex + 1) +\n \"'\" +\n result.slice(lastSpecialIndex + 1);\n\n return result;\n}\n","import { VAR_IDENTIFIER, VAR_NAME_IDENTIFIER } from './utils/constants';\nimport { sanitizeVar } from './utils/sanitizeVar';\n\n/**\n * Mark as a non-translatable string. Use within a derive() call to mark content as not derivable (e.g., not possible to statically analyze).\n *\n * @example\n * function nonDerivableFunction() {\n * return Math.random();\n * }\n *\n * function derivableFunction() {\n * if (condition) {\n * return declareVar(nonDerivableFunction())\n * }\n * return 'John Doe';\n * }\n *\n * const gt = useGT();\n * gt(`My name is ${derive(derivableFunction())}`);\n *\n * @param {string | number | boolean | null | undefined} variable - The variable to sanitize.\n * @param {Object} [options] - The options for the sanitization.\n * @param {string} [options.$name] - The name of the variable.\n * @returns {string} The sanitized value.\n */\nexport function declareVar(\n variable: string | number | boolean | null | undefined,\n options?: { $name?: string }\n): string {\n // Variable section.\n const sanitizedVariable = sanitizeVar(String(variable ?? ''));\n const variableSection = ` other {${sanitizedVariable}}`;\n\n // Name section.\n let nameSection = '';\n if (options?.$name) {\n const sanitizedName = sanitizeVar(options.$name);\n nameSection = ` ${VAR_NAME_IDENTIFIER} {${sanitizedName}}`;\n }\n\n // interpolate\n return `{${VAR_IDENTIFIER}, select,${variableSection}${nameSection}}`;\n}\n","/**\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` when a translation string or context needs content that is\n * computed from source code, but should still be discovered during extraction\n * instead of treated as a runtime interpolation variable. The CLI attempts to\n * resolve the derivable expression into every possible static value and\n * includes those values in the source content that gets translated.\n *\n * `derive()` returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing `derive()` calls to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${derive(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport function derive<T extends string | boolean | number | null | undefined>(\n content: T\n): T {\n return content;\n}\n\n/**\n * @deprecated Use derive() instead.\n *\n * Marks content as derivable by the GT compiler and CLI.\n *\n * Use `derive()` instead of `declareStatic()` for new code. This alias is kept\n * for backwards compatibility and returns its argument unchanged at runtime.\n *\n * Run `gt validate` after adding or changing derived content to verify that\n * each derivable expression can be resolved by the CLI before translating or\n * building.\n *\n * @example\n * ```jsx\n * function getSubject() {\n * return (Math.random() > 0.5) ? \"Alice\" : \"Brian\";\n * }\n * ...\n * gt(`My name is ${declareStatic(getSubject())}`);\n * ```\n *\n * @param {T extends string | boolean | number | null | undefined} content - Content to derive for translation extraction.\n * @returns {T} The same content, unchanged at runtime.\n */\nexport const declareStatic = derive;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import {\n type ArgumentElement,\n TYPE,\n} from '@formatjs/icu-messageformat-parser/types.js';\nimport { printAST } from '@formatjs/icu-messageformat-parser/printer.js';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\nconst CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\\\d+`);\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * Unindexed _gt_ source strings and indexed _gt_# translation strings\n * are mutually exclusive.\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains an indexed _gt_ identifier.\n if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n","import { JsxChild, JsxChildren } from '../types';\nimport {\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n} from './oldTypes.js';\nimport { Variable as VariableObject } from '../types';\n\n/**\n * Checks if a JSX child is an old variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is an old variable object (has 'key' property)\n */\nexport function isOldVariableObject(\n child: OldJsxChild | JsxChild\n): child is OldVariableObject {\n return typeof child === 'object' && child != null && 'key' in child;\n}\n\n/**\n * Checks if a JSX child is a new variable object format\n * @param child - The JSX child to check.\n * @returns True if the child is a new variable object (has 'k' property)\n */\nexport function isNewVariableObject(\n child: OldJsxChild | JsxChild\n): child is VariableObject {\n return typeof child === 'object' && child != null && 'k' in child;\n}\n\n/**\n * Checks if a JSX child is an old JSX element format\n * @param child - The JSX child to check.\n * @returns True if the child is an old JSX element (has 'type' and 'props' properties)\n */\nfunction isOldJsxElement(\n child: OldJsxChild | JsxChild\n): child is OldJsxElement {\n return (\n typeof child === 'object' &&\n child != null &&\n 'type' in child &&\n 'props' in child\n );\n}\n\n/**\n * Checks if a JSX child follows the old format (string, old variable object, or old JSX element)\n * @param child - The JSX child to check.\n * @returns True if the child is in the old format.\n */\nfunction isOldJsxChild(child: OldJsxChild | JsxChild): child is OldJsxChild {\n // string\n if (typeof child === 'string') {\n return true;\n }\n\n // variable object\n if (isOldVariableObject(child)) {\n return true;\n }\n\n // element\n return isOldJsxElement(child);\n}\n\n/**\n * Checks if JSX children follow the old format\n * @param children - The JSX children to check (can be string, array, or single child)\n * @returns True if all children are in the old format.\n */\nexport function isOldJsxChildren(\n children: OldJsxChildren | JsxChildren\n): children is OldJsxChildren {\n // string\n if (typeof children === 'string') {\n return true;\n }\n\n // array\n if (Array.isArray(children)) {\n return !children.some((child) => !isOldJsxChild(child));\n }\n\n // object\n return isOldJsxChild(children);\n}\n","import { Variable as VariableObject, VariableType } from '../types';\nimport {\n OldBranchType,\n OldGTProp,\n OldJsxChild,\n OldJsxChildren,\n OldJsxElement,\n OldVariableObject,\n OldVariableType,\n} from './oldTypes.js';\nimport { GTProp, JsxChild, JsxChildren, JsxElement } from '../types';\nimport {\n isOldJsxChildren,\n isNewVariableObject,\n isOldVariableObject,\n} from './typeChecking';\n\n/**\n * Convert request data from old format to new format\n */\n\nexport function getNewJsxChild(child: OldJsxChild): JsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isOldVariableObject(child)) {\n return getNewVariableObject(child);\n }\n\n // JsxElement\n return getNewJsxElement(child);\n}\n\nexport function getNewJsxChildren(children: OldJsxChildren): JsxChildren {\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getNewJsxChild);\n }\n\n // Object\n return getNewJsxChild(children);\n}\n\nexport function getNewJsxElement(element: OldJsxElement): JsxElement {\n // string (end case)\n if (typeof element === 'string') {\n return element;\n }\n\n // type\n let t: string | undefined = undefined;\n if (element.type != null) {\n t = element.type;\n }\n // children\n let c: JsxChildren | undefined = undefined;\n if (element.props?.children != null) {\n c = getNewJsxChildren(element.props.children);\n }\n return {\n ...(t && { t }),\n ...(c && { c }),\n d: getNewGTProp(element.props['data-_gt']),\n i: element.props['data-_gt'].id,\n };\n}\n\nexport function getNewBranchType(branch: OldBranchType): 'b' | 'p' {\n if (branch === 'branch') {\n return 'b';\n }\n return 'p';\n}\n\nexport function getNewVariableType(variable: OldVariableType): VariableType {\n switch (variable) {\n case 'number':\n return 'n';\n case 'variable':\n return 'v';\n case 'datetime':\n return 'd';\n case 'currency':\n return 'c';\n default:\n return 'v';\n }\n}\n\nexport function getNewVariableObject(\n variable: OldVariableObject\n): VariableObject {\n // variable type\n let v: VariableType | undefined = undefined;\n if (variable.variable != null) {\n v = getNewVariableType(variable.variable);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.id != null) {\n i = variable.id;\n }\n return {\n k: variable.key,\n ...(v && { v }),\n ...(i && { i }),\n };\n}\n\nexport function getNewGTProp(dataGT: OldGTProp): GTProp {\n // branches\n let b: Record<string, JsxChildren> | undefined = undefined;\n if (dataGT.branches) {\n b = Object.fromEntries(\n Object.entries(dataGT.branches).map(([key, value]) => [\n key,\n getNewJsxChildren(value),\n ])\n );\n }\n // transformation\n let t: 'b' | 'p' | undefined;\n if (dataGT.transformation) {\n t = getNewBranchType(dataGT.transformation);\n }\n return { ...(b && { b }), ...(t && { t }) };\n}\n\n/**\n * Convert response data from current format to old format\n */\n\nexport function getOldJsxChild(child: JsxChild): OldJsxChild {\n // string (end case)\n if (typeof child === 'string') {\n return child;\n }\n\n // VariableObject\n if (isNewVariableObject(child)) {\n return getOldVariableObject(child);\n }\n\n // JsxElement\n return getOldJsxElement(child);\n}\n\nexport function getOldJsxChildren(\n children: JsxChildren | OldJsxChildren\n): OldJsxChildren {\n // if children is already old, return it\n if (isOldJsxChildren(children)) {\n return children;\n }\n\n // string (end case)\n if (typeof children === 'string') {\n return children;\n }\n\n // Array\n if (Array.isArray(children)) {\n return children.map(getOldJsxChild);\n }\n\n // Object\n return getOldJsxChild(children);\n}\n\nexport function getOldJsxElement(element: JsxElement): OldJsxElement {\n // type (can assume that type will exist here)\n const type: string = element.t as string;\n // children\n let children: OldJsxChildren | undefined = undefined;\n if (element.c != null) {\n children = getOldJsxChildren(element.c);\n }\n // data-_gt (can assume id will exist here)\n const dataGT: OldGTProp = getOldGTProp(element.d || {}, element.i as number);\n return {\n type,\n props: { children, 'data-_gt': dataGT },\n };\n}\n\nexport function getOldBranchType(branch: 'b' | 'p'): OldBranchType {\n if (branch === 'b') {\n return 'branch';\n }\n return 'plural';\n}\n\nexport function getOldVariableType(variable: VariableType): OldVariableType {\n switch (variable) {\n case 'n':\n return 'number';\n case 'v':\n return 'variable';\n case 'd':\n return 'datetime';\n case 'c':\n return 'currency';\n default:\n return 'variable';\n }\n}\n\nexport function getOldVariableObject(\n variable: VariableObject\n): OldVariableObject {\n // variable type\n let v: OldVariableType | undefined = undefined;\n if (variable.v != null) {\n v = getOldVariableType(variable.v);\n }\n // variable id\n let i: number | undefined = undefined;\n if (variable.i != null) {\n i = variable.i;\n }\n return {\n key: variable.k,\n ...(v && { variable: v }),\n ...(i && { id: i }),\n };\n}\n\nexport function getOldGTProp(dataGT: GTProp, i: number): OldGTProp {\n // transformation\n let transformation: OldBranchType | undefined = undefined;\n if (dataGT.t != null) {\n transformation = getOldBranchType(dataGT.t);\n }\n // branches\n let branches: Record<string, OldJsxChildren> | undefined = undefined;\n if (dataGT.b != null) {\n branches = Object.fromEntries(\n Object.entries(dataGT.b).map(([key, value]) => [\n key,\n getOldJsxChildren(value),\n ])\n );\n }\n return {\n id: i,\n ...(transformation && { transformation }),\n ...(branches && { branches }),\n };\n}\n","// Functions provided to other GT libraries\n\nimport { OldJsxChild, OldJsxChildren, OldVariableObject } from './oldTypes';\nimport { stableStringify as stringify } from '../utils/stableStringify';\nimport { sha256 } from '@noble/hashes/sha2.js';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';\n\n// ----- FUNCTIONS ----- //\n/**\n * Calculates a unique hash for a given string using SHA-256.\n *\n * @param {string} string - The string to be hashed.\n * @returns {string} The resulting hash as a hexadecimal string.\n */\nexport function oldHashString(string: string): string {\n return bytesToHex(sha256(utf8ToBytes(string)));\n}\n\n/**\n * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation.\n *\n * @param {any} childrenAsObjects - The children objects to be hashed.\n * @param {string} context - The context for the children.\n * @param {string} id - The ID for the JSX children object.\n * @param {function} hashFunction - Custom hash function.\n * @returns {string} - The unique hash of the children.\n */\nexport function oldHashJsxChildren(\n {\n source,\n context,\n id,\n dataFormat,\n }: {\n source: OldJsxChildren;\n context?: string;\n id?: string;\n dataFormat: string;\n },\n hashFunction: (string: string) => string = oldHashString\n): string {\n const unhashedKey = stringify({\n source: sanitizeJsxChildren(source),\n ...(id && { id }),\n ...(context && { context }),\n ...(dataFormat && { dataFormat }),\n });\n return hashFunction(unhashedKey);\n}\n\ntype SanitizedVariable = Omit<OldVariableObject, 'id'>;\n\ntype SanitizedElement = {\n branches?: {\n [k: string]: SanitizedChildren;\n };\n children?: SanitizedChildren;\n transformation?: string;\n};\ntype SanitizedChild = SanitizedElement | SanitizedVariable | string;\ntype SanitizedChildren = SanitizedChild | SanitizedChild[];\n\nconst sanitizeChild = (child: OldJsxChild): SanitizedChild => {\n if (child && typeof child === 'object') {\n if ('props' in child) {\n const newChild: SanitizedChild = {};\n const dataGt = child?.props?.['data-_gt'];\n if (dataGt?.branches) {\n // The only thing that prevents sanitizeJsx from being stable is\n // the order of the keys in the branches object.\n // We don't sort them because stable-stringify sorts them anyways\n newChild.branches = Object.fromEntries(\n Object.entries(dataGt.branches).map(([key, value]) => [\n key,\n sanitizeJsxChildren(value as OldJsxChildren),\n ])\n );\n }\n if (child?.props?.children) {\n newChild.children = sanitizeJsxChildren(child.props.children);\n }\n if (child?.props?.['data-_gt']?.transformation) {\n newChild.transformation = child.props['data-_gt'].transformation;\n }\n return newChild;\n }\n if ('key' in child) {\n return {\n key: child.key,\n ...(child.variable && {\n variable: child.variable,\n }),\n };\n }\n }\n return child as string;\n};\n\nfunction sanitizeJsxChildren(\n childrenAsObjects: OldJsxChildren\n): SanitizedChildren {\n return Array.isArray(childrenAsObjects)\n ? childrenAsObjects.map(sanitizeChild)\n : sanitizeChild(childrenAsObjects);\n}\n"],"mappings":";;;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACDnE,SAAwB,eACtB,GACA,QAA+B,aAC/B,UAAoB,CAAA,KAAsB,EACzB;CAEjB,MAAM,wBADc,qBAAqB,QACA,CAAC,OAAO,EAAE;CAEnD,MAAM,OAAO,KAAK,IAAI,EAAE;AAExB,KAAI,SAAS,KAAK,MAAM,SAAS,OAAO,CAAE,QAAO;AAEjD,KAAI,SAAS,GAAG;AACd,MAAI,MAAM,SAAS,WAAW,CAAE,QAAO;AACvC,MAAI,MAAM,SAAS,MAAM,CAAE,QAAO;;AAEpC,KAAI,0BAA0B,SAAS,MAAM,SAAS,WAAW,CAC/D,QAAO;AAET,KAAI,SAAS,GAAG;AACd,MAAI,MAAM,SAAS,OAAO,CAAE,QAAO;AACnC,MAAI,MAAM,SAAS,MAAM,CAAE,QAAO;;AAEpC,KAAI,0BAA0B,SAAS,MAAM,SAAS,OAAO,CAAE,QAAO;AAEtE,KAAI,MAAM,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AAI;EACJ,GAAI,kBAAkB,EAAE,gBAAgB;EACxC,GAAI,YAAY,EAAE,UAAU;EAC7B;;;;;;;;;;ACjPH,SAAgB,cAAc,QAAwB;AACpD,QAAO,WAAW,OAAO,YAAY,OAAO,CAAC,CAAC;;;;;;;;;;;AAYhD,SAAgB,mBACd,EACE,QACA,SACA,IACA,cAOF,eAA2C,eACnC;AAOR,QAAO,aANaC,gBAAU;EAC5B,QAAQ,oBAAoB,OAAO;EACnC,GAAI,MAAM,EAAE,IAAI;EAChB,GAAI,WAAW,EAAE,SAAS;EAC1B,GAAI,cAAc,EAAE,YAAY;EACjC,CAC8B,CAAC;;AAelC,MAAM,iBAAiB,UAAuC;AAC5D,KAAI,SAAS,OAAO,UAAU,UAAU;AACtC,MAAI,WAAW,OAAO;GACpB,MAAM,WAA2B,EAAE;GACnC,MAAM,SAAS,OAAO,QAAQ;AAC9B,OAAI,QAAQ,SAIV,UAAS,WAAW,OAAO,YACzB,OAAO,QAAQ,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,WAAW,CACpD,KACA,oBAAoB,MAAwB,CAC7C,CAAC,CACH;AAEH,OAAI,OAAO,OAAO,SAChB,UAAS,WAAW,oBAAoB,MAAM,MAAM,SAAS;AAE/D,OAAI,OAAO,QAAQ,aAAa,eAC9B,UAAS,iBAAiB,MAAM,MAAM,YAAY;AAEpD,UAAO;;AAET,MAAI,SAAS,MACX,QAAO;GACL,KAAK,MAAM;GACX,GAAI,MAAM,YAAY,EACpB,UAAU,MAAM,UACjB;GACF;;AAGL,QAAO;;AAGT,SAAS,oBACP,mBACmB;AACnB,QAAO,MAAM,QAAQ,kBAAkB,GACnC,kBAAkB,IAAI,cAAc,GACpC,cAAc,kBAAkB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "8.2.15",
3
+ "version": "8.2.16",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",