Created
December 13, 2016 16:27
-
-
Save jthatch/f1bbd49d572dfef5345b505acc4f009d to your computer and use it in GitHub Desktop.
Strip mIRC color codes and tags from log files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* | |
* stripmirc.js | |
* strip mirc color codes from logs | |
* | |
* Examples: | |
* | |
* ./stripmirc.js irc-log.txt > irc-log-new.txt | |
* | |
* (c) jthatch http://github.com/jthatch | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
'use strict'; | |
const fs = require('fs'); | |
const util = require('util'); | |
const path = require('path'); | |
function Strip() { | |
this.logFile = process.argv[2] || false; | |
} | |
Strip.prototype.init = function() { | |
if (!this.logFile) { | |
this.usage(); | |
process.exit(); | |
} | |
this.strip(); | |
}; | |
/** | |
* reads a log file into a string | |
* @return string log | |
*/ | |
Strip.prototype.strip = function() { | |
try { | |
var log = fs.readFileSync(this.logFile).toString('utf8'); | |
log.replace(/\x03(?:\d{1,2}(?:,\d{1,2})?)?/g, ''); | |
console.log(log); | |
} | |
catch (e) { | |
console.log(" " + e); | |
return false; | |
} | |
}; | |
/** | |
* Show usage | |
*/ | |
Strip.prototype.usage = function() { | |
console.log("\n" + " Usage: " + path.parse(__filename).base + " [logfile]" + "\n"); | |
}; | |
var strip = new Strip(); | |
strip.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment