@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
17 lines (15 loc) • 1.1 kB
JavaScript
import * as NodeTypes from "@intlayer/types/nodeType";
//#region src/dictionaryManipulator/getContentNodeByKeyPath.ts
const getContentNodeByKeyPath = (dictionaryContent, keyPath, fallbackLocale) => {
let currentValue = structuredClone(dictionaryContent);
for (const keyObj of keyPath) {
if (fallbackLocale && currentValue?.nodeType === NodeTypes.TRANSLATION) currentValue = currentValue?.[NodeTypes.TRANSLATION]?.[fallbackLocale];
if (keyObj.type === NodeTypes.OBJECT || keyObj.type === NodeTypes.ARRAY) currentValue = currentValue?.[keyObj.key];
if (keyObj.type === NodeTypes.TRANSLATION || keyObj.type === NodeTypes.CONDITION || keyObj.type === NodeTypes.ENUMERATION || keyObj.type === NodeTypes.PLURAL) currentValue = currentValue?.[keyObj.type]?.[keyObj.key];
if (keyObj.type === NodeTypes.MARKDOWN || keyObj.type === NodeTypes.HTML || keyObj.type === NodeTypes.INSERTION || keyObj.type === NodeTypes.FILE) currentValue = currentValue?.[keyObj.type];
}
return currentValue;
};
//#endregion
export { getContentNodeByKeyPath };
//# sourceMappingURL=getContentNodeByKeyPath.mjs.map