@intlayer/core 8.9.7 → 8.9.8
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/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/interpreter/getCondition.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +1 -5
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getEnumeration.cjs.map +1 -1
- package/dist/cjs/interpreter/getGender.cjs.map +1 -1
- package/dist/cjs/interpreter/getHTML.cjs.map +1 -1
- package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
- package/dist/cjs/interpreter/getPlural.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
- package/dist/cjs/localization/generateSitemap.cjs.map +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/localization/localeDetector.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs.map +1 -1
- package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
- package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/constants.cjs.map +1 -1
- package/dist/cjs/markdown/parser.cjs.map +1 -1
- package/dist/cjs/markdown/renderer.cjs.map +1 -1
- package/dist/cjs/markdown/utils.cjs.map +1 -1
- package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
- package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
- package/dist/cjs/messageFormat/po.cjs.map +1 -1
- package/dist/cjs/messageFormat/verify-icu-format.cjs.map +1 -1
- package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
- package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
- package/dist/cjs/transpiler/html/html.cjs.map +1 -1
- package/dist/cjs/transpiler/html/htmlTags.cjs.map +1 -1
- package/dist/cjs/transpiler/html/validateHTML.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/validateMarkdown.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/plural/plural.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/utils/checkIsURLAbsolute.cjs.map +1 -1
- package/dist/cjs/utils/getCookie.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/cjs/utils/parseYaml.cjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/getSplittedContent.mjs.map +1 -1
- package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/interpreter/getCondition.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +1 -5
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getEnumeration.mjs.map +1 -1
- package/dist/esm/interpreter/getGender.mjs.map +1 -1
- package/dist/esm/interpreter/getHTML.mjs.map +1 -1
- package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getNesting.mjs.map +1 -1
- package/dist/esm/interpreter/getPlural.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
- package/dist/esm/localization/generateSitemap.mjs.map +1 -1
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
- package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
- package/dist/esm/localization/getLocaleName.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
- package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/localization/localeDetector.mjs.map +1 -1
- package/dist/esm/localization/localeMapper.mjs.map +1 -1
- package/dist/esm/localization/localeResolver.mjs.map +1 -1
- package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
- package/dist/esm/localization/validatePrefix.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/constants.mjs.map +1 -1
- package/dist/esm/markdown/parser.mjs.map +1 -1
- package/dist/esm/markdown/renderer.mjs.map +1 -1
- package/dist/esm/markdown/utils.mjs.map +1 -1
- package/dist/esm/messageFormat/ICU.mjs.map +1 -1
- package/dist/esm/messageFormat/i18next.mjs.map +1 -1
- package/dist/esm/messageFormat/po.mjs.map +1 -1
- package/dist/esm/messageFormat/verify-icu-format.mjs.map +1 -1
- package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
- package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
- package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/file/file.mjs.map +1 -1
- package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
- package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
- package/dist/esm/transpiler/html/html.mjs.map +1 -1
- package/dist/esm/transpiler/html/htmlTags.mjs.map +1 -1
- package/dist/esm/transpiler/html/validateHTML.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/validateMarkdown.mjs.map +1 -1
- package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
- package/dist/esm/transpiler/plural/plural.mjs.map +1 -1
- package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
- package/dist/esm/utils/checkIsURLAbsolute.mjs.map +1 -1
- package/dist/esm/utils/getCookie.mjs.map +1 -1
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/esm/utils/parseYaml.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +11 -12
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +11 -12
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +9 -10
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getMaskContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getMultilingualDictionary.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getSplittedContent.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getEmptyNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
- package/dist/types/formatters/compact.d.ts.map +1 -1
- package/dist/types/formatters/currency.d.ts.map +1 -1
- package/dist/types/formatters/date.d.ts.map +1 -1
- package/dist/types/formatters/list.d.ts.map +1 -1
- package/dist/types/formatters/relativeTime.d.ts.map +1 -1
- package/dist/types/formatters/units.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts +3 -3
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getEnumeration.d.ts.map +1 -1
- package/dist/types/interpreter/getGender.d.ts.map +1 -1
- package/dist/types/interpreter/getHTML.d.ts.map +1 -1
- package/dist/types/interpreter/getInsertion.d.ts.map +1 -1
- package/dist/types/interpreter/getNesting.d.ts.map +1 -1
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/dist/types/localization/generateSitemap.d.ts.map +1 -1
- package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
- package/dist/types/localization/getHTMLTextDir.d.ts.map +1 -1
- package/dist/types/localization/getLocaleFromPath.d.ts.map +1 -1
- package/dist/types/localization/getLocaleLang.d.ts.map +1 -1
- package/dist/types/localization/getLocaleName.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
- package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
- package/dist/types/localization/getPrefix.d.ts.map +1 -1
- package/dist/types/localization/localeDetector.d.ts.map +1 -1
- package/dist/types/localization/localeMapper.d.ts.map +1 -1
- package/dist/types/localization/rewriteUtils.d.ts.map +1 -1
- package/dist/types/localization/validatePrefix.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts.map +1 -1
- package/dist/types/markdown/constants.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +1 -1
- package/dist/types/markdown/types.d.ts.map +1 -1
- package/dist/types/markdown/utils.d.ts.map +1 -1
- package/dist/types/messageFormat/ICU.d.ts.map +1 -1
- package/dist/types/messageFormat/i18next.d.ts.map +1 -1
- package/dist/types/messageFormat/po.d.ts.map +1 -1
- package/dist/types/messageFormat/vue-i18n.d.ts.map +1 -1
- package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/file/file.d.ts.map +1 -1
- package/dist/types/transpiler/file/fileBrowser.d.ts.map +1 -1
- package/dist/types/transpiler/gender/gender.d.ts.map +1 -1
- package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts.map +1 -1
- package/dist/types/transpiler/html/html.d.ts.map +1 -1
- package/dist/types/transpiler/html/htmlTags.d.ts.map +1 -1
- package/dist/types/transpiler/html/validateHTML.d.ts.map +1 -1
- package/dist/types/transpiler/index.d.ts +1 -1
- package/dist/types/transpiler/insertion/getInsertionValues.d.ts.map +1 -1
- package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/index.d.ts +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/validateMarkdown.d.ts.map +1 -1
- package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
- package/dist/types/transpiler/plural/plural.d.ts.map +1 -1
- package/dist/types/utils/checkIsURLAbsolute.d.ts.map +1 -1
- package/dist/types/utils/getCookie.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/dist/types/utils/isSameKeyPath.d.ts.map +1 -1
- package/dist/types/utils/isValidReactElement.d.ts.map +1 -1
- package/dist/types/utils/localeStorage.d.ts.map +1 -1
- package/dist/types/utils/parseYaml.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMaskContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMaskContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { deepTransformNode, type Plugins } from '../interpreter';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const getMaskContent = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":";;;AAGA,MAAM,sBAA+B;CACnC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,OAAO,MAAM,aAAa;CACxD,YAAY,MAAM,OAAO,sBACvB,kBAAkB,KAAK,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"getMaskContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMaskContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { deepTransformNode, type Plugins } from '../interpreter';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const getMaskContent = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":";;;AAGA,MAAM,sBAA+B;CACnC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,OAAO,MAAM,aAAa;CACxD,YAAY,MAAM,OAAO,sBACvB,kBAAkB,KAAK,KAAK,WAAW,KAAK;AAChD;;AAGA,MAAa,kBAA2B;CACtC,IAAI;CACJ,YAAY,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS;CACjE,iBAAiB;AACnB;AAEA,MAAa,kBAAkB,YAA6B;CAC1D,GAAG;CACH,SAAS,kBAAkB,OAAO,SAAS;EACzC,eAAe,OAAO;EACtB,SAAS,CAAC;EACV,SAAS,CAAC,qBAAqB,eAAe;CAChD,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMissingLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Returns all key paths present in obj, INCLUDING those whose leaf value is null.\n * Used for structural presence checks (a locale must have every key another locale has,\n * even if the value is a null placeholder).\n */\nconst getAllKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Stop recursing into null — include the path but don't descend further\n if (value === null) {\n return [newPath];\n }\n return [newPath, ...getAllKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns key paths whose leaf value is non-null.\n * Used for translation value checks (a locale must not have null where another locale\n * already has a real translated value).\n */\nconst getNonNullKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Skip null-valued keys entirely\n if (value === null) {\n return [];\n }\n return [newPath, ...getNonNullKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns true if the key path EXISTS in obj (even if the terminal value is null).\n * Used for the structural presence check.\n */\nconst hasKey = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n return true; // key exists; value may be null\n};\n\n/**\n * Returns true if the key path exists in obj AND the terminal value is non-null.\n * Used for the translation value check.\n */\nconst hasNonNullValue = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n // null is treated as a missing translation (e.g., i18next-scanner sets null for untranslated keys)\n return current !== null;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const translations = node[NodeTypes.TRANSLATION] as Record<string, any>;\n\n /**\n * Two path sets built from all locales' content:\n *\n * presentPaths — every key path that exists in ANY locale, even those whose value\n * is null. A locale that is missing a path from this set is structurally incomplete\n * (the key doesn't exist at all).\n *\n * nonNullPaths — every key path that has a non-null value in at least one locale.\n * A locale that has the key but with null, when another locale already has a real\n * value, needs translation.\n */\n const presentPaths = new Set<string>();\n const nonNullPaths = new Set<string>();\n\n for (const locale of locales) {\n const value = translations[locale];\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n getAllKeyPaths(value).forEach((path) => {\n presentPaths.add(JSON.stringify(path));\n });\n\n getNonNullKeyPaths(value).forEach((path) => {\n nonNullPaths.add(JSON.stringify(path));\n });\n }\n }\n\n // If no locale has any content at all (all are null/undefined), the key is\n // universally pending — don't flag anyone.\n const hasAnyDefinedValue = locales.some(\n (locale) =>\n translations[locale] !== undefined && translations[locale] !== null\n );\n\n for (const locale of locales) {\n const value = translations[locale];\n\n if (value === null) {\n // Entire locale content is a null placeholder.\n // Flag only when some other locale already has real content.\n if (hasAnyDefinedValue) {\n onMissingLocale(locale);\n }\n continue;\n }\n\n if (!value) {\n // undefined / entirely absent\n onMissingLocale(locale);\n continue;\n }\n\n let flagged = false;\n\n // Structural check: every key that exists in any locale must also exist here\n // (even if the local value is null — at least the key must be present).\n for (const pathStr of presentPaths) {\n if (!hasKey(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n flagged = true;\n break;\n }\n }\n\n if (!flagged) {\n // Value check: every key that has a non-null value in some locale must also\n // be non-null here (null = untranslated, needs filling).\n for (const pathStr of nonNullPaths) {\n if (!hasNonNullValue(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n break;\n }\n }\n }\n }\n\n // Continue traversal inside the translation values\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = internationalization?.locales,\n\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n // eager: traversal of plain objects must run immediately. Without it the\n // returned tree is a proxy of lazy getters; we discard the tree, so nested\n // translation nodes inside plain objects (the typical dictionary shape) are\n // never visited and their missing locales go undetected.\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n eager: true,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"getMissingLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Returns all key paths present in obj, INCLUDING those whose leaf value is null.\n * Used for structural presence checks (a locale must have every key another locale has,\n * even if the value is a null placeholder).\n */\nconst getAllKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Stop recursing into null — include the path but don't descend further\n if (value === null) {\n return [newPath];\n }\n return [newPath, ...getAllKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns key paths whose leaf value is non-null.\n * Used for translation value checks (a locale must not have null where another locale\n * already has a real translated value).\n */\nconst getNonNullKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Skip null-valued keys entirely\n if (value === null) {\n return [];\n }\n return [newPath, ...getNonNullKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns true if the key path EXISTS in obj (even if the terminal value is null).\n * Used for the structural presence check.\n */\nconst hasKey = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n return true; // key exists; value may be null\n};\n\n/**\n * Returns true if the key path exists in obj AND the terminal value is non-null.\n * Used for the translation value check.\n */\nconst hasNonNullValue = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n // null is treated as a missing translation (e.g., i18next-scanner sets null for untranslated keys)\n return current !== null;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.TRANSLATION,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const translations = node[NodeTypes.TRANSLATION] as Record<string, any>;\n\n /**\n * Two path sets built from all locales' content:\n *\n * presentPaths — every key path that exists in ANY locale, even those whose value\n * is null. A locale that is missing a path from this set is structurally incomplete\n * (the key doesn't exist at all).\n *\n * nonNullPaths — every key path that has a non-null value in at least one locale.\n * A locale that has the key but with null, when another locale already has a real\n * value, needs translation.\n */\n const presentPaths = new Set<string>();\n const nonNullPaths = new Set<string>();\n\n for (const locale of locales) {\n const value = translations[locale];\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n getAllKeyPaths(value).forEach((path) => {\n presentPaths.add(JSON.stringify(path));\n });\n\n getNonNullKeyPaths(value).forEach((path) => {\n nonNullPaths.add(JSON.stringify(path));\n });\n }\n }\n\n // If no locale has any content at all (all are null/undefined), the key is\n // universally pending — don't flag anyone.\n const hasAnyDefinedValue = locales.some(\n (locale) =>\n translations[locale] !== undefined && translations[locale] !== null\n );\n\n for (const locale of locales) {\n const value = translations[locale];\n\n if (value === null) {\n // Entire locale content is a null placeholder.\n // Flag only when some other locale already has real content.\n if (hasAnyDefinedValue) {\n onMissingLocale(locale);\n }\n continue;\n }\n\n if (!value) {\n // undefined / entirely absent\n onMissingLocale(locale);\n continue;\n }\n\n let flagged = false;\n\n // Structural check: every key that exists in any locale must also exist here\n // (even if the local value is null — at least the key must be present).\n for (const pathStr of presentPaths) {\n if (!hasKey(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n flagged = true;\n break;\n }\n }\n\n if (!flagged) {\n // Value check: every key that has a non-null value in some locale must also\n // be non-null here (null = untranslated, needs filling).\n for (const pathStr of nonNullPaths) {\n if (!hasNonNullValue(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n break;\n }\n }\n }\n }\n\n // Continue traversal inside the translation values\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = internationalization?.locales,\n\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n // eager: traversal of plain objects must run immediately. Without it the\n // returned tree is a proxy of lazy getters; we discard the tree, so nested\n // translation nodes inside plain objects (the typical dictionary shape) are\n // never visited and their missing locales go undetected.\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n eager: true,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMultilingualDictionary.mjs","names":["t"],"sources":["../../../src/deepTransformPlugins/getMultilingualDictionary.ts"],"sourcesContent":["import type { Dictionary, TypedNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { t } from '../transpiler';\n\n/**\n * Transform a per-locale dictionary into a multilingual dictionary.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"locale\": \"en\",\n * \"content\": {\n * \"myContent\": \"English content\"\n * }\n * }\n * ```\n *\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"content\": {\n * \"myContent\": t({\n * \"en\": \"English content\",\n * })\n * }\n * }\n * ```\n */\nexport const getMultilingualDictionary = (\n dictionary: Dictionary\n): Dictionary => {\n if (!dictionary.locale) {\n return dictionary;\n }\n\n const locale = dictionary.locale;\n\n const wrapPrimitiveInTranslationPlugin: Plugins = {\n id: 'wrap-primitive-in-translation',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: (node) => t({ [locale]: node } as Record<string, unknown>),\n };\n\n const traverseTypedNodePlugin: Plugins = {\n id: 'traverse-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof (node as any)?.nodeType === 'string',\n transform: (node: TypedNode, props, transformFn) => {\n const nodeType = (node as any).nodeType as NodeType;\n const inner = structuredClone(\n (node as any)[nodeType as unknown as keyof TypedNode] as any\n );\n\n if (typeof inner !== 'object' || inner === null) {\n const transformed = transformFn(inner, {\n ...props,\n children: inner,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformed,\n };\n }\n\n for (const key in inner) {\n const childProps: NodeProps = {\n ...props,\n children: inner[key as unknown as keyof typeof inner],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n inner[key as unknown as keyof typeof inner] = transformFn(\n inner[key as unknown as keyof typeof inner],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: inner };\n },\n };\n\n const transformedContent = deepTransformNode(\n JSON.parse(JSON.stringify(dictionary.content)),\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [traverseTypedNodePlugin, wrapPrimitiveInTranslationPlugin],\n }\n );\n\n const { locale: _omitLocale, ...rest } = dictionary as any;\n return {\n ...rest,\n content: transformedContent,\n } as Dictionary;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,6BACX,eACe;CACf,IAAI,CAAC,WAAW,QACd,OAAO;CAGT,MAAM,SAAS,WAAW;CAoD1B,MAAM,qBAAqB,kBACzB,KAAK,MAAM,KAAK,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"getMultilingualDictionary.mjs","names":["t"],"sources":["../../../src/deepTransformPlugins/getMultilingualDictionary.ts"],"sourcesContent":["import type { Dictionary, TypedNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { t } from '../transpiler';\n\n/**\n * Transform a per-locale dictionary into a multilingual dictionary.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"locale\": \"en\",\n * \"content\": {\n * \"myContent\": \"English content\"\n * }\n * }\n * ```\n *\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"content\": {\n * \"myContent\": t({\n * \"en\": \"English content\",\n * })\n * }\n * }\n * ```\n */\nexport const getMultilingualDictionary = (\n dictionary: Dictionary\n): Dictionary => {\n if (!dictionary.locale) {\n return dictionary;\n }\n\n const locale = dictionary.locale;\n\n const wrapPrimitiveInTranslationPlugin: Plugins = {\n id: 'wrap-primitive-in-translation',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: (node) => t({ [locale]: node } as Record<string, unknown>),\n };\n\n const traverseTypedNodePlugin: Plugins = {\n id: 'traverse-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof (node as any)?.nodeType === 'string',\n transform: (node: TypedNode, props, transformFn) => {\n const nodeType = (node as any).nodeType as NodeType;\n const inner = structuredClone(\n (node as any)[nodeType as unknown as keyof TypedNode] as any\n );\n\n if (typeof inner !== 'object' || inner === null) {\n const transformed = transformFn(inner, {\n ...props,\n children: inner,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformed,\n };\n }\n\n for (const key in inner) {\n const childProps: NodeProps = {\n ...props,\n children: inner[key as unknown as keyof typeof inner],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n inner[key as unknown as keyof typeof inner] = transformFn(\n inner[key as unknown as keyof typeof inner],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: inner };\n },\n };\n\n const transformedContent = deepTransformNode(\n JSON.parse(JSON.stringify(dictionary.content)),\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [traverseTypedNodePlugin, wrapPrimitiveInTranslationPlugin],\n }\n );\n\n const { locale: _omitLocale, ...rest } = dictionary as any;\n return {\n ...rest,\n content: transformedContent,\n } as Dictionary;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,6BACX,eACe;CACf,IAAI,CAAC,WAAW,QACd,OAAO;CAGT,MAAM,SAAS,WAAW;CAoD1B,MAAM,qBAAqB,kBACzB,KAAK,MAAM,KAAK,UAAU,WAAW,OAAO,CAAC,GAC7C;EACE,eAAe,WAAW;EAC1B,SAAS,CAAC;EACV,SAAS,CAAC;GA7CZ,IAAI;GACJ,YAAY,SACV,OAAO,SAAS,YAAY,OAAQ,MAAc,aAAa;GACjE,YAAY,MAAiB,OAAO,gBAAgB;IAClD,MAAM,WAAY,KAAa;IAC/B,MAAM,QAAQ,gBACX,KAAa,SAChB;IAEA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;KAC/C,MAAM,cAAc,YAAY,OAAO;MACrC,GAAG;MACH,UAAU;MACV,SAAS,CACP,GAAG,MAAM,SACT;OAAE,MAAM;OAAU,KAAK;MAAS,CAClC;KACF,CAAC;KACD,OAAO;MACL,GAAG;OACF,WAAyC;KAC5C;IACF;IAEA,KAAK,MAAM,OAAO,OAAO;KACvB,MAAM,aAAwB;MAC5B,GAAG;MACH,UAAU,MAAM;MAChB,SAAS,CAAC,GAAG,MAAM,SAAS;OAAE,MAAM;OAAU;MAAI,CAAY;KAChE;KACA,MAAM,OAAwC,YAC5C,MAAM,MACN,UACF;IACF;IAEA,OAAO;KAAE,GAAG;MAAO,WAAyC;IAAM;GACpE;EAQkC,GAAG;GAtDrC,IAAI;GACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;GAClB,YAAY,SAASA,YAAE,GAAG,SAAS,KAAK,CAA4B;EAiDA,CAAC;CACrE,CACF;CAEA,MAAM,EAAE,QAAQ,aAAa,GAAG,SAAS;CACzC,OAAO;EACL,GAAG;EACH,SAAS;CACX;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getReplacedValuesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getReplacedValuesContent.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst replaceValuesPlugin = (value: string | number | boolean): Plugins => ({\n id: 'replace-values-plugin',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: () => value,\n});\n\nconst skipTypedNodePlugin: Plugins = {\n id: 'skip-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node: TypedNode, props, deepTransformNode) => {\n const nodeType = node.nodeType as NodeType;\n const result = structuredClone(\n node[nodeType as unknown as keyof TypedNode] as any\n );\n\n // If the result is a primitive value (string, number, boolean),\n // we need to transform it directly instead of iterating over its properties\n if (typeof result !== 'object' || result === null) {\n const transformedResult = deepTransformNode(result, {\n ...props,\n children: result,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformedResult,\n };\n }\n\n // For objects and arrays, iterate over their properties\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: result };\n },\n};\n\nexport const getReplacedValuesContent = (\n node: ContentNode,\n value: string | number | boolean,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n skipTypedNodePlugin,\n replaceValuesPlugin(value),\n ...(nodeProps.plugins ?? []),\n ];\n\n const JSONNode = JSON.parse(JSON.stringify(node));\n\n return deepTransformNode(JSONNode, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":";;;AASA,MAAM,uBAAuB,WAA+C;CAC1E,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"getReplacedValuesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getReplacedValuesContent.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst replaceValuesPlugin = (value: string | number | boolean): Plugins => ({\n id: 'replace-values-plugin',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: () => value,\n});\n\nconst skipTypedNodePlugin: Plugins = {\n id: 'skip-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node: TypedNode, props, deepTransformNode) => {\n const nodeType = node.nodeType as NodeType;\n const result = structuredClone(\n node[nodeType as unknown as keyof TypedNode] as any\n );\n\n // If the result is a primitive value (string, number, boolean),\n // we need to transform it directly instead of iterating over its properties\n if (typeof result !== 'object' || result === null) {\n const transformedResult = deepTransformNode(result, {\n ...props,\n children: result,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformedResult,\n };\n }\n\n // For objects and arrays, iterate over their properties\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: result };\n },\n};\n\nexport const getReplacedValuesContent = (\n node: ContentNode,\n value: string | number | boolean,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n skipTypedNodePlugin,\n replaceValuesPlugin(value),\n ...(nodeProps.plugins ?? []),\n ];\n\n const JSONNode = JSON.parse(JSON.stringify(node));\n\n return deepTransformNode(JSONNode, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":";;;AASA,MAAM,uBAAuB,WAA+C;CAC1E,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,iBAAiB;AACnB;AAEA,MAAM,sBAA+B;CACnC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,OAAO,MAAM,aAAa;CACxD,YAAY,MAAiB,OAAO,sBAAsB;EACxD,MAAM,WAAW,KAAK;EACtB,MAAM,SAAS,gBACb,KAAK,SACP;EAIA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM;GACjD,MAAM,oBAAoB,kBAAkB,QAAQ;IAClD,GAAG;IACH,UAAU;IACV,SAAS,CACP,GAAG,MAAM,SACT;KAAE,MAAM;KAAU,KAAK;IAAS,CAClC;GACF,CAAC;GACD,OAAO;IACL,GAAG;KACF,WAAyC;GAC5C;EACF;EAGA,KAAK,MAAM,OAAO,QAAQ;GACxB,MAAM,aAAa;IACjB,GAAG;IACH,UAAU,OAAO;IACjB,SAAS,CAAC,GAAG,MAAM,SAAS;KAAE,MAAM;KAAU;IAAI,CAAY;GAChE;GACA,OAAO,OAAyC,kBAC9C,OAAO,MACP,UACF;EACF;EAEA,OAAO;GAAE,GAAG;IAAO,WAAyC;EAAO;CACrE;AACF;AAEA,MAAa,4BACX,MACA,OACA,cACG;CACH,MAAM,UAAqB;EACzB;EACA,oBAAoB,KAAK;EACzB,GAAI,UAAU,WAAW,CAAC;CAC5B;CAIA,OAAO,kBAFU,KAAK,MAAM,KAAK,UAAU,IAAI,CAEf,GAAG;EACjC,GAAG;EACH;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSplittedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeTypes.TRANSLATION) {\n const translations = (node as any)[NodeTypes.TRANSLATION] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"getSplittedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeTypes.TRANSLATION) {\n const translations = (node as any)[NodeTypes.TRANSLATION] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertContentInDictionary.mjs","names":[],"sources":["../../../src/deepTransformPlugins/insertContentInDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\n// {\n// {\n// title: 'このページ',\n// linkLabel: 'セクションへ移動',\n// collapseButton: { label: '折りたたむ' }\n// },\n// }\n// {\n// dictionary: {\n// key: 'aside-navigation',\n// content: {\n// title: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'في هذه الصفحة',\n// de: 'Auf dieser Seite',\n// en: 'In this page',\n// 'en-GB': 'On this page',\n// es: 'En esta página',\n// fr: 'Dans cette page',\n// hi: 'इस पृष्ठ में',\n// it: 'In questa pagina',\n// ko: '이 페이지에서',\n// pt: 'Nesta página',\n// ru: 'На этой странице',\n// tr: 'Bu sayfada',\n// zh: '在此页面'\n// }\n// },\n// },\n// localId: 'aside-navigation::local::src/components/AsideNavigation/asideNavigation.content.ts',\n// location: 'local',\n// filePath: 'src/components/AsideNavigation/asideNavigation.content.ts'\n// }\n// }\n\n/**\n * Deep merge helper that handles translation blocks\n * @param target - The target object (dictionary content)\n * @param source - The source object (new content to merge)\n * @param locale - Optional locale to target specific translation\n * @returns Merged content\n */\nconst deepMergeContent = (\n target: any,\n source: any,\n locale?: LocalesValues\n): any => {\n // If source is null or undefined, return target\n if (source === null || source === undefined) return target;\n\n // If target is null or undefined, initialize based on source type\n if (target === null || target === undefined) {\n if (Array.isArray(source)) {\n target = [];\n } else if (typeof source === 'object') {\n target = {};\n } else {\n return source;\n }\n }\n\n // Handle translation nodes FIRST (before arrays) to support arrays within translations\n if (\n target &&\n typeof target === 'object' &&\n target.nodeType === NodeTypes.TRANSLATION\n ) {\n // Target is a translation block\n if (locale) {\n // Update only the specific locale - create new object to preserve order\n const existingLocaleContent = target[NodeTypes.TRANSLATION][locale];\n let newLocaleContent: any;\n\n if (typeof source === 'object' && !Array.isArray(source)) {\n // Source is an object, need to deep merge for this locale\n newLocaleContent = deepMergeContent(\n existingLocaleContent,\n source,\n undefined // Don't pass locale down for nested content\n );\n } else if (Array.isArray(source)) {\n // Source is an array, set it directly for this locale\n newLocaleContent = source;\n } else {\n // Source is a primitive, directly set it\n newLocaleContent = source;\n }\n\n // Return new object with locale appended at the end (preserve insertion order)\n return {\n ...target,\n [NodeTypes.TRANSLATION]: {\n ...target[NodeTypes.TRANSLATION],\n [locale]: newLocaleContent,\n },\n };\n } else {\n // No locale specified, replace/merge the entire translation\n if (\n typeof source === 'object' &&\n !Array.isArray(source) &&\n source.nodeType === NodeTypes.TRANSLATION\n ) {\n // Source is also a translation node, merge translations\n return {\n ...target,\n [NodeTypes.TRANSLATION]: {\n ...target[NodeTypes.TRANSLATION],\n ...source[NodeTypes.TRANSLATION],\n },\n };\n } else {\n // Source is not a translation node, wrap it\n return processNewContent(source, locale);\n }\n }\n }\n\n // Handle arrays\n if (Array.isArray(source)) {\n if (locale && Array.isArray(target)) {\n // When locale is specified and target is also an array, merge element by element\n const result = [];\n const maxLength = Math.max(source.length, target.length);\n\n for (let i = 0; i < maxLength; i++) {\n if (i < source.length) {\n if (i < target.length && target[i] !== undefined) {\n // Both source and target have element at this index - merge them\n result[i] = deepMergeContent(target[i], source[i], locale);\n } else {\n // Only source has element at this index - process new content\n result[i] = processNewContent(source[i], locale);\n }\n } else {\n // Only target has element at this index - keep it\n result[i] = target[i];\n }\n }\n\n return result;\n } else {\n // No locale or target is not an array - replace entirely\n return source.map((item) => {\n // Process each item in case it needs locale wrapping\n if (\n item &&\n typeof item === 'object' &&\n item.nodeType === NodeTypes.TRANSLATION\n ) {\n return item;\n }\n return processNewContent(item, locale);\n });\n }\n }\n\n // Handle objects\n if (typeof source === 'object' && !Array.isArray(source)) {\n if (typeof target !== 'object' || Array.isArray(target)) {\n target = {};\n }\n\n // Create new object to preserve key order and avoid mutation\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n if (target[key] !== undefined) {\n result[key] = deepMergeContent(target[key], source[key], locale);\n } else {\n result[key] = processNewContent(source[key], locale);\n }\n }\n }\n\n return result;\n }\n\n // For primitives, just return the source\n return source;\n};\n\n/**\n * Process new content that doesn't exist in target\n * @param content - New content to process\n * @param locale - Optional locale\n * @returns Processed content\n */\nconst processNewContent = (content: any, locale?: LocalesValues): any => {\n // Handle null and undefined\n if (content === null || content === undefined) {\n return content;\n }\n\n // If content is already a translation node, return as-is\n if (\n content &&\n typeof content === 'object' &&\n content.nodeType === NodeTypes.TRANSLATION\n ) {\n return content;\n }\n\n // Handle arrays\n if (Array.isArray(content)) {\n return content.map((item) => processNewContent(item, locale));\n }\n\n // Handle objects\n if (content && typeof content === 'object') {\n const result: any = {};\n\n for (const key in content) {\n if (Object.hasOwn(content, key)) {\n result[key] = processNewContent(content[key], locale);\n }\n }\n return result;\n }\n\n // Handle primitives\n if (locale) {\n // Wrap in translation node with the specific locale\n return {\n nodeType: NodeTypes.TRANSLATION,\n [NodeTypes.TRANSLATION]: {\n [locale]: content,\n },\n };\n } else {\n // If no locale, just return the content as-is (don't wrap)\n return content;\n }\n};\n\n/**\n * Insert content into a dictionary with deep merge support\n * Handles translation blocks and nested structures\n *\n * @param dictionary - The dictionary to insert content into\n * @param content - The content to insert\n * @param locale - Optional locale to target specific translation\n * @returns Updated dictionary\n *\n * @example\n * // Without locale - deep merge all content\n * insertContentInDictionary(dictionary, { title: 'New Title' })\n *\n * @example\n * // With locale - insert content for specific locale\n * insertContentInDictionary(dictionary, { title: 'このページ' }, 'ja')\n */\nexport const insertContentInDictionary = (\n dictionary: Dictionary,\n content: Dictionary['content'],\n locale?: LocalesValues\n): Dictionary => {\n const mergedContent = deepMergeContent(\n Array.isArray(dictionary.content)\n ? [...dictionary.content]\n : { ...dictionary.content },\n content,\n locale\n );\n\n return {\n ...dictionary,\n content: mergedContent,\n };\n};\n"],"mappings":";;;;;;;;;;AA+CA,MAAM,oBACJ,QACA,QACA,WACQ;CAER,IAAI,WAAW,QAAQ,WAAW,QAAW,OAAO;CAGpD,IAAI,WAAW,QAAQ,WAAW,QAChC,IAAI,MAAM,QAAQ,OAAO,EACvB,SAAS,EAAE;MACN,IAAI,OAAO,WAAW,UAC3B,SAAS,EAAE;MAEX,OAAO;CAKX,IACE,UACA,OAAO,WAAW,YAClB,OAAO,aAAa,UAAU,aAG9B,IAAI,QAAQ;EAEV,MAAM,wBAAwB,OAAO,UAAU,aAAa;EAC5D,IAAI;EAEJ,IAAI,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,EAEtD,mBAAmB,iBACjB,uBACA,QACA,OACD;OACI,IAAI,MAAM,QAAQ,OAAO,EAE9B,mBAAmB;OAGnB,mBAAmB;EAIrB,OAAO;GACL,GAAG;IACF,UAAU,cAAc;IACvB,GAAG,OAAO,UAAU;KACnB,SAAS;IACX;GACF;QAGD,IACE,OAAO,WAAW,YAClB,CAAC,MAAM,QAAQ,OAAO,IACtB,OAAO,aAAa,UAAU,aAG9B,OAAO;EACL,GAAG;GACF,UAAU,cAAc;GACvB,GAAG,OAAO,UAAU;GACpB,GAAG,OAAO,UAAU;GACrB;EACF;MAGD,OAAO,kBAAkB,QAAQ,OAAO;CAM9C,IAAI,MAAM,QAAQ,OAAO,EACvB,IAAI,UAAU,MAAM,QAAQ,OAAO,EAAE;EAEnC,MAAM,SAAS,EAAE;EACjB,MAAM,YAAY,KAAK,IAAI,OAAO,QAAQ,OAAO,OAAO;EAExD,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAC7B,IAAI,IAAI,OAAO,QACb,IAAI,IAAI,OAAO,UAAU,OAAO,OAAO,QAErC,OAAO,KAAK,iBAAiB,OAAO,IAAI,OAAO,IAAI,OAAO;OAG1D,OAAO,KAAK,kBAAkB,OAAO,IAAI,OAAO;OAIlD,OAAO,KAAK,OAAO;EAIvB,OAAO;QAGP,OAAO,OAAO,KAAK,SAAS;EAE1B,IACE,QACA,OAAO,SAAS,YAChB,KAAK,aAAa,UAAU,aAE5B,OAAO;EAET,OAAO,kBAAkB,MAAM,OAAO;GACtC;CAKN,IAAI,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,EAAE;EACxD,IAAI,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,EACrD,SAAS,EAAE;EAIb,MAAM,SAAc,EAAE,GAAG,QAAQ;EAEjC,KAAK,MAAM,OAAO,QAChB,IAAI,OAAO,OAAO,QAAQ,IAAI,EAC5B,IAAI,OAAO,SAAS,QAClB,OAAO,OAAO,iBAAiB,OAAO,MAAM,OAAO,MAAM,OAAO;OAEhE,OAAO,OAAO,kBAAkB,OAAO,MAAM,OAAO;EAK1D,OAAO;;CAIT,OAAO;;;;;;;;AAST,MAAM,qBAAqB,SAAc,WAAgC;CAEvE,IAAI,YAAY,QAAQ,YAAY,QAClC,OAAO;CAIT,IACE,WACA,OAAO,YAAY,YACnB,QAAQ,aAAa,UAAU,aAE/B,OAAO;CAIT,IAAI,MAAM,QAAQ,QAAQ,EACxB,OAAO,QAAQ,KAAK,SAAS,kBAAkB,MAAM,OAAO,CAAC;CAI/D,IAAI,WAAW,OAAO,YAAY,UAAU;EAC1C,MAAM,SAAc,EAAE;EAEtB,KAAK,MAAM,OAAO,SAChB,IAAI,OAAO,OAAO,SAAS,IAAI,EAC7B,OAAO,OAAO,kBAAkB,QAAQ,MAAM,OAAO;EAGzD,OAAO;;CAIT,IAAI,QAEF,OAAO;EACL,UAAU,UAAU;GACnB,UAAU,cAAc,GACtB,SAAS,SACX;EACF;MAGD,OAAO;;;;;;;;;;;;;;;;;;;AAqBX,MAAa,6BACX,YACA,SACA,WACe;CACf,MAAM,gBAAgB,iBACpB,MAAM,QAAQ,WAAW,QAAQ,GAC7B,CAAC,GAAG,WAAW,QAAQ,GACvB,EAAE,GAAG,WAAW,SAAS,EAC7B,SACA,OACD;CAED,OAAO;EACL,GAAG;EACH,SAAS;EACV"}
|
|
1
|
+
{"version":3,"file":"insertContentInDictionary.mjs","names":[],"sources":["../../../src/deepTransformPlugins/insertContentInDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\n// {\n// {\n// title: 'このページ',\n// linkLabel: 'セクションへ移動',\n// collapseButton: { label: '折りたたむ' }\n// },\n// }\n// {\n// dictionary: {\n// key: 'aside-navigation',\n// content: {\n// title: {\n// nodeType: 'translation',\n// translation: {\n// ar: 'في هذه الصفحة',\n// de: 'Auf dieser Seite',\n// en: 'In this page',\n// 'en-GB': 'On this page',\n// es: 'En esta página',\n// fr: 'Dans cette page',\n// hi: 'इस पृष्ठ में',\n// it: 'In questa pagina',\n// ko: '이 페이지에서',\n// pt: 'Nesta página',\n// ru: 'На этой странице',\n// tr: 'Bu sayfada',\n// zh: '在此页面'\n// }\n// },\n// },\n// localId: 'aside-navigation::local::src/components/AsideNavigation/asideNavigation.content.ts',\n// location: 'local',\n// filePath: 'src/components/AsideNavigation/asideNavigation.content.ts'\n// }\n// }\n\n/**\n * Deep merge helper that handles translation blocks\n * @param target - The target object (dictionary content)\n * @param source - The source object (new content to merge)\n * @param locale - Optional locale to target specific translation\n * @returns Merged content\n */\nconst deepMergeContent = (\n target: any,\n source: any,\n locale?: LocalesValues\n): any => {\n // If source is null or undefined, return target\n if (source === null || source === undefined) return target;\n\n // If target is null or undefined, initialize based on source type\n if (target === null || target === undefined) {\n if (Array.isArray(source)) {\n target = [];\n } else if (typeof source === 'object') {\n target = {};\n } else {\n return source;\n }\n }\n\n // Handle translation nodes FIRST (before arrays) to support arrays within translations\n if (\n target &&\n typeof target === 'object' &&\n target.nodeType === NodeTypes.TRANSLATION\n ) {\n // Target is a translation block\n if (locale) {\n // Update only the specific locale - create new object to preserve order\n const existingLocaleContent = target[NodeTypes.TRANSLATION][locale];\n let newLocaleContent: any;\n\n if (typeof source === 'object' && !Array.isArray(source)) {\n // Source is an object, need to deep merge for this locale\n newLocaleContent = deepMergeContent(\n existingLocaleContent,\n source,\n undefined // Don't pass locale down for nested content\n );\n } else if (Array.isArray(source)) {\n // Source is an array, set it directly for this locale\n newLocaleContent = source;\n } else {\n // Source is a primitive, directly set it\n newLocaleContent = source;\n }\n\n // Return new object with locale appended at the end (preserve insertion order)\n return {\n ...target,\n [NodeTypes.TRANSLATION]: {\n ...target[NodeTypes.TRANSLATION],\n [locale]: newLocaleContent,\n },\n };\n } else {\n // No locale specified, replace/merge the entire translation\n if (\n typeof source === 'object' &&\n !Array.isArray(source) &&\n source.nodeType === NodeTypes.TRANSLATION\n ) {\n // Source is also a translation node, merge translations\n return {\n ...target,\n [NodeTypes.TRANSLATION]: {\n ...target[NodeTypes.TRANSLATION],\n ...source[NodeTypes.TRANSLATION],\n },\n };\n } else {\n // Source is not a translation node, wrap it\n return processNewContent(source, locale);\n }\n }\n }\n\n // Handle arrays\n if (Array.isArray(source)) {\n if (locale && Array.isArray(target)) {\n // When locale is specified and target is also an array, merge element by element\n const result = [];\n const maxLength = Math.max(source.length, target.length);\n\n for (let i = 0; i < maxLength; i++) {\n if (i < source.length) {\n if (i < target.length && target[i] !== undefined) {\n // Both source and target have element at this index - merge them\n result[i] = deepMergeContent(target[i], source[i], locale);\n } else {\n // Only source has element at this index - process new content\n result[i] = processNewContent(source[i], locale);\n }\n } else {\n // Only target has element at this index - keep it\n result[i] = target[i];\n }\n }\n\n return result;\n } else {\n // No locale or target is not an array - replace entirely\n return source.map((item) => {\n // Process each item in case it needs locale wrapping\n if (\n item &&\n typeof item === 'object' &&\n item.nodeType === NodeTypes.TRANSLATION\n ) {\n return item;\n }\n return processNewContent(item, locale);\n });\n }\n }\n\n // Handle objects\n if (typeof source === 'object' && !Array.isArray(source)) {\n if (typeof target !== 'object' || Array.isArray(target)) {\n target = {};\n }\n\n // Create new object to preserve key order and avoid mutation\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n if (target[key] !== undefined) {\n result[key] = deepMergeContent(target[key], source[key], locale);\n } else {\n result[key] = processNewContent(source[key], locale);\n }\n }\n }\n\n return result;\n }\n\n // For primitives, just return the source\n return source;\n};\n\n/**\n * Process new content that doesn't exist in target\n * @param content - New content to process\n * @param locale - Optional locale\n * @returns Processed content\n */\nconst processNewContent = (content: any, locale?: LocalesValues): any => {\n // Handle null and undefined\n if (content === null || content === undefined) {\n return content;\n }\n\n // If content is already a translation node, return as-is\n if (\n content &&\n typeof content === 'object' &&\n content.nodeType === NodeTypes.TRANSLATION\n ) {\n return content;\n }\n\n // Handle arrays\n if (Array.isArray(content)) {\n return content.map((item) => processNewContent(item, locale));\n }\n\n // Handle objects\n if (content && typeof content === 'object') {\n const result: any = {};\n\n for (const key in content) {\n if (Object.hasOwn(content, key)) {\n result[key] = processNewContent(content[key], locale);\n }\n }\n return result;\n }\n\n // Handle primitives\n if (locale) {\n // Wrap in translation node with the specific locale\n return {\n nodeType: NodeTypes.TRANSLATION,\n [NodeTypes.TRANSLATION]: {\n [locale]: content,\n },\n };\n } else {\n // If no locale, just return the content as-is (don't wrap)\n return content;\n }\n};\n\n/**\n * Insert content into a dictionary with deep merge support\n * Handles translation blocks and nested structures\n *\n * @param dictionary - The dictionary to insert content into\n * @param content - The content to insert\n * @param locale - Optional locale to target specific translation\n * @returns Updated dictionary\n *\n * @example\n * // Without locale - deep merge all content\n * insertContentInDictionary(dictionary, { title: 'New Title' })\n *\n * @example\n * // With locale - insert content for specific locale\n * insertContentInDictionary(dictionary, { title: 'このページ' }, 'ja')\n */\nexport const insertContentInDictionary = (\n dictionary: Dictionary,\n content: Dictionary['content'],\n locale?: LocalesValues\n): Dictionary => {\n const mergedContent = deepMergeContent(\n Array.isArray(dictionary.content)\n ? [...dictionary.content]\n : { ...dictionary.content },\n content,\n locale\n );\n\n return {\n ...dictionary,\n content: mergedContent,\n };\n};\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editDictionaryByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKeys = [keyObj.key];\n\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n // Note: Logic above already handles Enumeration/Plural, ensure no duplication in your actual file\n // or keep the specific block if your logic differs.\n // The important part is below in the final update block.\n\n // Assuming this block runs for Condition/Gender/etc:\n\n if (\n keyObj.type !== NodeTypes.ENUMERATION &&\n keyObj.type !== NodeTypes.PLURAL\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION\n ) {\n lastKeys = [keyObj.type];\n\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeTypes.FILE) {\n lastKeys = ['content'];\n currentValue = currentValue.content;\n }\n\n // Only update the value when processing the last key in the keyPath.\n\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n\n // Drill down to the container holding the value to be changed\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n\n const finalKey = lastKeys[lastKeys.length - 1];\n\n if (typeof newValue === 'undefined') {\n // Use splice for arrays to re-index the list, use delete for objects\n\n if (Array.isArray(target)) {\n const index = Number(finalKey);\n\n if (!Number.isNaN(index) && index >= 0 && index < target.length) {\n target.splice(index, 1);\n }\n } else {\n delete target[finalKey];\n }\n } else {\n target[finalKey] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":";;;AAMA,MAAa,2BACX,mBACA,SACA,aACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,WAA0B,
|
|
1
|
+
{"version":3,"file":"editDictionaryByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n if (keyPath.length === 0) {\n return newValue;\n }\n\n try {\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKeys = [keyObj.key];\n\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n // Note: Logic above already handles Enumeration/Plural, ensure no duplication in your actual file\n // or keep the specific block if your logic differs.\n // The important part is below in the final update block.\n\n // Assuming this block runs for Condition/Gender/etc:\n\n if (\n keyObj.type !== NodeTypes.ENUMERATION &&\n keyObj.type !== NodeTypes.PLURAL\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION\n ) {\n lastKeys = [keyObj.type];\n\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeTypes.FILE) {\n lastKeys = ['content'];\n currentValue = currentValue.content;\n }\n\n // Only update the value when processing the last key in the keyPath.\n\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n\n // Drill down to the container holding the value to be changed\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n\n const finalKey = lastKeys[lastKeys.length - 1];\n\n if (typeof newValue === 'undefined') {\n // Use splice for arrays to re-index the list, use delete for objects\n\n if (Array.isArray(target)) {\n const index = Number(finalKey);\n\n if (!Number.isNaN(index) && index >= 0 && index < target.length) {\n target.splice(index, 1);\n }\n } else {\n delete target[finalKey];\n }\n } else {\n target[finalKey] = newValue;\n }\n }\n }\n\n return dictionaryContent;\n } catch (error) {\n console.error(\n 'Cannot edit dictionary by key path',\n { dictionaryContent, keyPath, newValue },\n error\n );\n return dictionaryContent;\n }\n};\n"],"mappings":";;;AAMA,MAAa,2BACX,mBACA,SACA,aACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,WAA0B,CAAC;CAE/B,IAAI,QAAQ,WAAW,GACrB,OAAO;CAGT,IAAI;EACF,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;GACvC,MAAM,SAAS,QAAQ;GACvB,cAAc;GAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;IACvE,WAAW,CAAC,OAAO,GAAG;IAEtB,IACE,CAAC,aAAa,OAAO,QACrB,OAAO,aAAa,OAAO,SAAS,UAEpC,aAAa,OAAO,OAAO,CAAC;IAE9B,eAAe,aAAa,OAAO;GACrC;GAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,QAC1B;IACA,WAAW,CAAC,OAAO,MAAM,OAAO,GAAG;IAEnC,IACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,UAErC,aAAa,OAAO,QAAQ,CAAC;IAG/B,IACE,CAAC,aAAa,OAAO,MAAM,OAAO,QAClC,OAAO,aAAa,OAAO,MAAM,OAAO,SAAS,UAEjD,aAAa,OAAO,MAAM,OAAO,OAAO,CAAC;IAE3C,eAAe,aAAa,OAAO,MAAM,OAAO;GAClD;GAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,WAQ1B;QACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,QAC1B;KACA,WAAW,CAAC,OAAO,MAAM,OAAO,GAAG;KACnC,eAAe,aAAa,OAAO,MAAM,OAAO;IAClD;;GAGF,IACE,OAAO,SAAS,UAAU,YAC1B,OAAO,SAAS,UAAU,QAC1B,OAAO,SAAS,UAAU,WAC1B;IACA,WAAW,CAAC,OAAO,IAAI;IAEvB,IACE,CAAC,aAAa,OAAO,SACrB,OAAO,aAAa,OAAO,UAAU,UAErC,aAAa,OAAO,QAAQ;IAE9B,eAAe,aAAa,OAAO;GACrC;GAEA,IAAI,OAAO,SAAS,UAAU,MAAM;IAClC,WAAW,CAAC,SAAS;IACrB,eAAe,aAAa;GAC9B;GAIA,IAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;IAClE,IAAI,SAAS;IAGb,KAAK,MAAM,OAAO,SAAS,MAAM,GAAG,EAAE,GACpC,SAAS,OAAO;IAGlB,MAAM,WAAW,SAAS,SAAS,SAAS;IAE5C,IAAI,OAAO,aAAa,aAGtB,IAAI,MAAM,QAAQ,MAAM,GAAG;KACzB,MAAM,QAAQ,OAAO,QAAQ;KAE7B,IAAI,CAAC,OAAO,MAAM,KAAK,KAAK,SAAS,KAAK,QAAQ,OAAO,QACvD,OAAO,OAAO,OAAO,CAAC;IAE1B,OACE,OAAO,OAAO;SAGhB,OAAO,YAAY;GAEvB;EACF;EAEA,OAAO;CACT,SAAS,OAAO;EACd,QAAQ,MACN,sCACA;GAAE;GAAmB;GAAS;EAAS,GACvC,KACF;EACA,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: LocalesValues\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeTypes.TRANSLATION) {\n currentValue = currentValue?.[NodeTypes.TRANSLATION]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.CONDITION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;AAKA,MAAa,2BACX,mBACA,SACA,mBACgB;CAChB,IAAI,eAAoB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"getContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n fallbackLocale?: LocalesValues\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n // Auto-resolve translation nodes when fallbackLocale is provided\n if (fallbackLocale && currentValue?.nodeType === NodeTypes.TRANSLATION) {\n currentValue = currentValue?.[NodeTypes.TRANSLATION]?.[fallbackLocale];\n }\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n currentValue = currentValue?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.CONDITION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL\n ) {\n currentValue = currentValue?.[keyObj.type]?.[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;AAKA,MAAa,2BACX,mBACA,SACA,mBACgB;CAChB,IAAI,eAAoB,gBAAgB,iBAAiB;CAEzD,KAAK,MAAM,UAAU,SAAS;EAE5B,IAAI,kBAAkB,cAAc,aAAa,UAAU,aACzD,eAAe,eAAe,UAAU,eAAe;EAGzD,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAChE,eAAe,eAAe,OAAO;EAGvC,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,QAE1B,eAAe,eAAe,OAAO,QAAQ,OAAO;EAGtD,IACE,OAAO,SAAS,UAAU,YAC1B,OAAO,SAAS,UAAU,QAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,MAE1B,eAAe,eAAe,OAAO;CAEzC;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeTypes.TRANSLATION:\n return {\n nodeType: NodeTypes.TRANSLATION,\n [NodeTypes.TRANSLATION]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeTypes.ENUMERATION:\n return {\n nodeType: NodeTypes.ENUMERATION,\n [NodeTypes.ENUMERATION]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.PLURAL:\n return {\n nodeType: NodeTypes.PLURAL,\n [NodeTypes.PLURAL]: {\n one: clonedContent ?? '',\n other: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.CONDITION:\n return {\n nodeType: NodeTypes.CONDITION,\n [NodeTypes.CONDITION]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.INSERTION:\n return {\n nodeType: NodeTypes.INSERTION,\n [NodeTypes.INSERTION]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeTypes.NESTED:\n return {\n nodeType: NodeTypes.NESTED,\n [NodeTypes.NESTED]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeTypes.MARKDOWN:\n return {\n nodeType: NodeTypes.MARKDOWN,\n [NodeTypes.MARKDOWN]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.HTML:\n return {\n nodeType: NodeTypes.HTML,\n [NodeTypes.HTML]: clonedContent ?? '',\n customComponents: [],\n } as ContentNode;\n\n case NodeTypes.FILE:\n return {\n nodeType: NodeTypes.FILE,\n [NodeTypes.FILE]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.OBJECT:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeTypes.ARRAY:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeTypes.TEXT:\n return clonedContent ?? '';\n\n case NodeTypes.NUMBER:\n return clonedContent ?? 0;\n\n case NodeTypes.BOOLEAN:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"getDefaultNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeTypes.TRANSLATION:\n return {\n nodeType: NodeTypes.TRANSLATION,\n [NodeTypes.TRANSLATION]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeTypes.ENUMERATION:\n return {\n nodeType: NodeTypes.ENUMERATION,\n [NodeTypes.ENUMERATION]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.PLURAL:\n return {\n nodeType: NodeTypes.PLURAL,\n [NodeTypes.PLURAL]: {\n one: clonedContent ?? '',\n other: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.CONDITION:\n return {\n nodeType: NodeTypes.CONDITION,\n [NodeTypes.CONDITION]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeTypes.INSERTION:\n return {\n nodeType: NodeTypes.INSERTION,\n [NodeTypes.INSERTION]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeTypes.NESTED:\n return {\n nodeType: NodeTypes.NESTED,\n [NodeTypes.NESTED]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeTypes.MARKDOWN:\n return {\n nodeType: NodeTypes.MARKDOWN,\n [NodeTypes.MARKDOWN]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.HTML:\n return {\n nodeType: NodeTypes.HTML,\n [NodeTypes.HTML]: clonedContent ?? '',\n customComponents: [],\n } as ContentNode;\n\n case NodeTypes.FILE:\n return {\n nodeType: NodeTypes.FILE,\n [NodeTypes.FILE]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeTypes.OBJECT:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeTypes.ARRAY:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeTypes.TEXT:\n return clonedContent ?? '';\n\n case NodeTypes.NUMBER:\n return clonedContent ?? 0;\n\n case NodeTypes.BOOLEAN:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,OAAO;CAC7C,QAAQ,UAAR;EACE,KAAK,UAAU,aACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,cAAc,OAAO,OAC9B,CAAC,GACD,GAAG,QAAQ,KAAK,YAAY,GACzB,SAAS,gBAAgB,aAAa,KAAK,GAC9C,EAAE,CACJ;EACF;EAEF,KAAK,UAAU,aACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,cAAc,EACvB,KAAK,iBAAiB,GACxB;EACF;EAEF,KAAK,UAAU,QACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,SAAS;IAClB,KAAK,iBAAiB;IACtB,OAAO,iBAAiB;GAC1B;EACF;EAEF,KAAK,UAAU,WACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,YAAY;IACrB,MAAM,iBAAiB;IACvB,OAAO,iBAAiB;GAC1B;EACF;EAEF,KAAK,UAAU,WACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,YAAY,EACrB,WAAW,iBAAiB,GAC9B;EACF;EAEF,KAAK,UAAU,QACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,SAAS,EAClB,eAAe,GACjB;EACF;EAEF,KAAK,UAAU,UACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,WAAW,iBAAiB;EACzC;EAEF,KAAK,UAAU,MACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,OAAO,iBAAiB;GACnC,kBAAkB,CAAC;EACrB;EAEF,KAAK,UAAU,MACb,OAAO;GACL,UAAU,UAAU;IACnB,UAAU,OAAO,iBAAiB;EACrC;EAEF,KAAK,UAAU,QACb,OAAO,EACL,QAAQ,iBAAiB,GAC3B;EAEF,KAAK,UAAU,OACb,OAAO,CAAC,iBAAiB,EAAE;EAE7B,KAAK,UAAU,MACb,OAAO,iBAAiB;EAE1B,KAAK,UAAU,QACb,OAAO,iBAAiB;EAE1B,KAAK,UAAU,SACb,OAAO,iBAAiB;EAE1B,SACE,OAAO,iBAAiB;CAC5B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEmptyNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeTypes.FILE) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeTypes.MARKDOWN) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":";;;AAIA,MAAa,gBAAgB,YAAsC;CACjE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,MAEjC,OAAO,aAAa,
|
|
1
|
+
{"version":3,"file":"getEmptyNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeTypes.FILE) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeTypes.MARKDOWN) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":";;;AAIA,MAAa,gBAAgB,YAAsC;CACjE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,MAEjC,OAAO,aAAa,OAAsB;EAG5C,IAAI,UAAU,aAAa,UAAU,QACnC,OAAO;EAGT,IAAI,UAAU,aAAa,UAAU,MACnC,OAAO;EAGT,IAAI,UAAU,aAAa,UAAU,UACnC,OAAO,aAAa,SAAS;EAG/B,OAAO;CACT;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAQ,QAA0B,IAChC,YACF;CAGF,MAAM,sBAAsB,OAAO,QAAQ,OAAO,EAAE,KAAK,CAAC,KAAK,WAAW,CACxE,KACA,aAAa,KAAoB,CACnC,CAAC;CAID,OAF2B,OAAO,YAAY,mBAEtB;AAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.GENDER ||\n typedNode.nodeType === NodeTypes.FILE ||\n typedNode.nodeType === NodeTypes.MARKDOWN ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;AAIA,MAAa,mBAAmB,YAAsC;CACpE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,QACjC,UAAU,aAAa,UAAU,YACjC,UAAU,aAAa,UAAU,MAGjC,OAAO,QADU,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION ||\n typedNode.nodeType === NodeTypes.INSERTION ||\n typedNode.nodeType === NodeTypes.GENDER ||\n typedNode.nodeType === NodeTypes.FILE ||\n typedNode.nodeType === NodeTypes.MARKDOWN ||\n typedNode.nodeType === NodeTypes.HTML\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;AAIA,MAAa,mBAAmB,YAAsC;CACpE,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,aACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,QACjC,UAAU,aAAa,UAAU,YACjC,UAAU,aAAa,UAAU,MAGjC,OAAO,QADU,OAAO,KAAK,OAAO,EAAE;EAIxC,IAAI,UAAU,aAAa,UAAU,QACnC;EAGF,OAAO;CACT;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAQ,QAA0B;CAGpC,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeType.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { isValidElement } from '../utils/isValidReactElement';\n\n/**\n * Type guard to check if content is a TypedNode\n */\nconst isTypedNode = (content: unknown): content is TypedNode => {\n return (\n typeof content === 'object' &&\n content !== null &&\n 'nodeType' in content &&\n typeof (content as TypedNode).nodeType === 'string'\n );\n};\n\n/**\n * Type guard to check if content is a valid NodeType\n */\nconst isValidNodeType = (nodeType: string): nodeType is NodeType => {\n return [\n NodeTypes.TRANSLATION,\n NodeTypes.ENUMERATION,\n NodeTypes.PLURAL,\n NodeTypes.CONDITION,\n NodeTypes.INSERTION,\n NodeTypes.FILE,\n NodeTypes.OBJECT,\n NodeTypes.ARRAY,\n NodeTypes.NESTED,\n NodeTypes.REACT_NODE,\n NodeTypes.MARKDOWN,\n NodeTypes.HTML,\n NodeTypes.TEXT,\n NodeTypes.NUMBER,\n NodeTypes.BOOLEAN,\n NodeTypes.GENDER,\n NodeTypes.NULL,\n NodeTypes.UNKNOWN,\n ].includes(nodeType as NodeType);\n};\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeTypes.TEXT;\n }\n\n if (isTypedNode(content)) {\n const nodeType = content.nodeType;\n if (isValidNodeType(nodeType)) {\n return nodeType;\n }\n // Fallback for unknown node types\n return NodeTypes.UNKNOWN;\n }\n\n if (Array.isArray(content)) {\n return NodeTypes.ARRAY;\n }\n\n if (isValidElement(content)) {\n return NodeTypes.REACT_NODE;\n }\n\n if (typeof content === 'number') {\n return NodeTypes.NUMBER;\n }\n\n if (typeof content === 'boolean') {\n return NodeTypes.BOOLEAN;\n }\n\n if (content && typeof content === 'object') {\n return NodeTypes.OBJECT;\n }\n\n if (content === null) {\n return NodeTypes.NULL;\n }\n\n return NodeTypes.UNKNOWN;\n};\n"],"mappings":";;;;;;;AASA,MAAM,eAAe,YAA2C;CAC9D,OACE,OAAO,YAAY,YACnB,YAAY,QACZ,cAAc,WACd,OAAQ,QAAsB,aAAa
|
|
1
|
+
{"version":3,"file":"getNodeType.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { isValidElement } from '../utils/isValidReactElement';\n\n/**\n * Type guard to check if content is a TypedNode\n */\nconst isTypedNode = (content: unknown): content is TypedNode => {\n return (\n typeof content === 'object' &&\n content !== null &&\n 'nodeType' in content &&\n typeof (content as TypedNode).nodeType === 'string'\n );\n};\n\n/**\n * Type guard to check if content is a valid NodeType\n */\nconst isValidNodeType = (nodeType: string): nodeType is NodeType => {\n return [\n NodeTypes.TRANSLATION,\n NodeTypes.ENUMERATION,\n NodeTypes.PLURAL,\n NodeTypes.CONDITION,\n NodeTypes.INSERTION,\n NodeTypes.FILE,\n NodeTypes.OBJECT,\n NodeTypes.ARRAY,\n NodeTypes.NESTED,\n NodeTypes.REACT_NODE,\n NodeTypes.MARKDOWN,\n NodeTypes.HTML,\n NodeTypes.TEXT,\n NodeTypes.NUMBER,\n NodeTypes.BOOLEAN,\n NodeTypes.GENDER,\n NodeTypes.NULL,\n NodeTypes.UNKNOWN,\n ].includes(nodeType as NodeType);\n};\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeTypes.TEXT;\n }\n\n if (isTypedNode(content)) {\n const nodeType = content.nodeType;\n if (isValidNodeType(nodeType)) {\n return nodeType;\n }\n // Fallback for unknown node types\n return NodeTypes.UNKNOWN;\n }\n\n if (Array.isArray(content)) {\n return NodeTypes.ARRAY;\n }\n\n if (isValidElement(content)) {\n return NodeTypes.REACT_NODE;\n }\n\n if (typeof content === 'number') {\n return NodeTypes.NUMBER;\n }\n\n if (typeof content === 'boolean') {\n return NodeTypes.BOOLEAN;\n }\n\n if (content && typeof content === 'object') {\n return NodeTypes.OBJECT;\n }\n\n if (content === null) {\n return NodeTypes.NULL;\n }\n\n return NodeTypes.UNKNOWN;\n};\n"],"mappings":";;;;;;;AASA,MAAM,eAAe,YAA2C;CAC9D,OACE,OAAO,YAAY,YACnB,YAAY,QACZ,cAAc,WACd,OAAQ,QAAsB,aAAa;AAE/C;;;;AAKA,MAAM,mBAAmB,aAA2C;CAClE,OAAO;EACL,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;EACV,UAAU;CACZ,EAAE,SAAS,QAAoB;AACjC;AAEA,MAAa,eAAe,YAAmC;CAC7D,IAAI,OAAO,YAAY,UACrB,OAAO,UAAU;CAGnB,IAAI,YAAY,OAAO,GAAG;EACxB,MAAM,WAAW,QAAQ;EACzB,IAAI,gBAAgB,QAAQ,GAC1B,OAAO;EAGT,OAAO,UAAU;CACnB;CAEA,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAO,UAAU;CAGnB,IAAI,eAAe,OAAO,GACxB,OAAO,UAAU;CAGnB,IAAI,OAAO,YAAY,UACrB,OAAO,UAAU;CAGnB,IAAI,OAAO,YAAY,WACrB,OAAO,UAAU;CAGnB,IAAI,WAAW,OAAO,YAAY,UAChC,OAAO,UAAU;CAGnB,IAAI,YAAY,MACd,OAAO,UAAU;CAGnB,OAAO,UAAU;AACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeDictionaries.mjs","names":[],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger({ log });\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n\n for (let i = 1; i < dictionaries.length; i++) {\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dictionaries[i]);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n }\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n localIds,\n };\n\n return mergedDictionary;\n};\n"],"mappings":";;;;;;AAaA,MAAM,mBACJ,SACA,SACA,gBACA,eACA,OAAiB,
|
|
1
|
+
{"version":3,"file":"mergeDictionaries.mjs","names":[],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger({ log });\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n\n for (let i = 1; i < dictionaries.length; i++) {\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dictionaries[i]);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n }\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n localIds,\n };\n\n return mergedDictionary;\n};\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeDictionary.mjs","names":["t"],"sources":["../../../src/dictionaryManipulator/normalizeDictionary.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"normalizeDictionary.mjs","names":["t"],"sources":["../../../src/dictionaryManipulator/normalizeDictionary.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getPerLocaleDictionary } from '../deepTransformPlugins';\nimport { t } from '../transpiler/translation';\nimport { orderDictionaries } from './orderDictionaries';\n\nexport const normalizeDictionary = (\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Dictionary => {\n const { locales } = configuration.internationalization;\n\n const parsedDictionary = JSON.parse(JSON.stringify(dictionary));\n\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n if (dictionary.locale) {\n return {\n ...dictionary,\n locale: undefined,\n content: t({\n [dictionary.locale]: dictionary.content,\n }),\n };\n }\n\n const perLocaleContent = locales.reduce(\n (acc, locale) => {\n const perLocaleDictionary = getPerLocaleDictionary(\n parsedDictionary,\n locale\n );\n\n acc[locale] = perLocaleDictionary.content;\n return acc;\n },\n {} as Record<Locale, Dictionary['content']>\n );\n\n return {\n ...dictionary,\n content: t(perLocaleContent),\n };\n};\n\nexport const normalizeDictionaries = (\n dictionaries: Dictionary[],\n configuration: IntlayerConfig\n): Dictionary[] => {\n const orderedDictionaries = orderDictionaries(dictionaries, configuration);\n\n const structuredDictionaries = orderedDictionaries.map((dictionary) =>\n normalizeDictionary(dictionary, configuration)\n );\n\n return structuredDictionaries;\n};\n"],"mappings":";;;;;AAOA,MAAa,uBACX,YACA,kBACe;CACf,MAAM,EAAE,YAAY,cAAc;CAElC,MAAM,mBAAmB,KAAK,MAAM,KAAK,UAAU,UAAU,CAAC;CAG9D,IAAI,WAAW,QACb,OAAO;EACL,GAAG;EACH,QAAQ;EACR,SAASA,YAAE,GACR,WAAW,SAAS,WAAW,QAClC,CAAC;CACH;CAGF,MAAM,mBAAmB,QAAQ,QAC9B,KAAK,WAAW;EAMf,IAAI,UALwB,uBAC1B,kBACA,MAG8B,EAAE;EAClC,OAAO;CACT,GACA,CAAC,CACH;CAEA,OAAO;EACL,GAAG;EACH,SAASA,YAAE,gBAAgB;CAC7B;AACF;AAEA,MAAa,yBACX,cACA,kBACiB;CAOjB,OAN4B,kBAAkB,cAAc,aAEX,EAAE,KAAK,eACtD,oBAAoB,YAAY,aAAa,CAGnB;AAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orderDictionaries.mjs","names":[],"sources":["../../../src/dictionaryManipulator/orderDictionaries.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\n\n/**\n * Orders dictionaries based on the dictionary priority strategy.\n *\n * @param dictionaries - Array of dictionaries to order\n * @param priorityStrategy - The priority strategy ('local_first' or 'distant_first')\n * @returns Ordered array of dictionaries\n */\nexport const orderDictionaries = (\n dictionaries: Dictionary[],\n config?: {\n editor: {\n dictionaryPriorityStrategy: 'local_first' | 'distant_first';\n };\n }\n): Dictionary[] => {\n const dictionaryPriorityStrategy =\n config?.editor?.dictionaryPriorityStrategy ??\n editor.dictionaryPriorityStrategy;\n\n if (dictionaries.length <= 1) {\n return dictionaries;\n }\n\n // Stabilize original indices to preserve relative order for complete ties\n const withIndex = dictionaries.map((dictionary, index) => ({\n dictionary,\n index,\n }));\n\n const getPriority = (dictionary: Dictionary): number => {\n const p = dictionary.priority ?? 0;\n\n return Number.isFinite(p) ? p : 0;\n };\n\n const getLocationWeight = (d: Dictionary): number => {\n const location = d.location;\n\n // undefined location should always be last\n if (location === undefined) {\n return 2;\n }\n\n if (dictionaryPriorityStrategy === 'distant_first') {\n // distant should come first\n return location === 'remote' ? 0 : 1;\n }\n // default: local_first\n return location === 'local' ? 0 : 1;\n };\n\n withIndex.sort((a, b) => {\n // 1) Non-autoFilled before autoFilled (autoFilled have lower precedence)\n const aAuto = a.dictionary.filled ? 1 : 0;\n const bAuto = b.dictionary.filled ? 1 : 0;\n if (aAuto !== bAuto) return aAuto - bAuto; // 0 before 1\n\n // 2) Higher priority first (larger number wins)\n const aP = getPriority(a.dictionary);\n const bP = getPriority(b.dictionary);\n if (aP !== bP) return bP - aP; // descending\n\n // 3) Location according to strategy\n const aLocation = getLocationWeight(a.dictionary);\n const bLocation = getLocationWeight(b.dictionary);\n if (aLocation !== bLocation) return aLocation - bLocation;\n\n // 4) Stable fallback by original index\n return a.index - b.index;\n });\n\n return withIndex.map(({ dictionary }) => dictionary);\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,qBACX,cACA,WAKiB;CACjB,MAAM,6BACJ,QAAQ,QAAQ,8BAChB,OAAO;CAET,IAAI,aAAa,UAAU,GACzB,OAAO;CAIT,MAAM,YAAY,aAAa,KAAK,YAAY,WAAW;EACzD;EACA;
|
|
1
|
+
{"version":3,"file":"orderDictionaries.mjs","names":[],"sources":["../../../src/dictionaryManipulator/orderDictionaries.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\n\n/**\n * Orders dictionaries based on the dictionary priority strategy.\n *\n * @param dictionaries - Array of dictionaries to order\n * @param priorityStrategy - The priority strategy ('local_first' or 'distant_first')\n * @returns Ordered array of dictionaries\n */\nexport const orderDictionaries = (\n dictionaries: Dictionary[],\n config?: {\n editor: {\n dictionaryPriorityStrategy: 'local_first' | 'distant_first';\n };\n }\n): Dictionary[] => {\n const dictionaryPriorityStrategy =\n config?.editor?.dictionaryPriorityStrategy ??\n editor.dictionaryPriorityStrategy;\n\n if (dictionaries.length <= 1) {\n return dictionaries;\n }\n\n // Stabilize original indices to preserve relative order for complete ties\n const withIndex = dictionaries.map((dictionary, index) => ({\n dictionary,\n index,\n }));\n\n const getPriority = (dictionary: Dictionary): number => {\n const p = dictionary.priority ?? 0;\n\n return Number.isFinite(p) ? p : 0;\n };\n\n const getLocationWeight = (d: Dictionary): number => {\n const location = d.location;\n\n // undefined location should always be last\n if (location === undefined) {\n return 2;\n }\n\n if (dictionaryPriorityStrategy === 'distant_first') {\n // distant should come first\n return location === 'remote' ? 0 : 1;\n }\n // default: local_first\n return location === 'local' ? 0 : 1;\n };\n\n withIndex.sort((a, b) => {\n // 1) Non-autoFilled before autoFilled (autoFilled have lower precedence)\n const aAuto = a.dictionary.filled ? 1 : 0;\n const bAuto = b.dictionary.filled ? 1 : 0;\n if (aAuto !== bAuto) return aAuto - bAuto; // 0 before 1\n\n // 2) Higher priority first (larger number wins)\n const aP = getPriority(a.dictionary);\n const bP = getPriority(b.dictionary);\n if (aP !== bP) return bP - aP; // descending\n\n // 3) Location according to strategy\n const aLocation = getLocationWeight(a.dictionary);\n const bLocation = getLocationWeight(b.dictionary);\n if (aLocation !== bLocation) return aLocation - bLocation;\n\n // 4) Stable fallback by original index\n return a.index - b.index;\n });\n\n return withIndex.map(({ dictionary }) => dictionary);\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,qBACX,cACA,WAKiB;CACjB,MAAM,6BACJ,QAAQ,QAAQ,8BAChB,OAAO;CAET,IAAI,aAAa,UAAU,GACzB,OAAO;CAIT,MAAM,YAAY,aAAa,KAAK,YAAY,WAAW;EACzD;EACA;CACF,EAAE;CAEF,MAAM,eAAe,eAAmC;EACtD,MAAM,IAAI,WAAW,YAAY;EAEjC,OAAO,OAAO,SAAS,CAAC,IAAI,IAAI;CAClC;CAEA,MAAM,qBAAqB,MAA0B;EACnD,MAAM,WAAW,EAAE;EAGnB,IAAI,aAAa,QACf,OAAO;EAGT,IAAI,+BAA+B,iBAEjC,OAAO,aAAa,WAAW,IAAI;EAGrC,OAAO,aAAa,UAAU,IAAI;CACpC;CAEA,UAAU,MAAM,GAAG,MAAM;EAEvB,MAAM,QAAQ,EAAE,WAAW,SAAS,IAAI;EACxC,MAAM,QAAQ,EAAE,WAAW,SAAS,IAAI;EACxC,IAAI,UAAU,OAAO,OAAO,QAAQ;EAGpC,MAAM,KAAK,YAAY,EAAE,UAAU;EACnC,MAAM,KAAK,YAAY,EAAE,UAAU;EACnC,IAAI,OAAO,IAAI,OAAO,KAAK;EAG3B,MAAM,YAAY,kBAAkB,EAAE,UAAU;EAChD,MAAM,YAAY,kBAAkB,EAAE,UAAU;EAChD,IAAI,cAAc,WAAW,OAAO,YAAY;EAGhD,OAAO,EAAE,QAAQ,EAAE;CACrB,CAAC;CAED,OAAO,UAAU,KAAK,EAAE,iBAAiB,UAAU;AACrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAKA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO
|
|
1
|
+
{"version":3,"file":"removeContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAKA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;EAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,WAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO,MAAM,OAAO;EAClD;EAEA,IACE,OAAO,SAAS,UAAU,YAC1B,OAAO,SAAS,UAAU,cAC1B,OAAO,SAAS,UAAU,QAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,MAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;CACF;CAEA,IAAI,eAAe,YAAY,MAC7B,IAAI,MAAM,QAAQ,WAAW,GAC3B,YAAY,OAAO,SAA8B,CAAC;MAElD,OAAO,YAAY;CAIvB,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renameContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const renameContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n newKey: KeyPath['key'],\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey && typeof newKey !== 'undefined') {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => {\n delete parentValue[key];\n });\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAKA,MAAa,8BACX,mBACA,QACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO
|
|
1
|
+
{"version":3,"file":"renameContentNodeByKeyPath.mjs","names":[],"sources":["../../../src/dictionaryManipulator/renameContentNodeByKeyPath.ts"],"sourcesContent":["import type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const renameContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n newKey: KeyPath['key'],\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.TRANSLATION ||\n keyObj.type === NodeTypes.ENUMERATION ||\n keyObj.type === NodeTypes.PLURAL ||\n keyObj.type === NodeTypes.CONDITION\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeTypes.MARKDOWN ||\n keyObj.type === NodeTypes.REACT_NODE ||\n keyObj.type === NodeTypes.HTML ||\n keyObj.type === NodeTypes.INSERTION ||\n keyObj.type === NodeTypes.FILE\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n // Assign the new value to the last key of the parent while preserving the order\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue[lastKey as number] = currentValue;\n } else {\n const newParentValue: any = {};\n for (const key of Object.keys(parentValue)) {\n if (key === lastKey && typeof newKey !== 'undefined') {\n newParentValue[newKey] = currentValue;\n } else {\n newParentValue[key] = parentValue[key];\n }\n }\n // Replace the contents of parentValue with newParentValue\n Object.keys(parentValue).forEach((key) => {\n delete parentValue[key];\n });\n Object.assign(parentValue, newParentValue);\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAKA,MAAa,8BACX,mBACA,QACA,YACgB;CAChB,IAAI,eAAoB;CACxB,IAAI,cAAmB;CACvB,IAAI,UAAkC;CAEtC,KAAK,MAAM,UAAU,SAAS;EAC5B,cAAc;EAEd,IAAI,OAAO,SAAS,UAAU,UAAU,OAAO,SAAS,UAAU,OAAO;GACvE,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;EAEA,IACE,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,eAC1B,OAAO,SAAS,UAAU,UAC1B,OAAO,SAAS,UAAU,WAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO,MAAM,OAAO;EAClD;EAEA,IACE,OAAO,SAAS,UAAU,YAC1B,OAAO,SAAS,UAAU,cAC1B,OAAO,SAAS,UAAU,QAC1B,OAAO,SAAS,UAAU,aAC1B,OAAO,SAAS,UAAU,MAC1B;GACA,UAAU,OAAO;GACjB,eAAe,aAAa,OAAO;EACrC;CACF;CAGA,IAAI,eAAe,YAAY,MAC7B,IAAI,MAAM,QAAQ,WAAW,GAC3B,YAAY,WAAqB;MAC5B;EACL,MAAM,iBAAsB,CAAC;EAC7B,KAAK,MAAM,OAAO,OAAO,KAAK,WAAW,GACvC,IAAI,QAAQ,WAAW,OAAO,WAAW,aACvC,eAAe,UAAU;OAEzB,eAAe,OAAO,YAAY;EAItC,OAAO,KAAK,WAAW,EAAE,SAAS,QAAQ;GACxC,OAAO,YAAY;EACrB,CAAC;EACD,OAAO,OAAO,aAAa,cAAc;CAC3C;CAGF,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/updateNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const updateNodeChildren = <\n T extends ContentNode,\n U extends ContentNode,\n>(\n section: T,\n newChildren: U\n): ContentNode => {\n if (typeof section === 'string') {\n return newChildren;\n }\n if (typeof section === 'number') {\n return newChildren;\n }\n if (typeof section === 'boolean') {\n return newChildren;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION\n ) {\n const newContent = Object.entries(content).reduce(\n (acc, [key]) => {\n acc[key] = newChildren;\n return acc;\n },\n {} as Record<string, ContentNode>\n );\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newContent,\n };\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return typedNode;\n }\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newChildren,\n };\n }\n\n if (!section || typeof section !== 'object') {\n return newChildren;\n }\n\n if (Array.isArray(section)) {\n return section.map(() => newChildren) as unknown as ContentNode;\n }\n\n return Object.entries(\n section as unknown as Record<string, ContentNode>\n ).reduce(\n (acc, [key]) => ({\n ...acc,\n [key]: newChildren,\n }),\n {} as Record<string, ContentNode>\n ) as unknown as ContentNode;\n};\n"],"mappings":";;;AAIA,MAAa,sBAIX,SACA,gBACgB;CAChB,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,WACjC;GACA,MAAM,aAAa,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"updateNodeChildren.mjs","names":[],"sources":["../../../src/dictionaryManipulator/updateNodeChildren.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\n\nimport * as NodeTypes from '@intlayer/types/nodeType';\n\nexport const updateNodeChildren = <\n T extends ContentNode,\n U extends ContentNode,\n>(\n section: T,\n newChildren: U\n): ContentNode => {\n if (typeof section === 'string') {\n return newChildren;\n }\n if (typeof section === 'number') {\n return newChildren;\n }\n if (typeof section === 'boolean') {\n return newChildren;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content =\n typedNode[typedNode.nodeType as unknown as keyof typeof typedNode];\n\n if (\n typedNode.nodeType === NodeTypes.TRANSLATION ||\n typedNode.nodeType === NodeTypes.ENUMERATION ||\n typedNode.nodeType === NodeTypes.PLURAL ||\n typedNode.nodeType === NodeTypes.CONDITION\n ) {\n const newContent = Object.entries(content).reduce(\n (acc, [key]) => {\n acc[key] = newChildren;\n return acc;\n },\n {} as Record<string, ContentNode>\n );\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newContent,\n };\n }\n\n if (typedNode.nodeType === NodeTypes.NESTED) {\n return typedNode;\n }\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newChildren,\n };\n }\n\n if (!section || typeof section !== 'object') {\n return newChildren;\n }\n\n if (Array.isArray(section)) {\n return section.map(() => newChildren) as unknown as ContentNode;\n }\n\n return Object.entries(\n section as unknown as Record<string, ContentNode>\n ).reduce(\n (acc, [key]) => ({\n ...acc,\n [key]: newChildren,\n }),\n {} as Record<string, ContentNode>\n ) as unknown as ContentNode;\n};\n"],"mappings":";;;AAIA,MAAa,sBAIX,SACA,gBACgB;CAChB,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,UACrB,OAAO;CAET,IAAI,OAAO,YAAY,WACrB,OAAO;CAET,IAAI,OAAQ,SAAuB,aAAa,UAAU;EACxD,MAAM,YAAY;EAClB,MAAM,UACJ,UAAU,UAAU;EAEtB,IACE,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,eACjC,UAAU,aAAa,UAAU,UACjC,UAAU,aAAa,UAAU,WACjC;GACA,MAAM,aAAa,OAAO,QAAQ,OAAO,EAAE,QACxC,KAAK,CAAC,SAAS;IACd,IAAI,OAAO;IACX,OAAO;GACT,GACA,CAAC,CACH;GAEA,OAAO;IACL,GAAG;KACF,UAAU,WAAW;GACxB;EACF;EAEA,IAAI,UAAU,aAAa,UAAU,QACnC,OAAO;EAGT,OAAO;GACL,GAAG;IACF,UAAU,WAAW;EACxB;CACF;CAEA,IAAI,CAAC,WAAW,OAAO,YAAY,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAO,QAAQ,UAAU,WAAW;CAGtC,OAAO,OAAO,QACZ,OACF,EAAE,QACC,KAAK,CAAC,UAAU;EACf,GAAG;GACF,MAAM;CACT,IACA,CAAC,CACH;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact.mjs","names":[],"sources":["../../../src/formatters/compact.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using compact notation (e.g., 1K, 1M, 1B)\n * based on locale and formatting options.\n *\n * @example\n * compact(1200); // \"1.2K\"\n *\n * @example\n * compact(\"1000000\", { locale: Locales.FRENCH, compactDisplay: \"long\" });\n * // \"1 million\"\n */\nexport const compact = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? internationalization?.defaultLocale,\n\n {\n ...options,\n notation: 'compact',\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,WACX,OACA,YAEA,cACE,KAAK,cACL,SAAS,UAAU,sBAAsB,eAEzC;CACE,GAAG;CACH,UAAU;
|
|
1
|
+
{"version":3,"file":"compact.mjs","names":[],"sources":["../../../src/formatters/compact.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using compact notation (e.g., 1K, 1M, 1B)\n * based on locale and formatting options.\n *\n * @example\n * compact(1200); // \"1.2K\"\n *\n * @example\n * compact(\"1000000\", { locale: Locales.FRENCH, compactDisplay: \"long\" });\n * // \"1 million\"\n */\nexport const compact = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? internationalization?.defaultLocale,\n\n {\n ...options,\n notation: 'compact',\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,WACX,OACA,YAEA,cACE,KAAK,cACL,SAAS,UAAU,sBAAsB,eAEzC;CACE,GAAG;CACH,UAAU;AACZ,CACF,EAAE,OAAO,OAAO,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.mjs","names":[],"sources":["../../../src/formatters/currency.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric or string value into a localized currency string using the Intl API.\n *\n * @example\n * currency(1234.5, { currency: 'EUR' });\n * // \"€1,234.50\"\n *\n * @example\n * currency(\"5000\", { locale: Locales.FRENCH, currency: \"CAD\", currencyDisplay: \"code\" });\n * // \"5 000,00 CAD\"\n */\nexport const currency = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? internationalization?.defaultLocale,\n\n {\n style: 'currency',\n currency: options?.currency ?? 'USD',\n currencyDisplay: options?.currencyDisplay ?? 'symbol',\n minimumFractionDigits: options?.minimumFractionDigits ?? 2,\n maximumFractionDigits: options?.maximumFractionDigits ?? 2,\n ...options,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,YACX,OACA,YAEA,cACE,KAAK,cACL,SAAS,UAAU,sBAAsB,eAEzC;CACE,OAAO;CACP,UAAU,SAAS,YAAY;CAC/B,iBAAiB,SAAS,mBAAmB;CAC7C,uBAAuB,SAAS,yBAAyB;CACzD,uBAAuB,SAAS,yBAAyB;CACzD,GAAG;
|
|
1
|
+
{"version":3,"file":"currency.mjs","names":[],"sources":["../../../src/formatters/currency.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric or string value into a localized currency string using the Intl API.\n *\n * @example\n * currency(1234.5, { currency: 'EUR' });\n * // \"€1,234.50\"\n *\n * @example\n * currency(\"5000\", { locale: Locales.FRENCH, currency: \"CAD\", currencyDisplay: \"code\" });\n * // \"5 000,00 CAD\"\n */\nexport const currency = (\n value: string | number,\n options?: Intl.NumberFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n options?.locale ?? internationalization?.defaultLocale,\n\n {\n style: 'currency',\n currency: options?.currency ?? 'USD',\n currencyDisplay: options?.currencyDisplay ?? 'symbol',\n minimumFractionDigits: options?.minimumFractionDigits ?? 2,\n maximumFractionDigits: options?.maximumFractionDigits ?? 2,\n ...options,\n }\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,YACX,OACA,YAEA,cACE,KAAK,cACL,SAAS,UAAU,sBAAsB,eAEzC;CACE,OAAO;CACP,UAAU,SAAS,YAAY;CAC/B,iBAAiB,SAAS,mBAAmB;CAC7C,uBAAuB,SAAS,yBAAyB;CACzD,uBAAuB,SAAS,yBAAyB;CACzD,GAAG;AACL,CACF,EAAE,OAAO,OAAO,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.mjs","names":[],"sources":["../../../src/formatters/date.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\nexport type DateTimePreset =\n | 'short'\n | 'long'\n | 'dateOnly'\n | 'timeOnly'\n | 'full';\n\nexport const presets: Record<DateTimePreset, Intl.DateTimeFormatOptions> = {\n short: {\n year: '2-digit',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n },\n long: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n },\n full: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n hour12: false,\n },\n dateOnly: {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n },\n timeOnly: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n },\n};\n\n/**\n * Formats a date/time value into a localized string using Intl.DateTimeFormat.\n *\n * @example\n * date(new Date('2025-08-02T14:30:00Z'), { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });\n * // \"08/02/25, 14:30\"\n *\n * @example\n * date(\"2025-08-02T14:30:00Z\", { locale: Locales.FRENCH, month: \"long\", day: \"numeric\" });\n * // \"2 août\"\n */\nexport const date = (\n date: Date | string | number,\n options?:\n | (Intl.DateTimeFormatOptions & { locale?: LocalesValues })\n | DateTimePreset\n): string => {\n const dateTime = new Date(date);\n\n const resolvedOptions =\n typeof options === 'string' ? (presets[options] ?? {}) : options;\n\n const locale =\n (typeof options === 'object' ? options?.locale : undefined) ??\n internationalization?.defaultLocale;\n\n const formatter = getCachedIntl(Intl.DateTimeFormat, locale, resolvedOptions);\n\n return formatter.format(dateTime);\n};\n"],"mappings":";;;;AAWA,MAAa,UAA8D;CACzE,OAAO;EACL,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;
|
|
1
|
+
{"version":3,"file":"date.mjs","names":[],"sources":["../../../src/formatters/date.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\nexport type DateTimePreset =\n | 'short'\n | 'long'\n | 'dateOnly'\n | 'timeOnly'\n | 'full';\n\nexport const presets: Record<DateTimePreset, Intl.DateTimeFormatOptions> = {\n short: {\n year: '2-digit',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n },\n long: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n },\n full: {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n hour12: false,\n },\n dateOnly: {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n },\n timeOnly: {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n },\n};\n\n/**\n * Formats a date/time value into a localized string using Intl.DateTimeFormat.\n *\n * @example\n * date(new Date('2025-08-02T14:30:00Z'), { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' });\n * // \"08/02/25, 14:30\"\n *\n * @example\n * date(\"2025-08-02T14:30:00Z\", { locale: Locales.FRENCH, month: \"long\", day: \"numeric\" });\n * // \"2 août\"\n */\nexport const date = (\n date: Date | string | number,\n options?:\n | (Intl.DateTimeFormatOptions & { locale?: LocalesValues })\n | DateTimePreset\n): string => {\n const dateTime = new Date(date);\n\n const resolvedOptions =\n typeof options === 'string' ? (presets[options] ?? {}) : options;\n\n const locale =\n (typeof options === 'object' ? options?.locale : undefined) ??\n internationalization?.defaultLocale;\n\n const formatter = getCachedIntl(Intl.DateTimeFormat, locale, resolvedOptions);\n\n return formatter.format(dateTime);\n};\n"],"mappings":";;;;AAWA,MAAa,UAA8D;CACzE,OAAO;EACL,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;CACV;CACA,MAAM;EACJ,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;CACV;CACA,MAAM;EACJ,MAAM;EACN,OAAO;EACP,KAAK;EACL,MAAM;EACN,QAAQ;EACR,QAAQ;CACV;CACA,UAAU;EACR,MAAM;EACN,OAAO;EACP,KAAK;CACP;CACA,UAAU;EACR,MAAM;EACN,QAAQ;EACR,QAAQ;CACV;AACF;;;;;;;;;;;;AAaA,MAAa,QACX,MACA,YAGW;CACX,MAAM,WAAW,IAAI,KAAK,IAAI;CAE9B,MAAM,kBACJ,OAAO,YAAY,WAAY,QAAQ,YAAY,CAAC,IAAK;CAE3D,MAAM,UACH,OAAO,YAAY,WAAW,SAAS,SAAS,WACjD,sBAAsB;CAIxB,OAFkB,cAAc,KAAK,gBAAgB,QAAQ,eAE9C,EAAE,OAAO,QAAQ;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.mjs","names":[],"sources":["../../../src/formatters/list.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/** Locally defined subset of Intl.ListFormatOptions so consumers don't need ES2021.Intl in their lib. */\ntype ListFormatOptions = {\n localeMatcher?: 'lookup' | 'best fit';\n type?: 'conjunction' | 'disjunction' | 'unit';\n style?: 'long' | 'short' | 'narrow';\n};\n\n/**\n * Formats an array of values into a localized list string using the Intl API.\n *\n * @example\n * list(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * @example\n * list(['red', 'green', 'blue'], { locale: Locales.FRENCH, type: 'disjunction' });\n * // \"rouge, vert ou bleu\"\n *\n * @example\n * list([1, 2, 3], { type: 'unit' });\n * // \"1, 2, 3\"\n */\nexport const list = (\n values: (string | number)[],\n options?: ListFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n (Intl as any).ListFormat,\n options?.locale ?? internationalization?.defaultLocale,\n\n {\n type: options?.type ?? 'conjunction',\n style: options?.style ?? 'long',\n ...options,\n }\n ).format(values.map(String));\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,MAAa,QACX,QACA,YAEA,cACG,KAAa,YACd,SAAS,UAAU,sBAAsB,eAEzC;CACE,MAAM,SAAS,QAAQ;CACvB,OAAO,SAAS,SAAS;CACzB,GAAG;
|
|
1
|
+
{"version":3,"file":"list.mjs","names":[],"sources":["../../../src/formatters/list.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/** Locally defined subset of Intl.ListFormatOptions so consumers don't need ES2021.Intl in their lib. */\ntype ListFormatOptions = {\n localeMatcher?: 'lookup' | 'best fit';\n type?: 'conjunction' | 'disjunction' | 'unit';\n style?: 'long' | 'short' | 'narrow';\n};\n\n/**\n * Formats an array of values into a localized list string using the Intl API.\n *\n * @example\n * list(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * @example\n * list(['red', 'green', 'blue'], { locale: Locales.FRENCH, type: 'disjunction' });\n * // \"rouge, vert ou bleu\"\n *\n * @example\n * list([1, 2, 3], { type: 'unit' });\n * // \"1, 2, 3\"\n */\nexport const list = (\n values: (string | number)[],\n options?: ListFormatOptions & { locale?: LocalesValues }\n): string =>\n getCachedIntl(\n (Intl as any).ListFormat,\n options?.locale ?? internationalization?.defaultLocale,\n\n {\n type: options?.type ?? 'conjunction',\n style: options?.style ?? 'long',\n ...options,\n }\n ).format(values.map(String));\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,MAAa,QACX,QACA,YAEA,cACG,KAAa,YACd,SAAS,UAAU,sBAAsB,eAEzC;CACE,MAAM,SAAS,QAAQ;CACvB,OAAO,SAAS,SAAS;CACzB,GAAG;AACL,CACF,EAAE,OAAO,OAAO,IAAI,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.mjs","names":[],"sources":["../../../src/formatters/number.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using locale-aware formatting.\n *\n * @example\n * number(123456.789); // \"123,456.789\"\n *\n * @example\n * number(\"1000000\", { locale: Locales.FRENCH }); // \"1 000 000\"\n */\nexport const number = (\n value: string | number,\n {\n locale,\n ...options\n }: Intl.NumberFormatOptions & { locale?: LocalesValues } = {}\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n locale ?? internationalization?.defaultLocale,\n\n options\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,UACX,OACA,EACE,QACA,GAAG,YACsD,
|
|
1
|
+
{"version":3,"file":"number.mjs","names":[],"sources":["../../../src/formatters/number.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a numeric value using locale-aware formatting.\n *\n * @example\n * number(123456.789); // \"123,456.789\"\n *\n * @example\n * number(\"1000000\", { locale: Locales.FRENCH }); // \"1 000 000\"\n */\nexport const number = (\n value: string | number,\n {\n locale,\n ...options\n }: Intl.NumberFormatOptions & { locale?: LocalesValues } = {}\n): string =>\n getCachedIntl(\n Intl.NumberFormat,\n locale ?? internationalization?.defaultLocale,\n\n options\n ).format(Number(value));\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,UACX,OACA,EACE,QACA,GAAG,YACsD,CAAC,MAE5D,cACE,KAAK,cACL,UAAU,sBAAsB,eAEhC,OACF,EAAE,OAAO,OAAO,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percentage.mjs","names":[],"sources":["../../../src/formatters/percentage.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a number as a percentage string (e.g., 0.25 → \"25%\").\n *\n * @example\n * percentage(0.25); // \"25%\"\n *\n * @example\n * percentage(0.25, { minimumFractionDigits: 2 }); // \"25.00%\"\n */\nexport const percentage = (\n value: string | number,\n {\n locale,\n ...options\n }: Intl.NumberFormatOptions & { locale?: LocalesValues } = {}\n): string => {\n let numericValue = Number(value);\n\n // Normalize: if user passes 10, treat it as 10% instead of 1000%\n if (numericValue > 1) {\n numericValue /= 100;\n }\n\n const formatter = getCachedIntl(\n Intl.NumberFormat,\n locale ?? internationalization?.defaultLocale,\n\n {\n style: 'percent',\n ...options,\n }\n );\n\n return formatter.format(Number(numericValue));\n};\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,cACX,OACA,EACE,QACA,GAAG,YACsD,
|
|
1
|
+
{"version":3,"file":"percentage.mjs","names":[],"sources":["../../../src/formatters/percentage.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getCachedIntl } from '../utils/intl';\n\n/**\n * Formats a number as a percentage string (e.g., 0.25 → \"25%\").\n *\n * @example\n * percentage(0.25); // \"25%\"\n *\n * @example\n * percentage(0.25, { minimumFractionDigits: 2 }); // \"25.00%\"\n */\nexport const percentage = (\n value: string | number,\n {\n locale,\n ...options\n }: Intl.NumberFormatOptions & { locale?: LocalesValues } = {}\n): string => {\n let numericValue = Number(value);\n\n // Normalize: if user passes 10, treat it as 10% instead of 1000%\n if (numericValue > 1) {\n numericValue /= 100;\n }\n\n const formatter = getCachedIntl(\n Intl.NumberFormat,\n locale ?? internationalization?.defaultLocale,\n\n {\n style: 'percent',\n ...options,\n }\n );\n\n return formatter.format(Number(numericValue));\n};\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,cACX,OACA,EACE,QACA,GAAG,YACsD,CAAC,MACjD;CACX,IAAI,eAAe,OAAO,KAAK;CAG/B,IAAI,eAAe,GACjB,gBAAgB;CAalB,OAVkB,cAChB,KAAK,cACL,UAAU,sBAAsB,eAEhC;EACE,OAAO;EACP,GAAG;CACL,CAGa,EAAE,OAAO,OAAO,YAAY,CAAC;AAC9C"}
|