0

I have this gulp task

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);
        }

And I'm getting this maddening output

enter image description here

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

Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
  • 2
    Unless you did something fancy with console.log output, it appears that `adjusted` is wrapped in a color control sequence e.g. `\e[31m`. This answer might help: http://stackoverflow.com/a/29497680/693275 – Rob M. Aug 09 '16 at 17:26
  • @RobM. Ah - that makes sense. I spotted the coloring - foolish of me not to have put 2 and 2 together. Post an answer so I can accept? – Adam Rackis Aug 09 '16 at 17:30
  • Glad that worked for you, answer added :-) – Rob M. Aug 09 '16 at 17:47

1 Answers1

1

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:

/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
Community
  • 1
  • 1
Rob M.
  • 35,491
  • 6
  • 51
  • 50