(baseName: string, existingNames: string[])
| 290 | } |
| 291 | |
| 292 | function getNextIndexedName(baseName: string, existingNames: string[]): string { |
| 293 | const normalizedBase = baseName.trim() |
| 294 | const indexedNameRe = new RegExp( |
| 295 | `^${escapeRegExp(normalizedBase)}(?:\\s+(\\d+))?$`, |
| 296 | 'i', |
| 297 | ) |
| 298 | |
| 299 | let maxIndex = 0 |
| 300 | |
| 301 | existingNames.forEach((name) => { |
| 302 | const match = name.trim().match(indexedNameRe) |
| 303 | if (!match) { |
| 304 | return |
| 305 | } |
| 306 | |
| 307 | const index = match[1] ? Number(match[1]) : 0 |
| 308 | if (Number.isFinite(index)) { |
| 309 | maxIndex = Math.max(maxIndex, index) |
| 310 | } |
| 311 | }) |
| 312 | |
| 313 | return `${normalizedBase} ${maxIndex + 1}` |
| 314 | } |
| 315 | |
| 316 | function hasDisplayedNote(noteId: number): boolean { |
| 317 | const source = isSearch.value ? notesBySearch.value : notes.value |
no test coverage detected