JSONStream
Advanced tools
Comparing version 1.1.4 to 1.2.0
34
index.js
@@ -18,3 +18,3 @@ #! /usr/bin/env node | ||
exports.parse = function (path, map) { | ||
var header, footer | ||
var parser = new Parser() | ||
@@ -29,2 +29,6 @@ var stream = through(function (chunk) { | ||
stream.write(data) | ||
if (header) | ||
stream.emit('header', header) | ||
if (footer) | ||
stream.emit('footer', footer) | ||
stream.queue(null) | ||
@@ -67,3 +71,6 @@ }) | ||
if (!c) return | ||
if (! check(key, c.key)) return | ||
if (! check(key, c.key)) { | ||
setHeaderFooter(c.key, value) | ||
return | ||
} | ||
emitKey = !!key.emitKey; | ||
@@ -83,2 +90,4 @@ i++ | ||
break | ||
} else { | ||
setHeaderFooter(c.key, value) | ||
} | ||
@@ -104,2 +113,8 @@ j++ | ||
this.stack[k].value = null | ||
// emit header | ||
if (header) { | ||
stream.emit('header', header); | ||
header = false; | ||
} | ||
} | ||
@@ -126,4 +141,17 @@ parser._onToken = parser.onToken; | ||
return stream | ||
return stream | ||
function setHeaderFooter(key, value) { | ||
// header has not been emitted yet | ||
if (header !== false) { | ||
header = header || {} | ||
header[key] = value | ||
} | ||
// footer has not been emitted yet but header has | ||
if (footer !== false && header === false) { | ||
footer = footer || {} | ||
footer[key] = value | ||
} | ||
} | ||
} | ||
@@ -130,0 +158,0 @@ |
{ | ||
"name": "JSONStream", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"description": "rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/dominictarr/JSONStream", |
407100
35
5067
16