MCPcopy Create free account
hub / github.com/massCodeIO/massCode / getNextIndexedName

Function getNextIndexedName

src/renderer/composables/spaces/notes/useNotes.ts:292–314  ·  view source on GitHub ↗
(baseName: string, existingNames: string[])

Source from the content-addressed store, hash-verified

290}
291
292function 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
316function hasDisplayedNote(noteId: number): boolean {
317 const source = isSearch.value ? notesBySearch.value : notes.value

Callers 1

createNoteFunction · 0.70

Calls 1

escapeRegExpFunction · 0.70

Tested by

no test coverage detected