Adam Rackis Adam Rackis - 8 months ago 59
Javascript Question

Basic JavaScript string equality failing in Gulp

I have this gulp task

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

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

And I'm getting this maddening output

enter image description here

Why aren't those strings matching? Does
have a different unicode encoding? If so how do I reconcile it?


Unless you did something to highlight the console.log output for us, it appears that adjusted is wrapped in a color control sequence e.g. \e[31m.

This answer might help, which provides this regex to replace control sequences: