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

Function convertToValidFileName

SurgeModuleTool.js:20–34  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

18 return true
19}
20function convertToValidFileName(str) {
21 // 替换非法字符为下划线
22 const invalidCharsRegex = /[\/:*?"<>|]/g
23 const validFileName = str.replace(invalidCharsRegex, '_')
24
25 // 删除多余的点号
26 const multipleDotsRegex = /\.{2,}/g
27 const fileNameWithoutMultipleDots = validFileName.replace(multipleDotsRegex, '.')
28
29 // 删除文件名开头和结尾的点号和空格
30 const leadingTrailingDotsSpacesRegex = /^[\s.]+|[\s.]+$/g
31 const finalFileName = fileNameWithoutMultipleDots.replace(leadingTrailingDotsSpacesRegex, '')
32
33 return finalFileName
34}
35
36function addLineAfterLastOccurrence(text, addition) {
37 const regex = /^#!.+?$/gm

Callers 1

SurgeModuleTool.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected