[Pkg-javascript-commits] [node-jsonstream] 128/214: Non-object JSON roots
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 1 12:58:49 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 9a880fc73eafefaaf5b8dea0182e90669cae34b6
Author: DullReferenceException <jpage at godaddy.com>
Date: Fri Nov 21 16:15:24 2014 -0800
Non-object JSON roots
Updated parser to emit the `root` event for the top-level JSON value, not just objects & arrays.
---
.gitignore | 1 +
index.js | 6 +++---
test/non_object_roots.js | 16 ++++++++++++++++
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index 13abef4..fff3b1a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
node_modules
node_modules/*
npm_debug.log
+.idea
diff --git a/index.js b/index.js
index 83848af..2422c9c 100755
--- a/index.js
+++ b/index.js
@@ -41,9 +41,9 @@ exports.parse = function (path, map) {
if(!path || !path.length)
path = null
- parser.onValue = function () {
- if (!this.root && this.stack.length == 1)
- stream.root = this.value
+ parser.onValue = function (value) {
+ if (!this.root)
+ stream.root = value
if(! path) return
diff --git a/test/non_object_roots.js b/test/non_object_roots.js
new file mode 100644
index 0000000..8055ad6
--- /dev/null
+++ b/test/non_object_roots.js
@@ -0,0 +1,16 @@
+var JSONStream = require('../');
+var it = require('it-is');
+var parser = JSONStream.parse();
+
+var succeeded = false;
+
+parser.on('root', function (value) {
+ it(value).equal(true);
+ succeeded = true;
+});
+
+parser.on('end', function() {
+ it(succeeded).equal(true);
+});
+
+parser.end('true');
--
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