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

Function getNextIndexedName

src/renderer/composables/useSnippets.ts:67–89  ·  view source on GitHub ↗
(baseName: string, existingNames: string[])

Source from the content-addressed store, hash-verified

65}
66
67function getNextIndexedName(baseName: string, existingNames: string[]): string {
68 const normalizedBase = baseName.trim()
69 const indexedNameRe = new RegExp(
70 `^${escapeRegExp(normalizedBase)}(?:\\s+(\\d+))?$`,
71 'i',
72 )
73
74 let maxIndex = 0
75
76 existingNames.forEach((name) => {
77 const match = name.trim().match(indexedNameRe)
78 if (!match) {
79 return
80 }
81
82 const index = match[1] ? Number(match[1]) : 0
83 if (Number.isFinite(index)) {
84 maxIndex = Math.max(maxIndex, index)
85 }
86 })
87
88 return `${normalizedBase} ${maxIndex + 1}`
89}
90
91async function getSnippetNamesForCreate(
92 folderId: number | null,

Callers 1

createSnippetFunction · 0.70

Calls 1

escapeRegExpFunction · 0.70

Tested by

no test coverage detected