* Find the highest sequential number among items that match `prefix trailingSuffix`. * Returns 0 when no items match.
(items: string[], prefix: string, trailingSuffix = "")
| 718 | * Returns 0 when no items match. |
| 719 | */ |
| 720 | function findMaxSequentialNumber(items: string[], prefix: string, trailingSuffix = ""): number { |
| 721 | let max = 0; |
| 722 | for (const item of items) { |
| 723 | if (!item.startsWith(prefix)) continue; |
| 724 | if (trailingSuffix && !item.endsWith(trailingSuffix)) continue; |
| 725 | |
| 726 | const numberStr = trailingSuffix |
| 727 | ? item.slice(prefix.length, -trailingSuffix.length) |
| 728 | : item.slice(prefix.length); |
| 729 | if (!/^\d+$/.test(numberStr)) continue; |
| 730 | |
| 731 | const n = Number(numberStr); |
| 732 | if (n > max) max = n; |
| 733 | } |
| 734 | return max; |
| 735 | } |
| 736 | |
| 737 | function deriveForkFamilyBaseName(metadata: { name: string; forkFamilyBaseName?: string }): string { |
| 738 | if (metadata.forkFamilyBaseName) { |
no test coverage detected