UNPKG

@intlayer/core

Version:

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

41 lines (39 loc) 1.37 kB
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); let __intlayer_types = require("@intlayer/types"); __intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types); //#region src/interpreter/getContent/deepTransform.ts /** * Recursively traverses a node (object/array/primitive). * Applies the *first* plugin that can transform a node, then stops descending further. * If no plugin transforms it, it recurses into its children. */ const deepTransformNode = (node, props) => { for (const plugin of props.plugins ?? []) if (plugin.canHandle(node)) return plugin.transform(node, props, (node$1, props$1) => deepTransformNode(node$1, props$1)); if (node === null || typeof node !== "object") return node; if (Array.isArray(node)) return node.map((child, index) => { return deepTransformNode(child, { ...props, children: child, keyPath: [...props.keyPath, { type: __intlayer_types.NodeType.Array, key: index }] }); }); const result = {}; for (const key in node) { const childProps = { ...props, children: node[key], keyPath: [...props.keyPath, { type: __intlayer_types.NodeType.Object, key }] }; result[key] = deepTransformNode(node[key], childProps); } return result; }; //#endregion exports.deepTransformNode = deepTransformNode; //# sourceMappingURL=deepTransform.cjs.map