@intlayer/core 9.0.1 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +5 -5
  2. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
  3. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -1
  4. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
  5. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +15 -0
  6. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
  7. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +1 -1
  8. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
  9. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
  10. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
  11. package/dist/cjs/dictionaryManipulator/getNodeType.cjs +30 -22
  12. package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
  13. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +1 -1
  14. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
  15. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +1 -1
  16. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
  17. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +1 -1
  18. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
  19. package/dist/cjs/index.cjs +7 -0
  20. package/dist/cjs/interpreter/getContent/getContent.cjs +2 -1
  21. package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
  22. package/dist/cjs/interpreter/getContent/index.cjs +1 -0
  23. package/dist/cjs/interpreter/getContent/plugins.cjs +28 -0
  24. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  25. package/dist/cjs/interpreter/getSelect.cjs +36 -0
  26. package/dist/cjs/interpreter/getSelect.cjs.map +1 -0
  27. package/dist/cjs/interpreter/index.cjs +5 -0
  28. package/dist/cjs/messageFormat/ICU.cjs +23 -6
  29. package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
  30. package/dist/cjs/messageFormat/i18next.cjs +24 -6
  31. package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
  32. package/dist/cjs/messageFormat/resolveMessage.cjs +8 -0
  33. package/dist/cjs/messageFormat/resolveMessage.cjs.map +1 -1
  34. package/dist/cjs/messageFormat/vue-i18n.cjs +11 -2
  35. package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
  36. package/dist/cjs/transpiler/index.cjs +2 -0
  37. package/dist/cjs/transpiler/select/index.cjs +4 -0
  38. package/dist/cjs/transpiler/select/select.cjs +42 -0
  39. package/dist/cjs/transpiler/select/select.cjs.map +1 -0
  40. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +5 -5
  41. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
  42. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -1
  43. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
  44. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +15 -0
  45. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
  46. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +1 -1
  47. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
  48. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
  49. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
  50. package/dist/esm/dictionaryManipulator/getNodeType.mjs +30 -22
  51. package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
  52. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +1 -1
  53. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
  54. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +1 -1
  55. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
  56. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +1 -1
  57. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
  58. package/dist/esm/index.mjs +5 -2
  59. package/dist/esm/interpreter/getContent/getContent.mjs +3 -2
  60. package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
  61. package/dist/esm/interpreter/getContent/index.mjs +2 -2
  62. package/dist/esm/interpreter/getContent/plugins.mjs +28 -1
  63. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  64. package/dist/esm/interpreter/getSelect.mjs +34 -0
  65. package/dist/esm/interpreter/getSelect.mjs.map +1 -0
  66. package/dist/esm/interpreter/index.mjs +4 -2
  67. package/dist/esm/messageFormat/ICU.mjs +23 -6
  68. package/dist/esm/messageFormat/ICU.mjs.map +1 -1
  69. package/dist/esm/messageFormat/i18next.mjs +24 -6
  70. package/dist/esm/messageFormat/i18next.mjs.map +1 -1
  71. package/dist/esm/messageFormat/resolveMessage.mjs +8 -0
  72. package/dist/esm/messageFormat/resolveMessage.mjs.map +1 -1
  73. package/dist/esm/messageFormat/vue-i18n.mjs +11 -2
  74. package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
  75. package/dist/esm/transpiler/index.mjs +2 -1
  76. package/dist/esm/transpiler/select/index.mjs +3 -0
  77. package/dist/esm/transpiler/select/select.mjs +41 -0
  78. package/dist/esm/transpiler/select/select.mjs.map +1 -0
  79. package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
  80. package/dist/types/index.d.ts +5 -2
  81. package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
  82. package/dist/types/interpreter/getContent/index.d.ts +2 -2
  83. package/dist/types/interpreter/getContent/plugins.d.ts +22 -1
  84. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  85. package/dist/types/interpreter/getSelect.d.ts +31 -0
  86. package/dist/types/interpreter/getSelect.d.ts.map +1 -0
  87. package/dist/types/interpreter/index.d.ts +4 -2
  88. package/dist/types/messageFormat/ICU.d.ts.map +1 -1
  89. package/dist/types/messageFormat/i18next.d.ts.map +1 -1
  90. package/dist/types/messageFormat/resolveMessage.d.ts.map +1 -1
  91. package/dist/types/messageFormat/vue-i18n.d.ts.map +1 -1
  92. package/dist/types/transpiler/index.d.ts +3 -1
  93. package/dist/types/transpiler/select/index.d.ts +2 -0
  94. package/dist/types/transpiler/select/select.d.ts +62 -0
  95. package/dist/types/transpiler/select/select.d.ts.map +1 -0
  96. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"vue-i18n.mjs","names":["insert","enu"],"sources":["../../../src/messageFormat/vue-i18n.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, insert } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n// Types for our AST\ntype VueI18nNode =\n | string\n | {\n type: 'argument';\n name: string;\n };\n\nconst parseVueI18nPart = (text: string): VueI18nNode[] => {\n let index = 0;\n const nodes: VueI18nNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n let name = '';\n while (index < text.length && text[index] !== '}') {\n name += text[index];\n index++;\n }\n if (index < text.length) {\n index++; // skip }\n }\n nodes.push({ type: 'argument', name: name.trim() });\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n\n return nodes;\n};\n\nconst parseVueI18n = (text: string): VueI18nNode[][] => {\n // Split by | but handle escaped \\|\n const parts: string[] = [];\n let currentPart = '';\n let index = 0;\n\n while (index < text.length) {\n const char = text[index];\n if (char === '\\\\' && index + 1 < text.length && text[index + 1] === '|') {\n currentPart += '|';\n index += 2;\n } else if (char === '|') {\n parts.push(currentPart.trim()); // Trim to remove surrounding spaces\n currentPart = '';\n index++;\n } else {\n currentPart += char;\n index++;\n }\n }\n parts.push(currentPart.trim()); // Trim last part too\n\n return parts.map(parseVueI18nPart);\n};\n\nconst vueI18nPartToIntlayer = (nodes: VueI18nNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') return nodes[0];\n\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else {\n str += `{{${node.name}}}`;\n }\n }\n return insert(str);\n};\n\nconst vueI18nNodesToIntlayer = (parts: VueI18nNode[][]): any => {\n if (parts.length === 1) {\n return vueI18nPartToIntlayer(parts[0]);\n }\n\n // Handle pluralization (choice).\n // vue-i18n's choice rule is POSITIONAL (0 | 1 | other), not CLDR-based:\n // an enumeration node preserves those semantics in every locale, whereas\n // a plural node would select by CLDR category (e.g. count 0 resolves to\n // 'one' in French, 'other' in English — never 'zero').\n const options: Record<string, any> = {};\n const varName = 'count'; // Default variable for vue-i18n choices\n\n if (parts.length === 2) {\n // 2 choices: 1 | other\n return enu({\n '1': vueI18nPartToIntlayer(parts[0]),\n fallback: vueI18nPartToIntlayer(parts[1]),\n });\n }\n\n if (parts.length === 3) {\n // 3 choices: 0 | 1 | other\n return enu({\n '0': vueI18nPartToIntlayer(parts[0]),\n '1': vueI18nPartToIntlayer(parts[1]),\n fallback: vueI18nPartToIntlayer(parts[2]),\n });\n }\n\n // > 3 choices: 0 | 1 | 2 | ... | other\n parts.forEach((part, index) => {\n if (index === parts.length - 1) {\n options.fallback = vueI18nPartToIntlayer(part);\n } else {\n options[index.toString()] = vueI18nPartToIntlayer(part);\n }\n });\n\n // Preserve variable name\n options.__intlayer_vue_i18n_var = varName;\n\n return enu(options);\n};\n\nconst vueI18nToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' && (node.includes('{') || node.includes('|')),\n transform: (node: any) => {\n try {\n const ast = parseVueI18n(node);\n return vueI18nNodesToIntlayer(ast);\n } catch {\n return node;\n }\n },\n};\n\nconst intlayerToVueI18nPlugin = {\n canHandle: (node: any) => {\n if (typeof node === 'string') return true;\n\n if (\n node &&\n typeof node === 'object' &&\n (node.nodeType === NodeTypes.INSERTION ||\n node.nodeType === NodeTypes.ENUMERATION ||\n node.nodeType === NodeTypes.PLURAL ||\n node.nodeType === NodeTypes.GENDER ||\n node.nodeType === 'composite')\n ) {\n return true;\n }\n\n if (Array.isArray(node)) {\n if (node.length === 0) return false;\n\n let hasNode = false;\n let hasPlainObjectOrArray = false;\n\n for (const item of node) {\n if (typeof item === 'string') {\n } else if (\n item &&\n typeof item === 'object' &&\n (item.nodeType === NodeTypes.INSERTION ||\n item.nodeType === NodeTypes.ENUMERATION ||\n item.nodeType === NodeTypes.GENDER ||\n item.nodeType === 'composite')\n ) {\n hasNode = true;\n } else {\n hasPlainObjectOrArray = true;\n }\n }\n\n // If it contains plain objects or nested arrays, it's a structural array\n if (hasPlainObjectOrArray) return false;\n // If it contains ONLY strings, it's a structural array, not a composite string\n if (!hasNode) return false;\n\n return true;\n }\n\n return false;\n },\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n // replace {{...}} with {...} even in strings\n return node.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeTypes.INSERTION) {\n // {{name}} -> {name}\n return node[NodeTypes.INSERTION].replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeTypes.PLURAL) {\n const options = node[NodeTypes.PLURAL];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n if (\n transformedOptions.zero &&\n transformedOptions.one &&\n transformedOptions.other\n ) {\n return `${transformedOptions.zero} | ${transformedOptions.one} | ${transformedOptions.other}`;\n }\n\n if (transformedOptions.one && transformedOptions.other) {\n return `${transformedOptions.one} | ${transformedOptions.other}`;\n }\n\n return transformedOptions.other || Object.values(transformedOptions)[0];\n }\n\n if (node.nodeType === NodeTypes.ENUMERATION) {\n const options = node[NodeTypes.ENUMERATION];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (\n key === '__intlayer_vue_i18n_var' ||\n key === '__intlayer_icu_var' ||\n key === '__intlayer_icu_ordinal'\n )\n continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n const keys = Object.keys(transformedOptions);\n\n if (keys.includes('0')) {\n const indices = keys.filter((key) => /^\\d+$/.test(key)).map(Number);\n const maxIndex = Math.max(...indices);\n\n const fallback =\n transformedOptions.fallback || transformedOptions.other;\n const resultParts = [];\n\n if (maxIndex <= 1 && !keys.includes('2')) {\n const zero = transformedOptions['0'] || '';\n const one = transformedOptions['1'] || '';\n return `${zero} | ${one} | ${fallback}`;\n }\n\n const limit = Math.max(1, maxIndex);\n\n for (let i = 0; i <= limit; i++) {\n const key = i.toString();\n if (transformedOptions[key]) {\n resultParts.push(transformedOptions[key]);\n } else {\n resultParts.push('');\n }\n }\n resultParts.push(fallback);\n return resultParts.join(' | ').replace(/ \\| {2}\\| /g, ' | | ');\n }\n\n if (\n keys.includes('1') &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return `${transformedOptions['1']} | ${transformedOptions.fallback || transformedOptions.other}`;\n }\n\n if (\n keys.length === 1 &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return transformedOptions.fallback || transformedOptions.other;\n }\n\n return (\n transformedOptions.fallback || Object.values(transformedOptions)[0]\n );\n }\n\n if (node.nodeType === NodeTypes.GENDER) {\n const options = node[NodeTypes.GENDER];\n const transformedOptions: Record<string, any> = {};\n\n for (const [key, val] of Object.entries(options)) {\n let newKey = key;\n if (key === 'fallback') newKey = 'other';\n\n const childVal = next(val, props);\n transformedOptions[newKey] = childVal;\n }\n return transformedOptions;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToVueI18nFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...intlayerToVueI18nPlugin }],\n });\n};\n\nexport const vueI18nToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...vueI18nToIntlayerPlugin }],\n });\n};\n"],"mappings":";;;;;;AAcA,MAAM,oBAAoB,SAAgC;CACxD,IAAI,QAAQ;CACZ,MAAM,QAAuB,CAAC;CAC9B,IAAI,cAAc;CAElB,OAAO,QAAQ,KAAK,QAAQ;EAC1B,MAAM,OAAO,KAAK;EAElB,IAAI,SAAS,KAAK;GAChB,IAAI,aAAa;IACf,MAAM,KAAK,WAAW;IACtB,cAAc;GAChB;GACA;GACA,IAAI,OAAO;GACX,OAAO,QAAQ,KAAK,UAAU,KAAK,WAAW,KAAK;IACjD,QAAQ,KAAK;IACb;GACF;GACA,IAAI,QAAQ,KAAK,QACf;GAEF,MAAM,KAAK;IAAE,MAAM;IAAY,MAAM,KAAK,KAAK;GAAE,CAAC;EACpD,OAAO;GACL,eAAe;GACf;EACF;CACF;CAEA,IAAI,aACF,MAAM,KAAK,WAAW;CAGxB,OAAO;AACT;AAEA,MAAM,gBAAgB,SAAkC;CAEtD,MAAM,QAAkB,CAAC;CACzB,IAAI,cAAc;CAClB,IAAI,QAAQ;CAEZ,OAAO,QAAQ,KAAK,QAAQ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AACH"}
1
+ {"version":3,"file":"vue-i18n.mjs","names":["insert","enu"],"sources":["../../../src/messageFormat/vue-i18n.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { deepTransformNode } from '../interpreter';\nimport { enu, insert } from '../transpiler';\nimport type { JsonValue } from './ICU';\n\n// Types for our AST\ntype VueI18nNode =\n | string\n | {\n type: 'argument';\n name: string;\n };\n\nconst parseVueI18nPart = (text: string): VueI18nNode[] => {\n let index = 0;\n const nodes: VueI18nNode[] = [];\n let currentText = '';\n\n while (index < text.length) {\n const char = text[index];\n\n if (char === '{') {\n if (currentText) {\n nodes.push(currentText);\n currentText = '';\n }\n index++; // skip {\n let name = '';\n while (index < text.length && text[index] !== '}') {\n name += text[index];\n index++;\n }\n if (index < text.length) {\n index++; // skip }\n }\n nodes.push({ type: 'argument', name: name.trim() });\n } else {\n currentText += char;\n index++;\n }\n }\n\n if (currentText) {\n nodes.push(currentText);\n }\n\n return nodes;\n};\n\nconst parseVueI18n = (text: string): VueI18nNode[][] => {\n // Split by | but handle escaped \\|\n const parts: string[] = [];\n let currentPart = '';\n let index = 0;\n\n while (index < text.length) {\n const char = text[index];\n if (char === '\\\\' && index + 1 < text.length && text[index + 1] === '|') {\n currentPart += '|';\n index += 2;\n } else if (char === '|') {\n parts.push(currentPart.trim()); // Trim to remove surrounding spaces\n currentPart = '';\n index++;\n } else {\n currentPart += char;\n index++;\n }\n }\n parts.push(currentPart.trim()); // Trim last part too\n\n return parts.map(parseVueI18nPart);\n};\n\nconst vueI18nPartToIntlayer = (nodes: VueI18nNode[]): any => {\n if (nodes.length === 0) return '';\n if (nodes.length === 1 && typeof nodes[0] === 'string') return nodes[0];\n\n let str = '';\n for (const node of nodes) {\n if (typeof node === 'string') {\n str += node;\n } else {\n str += `{{${node.name}}}`;\n }\n }\n return insert(str);\n};\n\nconst vueI18nNodesToIntlayer = (parts: VueI18nNode[][]): any => {\n if (parts.length === 1) {\n return vueI18nPartToIntlayer(parts[0]);\n }\n\n // Handle pluralization (choice).\n // vue-i18n's choice rule is POSITIONAL (0 | 1 | other), not CLDR-based:\n // an enumeration node preserves those semantics in every locale, whereas\n // a plural node would select by CLDR category (e.g. count 0 resolves to\n // 'one' in French, 'other' in English — never 'zero').\n const options: Record<string, any> = {};\n const varName = 'count'; // Default variable for vue-i18n choices\n\n if (parts.length === 2) {\n // 2 choices: 1 | other\n return enu({\n '1': vueI18nPartToIntlayer(parts[0]),\n fallback: vueI18nPartToIntlayer(parts[1]),\n });\n }\n\n if (parts.length === 3) {\n // 3 choices: 0 | 1 | other\n return enu({\n '0': vueI18nPartToIntlayer(parts[0]),\n '1': vueI18nPartToIntlayer(parts[1]),\n fallback: vueI18nPartToIntlayer(parts[2]),\n });\n }\n\n // > 3 choices: 0 | 1 | 2 | ... | other\n parts.forEach((part, index) => {\n if (index === parts.length - 1) {\n options.fallback = vueI18nPartToIntlayer(part);\n } else {\n options[index.toString()] = vueI18nPartToIntlayer(part);\n }\n });\n\n // Preserve variable name\n options.__intlayer_vue_i18n_var = varName;\n\n return enu(options);\n};\n\nconst vueI18nToIntlayerPlugin = {\n canHandle: (node: any) =>\n typeof node === 'string' && (node.includes('{') || node.includes('|')),\n transform: (node: any) => {\n try {\n const ast = parseVueI18n(node);\n return vueI18nNodesToIntlayer(ast);\n } catch {\n return node;\n }\n },\n};\n\nconst intlayerToVueI18nPlugin = {\n canHandle: (node: any) => {\n if (typeof node === 'string') return true;\n\n if (\n node &&\n typeof node === 'object' &&\n (node.nodeType === NodeTypes.INSERTION ||\n node.nodeType === NodeTypes.ENUMERATION ||\n node.nodeType === NodeTypes.PLURAL ||\n node.nodeType === NodeTypes.GENDER ||\n node.nodeType === NodeTypes.SELECT ||\n node.nodeType === 'composite')\n ) {\n return true;\n }\n\n if (Array.isArray(node)) {\n if (node.length === 0) return false;\n\n let hasNode = false;\n let hasPlainObjectOrArray = false;\n\n for (const item of node) {\n if (typeof item === 'string') {\n } else if (\n item &&\n typeof item === 'object' &&\n (item.nodeType === NodeTypes.INSERTION ||\n item.nodeType === NodeTypes.ENUMERATION ||\n item.nodeType === NodeTypes.GENDER ||\n item.nodeType === NodeTypes.SELECT ||\n item.nodeType === 'composite')\n ) {\n hasNode = true;\n } else {\n hasPlainObjectOrArray = true;\n }\n }\n\n // If it contains plain objects or nested arrays, it's a structural array\n if (hasPlainObjectOrArray) return false;\n // If it contains ONLY strings, it's a structural array, not a composite string\n if (!hasNode) return false;\n\n return true;\n }\n\n return false;\n },\n transform: (node: any, props: any, next: any) => {\n if (typeof node === 'string') {\n // replace {{...}} with {...} even in strings\n return node.replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeTypes.INSERTION) {\n // {{name}} -> {name}\n return node[NodeTypes.INSERTION].replace(/\\{\\{([^}]+)\\}\\}/g, '{$1}');\n }\n\n if (node.nodeType === NodeTypes.PLURAL) {\n const options = node[NodeTypes.PLURAL];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n if (\n transformedOptions.zero &&\n transformedOptions.one &&\n transformedOptions.other\n ) {\n return `${transformedOptions.zero} | ${transformedOptions.one} | ${transformedOptions.other}`;\n }\n\n if (transformedOptions.one && transformedOptions.other) {\n return `${transformedOptions.one} | ${transformedOptions.other}`;\n }\n\n return transformedOptions.other || Object.values(transformedOptions)[0];\n }\n\n if (node.nodeType === NodeTypes.ENUMERATION) {\n const options = node[NodeTypes.ENUMERATION];\n\n const transformedOptions: Record<string, string> = {};\n for (const [key, val] of Object.entries(options)) {\n if (\n key === '__intlayer_vue_i18n_var' ||\n key === '__intlayer_icu_var' ||\n key === '__intlayer_icu_ordinal'\n )\n continue;\n const childVal = next(val, props);\n transformedOptions[key] =\n typeof childVal === 'string' ? childVal : JSON.stringify(childVal);\n }\n\n const keys = Object.keys(transformedOptions);\n\n if (keys.includes('0')) {\n const indices = keys.filter((key) => /^\\d+$/.test(key)).map(Number);\n const maxIndex = Math.max(...indices);\n\n const fallback =\n transformedOptions.fallback || transformedOptions.other;\n const resultParts = [];\n\n if (maxIndex <= 1 && !keys.includes('2')) {\n const zero = transformedOptions['0'] || '';\n const one = transformedOptions['1'] || '';\n return `${zero} | ${one} | ${fallback}`;\n }\n\n const limit = Math.max(1, maxIndex);\n\n for (let i = 0; i <= limit; i++) {\n const key = i.toString();\n if (transformedOptions[key]) {\n resultParts.push(transformedOptions[key]);\n } else {\n resultParts.push('');\n }\n }\n resultParts.push(fallback);\n return resultParts.join(' | ').replace(/ \\| {2}\\| /g, ' | | ');\n }\n\n if (\n keys.includes('1') &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return `${transformedOptions['1']} | ${transformedOptions.fallback || transformedOptions.other}`;\n }\n\n if (\n keys.length === 1 &&\n (keys.includes('fallback') || keys.includes('other'))\n ) {\n return transformedOptions.fallback || transformedOptions.other;\n }\n\n return (\n transformedOptions.fallback || Object.values(transformedOptions)[0]\n );\n }\n\n if (node.nodeType === NodeTypes.GENDER) {\n const options = node[NodeTypes.GENDER];\n const transformedOptions: Record<string, any> = {};\n\n for (const [key, val] of Object.entries(options)) {\n let newKey = key;\n if (key === 'fallback') newKey = 'other';\n\n const childVal = next(val, props);\n transformedOptions[newKey] = childVal;\n }\n return transformedOptions;\n }\n\n if (node.nodeType === NodeTypes.SELECT) {\n const options = node[NodeTypes.SELECT];\n const transformedOptions: Record<string, any> = {};\n\n // vue-i18n has no `select` syntax: the cases become a nested message\n // object, resolved by the caller with `t('key.Draft')`.\n for (const [key, val] of Object.entries(options)) {\n const newKey = key === 'fallback' ? 'other' : key;\n\n transformedOptions[newKey] = next(val, props);\n }\n return transformedOptions;\n }\n\n if (\n Array.isArray(node) ||\n (node.nodeType === 'composite' && Array.isArray(node.composite))\n ) {\n const arr = Array.isArray(node) ? node : node.composite;\n const items = arr.map((item: any) => next(item, props));\n return items.join('');\n }\n\n return next(node, props);\n },\n};\n\nexport const intlayerToVueI18nFormatter = (\n message: Dictionary['content']\n): JsonValue => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...intlayerToVueI18nPlugin }],\n });\n};\n\nexport const vueI18nToIntlayerFormatter = (\n message: JsonValue\n): Dictionary['content'] => {\n return deepTransformNode(message, {\n dictionaryKey: 'vue-i18n',\n keyPath: [],\n plugins: [{ id: 'vue-i18n', ...vueI18nToIntlayerPlugin }],\n });\n};\n"],"mappings":";;;;;;AAcA,MAAM,oBAAoB,SAAgC;CACxD,IAAI,QAAQ;CACZ,MAAM,QAAuB,CAAC;CAC9B,IAAI,cAAc;CAElB,OAAO,QAAQ,KAAK,QAAQ;EAC1B,MAAM,OAAO,KAAK;EAElB,IAAI,SAAS,KAAK;GAChB,IAAI,aAAa;IACf,MAAM,KAAK,WAAW;IACtB,cAAc;GAChB;GACA;GACA,IAAI,OAAO;GACX,OAAO,QAAQ,KAAK,UAAU,KAAK,WAAW,KAAK;IACjD,QAAQ,KAAK;IACb;GACF;GACA,IAAI,QAAQ,KAAK,QACf;GAEF,MAAM,KAAK;IAAE,MAAM;IAAY,MAAM,KAAK,KAAK;GAAE,CAAC;EACpD,OAAO;GACL,eAAe;GACf;EACF;CACF;CAEA,IAAI,aACF,MAAM,KAAK,WAAW;CAGxB,OAAO;AACT;AAEA,MAAM,gBAAgB,SAAkC;CAEtD,MAAM,QAAkB,CAAC;CACzB,IAAI,cAAc;CAClB,IAAI,QAAQ;CAEZ,OAAO,QAAQ,KAAK,QAAQ;EAC1B,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,QAAQ,QAAQ,IAAI,KAAK,UAAU,KAAK,QAAQ,OAAO,KAAK;GACvE,eAAe;GACf,SAAS;EACX,OAAO,IAAI,SAAS,KAAK;GACvB,MAAM,KAAK,YAAY,KAAK,CAAC;GAC7B,cAAc;GACd;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AAS;EAChC,eAAe;EACf,SAAS,CAAC;EACV,SAAS,CAAC;GAAE,IAAI;GAAY,GAAG;EAAwB,CAAC;CAC1D,CAAC;AACH"}
@@ -11,6 +11,7 @@ import { validateMarkdown } from "./markdown/validateMarkdown.mjs";
11
11
  import { md as markdown } from "./markdown/markdown.mjs";
12
12
  import { nest as nesting } from "./nesting/nesting.mjs";
13
13
  import { plural } from "./plural/plural.mjs";
14
+ import { select } from "./select/select.mjs";
14
15
  import { t as translation } from "./translation/translation.mjs";
15
16
 
16
- export { HTML_TAGS, VOID_HTML_ELEMENTS, condition as cond, enumeration as enu, gender, getInsertionValues, getMarkdownMetadata, html, insertion as insert, markdown as md, nesting as nest, plural, translation as t, validateHTML, validateMarkdown };
17
+ export { HTML_TAGS, VOID_HTML_ELEMENTS, condition as cond, enumeration as enu, gender, getInsertionValues, getMarkdownMetadata, html, insertion as insert, markdown as md, nesting as nest, plural, select, translation as t, validateHTML, validateMarkdown };
@@ -0,0 +1,3 @@
1
+ import { select } from "./select.mjs";
2
+
3
+ export { select };
@@ -0,0 +1,41 @@
1
+ import { SELECT, formatNodeType } from "@intlayer/types/nodeType";
2
+
3
+ //#region src/transpiler/select/select.ts
4
+ /**
5
+ * Function intended to be used to build intlayer dictionaries.
6
+ *
7
+ * Allow to pick a content based on an arbitrary string value — the equivalent
8
+ * of an ICU `{value, select, …}` message, or of a `switch` statement in the
9
+ * application code.
10
+ *
11
+ * Use it when the discriminant is neither a quantity (`enu`), a boolean
12
+ * (`cond`), nor a gender (`gender`).
13
+ *
14
+ * Usage:
15
+ *
16
+ * ```ts
17
+ * select({
18
+ * draft: 'This post is a draft',
19
+ * published: 'This post is live',
20
+ * scheduled: 'This post is scheduled',
21
+ * fallback: 'Unknown status',
22
+ * });
23
+ * ```
24
+ *
25
+ * When no `fallback` key is provided, the last key declared is used as the
26
+ * fallback value — the same contract as `cond()` and `gender()`.
27
+ *
28
+ * Prefer `select()` over indexing a plain object (`content.status[value]`):
29
+ * a dynamic computed access cannot be resolved statically by the Intlayer
30
+ * compiler, which forces the whole branch to be kept and its keys to stay
31
+ * un-minified.
32
+ *
33
+ * @param content - The map of cases to content.
34
+ * @param variable - Optional name of the variable being selected on. Preserved
35
+ * for the ICU / i18next round-trip; unused at runtime.
36
+ */
37
+ const select = (content, variable) => formatNodeType(SELECT, content, { variable });
38
+
39
+ //#endregion
40
+ export { select };
41
+ //# sourceMappingURL=select.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.mjs","names":[],"sources":["../../../../src/transpiler/select/select.ts"],"sourcesContent":["import type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport { formatNodeType, SELECT } from '@intlayer/types/nodeType';\n\n/**\n * Map of arbitrary string cases to their content.\n *\n * Every key is a case the application can switch on (`'Draft'`, `'Published'`,\n * `'Scheduled'`, …). The optional `fallback` key is picked when the provided\n * value matches no declared case.\n */\nexport type SelectContentStates<Content = unknown> = {\n [caseKey: string]: Content;\n} & {\n fallback?: Content;\n};\n\nexport type SelectContent<\n States extends SelectContentStates = SelectContentStates,\n> = TypedNodeModel<\n typeof SELECT,\n States,\n {\n /**\n * Name of the variable the cases are selected on.\n *\n * Purely informational at runtime — the selector is passed explicitly by\n * the caller. It is preserved so content imported from, or exported to, an\n * ICU `{publishType, select, …}` message keeps its variable name across\n * the round-trip.\n */\n variable?: string;\n }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on an arbitrary string value — the equivalent\n * of an ICU `{value, select, …}` message, or of a `switch` statement in the\n * application code.\n *\n * Use it when the discriminant is neither a quantity (`enu`), a boolean\n * (`cond`), nor a gender (`gender`).\n *\n * Usage:\n *\n * ```ts\n * select({\n * draft: 'This post is a draft',\n * published: 'This post is live',\n * scheduled: 'This post is scheduled',\n * fallback: 'Unknown status',\n * });\n * ```\n *\n * When no `fallback` key is provided, the last key declared is used as the\n * fallback value — the same contract as `cond()` and `gender()`.\n *\n * Prefer `select()` over indexing a plain object (`content.status[value]`):\n * a dynamic computed access cannot be resolved statically by the Intlayer\n * compiler, which forces the whole branch to be kept and its keys to stay\n * un-minified.\n *\n * @param content - The map of cases to content.\n * @param variable - Optional name of the variable being selected on. Preserved\n * for the ICU / i18next round-trip; unused at runtime.\n */\nconst select = <const States extends SelectContentStates>(\n content?: States,\n variable?: string\n): SelectContent<States> =>\n formatNodeType(SELECT, content as States, { variable });\n\nexport { select };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAM,UACJ,SACA,aAEA,eAAe,QAAQ,SAAmB,EAAE,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getNodeType.d.ts","names":[],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"mappings":";;;cA4Ca,cAAW,SAAa,gBAAc"}
1
+ {"version":3,"file":"getNodeType.d.ts","names":[],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"mappings":";;;cAsDa,cAAW,SAAa,gBAAc"}
@@ -13,19 +13,22 @@ import { MarkdownContent, MarkdownContentConstructor, md as markdown } from "./t
13
13
  import { MarkdownValidationResult, validateMarkdown } from "./transpiler/markdown/validateMarkdown.js";
14
14
  import { DotPath, NestedContent, NestedContentState, ValidDotPathsFor, nest as nesting } from "./transpiler/nesting/nesting.js";
15
15
  import { PluralCategory, PluralContent, PluralContentState, plural } from "./transpiler/plural/plural.js";
16
+ import { SelectContent, SelectContentStates, select } from "./transpiler/select/select.js";
16
17
  import { TranslationContent, t as translation } from "./transpiler/translation/translation.js";
17
18
  import "./transpiler/index.js";
18
19
  import { getCondition } from "./interpreter/getCondition.js";
19
20
  import { GetNestingResult, getNesting } from "./interpreter/getNesting.js";
20
- import { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin } from "./interpreter/getContent/plugins.js";
21
+ import { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, SelectCond, SelectSelector, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./interpreter/getContent/plugins.js";
21
22
  import { deepTransformNode } from "./interpreter/getContent/deepTransform.js";
22
23
  import { getBasePlugins, getContent } from "./interpreter/getContent/getContent.js";
23
24
  import { getDictionary } from "./interpreter/getDictionary.js";
24
25
  import { findMatchingCondition, getEnumeration } from "./interpreter/getEnumeration.js";
26
+ import { getGender } from "./interpreter/getGender.js";
25
27
  import { getHTML } from "./interpreter/getHTML.js";
26
28
  import { getInsertion } from "./interpreter/getInsertion.js";
27
29
  import { getIntlayer } from "./interpreter/getIntlayer.js";
28
30
  import { getPlural } from "./interpreter/getPlural.js";
31
+ import { getSelect } from "./interpreter/getSelect.js";
29
32
  import { getTranslation } from "./interpreter/getTranslation.js";
30
33
  import { InterpolableNode, getInterpolableContent, isInterpolableWrapperNode, rebuildInterpolableContent, transformInterpolableNode } from "./interpreter/interpolableNode.js";
31
34
  import { splitInsertionTemplate } from "./interpreter/splitAndJoinInsertion.js";
@@ -107,4 +110,4 @@ import { CookieBuildAttributes, LocaleStorage, LocaleStorageClient, LocaleStorag
107
110
  import { YamlRecord, YamlValue, parseYaml } from "./utils/parseYaml.js";
108
111
  import { stringifyYaml } from "./utils/stringifyYaml.js";
109
112
  import "./utils/index.js";
110
- export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, type BlockQuoteNode, type BoldTextNode, type BreakLineNode, type BreakThematicNode, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, type CodeBlockNode, type CodeFencedNode, type CodeInlineNode, type CompileOptions, type ComponentOverrides, ConditionCond, ConditionContent, ConditionContentStates, CookieBuildAttributes, type CustomComponentNode, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, DateTimePreset, DeepTransformContent, DotPath, DynamicDictionaryLoader, type ElementType, EnterFormat, EnumerationCond, EnumerationContent, EnumerationContentState, type EscapedTextNode, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, FileCond, type FileContent, type FileContentConstructor, type FootnoteNode, type FootnoteReferenceNode, type GFMTaskNode, GFM_TASK_R, Gender, GenderCond, GenderContent, GenderContentStates, type GenerateSitemapOptions, GetNestingResult, type GetPrefixOptions, type GetPrefixResult, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, type HTMLCommentNode, HTMLContent, HTMLContentConstructor, type HTMLNode, type HTMLSelfClosingNode, type HTMLTag, HTMLTagsType, HTMLValidationIssue, HTMLValidationResult, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, type HeadingNode, type HeadingSetextNode, IInterpreterPlugin, IInterpreterPluginState, INLINE_SKIP_R, INTERPOLATION_R, type ImageNode, InsertionCond, InsertionContent, InsertionContentConstructor, InterpolableNode, IntlConstructorName, IsAny, type ItalicTextNode, JsonValue, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, type LinkAngleBraceNode, type LinkBareURLNode, type LinkNode, ListType, type LocaleDomainMap, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, type LocalizedPathResult, MarkdownContent, MarkdownContentConstructor, type MarkdownContext, type MarkdownOptions, type MarkdownRuntime, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, type MarkedTextNode, MessageFormatDialect, MessageValues, NAMED_CODES_TO_UNICODE, NP_TABLE_R, NestedCond, NestedContent, NestedContentState, type NestedParser, type NewlineNode, NodeProps, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, type OrderedListNode, PARAGRAPH_R, type ParagraphNode, type ParseState, ParsedMarkdown, type Parser, type ParserResult, Plugins, PluralCategory, PluralCond, PluralContent, PluralContentState, PortableObject, Priority, PriorityValue, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, QualifiedDynamicLoaderMap, QualifiedDynamicLoaderTree, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, type ReferenceImageNode, type ReferenceLinkNode, type ReferenceNode, type RenderRuleHook, type Rule, type RuleOutput, RuleType, RuleTypeValue, type Rules, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, type SitemapUrlEntry, type StrikethroughTextNode, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, type TableNode, type TableSeparatorNode, TaggedMessageToken, type TextNode, TranslationCond, TranslationContent, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, UnionKeys, type UnorderedListNode, VOID_HTML_ELEMENTS, ValidDotPathsFor, ValueAtKey, WrappedIntl, YamlRecord, YamlValue, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, type file, type fileContent, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveMessage, resolveMessageNode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, serializeVariant, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter };
113
+ export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, type BlockQuoteNode, type BoldTextNode, type BreakLineNode, type BreakThematicNode, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, type CodeBlockNode, type CodeFencedNode, type CodeInlineNode, type CompileOptions, type ComponentOverrides, ConditionCond, ConditionContent, ConditionContentStates, CookieBuildAttributes, type CustomComponentNode, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, DateTimePreset, DeepTransformContent, DotPath, DynamicDictionaryLoader, type ElementType, EnterFormat, EnumerationCond, EnumerationContent, EnumerationContentState, type EscapedTextNode, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, FileCond, type FileContent, type FileContentConstructor, type FootnoteNode, type FootnoteReferenceNode, type GFMTaskNode, GFM_TASK_R, Gender, GenderCond, GenderContent, GenderContentStates, type GenerateSitemapOptions, GetNestingResult, type GetPrefixOptions, type GetPrefixResult, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, type HTMLCommentNode, HTMLContent, HTMLContentConstructor, type HTMLNode, type HTMLSelfClosingNode, type HTMLTag, HTMLTagsType, HTMLValidationIssue, HTMLValidationResult, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, type HeadingNode, type HeadingSetextNode, IInterpreterPlugin, IInterpreterPluginState, INLINE_SKIP_R, INTERPOLATION_R, type ImageNode, InsertionCond, InsertionContent, InsertionContentConstructor, InterpolableNode, IntlConstructorName, IsAny, type ItalicTextNode, JsonValue, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, type LinkAngleBraceNode, type LinkBareURLNode, type LinkNode, ListType, type LocaleDomainMap, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, type LocalizedPathResult, MarkdownContent, MarkdownContentConstructor, type MarkdownContext, type MarkdownOptions, type MarkdownRuntime, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, type MarkedTextNode, MessageFormatDialect, MessageValues, NAMED_CODES_TO_UNICODE, NP_TABLE_R, NestedCond, NestedContent, NestedContentState, type NestedParser, type NewlineNode, NodeProps, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, type OrderedListNode, PARAGRAPH_R, type ParagraphNode, type ParseState, ParsedMarkdown, type Parser, type ParserResult, Plugins, PluralCategory, PluralCond, PluralContent, PluralContentState, PortableObject, Priority, PriorityValue, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, QualifiedDynamicLoaderMap, QualifiedDynamicLoaderTree, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, type ReferenceImageNode, type ReferenceLinkNode, type ReferenceNode, type RenderRuleHook, type Rule, type RuleOutput, RuleType, RuleTypeValue, type Rules, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, SelectCond, SelectContent, SelectContentStates, SelectSelector, type SitemapUrlEntry, type StrikethroughTextNode, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, type TableNode, type TableSeparatorNode, TaggedMessageToken, type TextNode, TranslationCond, TranslationContent, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, UnionKeys, type UnorderedListNode, VOID_HTML_ELEMENTS, ValidDotPathsFor, ValueAtKey, WrappedIntl, YamlRecord, YamlValue, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, type file, type fileContent, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveMessage, resolveMessageNode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, select, selectPlugin, serializeVariant, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter };
@@ -1 +1 @@
1
- {"version":3,"file":"getContent.d.ts","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"mappings":";;;;cAqBa,iBAAc,SAChB,eAAa,uBAErB;;;;;;;cAoBU,mBACL,UAAU,mBACV,UAAU,gBAAgB,iBAAe,MAEzC,GAAC,WACI,WAAS,UACX,cAKH,qBAAqB,GAAG,yBAAyB"}
1
+ {"version":3,"file":"getContent.d.ts","names":[],"sources":["../../../../src/interpreter/getContent/getContent.ts"],"mappings":";;;;cAsBa,iBAAc,SAChB,eAAa,uBAErB;;;;;;;cAqBU,mBACL,UAAU,mBACV,UAAU,gBAAgB,iBAAe,MAEzC,GAAC,WACI,WAAS,UACX,cAKH,qBAAqB,GAAG,yBAAyB"}
@@ -1,4 +1,4 @@
1
- import { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin } from "./plugins.js";
1
+ import { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, SelectCond, SelectSelector, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./plugins.js";
2
2
  import { deepTransformNode } from "./deepTransform.js";
3
3
  import { getBasePlugins, getContent } from "./getContent.js";
4
- export { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getBasePlugins, getContent, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin };
4
+ export { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, SelectCond, SelectSelector, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, getBasePlugins, getContent, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin };
@@ -94,6 +94,25 @@ type GenderCond<T, S, _L> = T extends {
94
94
  } ? (value: Gender) => DeepTransformContent<T[typeof NodeTypes.GENDER][keyof T[typeof NodeTypes.GENDER]], S> : never;
95
95
  /** Gender plugin. Replaces node with a function that takes gender => string. */
96
96
  declare const genderPlugin: Plugins;
97
+ /** ---------------------------------------------
98
+ * SELECT PLUGIN
99
+ * --------------------------------------------- */
100
+ /**
101
+ * Accepted selector for a select node.
102
+ *
103
+ * When the node declares a `fallback` case, any string is accepted (the
104
+ * fallback covers the unmatched values) while the declared cases still
105
+ * autocomplete. Without a `fallback`, only the declared cases are accepted.
106
+ */
107
+ type SelectSelector<States> = 'fallback' extends keyof States ? Exclude<keyof States & string, 'fallback'> | (string & {}) : keyof States & string;
108
+ type SelectCond<T, S, _L> = T extends {
109
+ nodeType: NodeType | string;
110
+ [NodeTypes.SELECT]: object;
111
+ } ? (value: SelectSelector<T[typeof NodeTypes.SELECT]> | {
112
+ value: SelectSelector<T[typeof NodeTypes.SELECT]>;
113
+ }) => DeepTransformContent<T[typeof NodeTypes.SELECT][keyof T[typeof NodeTypes.SELECT]], S> : never;
114
+ /** Select plugin. Replaces node with a function that takes a string => content. */
115
+ declare const selectPlugin: Plugins;
97
116
  /** ---------------------------------------------
98
117
  * NESTED PLUGIN
99
118
  * --------------------------------------------- */
@@ -149,6 +168,7 @@ interface IInterpreterPlugin<T, S, L extends LocalesValues> {
149
168
  condition: ConditionCond<T, S, L>;
150
169
  insertion: InsertionCond<T, S, L>;
151
170
  gender: GenderCond<T, S, L>;
171
+ select: SelectCond<T, S, L>;
152
172
  nested: NestedCond<T, S, L>;
153
173
  file: FileCond<T, S, L>;
154
174
  }
@@ -162,6 +182,7 @@ type IInterpreterPluginState = {
162
182
  condition: true;
163
183
  insertion: true;
164
184
  gender: true;
185
+ select: true;
165
186
  nested: true;
166
187
  file: true;
167
188
  };
@@ -179,5 +200,5 @@ type IsAny<T> = 0 extends 1 & T ? true : false;
179
200
  */
180
201
  type DeepTransformContent<T, S = IInterpreterPluginState, L extends LocalesValues = DeclaredLocales> = IsAny<T> extends true ? T : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L> extends never ? Traverse<T, S, L> : CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S, L>, S, L>;
181
202
  //#endregion
182
- export { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin };
203
+ export { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, SelectCond, SelectSelector, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin };
183
204
  //# sourceMappingURL=plugins.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.d.ts","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"mappings":";;;;;;;;;;;;;;;;;;;KAgDY;EACV;EACA,YAAY;EACZ,YACE,WACA,OAAO,WACP,cAAc,WAAW,OAAO;;;;;;;cAUvB,gBAAgB;;;;KAUjB,UAAU,KAAK,0BAA0B;KACzC,WAAW,GAAG,KAAK,oBAC3B,gBAAgB,IACd,EAAE;KAII,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,SAAa,kBAAgB;;;;KAuB1C,SAAS,GAAG,GAAG,MAAM;EAC/B,UAAU;GACT,UAAU;EACX;IAEE,6BAA6B;;cAIpB,YAAY;;;;;;;;UAsBR;EACf;EACA,SAAS;EACT,UAAU;EACV,SAAS;EACT;EACA;;;;;;;EAOA;;;;;;UAOe,mBAAmB,GAAG,GAAG,UAAU;EAClD,aAAa,gBAAgB,GAAG,GAAG;EACnC,aAAa,gBAAgB,GAAG,GAAG;EACnC,QAAQ,WAAW,GAAG,GAAG;EACzB,WAAW,cAAc,GAAG,GAAG;EAC/B,WAAW,cAAc,GAAG,GAAG;EAC/B,QAAQ,WAAW,GAAG,GAAG;EACzB,QAAQ,WAAW,GAAG,GAAG;EACzB,MAAM,SAAS,GAAG,GAAG;;;;;KAMX;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;KAMG,iBACH,GACA,gBAAgB,mBAAmB,GAAG,GAAG,IACzC,GACA,UAAU,gBAAgB,mBACxB,gBAAgB,IAEhB,EAAE,kBAEA,mBAAmB,GAAG,GAAG,GAAG,2BAG1B,mBAAmB,GAAG,GAAG,GAAG;;;;KAO/B,SAAS,GAAG,GAAG,UAAU,gBAAgB,mBAC5C,UAAU,oBAAoB,KAC1B,MAAM,qBAAqB,GAAG,GAAG,MACjC,sBACK,WAAW,IAAI,qBAAqB,EAAE,IAAI,GAAG,QAChD;KAEI,MAAM,mBAAmB;;;;KAKzB,qBACV,GACA,IAAI,yBACJ,UAAU,gBAAgB,mBAE1B,MAAM,kBACF,IACA,iBAAiB,SAAS,mBAAmB,GAAG,GAAG,IAAI,GAAG,mBAExD,SAAS,GAAG,GAAG,KAEf,iBAAiB,SAAS,mBAAmB,GAAG,GAAG,IAAI,GAAG"}
1
+ {"version":3,"file":"plugins.d.ts","names":[],"sources":["../../../../src/interpreter/getContent/plugins.ts"],"mappings":";;;;;;;;;;;;;;;;;;;KAkDY;EACV;EACA,YAAY;EACZ,YACE,WACA,OAAO,WACP,cAAc,WAAW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ChD;KAEI,MAAM,mBAAmB;;;;KAKzB,qBACV,GACA,IAAI,yBACJ,UAAU,gBAAgB,mBAE1B,MAAM,kBACF,IACA,iBAAiB,SAAS,mBAAmB,GAAG,GAAG,IAAI,GAAG,mBAExD,SAAS,GAAG,GAAG,KAEf,iBAAiB,SAAS,mBAAmB,GAAG,GAAG,IAAI,GAAG"}
@@ -0,0 +1,31 @@
1
+ import { SelectContentStates } from "../transpiler/select/select.js";
2
+ import "../transpiler/index.js";
3
+ //#region src/interpreter/getSelect.d.ts
4
+ /**
5
+ * Picks content from a select map based on an arbitrary string value.
6
+ *
7
+ * Resolution order:
8
+ * 1. Exact match on the provided value.
9
+ * 2. The `fallback` key.
10
+ * 3. The `other` key — kept for content imported from an ICU `select` message,
11
+ * where the catch-all case is named `other`.
12
+ * 4. The last declared key, so a select node never resolves to `undefined`.
13
+ *
14
+ * @param selectContent - A map of string cases to content.
15
+ * @param value - The value to match against the declared cases.
16
+ * @returns The matching content.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const content = getSelect({
21
+ * draft: 'This post is a draft',
22
+ * published: 'This post is live',
23
+ * fallback: 'Unknown status',
24
+ * }, 'published');
25
+ * // 'This post is live'
26
+ * ```
27
+ */
28
+ declare const getSelect: <const Content>(selectContent: SelectContentStates<Content>, value?: string) => Content;
29
+ //#endregion
30
+ export { getSelect };
31
+ //# sourceMappingURL=getSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSelect.d.ts","names":[],"sources":["../../../src/interpreter/getSelect.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;cA0Ba,kBAAmB,SAAO,eACtB,oBAAoB,UAAQ,mBAE1C"}
@@ -1,16 +1,18 @@
1
1
  import { getCondition } from "./getCondition.js";
2
2
  import { GetNestingResult, getNesting } from "./getNesting.js";
3
- import { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, translationPlugin } from "./getContent/plugins.js";
3
+ import { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, IsAny, NestedCond, NodeProps, Plugins, PluralCond, SelectCond, SelectSelector, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, insertionPlugin, nestedPlugin, pluralPlugin, selectPlugin, translationPlugin } from "./getContent/plugins.js";
4
4
  import { deepTransformNode } from "./getContent/deepTransform.js";
5
5
  import { getBasePlugins, getContent } from "./getContent/getContent.js";
6
6
  import "./getContent/index.js";
7
7
  import { getDictionary } from "./getDictionary.js";
8
8
  import { findMatchingCondition, getEnumeration } from "./getEnumeration.js";
9
+ import { getGender } from "./getGender.js";
9
10
  import { getHTML } from "./getHTML.js";
10
11
  import { getInsertion } from "./getInsertion.js";
11
12
  import { getIntlayer } from "./getIntlayer.js";
12
13
  import { getPlural } from "./getPlural.js";
14
+ import { getSelect } from "./getSelect.js";
13
15
  import { getTranslation } from "./getTranslation.js";
14
16
  import { InterpolableNode, getInterpolableContent, isInterpolableWrapperNode, rebuildInterpolableContent, transformInterpolableNode } from "./interpolableNode.js";
15
17
  import { splitInsertionTemplate } from "./splitAndJoinInsertion.js";
16
- export { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, GetNestingResult, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, InterpolableNode, IsAny, NestedCond, NodeProps, Plugins, PluralCond, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, findMatchingCondition, genderPlugin, getBasePlugins, getCondition, getContent, getDictionary, getEnumeration, getHTML, getInsertion, getInterpolableContent, getIntlayer, getNesting, getPlural, getTranslation, insertionPlugin, isInterpolableWrapperNode, nestedPlugin, pluralPlugin, rebuildInterpolableContent, splitInsertionTemplate, transformInterpolableNode, translationPlugin };
18
+ export { ConditionCond, DeepTransformContent, EnumerationCond, FileCond, GenderCond, GetNestingResult, IInterpreterPlugin, IInterpreterPluginState, InsertionCond, InterpolableNode, IsAny, NestedCond, NodeProps, Plugins, PluralCond, SelectCond, SelectSelector, TranslationCond, UnionKeys, ValueAtKey, conditionPlugin, deepTransformNode, enumerationPlugin, fallbackPlugin, filePlugin, findMatchingCondition, genderPlugin, getBasePlugins, getCondition, getContent, getDictionary, getEnumeration, getGender, getHTML, getInsertion, getInterpolableContent, getIntlayer, getNesting, getPlural, getSelect, getTranslation, insertionPlugin, isInterpolableWrapperNode, nestedPlugin, pluralPlugin, rebuildInterpolableContent, selectPlugin, splitInsertionTemplate, transformInterpolableNode, translationPlugin };
@@ -1 +1 @@
1
- {"version":3,"file":"ICU.d.ts","names":[],"sources":["../../../src/messageFormat/ICU.ts"],"mappings":";;KAkDY,+CAKR;GACG,cAAc;;cAwlBR,yBAAsB,SACxB,0BACR;cAQU,yBAAsB,SACxB,0BACR"}
1
+ {"version":3,"file":"ICU.d.ts","names":[],"sources":["../../../src/messageFormat/ICU.ts"],"mappings":";;KAkDY,+CAKR;GACG,cAAc;;cAknBR,yBAAsB,SACxB,0BACR;cAQU,yBAAsB,SACxB,0BACR"}
@@ -1 +1 @@
1
- {"version":3,"file":"i18next.d.ts","names":[],"sources":["../../../src/messageFormat/i18next.ts"],"mappings":";;;cAsjBa,6BAA0B,SAC5B,0BACR;cAQU,6BAA0B,SAC5B,cACR"}
1
+ {"version":3,"file":"i18next.d.ts","names":[],"sources":["../../../src/messageFormat/i18next.ts"],"mappings":";;;cAklBa,6BAA0B,SAC5B,0BACR;cAQU,6BAA0B,SAC5B,cACR"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveMessage.d.ts","names":[],"sources":["../../../src/messageFormat/resolveMessage.ts"],"mappings":";;;;;;;;;;;;;;;KAwBY;;KAGA,gBAAgB;;;;;;;;;cAsFf,qBAAkB,kBACb,SACR,eAAa,SACb;;;;;;;;;cAkCG,qBAAkB,eAChB,SACL,eAAa,SACb;;;;;;;;;;;;;;;;;;;cA6IG,iBAAc,kBACT,SACR,eAAa,SACb,eAAa,UACZ;;KAaC;EAEN;EAAa,UAAU;;;;;;;;;cAShB,qBAAkB,oBAAsB"}
1
+ {"version":3,"file":"resolveMessage.d.ts","names":[],"sources":["../../../src/messageFormat/resolveMessage.ts"],"mappings":";;;;;;;;;;;;;;;KAyBY;;KAGA,gBAAgB;;;;;;;;;cAsFf,qBAAkB,kBACb,SACR,eAAa,SACb;;;;;;;;;cAkCG,qBAAkB,eAChB,SACL,eAAa,SACb;;;;;;;;;;;;;;;;;;;cA2JG,iBAAc,kBACT,SACR,eAAa,SACb,eAAa,UACZ;;KAaC;EAEN;EAAa,UAAU;;;;;;;;;cAShB,qBAAkB,oBAAsB"}
@@ -1 +1 @@
1
- {"version":3,"file":"vue-i18n.d.ts","names":[],"sources":["../../../src/messageFormat/vue-i18n.ts"],"mappings":";;;cAoUa,6BAA0B,SAC5B,0BACR;cAQU,6BAA0B,SAC5B,cACR"}
1
+ {"version":3,"file":"vue-i18n.d.ts","names":[],"sources":["../../../src/messageFormat/vue-i18n.ts"],"mappings":";;;cAoVa,6BAA0B,SAC5B,0BACR;cAQU,6BAA0B,SAC5B,cACR"}
@@ -21,6 +21,8 @@ import { DotPath, NestedContent, NestedContentState, ValidDotPathsFor, nest as n
21
21
  import "./nesting/index.js";
22
22
  import { PluralCategory, PluralContent, PluralContentState, plural } from "./plural/plural.js";
23
23
  import "./plural/index.js";
24
+ import { SelectContent, SelectContentStates, select } from "./select/select.js";
25
+ import "./select/index.js";
24
26
  import { TranslationContent, t as translation } from "./translation/translation.js";
25
27
  import "./translation/index.js";
26
- export { ConditionContent, ConditionContentStates, DotPath, EnterFormat, EnumerationContent, EnumerationContentState, type FileContent, type FileContentConstructor, Gender, GenderContent, GenderContentStates, HTMLContent, HTMLContentConstructor, HTMLTagsType, HTMLValidationIssue, HTMLValidationResult, HTML_TAGS, InsertionContent, InsertionContentConstructor, MarkdownContent, MarkdownContentConstructor, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, NestedContent, NestedContentState, PluralCategory, PluralContent, PluralContentState, TranslationContent, VOID_HTML_ELEMENTS, ValidDotPathsFor, condition as cond, enumeration as enu, type file, type fileContent, gender, getInsertionValues, getMarkdownMetadata, html, insertion as insert, markdown as md, nesting as nest, plural, translation as t, validateHTML, validateMarkdown };
28
+ export { ConditionContent, ConditionContentStates, DotPath, EnterFormat, EnumerationContent, EnumerationContentState, type FileContent, type FileContentConstructor, Gender, GenderContent, GenderContentStates, HTMLContent, HTMLContentConstructor, HTMLTagsType, HTMLValidationIssue, HTMLValidationResult, HTML_TAGS, InsertionContent, InsertionContentConstructor, MarkdownContent, MarkdownContentConstructor, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, NestedContent, NestedContentState, PluralCategory, PluralContent, PluralContentState, SelectContent, SelectContentStates, TranslationContent, VOID_HTML_ELEMENTS, ValidDotPathsFor, condition as cond, enumeration as enu, type file, type fileContent, gender, getInsertionValues, getMarkdownMetadata, html, insertion as insert, markdown as md, nesting as nest, plural, select, translation as t, validateHTML, validateMarkdown };
@@ -0,0 +1,2 @@
1
+ import { SelectContent, SelectContentStates, select } from "./select.js";
2
+ export { SelectContent, SelectContentStates, select };
@@ -0,0 +1,62 @@
1
+ import { SELECT, TypedNodeModel } from "@intlayer/types/nodeType";
2
+ //#region src/transpiler/select/select.d.ts
3
+ /**
4
+ * Map of arbitrary string cases to their content.
5
+ *
6
+ * Every key is a case the application can switch on (`'Draft'`, `'Published'`,
7
+ * `'Scheduled'`, …). The optional `fallback` key is picked when the provided
8
+ * value matches no declared case.
9
+ */
10
+ type SelectContentStates<Content = unknown> = {
11
+ [caseKey: string]: Content;
12
+ } & {
13
+ fallback?: Content;
14
+ };
15
+ type SelectContent<States extends SelectContentStates = SelectContentStates> = TypedNodeModel<typeof SELECT, States, {
16
+ /**
17
+ * Name of the variable the cases are selected on.
18
+ *
19
+ * Purely informational at runtime — the selector is passed explicitly by
20
+ * the caller. It is preserved so content imported from, or exported to, an
21
+ * ICU `{publishType, select, …}` message keeps its variable name across
22
+ * the round-trip.
23
+ */
24
+ variable?: string;
25
+ }>;
26
+ /**
27
+ * Function intended to be used to build intlayer dictionaries.
28
+ *
29
+ * Allow to pick a content based on an arbitrary string value — the equivalent
30
+ * of an ICU `{value, select, …}` message, or of a `switch` statement in the
31
+ * application code.
32
+ *
33
+ * Use it when the discriminant is neither a quantity (`enu`), a boolean
34
+ * (`cond`), nor a gender (`gender`).
35
+ *
36
+ * Usage:
37
+ *
38
+ * ```ts
39
+ * select({
40
+ * draft: 'This post is a draft',
41
+ * published: 'This post is live',
42
+ * scheduled: 'This post is scheduled',
43
+ * fallback: 'Unknown status',
44
+ * });
45
+ * ```
46
+ *
47
+ * When no `fallback` key is provided, the last key declared is used as the
48
+ * fallback value — the same contract as `cond()` and `gender()`.
49
+ *
50
+ * Prefer `select()` over indexing a plain object (`content.status[value]`):
51
+ * a dynamic computed access cannot be resolved statically by the Intlayer
52
+ * compiler, which forces the whole branch to be kept and its keys to stay
53
+ * un-minified.
54
+ *
55
+ * @param content - The map of cases to content.
56
+ * @param variable - Optional name of the variable being selected on. Preserved
57
+ * for the ICU / i18next round-trip; unused at runtime.
58
+ */
59
+ declare const select: <const States extends SelectContentStates>(content?: States, variable?: string) => SelectContent<States>;
60
+ //#endregion
61
+ export { SelectContent, SelectContentStates, select };
62
+ //# sourceMappingURL=select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.d.ts","names":[],"sources":["../../../../src/transpiler/select/select.ts"],"mappings":";;;;;;;;;KAUY,oBAAoB;GAC7B,kBAAkB;;EAEnB,WAAW;;KAGD,cACV,eAAe,sBAAsB,uBACnC,sBACK,QACP;;;;;;;;;EAUE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqCE,eAAgB,eAAe,qBAAmB,UAC5C,QAAM,sBAEf,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/core",
3
- "version": "9.0.1",
3
+ "version": "9.1.0",
4
4
  "private": false,
5
5
  "description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
6
6
  "keywords": [
@@ -172,20 +172,20 @@
172
172
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
173
173
  },
174
174
  "dependencies": {
175
- "@intlayer/api": "9.0.1",
176
- "@intlayer/config": "9.0.1",
177
- "@intlayer/dictionaries-entry": "9.0.1",
178
- "@intlayer/types": "9.0.1",
179
- "@intlayer/unmerged-dictionaries-entry": "9.0.1",
175
+ "@intlayer/api": "9.1.0",
176
+ "@intlayer/config": "9.1.0",
177
+ "@intlayer/dictionaries-entry": "9.1.0",
178
+ "@intlayer/types": "9.1.0",
179
+ "@intlayer/unmerged-dictionaries-entry": "9.1.0",
180
180
  "defu": "6.1.7"
181
181
  },
182
182
  "devDependencies": {
183
- "@types/node": "26.1.1",
183
+ "@types/node": "26.1.2",
184
184
  "@utils/ts-config": "1.0.4",
185
185
  "@utils/ts-config-types": "1.0.4",
186
186
  "@utils/tsdown-config": "1.0.4",
187
187
  "rimraf": "6.1.3",
188
- "tsdown": "0.22.13",
188
+ "tsdown": "0.22.14",
189
189
  "typescript": "7.0.2",
190
190
  "vitest": "4.1.10"
191
191
  },