UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

20 lines (18 loc) 1.53 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../_virtual/_rolldown/runtime.cjs'); let _intlayer_types_nodeType = require("@intlayer/types/nodeType"); _intlayer_types_nodeType = require_runtime.__toESM(_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 === _intlayer_types_nodeType.TRANSLATION) currentValue = currentValue?.[_intlayer_types_nodeType.TRANSLATION]?.[fallbackLocale]; if (keyObj.type === _intlayer_types_nodeType.OBJECT || keyObj.type === _intlayer_types_nodeType.ARRAY) currentValue = currentValue?.[keyObj.key]; if (keyObj.type === _intlayer_types_nodeType.TRANSLATION || keyObj.type === _intlayer_types_nodeType.CONDITION || keyObj.type === _intlayer_types_nodeType.ENUMERATION || keyObj.type === _intlayer_types_nodeType.PLURAL) currentValue = currentValue?.[keyObj.type]?.[keyObj.key]; if (keyObj.type === _intlayer_types_nodeType.MARKDOWN || keyObj.type === _intlayer_types_nodeType.HTML || keyObj.type === _intlayer_types_nodeType.INSERTION || keyObj.type === _intlayer_types_nodeType.FILE) currentValue = currentValue?.[keyObj.type]; } return currentValue; }; //#endregion exports.getContentNodeByKeyPath = getContentNodeByKeyPath; //# sourceMappingURL=getContentNodeByKeyPath.cjs.map