(baseName: string, existingNames: string[])
| 113 | } |
| 114 | |
| 115 | function getNextIndexedName(baseName: string, existingNames: string[]): string { |
| 116 | const normalizedBase = baseName.trim() |
| 117 | const indexedNameRe = new RegExp( |
| 118 | `^${escapeRegExp(normalizedBase)}(?:\\s+(\\d+))?$`, |
| 119 | 'i', |
| 120 | ) |
| 121 | |
| 122 | let maxIndex = 0 |
| 123 | existingNames.forEach((name) => { |
| 124 | const match = name.trim().match(indexedNameRe) |
| 125 | if (!match) { |
| 126 | return |
| 127 | } |
| 128 | |
| 129 | const index = match[1] ? Number(match[1]) : 0 |
| 130 | if (Number.isFinite(index)) { |
| 131 | maxIndex = Math.max(maxIndex, index) |
| 132 | } |
| 133 | }) |
| 134 | |
| 135 | return `${normalizedBase} ${maxIndex + 1}` |
| 136 | } |
| 137 | |
| 138 | function getUniqueName(baseName: string, existingNames: string[]): string { |
| 139 | const normalizedBase = sanitizeCaptureName(baseName, 'Captured item') |
no test coverage detected