基本 JavaScript 字符串相等性在 Gulp 中失败

Basic JavaScript string equality failing in Gulp

我有这个gulp任务

gulp.src([`../../**/*.js`].concat(dontCheck.map(p => '!../../' + p)))
    .pipe(gulpPrint(path => {
        let adjusted = path.replace('..\..\', '').replace(/\/g, '/');

        let target = 'account/account.js';
        if (adjusted == target){
            console.log('FOUND');
        } else {
            console.log('NOT FOUND', '|' + target + '|', '|' + adjusted + '|', String(target) == String(adjusted), typeof target, typeof adjusted);
        }

我得到了这个令人抓狂的输出

为什么这些字符串不匹配? adjusted 是否有不同的 unicode 编码?如果是这样,我该如何调和呢?

除非你做了一些事情来为我们突出显示 console.log 输出,否则 adjusted 似乎包含在颜色控制序列中,例如\e[31m

This answer might help,它提供了这个正则表达式来替换控制序列:

/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g