MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / convertToValidFileName

Function convertToValidFileName

SurgeModuleTool_macOS.js:176–190  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

174 })
175}
176function convertToValidFileName(str) {
177 // 替换非法字符为下划线
178 const invalidCharsRegex = /[\/:*?"<>|]/g
179 const validFileName = str.replace(invalidCharsRegex, '_')
180
181 // 删除多余的点号
182 const multipleDotsRegex = /\.{2,}/g
183 const fileNameWithoutMultipleDots = validFileName.replace(multipleDotsRegex, '.')
184
185 // 删除文件名开头和结尾的点号和空格
186 const leadingTrailingDotsSpacesRegex = /^[\s.]+|[\s.]+$/g
187 const finalFileName = fileNameWithoutMultipleDots.replace(leadingTrailingDotsSpacesRegex, '')
188
189 return finalFileName
190}
191function addLineAfterLastOccurrence(text, addition) {
192 const regex = /^#!.+?$/gm
193 const matchArray = text.match(regex)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected