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

Function getNextIndexedName

src/renderer/composables/useFolders.ts:25–47  ·  view source on GitHub ↗
(baseName: string, existingNames: string[])

Source from the content-addressed store, hash-verified

23}
24
25function 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
49function getNextUntitledFolderName(parentId?: number): string {
50 const normalizedParentId = parentId ?? null

Callers 1

Calls 1

escapeRegExpFunction · 0.70

Tested by

no test coverage detected