(titles: Array<string | null | undefined>)
| 866 | } |
| 867 | |
| 868 | function createNextDefaultThreadTitle(titles: Array<string | null | undefined>): string { |
| 869 | let max = 0; |
| 870 | const pattern = new RegExp(`^${escapeRegExp(DEFAULT_THREAD_TITLE_PREFIX)}(\\d{5})$`, 'u'); |
| 871 | for (const title of titles) { |
| 872 | const match = normalizeThreadTitle(title)?.match(pattern); |
| 873 | if (!match) { |
| 874 | continue; |
| 875 | } |
| 876 | max = Math.max(max, Number(match[1])); |
| 877 | } |
| 878 | const next = max >= 99999 ? 1 : max + 1; |
| 879 | return `${DEFAULT_THREAD_TITLE_PREFIX}${String(next).padStart(5, '0')}`; |
| 880 | } |
| 881 | |
| 882 | function escapeRegExp(value: string): string { |
| 883 | return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
no test coverage detected