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

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;
  }
相关推荐
风尘小子1 天前
node.js系列:process配置
前端·node.js
怕浪猫1 天前
ZCode 开源了来看看这是个什么东西
node.js·github·代码规范
flash俊杰2 天前
Electron 打包后窗口 30 秒不出现:一个 ABI 不匹配的血案
electron·node.js
@tangguo1232 天前
npm 和 yarn 配置说明
前端·javascript·npm·node.js·yarn
flash俊杰2 天前
一套代码接入所有大模型:OpenAI 兼容适配器设计
node.js·openai
右耳朵猫AI2 天前
Node.js周刊2026W38 | 进程中断缺陷修复、Copilot 迁至 Rust、Node 新增 VFS
javascript·后端·node.js
光影少年3 天前
Express 中间件原理
后端·node.js·express
时速GEO系统3 天前
初元 AI V1.1 版本升级,首个正式版发布一周・实现生成、部署、上线、优化全流程自动化闭环
人工智能·数据挖掘·node.js
console.log('npc')3 天前
06 — Model 层:数据模型与操作
前端·后端·node.js·express