Adam Rackis Adam Rackis - 1 year ago 127
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?

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download