UNPKG

@intlayer/core

Version:

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

42 lines 1.05 kB
import { NodeType } from "../../types/index.mjs"; const deepTransformNode = (node, props) => { for (const plugin of props.plugins ?? []) { if (plugin.canHandle(node)) { return plugin.transform( node, props, (node2, props2) => deepTransformNode(node2, props2) ); } } if (node === null || typeof node !== "object") { return node; } if (Array.isArray(node)) { return node.map((child, index) => { const childProps = { ...props, children: child, keyPath: [ ...props.keyPath, { type: NodeType.Array, key: index } ] }; return deepTransformNode(child, childProps); }); } const result = {}; for (const key in node) { const childProps = { ...props, children: node[key], keyPath: [...props.keyPath, { type: NodeType.Object, key }] }; result[key] = deepTransformNode(node[key], childProps); } return result; }; export { deepTransformNode }; //# sourceMappingURL=deepTransform.mjs.map