(
entries: readonly PathTreeEntry[],
options: PathTreeFormatOptions = {},
)
| 147 | } |
| 148 | |
| 149 | export function formatPathTree( |
| 150 | entries: readonly PathTreeEntry[], |
| 151 | options: PathTreeFormatOptions = {}, |
| 152 | ): string[] { |
| 153 | const formatPath = options.formatPath ?? ((path: string): string => path); |
| 154 | const root = createNode('', ''); |
| 155 | const parsedPaths = entries |
| 156 | .map(parseRawPath) |
| 157 | .filter((entry): entry is ParsedPath => entry !== null) |
| 158 | .sort((left, right) => left.sortablePath.localeCompare(right.sortablePath)); |
| 159 | |
| 160 | for (const parsedPath of parsedPaths) { |
| 161 | addPath(root, parsedPath); |
| 162 | } |
| 163 | |
| 164 | const nodes = topLevelNodes(root).sort((left, right) => |
| 165 | left.rawPath.localeCompare(right.rawPath), |
| 166 | ); |
| 167 | return nodes.flatMap((child, index) => |
| 168 | renderNode(child, '', index === nodes.length - 1, undefined, formatPath), |
| 169 | ); |
| 170 | } |
no test coverage detected