Skip to content

Instantly share code, notes, and snippets.

@amoilanen
Created March 13, 2015 12:14
Show Gist options
  • Save amoilanen/01bd492be4d1a53816e9 to your computer and use it in GitHub Desktop.
Save amoilanen/01bd492be4d1a53816e9 to your computer and use it in GitHub Desktop.
Command line tool to make readable the code that was minified with Uglify.js
var help = [
'Command line tool to unuglify a JavaScript file.',
'',
'Before using install js-beautify:',
'',
'npm install js-beautify',
'',
'To unuglify file code.js run:',
'',
'node unuglify code.js > code.unuglified.js'
].join('\n');
var beautify = require('js-beautify').js_beautify;
var fs = require('fs');
var beautifyOptions = {
indent_size: 2
};
function unuglify(file, callback) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
throw err;
}
callback(beautify(data, beautifyOptions));
});
}
var codePath = process.argv[2];
if (codePath) {
unuglify(codePath, function(unuglifiedCode) {
console.log(unuglifiedCode);
});
} else {
console.log(help);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment