(baseName: string, existingNames: string[])
| 23 | } |
| 24 | |
| 25 | function getNextIndexedName(baseName: string, existingNames: string[]): string { |
| 26 | const normalizedBase = baseName.trim() |
| 27 | const indexedNameRe = new RegExp( |
| 28 | `^${escapeRegExp(normalizedBase)}(?:\\s+(\\d+))?$`, |
| 29 | 'i', |
| 30 | ) |
| 31 | |
| 32 | let maxIndex = 0 |
| 33 | |
| 34 | existingNames.forEach((name) => { |
| 35 | const match = name.trim().match(indexedNameRe) |
| 36 | if (!match) { |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | const index = match[1] ? Number(match[1]) : 0 |
| 41 | if (Number.isFinite(index)) { |
| 42 | maxIndex = Math.max(maxIndex, index) |
| 43 | } |
| 44 | }) |
| 45 | |
| 46 | return `${normalizedBase} ${maxIndex + 1}` |
| 47 | } |
| 48 | |
| 49 | function getNextUntitledFolderName(parentId?: number): string { |
| 50 | const normalizedParentId = parentId ?? null |
no test coverage detected