[Pkg-javascript-commits] [node-jsonstream] 15/214: stringifyObject implementation

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 12:58:33 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 3e9643faa6e30e2b7fff31a410a84bdc17840bd1
Author: James Halliday <mail at substack.net>
Date:   Wed Feb 22 07:57:57 2012 -0800

    stringifyObject implementation
---
 index.js | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index bdec5ed..210b454 100644
--- a/index.js
+++ b/index.js
@@ -115,4 +115,43 @@ exports.stringify = function (op, sep, cl) {
   stream.readable = true
 
   return stream
-}
\ No newline at end of file
+}
+
+exports.stringifyObject = function (op, sep, cl) {
+  if (op === false){
+    op = ''
+    sep = '\n'
+    cl = ''
+  } else if (op == null) {
+  
+    op = '{\n'
+    sep = '\n,\n'
+    cl = '\n}\n'
+  
+  }
+
+  //else, what ever you like
+  
+  var stream = new Stream ()
+    , first = true
+    , ended = false
+  stream.write = function (key, data) {
+    var json = JSON.stringify(key) + ':' + JSON.stringify(data)
+    if(first) { first = false ; stream.emit('data', op + json)}
+    else stream.emit('data', sep + json)
+  }
+  stream.end = function (key, data) {
+    if(ended)
+      return
+    ended = true
+    if(key !== undefined)
+      stream.write(key, data)
+    stream.emit('data', cl)
+    
+    stream.emit('end')
+  }
+  stream.writable = true
+  stream.readable = true
+
+  return stream
+}

-- 
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