| 452 | |
| 453 | // Splits a type expression at a top-level separator, outside `<>`, `()`, `{}`, and `[]`. |
| 454 | function splitTopLevel(type: string, separator: string) { |
| 455 | const parts: Array<string> = [] |
| 456 | let depth = 0 |
| 457 | let start = 0 |
| 458 | for (let index = 0; index < type.length; index++) { |
| 459 | const char = type[index]! |
| 460 | if ('<({['.includes(char)) { |
| 461 | depth++ |
| 462 | } else if ( |
| 463 | ')}]'.includes(char) || |
| 464 | (char === '>' && type[index - 1] !== '=') |
| 465 | ) { |
| 466 | depth-- |
| 467 | } else if (depth === 0 && type.startsWith(separator, index)) { |
| 468 | parts.push(type.slice(start, index)) |
| 469 | start = index + separator.length |
| 470 | index += separator.length - 1 |
| 471 | } |
| 472 | } |
| 473 | parts.push(type.slice(start)) |
| 474 | return parts.map((part) => part.trim()).filter(Boolean) |
| 475 | } |
| 476 | |
| 477 | async function typePage(outputDir: string, name: string) { |
| 478 | for (const from of [`interfaces/${name}`, `type-aliases/${name}`]) { |