Kaizen
Browse modulesReportsFunctions

Function: mapTree()

function mapTree<T extends Node>(tree: T, mapper: (node: Node) => Node): T;

Defined in: server/reports/tree.ts:29

Recursively maps a tree, creating new node objects via the mapper function. The mapper receives a shallow copy of each node (with children already mapped), so it can modify properties on the copy without mutating the original.

We use shallow copies instead of structuredClone because structuredClone would deep-copy large leaf values like Buffers (e.g. ImageNode.url) that are read-only and safe to share by reference. It would also require a separate walk pass to apply transforms, whereas mapTree combines the copy and transform in one pass.

Type Parameters

Type Parameter
T extends Node

Parameters

ParameterType
treeT
mapper(node: Node) => Node

Returns

T

On this page