Skip to content

Instantly share code, notes, and snippets.

@vermilion1
Last active September 13, 2017 08:24
Show Gist options
  • Save vermilion1/b78024dbed6b20968bde0bf28c24c030 to your computer and use it in GitHub Desktop.
Save vermilion1/b78024dbed6b20968bde0bf28c24c030 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const args = process.argv.slice(2);
const [filename] = args;
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
return console.log(err);
}
let r = 0;
let n = 0;
let rn = 0;
let output = '';
for (let i = 0; i < data.length; i++) {
switch(data[i]) {
case '\r':
if (data[i + 1] === '\n') {
rn += 1;
i += 1;
output += '\x1b[41m\x1b[37m\\r\\n\x1b[0m \n';
} else {
r += 1;
output += '\x1b[41m\x1b[37m\\r\x1b[0m \n';
}
break;
case '\n':
r += 1;
output += '\x1b[41m\x1b[37m\\n\x1b[0m \n';
break;
default:
output += data[i];
break;
}
}
console.log(output);
console.log('------------------------');
console.log('r: ', r);
console.log('n: ', n);
console.log('rn: ', rn);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment