Node.js 正则表达式 test is not a function

当变量为对象的key时,报错test is not  a function

当赋值变量时,不报错

错误代码如下:

//封装重命名文件函数
function renameTicket(dir, month){
    fs.readdir(dir, (error, content)=>{
        // console.log(content)
        //定义对象存放名单
        var numObj = {
            13387677700:'余',
            13733443335:'钟'
        }
        content.forEach((value, index)=>{
            let path = `${dir}/${value}`
            //名单对象遍历
            Object.keys(numObj).forEach((key)=>{
                // console.log(key)--13387677700
                // console.log(numObj[key])--余
                // var keyP = /13387679700/
                console.log(`/${key}/`.test(value))
                 if(key.test(value)){
                     console.log('号码匹配')
                 }
            })

            let joinDir = `${dir}/${value}`
            fs.stat(joinDir, (error, stats)=>{
                if(error) throw error
                if(stats.isDirectory()){
                    renameTicket(joinDir)
                }
            })
        })
    })
}

renameTicket('./202105', '202106')

 

错误的形式?

https://blog.csdn.net/yrx0619/article/details/82183129