@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
30 lines (28 loc) • 1.19 kB
JavaScript
import { NodeType } from "@intlayer/types";
//#region src/dictionaryManipulator/removeContentNodeByKeyPath.ts
const removeContentNodeByKeyPath = (dictionaryContent, keyPath) => {
let currentValue = dictionaryContent;
let parentValue = null;
let lastKey = null;
for (const keyObj of keyPath) {
parentValue = currentValue;
if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {
lastKey = keyObj.key;
currentValue = currentValue[keyObj.key];
}
if (keyObj.type === NodeType.Translation || keyObj.type === NodeType.Enumeration || keyObj.type === NodeType.Condition) {
lastKey = keyObj.type;
currentValue = currentValue[keyObj.type][keyObj.key];
}
if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.ReactNode || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
lastKey = keyObj.type;
currentValue = currentValue[keyObj.type];
}
}
if (parentValue && lastKey !== null) if (Array.isArray(parentValue)) parentValue.splice(lastKey, 1);
else delete parentValue[lastKey];
return dictionaryContent;
};
//#endregion
export { removeContentNodeByKeyPath };
//# sourceMappingURL=removeContentNodeByKeyPath.mjs.map