(links: ReadonlyArray<{ when: string; sites?: ReadonlyArray<{ when: string }> }>)
| 261 | * apart, and the full text is a hover away. |
| 262 | */ |
| 263 | export function edgeLabel(links: ReadonlyArray<{ when: string; sites?: ReadonlyArray<{ when: string }> }>): string { |
| 264 | // A link with several call sites is several scenarios: count them as ways. |
| 265 | const ways = links.flatMap((l) => (l.sites && l.sites.length > 1 ? l.sites.map((s) => s.when) : [l.when])); |
| 266 | if (ways.length === 1) { |
| 267 | const when = ways[0]!; |
| 268 | if (!when) return ''; |
| 269 | const parts = clauses(when); |
| 270 | const last = clauseWords(parts[parts.length - 1] ?? when); |
| 271 | const text = parts.length > 1 ? `…${last}` : last; |
| 272 | return text.length > EDGE_LABEL_MAX ? `${text.slice(0, EDGE_LABEL_MAX - 1)}…` : text; |
| 273 | } |
| 274 | const conditional = ways.filter((w) => w).length; |
| 275 | return conditional > 0 ? `${ways.length} ways · ${conditional} conditional` : `${ways.length} ways`; |
| 276 | } |
| 277 | |
| 278 | /* ---------------------------------------------------------------- build -- */ |
| 279 |
no test coverage detected