/** * Function to render a node value for display * @param node The node to render * @returns A string representation or undefined if should not render */ export type TreeRenderFunction = (node: unknown) => string | undefined; /** * Function to sort keys during tree traversal * @param a First key for comparison * @param b Second key for comparison * @returns Negative if a < b, positive if a > b, 0 if equal */ export type TreeSortFunction = (a: string, b: string) => number; /** * Configuration options for object tree rendering */ export interface ObjectTreeOptions { /** Text to display for circular references (default: " (circular ref.)") */ breakCircularWith?: string | null | undefined; /** Whether to return as single string or array of lines (default: true) */ joined?: boolean; /** Connector for neighbor keys (default: "├─ ") */ keyNeighbour?: string; /** Connector for non-neighbor keys (default: "└─ ") */ keyNoNeighbour?: string; /** Function to render node values (default: renders primitives) */ renderFn?: TreeRenderFunction; /** Separator between key and value (default: ": ") */ separator?: string; /** Function to sort object keys (default: natural order) */ sortFn?: TreeSortFunction | undefined; /** Spacer for neighbor branches (default: "│ ") */ spacerNeighbour?: string; /** Spacer for non-neighbor branches (default: " ") */ spacerNoNeighbour?: string; } /** * Renders an object as an ASCII tree structure. * @param tree The object to render as a tree * @param options Configuration options for tree rendering * @returns Formatted tree as string or array of lines * @example * ```typescript * const obj = { * name: "John", * age: 30, * address: { * street: "Main St", * city: "New York" * } * }; * * // Default output as string * console.log(renderObjectTree(obj)); * * // Custom rendering * console.log(renderObjectTree(obj, { * sortFn: (a, b) => a.localeCompare(b), * renderFn: (node) => { * if (typeof node === 'string') return node.toUpperCase(); * return ['boolean', 'string', 'number'].includes(typeof node) * ? String(node) * : undefined; * } * })); * * // Get as array of lines * const lines = renderObjectTree(obj, { joined: false }); * ``` */ export declare const renderObjectTree: (tree: Record | unknown[], options?: ObjectTreeOptions) => string | string[]; /** * Default export for CommonJS compatibility */ export default renderObjectTree;