(baseName: string, existingNames: string[])
| 65 | } |
| 66 | |
| 67 | function getNextIndexedName(baseName: string, existingNames: string[]): string { |
| 68 | const normalizedBase = baseName.trim() |
| 69 | const indexedNameRe = new RegExp( |
| 70 | `^${escapeRegExp(normalizedBase)}(?:\\s+(\\d+))?$`, |
| 71 | 'i', |
| 72 | ) |
| 73 | |
| 74 | let maxIndex = 0 |
| 75 | |
| 76 | existingNames.forEach((name) => { |
| 77 | const match = name.trim().match(indexedNameRe) |
| 78 | if (!match) { |
| 79 | return |
| 80 | } |
| 81 | |
| 82 | const index = match[1] ? Number(match[1]) : 0 |
| 83 | if (Number.isFinite(index)) { |
| 84 | maxIndex = Math.max(maxIndex, index) |
| 85 | } |
| 86 | }) |
| 87 | |
| 88 | return `${normalizedBase} ${maxIndex + 1}` |
| 89 | } |
| 90 | |
| 91 | async function getSnippetNamesForCreate( |
| 92 | folderId: number | null, |
no test coverage detected