JSFiddle - React, Tailwind, and code Playground

JavaScript

var logLine = '07/12/2017  11:01 AM             21523 filename with s p a c  e  s.js';
var N = 4;
while(--N + 1){
  logLine = logLine.replace(/\s+/, '|');
}
console.log(logLine);