Created
November 26, 2014 15:59
-
-
Save oliveiraev/a900f84c0158fc985dbb to your computer and use it in GitHub Desktop.
Given an input (filename or stdin), prints out it space-indented
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
#!/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); | |
}()); |
Author
oliveiraev
commented
Nov 26, 2014
fails with {"content":{"rendered":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies nunc id tellus cursus volutpat. Vivamus \u0003ac rhoncus quam"}}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment