[Pkg-javascript-commits] [node-jsonstream] 111/214: work as cli tool, plus mapper function

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 75de2973ebed66d40c56122649e52f8b69d6136f
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Tue May 13 15:45:01 2014 +0200

    work as cli tool, plus mapper function
---
 index.js | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
old mode 100644
new mode 100755
index 5932ab2..db6d97d
--- a/index.js
+++ b/index.js
@@ -1,3 +1,5 @@
+#! /usr/bin/env node
+
 var Parser = require('jsonparse')
   , Stream = require('stream').Stream
   , through = require('through')
@@ -11,7 +13,7 @@ var Parser = require('jsonparse')
 
 */
 
-exports.parse = function (path) {
+exports.parse = function (path, map) {
 
   var parser = new Parser()
   var stream = through(function (chunk) {
@@ -80,8 +82,9 @@ exports.parse = function (path) {
     if (j !== this.stack.length) return
 
     count ++
-    if(null != this.value[this.key])
-      stream.queue(this.value[this.key])
+    var data = this.value[this.key]
+    if(null != data)
+      stream.queue(map ? map(data) : data)
     delete this.value[this.key]
   }
   parser._onToken = parser.onToken;
@@ -186,3 +189,10 @@ exports.stringifyObject = function (op, sep, cl) {
 
   return stream
 }
+
+if(!module.parent && process.title !== 'browser') {
+  process.stdin
+    .pipe(exports.parse(process.argv[2]))
+    .pipe(exports.stringify())
+    .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