Created
November 26, 2014 15:59
-
-
Save oliveiraev/a900f84c0158fc985dbb to your computer and use it in GitHub Desktop.
Revisions
-
oliveiraev created this gist
Nov 26, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/usr/bin/env node /** * @name JSON Prettifier * @summary Given an input (filename or stdin), prints out it space-indented * @license [LGPLv3]{@link https://www.gnu.org/licenses/lgpl-3.0.txt} * @version 0.0.1a * */ (function () { "use strict"; var buffer, output; /** * Stores formatted JSON into <code>shared</code> output var * @param {String} input Unformatted json */ function prettify(input) { input = JSON.parse(input); output = JSON.stringify(input, null, 4); } /** * Send data stored into <code>shared</code> to standard output */ function print() { process.stdout.write(output + "\r\n"); } buffer = process.stdin; if (process.argv.length > 2) { buffer = require("fs").createReadStream(process.argv[2]); } buffer.on("data", prettify); buffer.on("end", print); }());