Skip to content

Instantly share code, notes, and snippets.

@Hesse
Created September 10, 2013 18:47
Show Gist options
  • Save Hesse/6513835 to your computer and use it in GitHub Desktop.
Save Hesse/6513835 to your computer and use it in GitHub Desktop.
Scrubs comments from JSON file.
// Matches HTML comments <!-- -->
// Matches double slash
// Matches C like comments /* */
var fs = require('fs');
var jsonlint = require('jsonlint');
var file = process.argv[2];
if(!file) {
return console.log("Must supply path to file.");
}
function output(data) {
var pretty = jsonlint.parse(data);
console.log(pretty);
}
function run() {
fs.readFile(file, 'utf8',
function (err, data) {
if (err) {
return console.log(err);
}
var re = /(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)/gi;
var clean = data.replace(re, "");
output(clean);
});
}
module = module.exports.run = run;
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment