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

Function getNextIndexedName

src/main/api/routes/captures.ts:115–136  ·  view source on GitHub ↗
(baseName: string, existingNames: string[])

Source from the content-addressed store, hash-verified

113}
114
115function 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
138function getUniqueName(baseName: string, existingNames: string[]): string {
139 const normalizedBase = sanitizeCaptureName(baseName, 'Captured item')

Callers 1

getUniqueNameFunction · 0.70

Calls 1

escapeRegExpFunction · 0.70

Tested by

no test coverage detected