校验系统文件名是否符合标准

javascript 复制代码
  function isValidFilename(filename) {
    const forbiddenChars = /[<>:"/\\|?*]/;
    if (forbiddenChars.test(filename)) {
        return false;
    }
  
    if (filename.endsWith(' ') || filename.endsWith('.')) {
        return false;
    }
  
    const reservedNames = ['CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9'];
    const nameWithoutExtension = filename.split('.')[0];
    if (reservedNames.includes(nameWithoutExtension.toUpperCase())) {
        return false;
    }
  
    return true;
  }
相关推荐
岁月宁静2 小时前
AI 多模态全栈应用项目描述
前端·vue.js·node.js
格鸰爱童话3 小时前
next.js学习——react入门
学习·react.js·node.js
南方的狮子先生5 小时前
【C++】C++文件读写
java·开发语言·数据结构·c++·算法·1024程序员节
GISer_Jing6 小时前
Node.js 开发实战:从入门到精通
javascript·后端·node.js
星光一影10 小时前
基于SpringBoot与Vue的海外理财系统设计与实现
vue.js·spring boot·后端·mysql·node.js·html5
百***926510 小时前
Node.js npm 安装过程中 EBUSY 错误的分析与解决方案
前端·npm·node.js
百***353310 小时前
node.js+npm的环境配置以及添加镜像(保姆级教程)
arcgis·npm·node.js
Neil今天也要学习10 小时前
永磁同步电机无速度算法--基于三阶LESO的反电动势观测器
算法·1024程序员节
濮水大叔11 小时前
VonaJS: 序列化/数据脱敏(上)
typescript·node.js·nestjs