[Pkg-javascript-commits] [node-jsonstream] 114/214: add indent, prettiest defaults for unix tool

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 12:58:47 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-jsonstream.

commit de41da312c2ff5a5c36a72b5d927d72533defa99
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Tue May 13 15:59:33 2014 +0200

    add indent, prettiest defaults for unix tool
---
 index.js | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/index.js b/index.js
index 5431db2..9fd0a39 100755
--- a/index.js
+++ b/index.js
@@ -123,7 +123,8 @@ function check (x, y) {
   return false
 }
 
-exports.stringify = function (op, sep, cl) {
+exports.stringify = function (op, sep, cl, indent) {
+  indent = indent || 0
   if (op === false){
     op = ''
     sep = '\n'
@@ -143,7 +144,7 @@ exports.stringify = function (op, sep, cl) {
     , anyData = false
   stream = through(function (data) {
     anyData = true
-    var json = JSON.stringify(data)
+    var json = JSON.stringify(data, null, indent)
     if(first) { first = false ; stream.queue(op + json)}
     else stream.queue(sep + json)
   },
@@ -157,7 +158,8 @@ exports.stringify = function (op, sep, cl) {
   return stream
 }
 
-exports.stringifyObject = function (op, sep, cl) {
+exports.stringifyObject = function (op, sep, cl, indent) {
+  indent = indent || 0
   if (op === false){
     op = ''
     sep = '\n'
@@ -177,10 +179,10 @@ exports.stringifyObject = function (op, sep, cl) {
     , anyData = false
   stream = through(function (data) {
     anyData = true
-    var json = JSON.stringify(data[0]) + ':' + JSON.stringify(data[1])
+    var json = JSON.stringify(data[0]) + ':' + JSON.stringify(data[1], null, indent)
     if(first) { first = false ; stream.queue(op + json)}
     else stream.queue(sep + json)
-  }, 
+  },
   function (data) {
     if(!anyData) stream.queue(op)
     stream.queue(cl)
@@ -194,6 +196,6 @@ exports.stringifyObject = function (op, sep, cl) {
 if(!module.parent && process.title !== 'browser') {
   process.stdin
     .pipe(exports.parse(process.argv[2]))
-    .pipe(exports.stringify())
+    .pipe(exports.stringify('[', ',\n', ']\n', 2))
     .pipe(process.stdout)
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jsonstream.git



More information about the Pkg-javascript-commits mailing list