UNPKG

@intlayer/core

Version:

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

41 lines (39 loc) 2.04 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/renameContentNodeByKeyPath.ts const renameContentNodeByKeyPath = (dictionaryContent, newKey, keyPath) => { let currentValue = dictionaryContent; let parentValue = null; let lastKey = null; for (const keyObj of keyPath) { parentValue = currentValue; if (keyObj.type === _intlayer_types_nodeType.OBJECT || keyObj.type === _intlayer_types_nodeType.ARRAY) { lastKey = keyObj.key; currentValue = currentValue[keyObj.key]; } if (keyObj.type === _intlayer_types_nodeType.TRANSLATION || keyObj.type === _intlayer_types_nodeType.ENUMERATION || keyObj.type === _intlayer_types_nodeType.PLURAL || keyObj.type === _intlayer_types_nodeType.CONDITION) { lastKey = keyObj.type; currentValue = currentValue[keyObj.type][keyObj.key]; } if (keyObj.type === _intlayer_types_nodeType.MARKDOWN || keyObj.type === _intlayer_types_nodeType.REACT_NODE || keyObj.type === _intlayer_types_nodeType.HTML || keyObj.type === _intlayer_types_nodeType.INSERTION || keyObj.type === _intlayer_types_nodeType.FILE) { lastKey = keyObj.type; currentValue = currentValue[keyObj.type]; } } if (parentValue && lastKey !== null) if (Array.isArray(parentValue)) parentValue[lastKey] = currentValue; else { const newParentValue = {}; for (const key of Object.keys(parentValue)) if (key === lastKey && typeof newKey !== "undefined") newParentValue[newKey] = currentValue; else newParentValue[key] = parentValue[key]; Object.keys(parentValue).forEach((key) => { delete parentValue[key]; }); Object.assign(parentValue, newParentValue); } return dictionaryContent; }; //#endregion exports.renameContentNodeByKeyPath = renameContentNodeByKeyPath; //# sourceMappingURL=renameContentNodeByKeyPath.cjs.map