| 18 | return true |
| 19 | } |
| 20 | function 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 | |
| 36 | function addLineAfterLastOccurrence(text, addition) { |
| 37 | const regex = /^#!.+?$/gm |