diff --git a/bin/jsnice b/bin/jsnice new file mode 100755 index 0000000..80f2b91 --- /dev/null +++ b/bin/jsnice @@ -0,0 +1,28 @@ +#!/usr/bin/env node +var fs = require('fs'); +var path = require('path'); + +var docopt = require('docopt'); +var jsnice = require('../'); + +var doc = [ + 'Usage:', + ' jsnice ', + ' jsnice (--help | --version)', + '', + 'Options:', + ' --help Show this text', + ' --version Show jsnice version info', +].join('\r\n'); + +var args = docopt.docopt(doc, { + help: true, + version: 'jsnice ' + require('../package.json').version, +}); +var cwd = process.cwd(); +filePath = path.join(cwd, args['']); + +var js = fs.readFileSync(filePath); +jsnice.nicify(js, function(data) { + console.log(data.js); +}); diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..6323597 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,35 @@ +var http = require('http'); + +module.exports.nicify = function(js, options, callback) { + if (typeof options === 'function') { + callback = options; + options = {}; + } + + options = options || {}; + + var reqOptions = { + hostname: 'www.jsnice.org', + path: '/beautify?pretty=1&rename=1&types=1&suggest=0', + port: 80, + method: 'POST', + }; + var req = http.request(reqOptions, function(res) { + var data = ''; + res.on('data', function(chunk) { + data += chunk.toString(); + }); + + res.on('end', function() { + data = JSON.parse(data); + callback(data); + }); + }); + + req.on('error', function(err) { + console.dir(err); + }); + + req.write(js); + req.end(); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..c5f0114 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "jsnice", + "version": "0.1.0", + "description": "Run JSNice on your javascripts", + "main": "lib/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "bin": { + "jsnice": "bin/jsnice" + }, + "repository": { + "type": "git", + "url": "git://github.com/brettlangdon/jsnice.git" + }, + "keywords": [ + "js", + "nice", + "jsnice", + "unminify", + "minify", + "deobfuscation", + "obfuscation" + ], + "author": "Brett Langdon (http://brett.is)", + "license": "MIT", + "bugs": { + "url": "https://github.com/brettlangdon/jsnice/issues" + }, + "homepage": "https://github.com/brettlangdon/jsnice", + "dependencies": { + "docopt": "~0.4.0" + } +}