Created
September 10, 2013 18:47
-
-
Save Hesse/6513835 to your computer and use it in GitHub Desktop.
Scrubs comments from JSON file.
This file contains 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
// 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