| 88 | } |
| 89 | |
| 90 | const groupEntities = (entities: Iterable<ApiEntity>): ReadonlyArray<ApiGroup> => { |
| 91 | const groups = new Map<string, Array<ApiEntity>>() |
| 92 | for (const entity of entities) { |
| 93 | const key = `${entity.module}#${entity.path.join(".")}` |
| 94 | const group = groups.get(key) |
| 95 | if (group === undefined) { |
| 96 | groups.set(key, [entity]) |
| 97 | } else { |
| 98 | group.push(entity) |
| 99 | } |
| 100 | } |
| 101 | return [...groups.values()].map((group) => ({ |
| 102 | module: group[0]!.module, |
| 103 | path: group[0]!.path, |
| 104 | entities: group.sort((left, right) => left.bucket.localeCompare(right.bucket)) |
| 105 | })) |
| 106 | } |
| 107 | |
| 108 | const groupName = (group: ApiGroup): string => group.path.at(-1) ?? "" |
| 109 | |