Comparing version 1.2.1 to 1.2.2
@@ -6,3 +6,3 @@ var through = require('through2') | ||
module.exports = parse | ||
module.exports.serialize = serialize | ||
module.exports.serialize = exports.stringify = serialize | ||
module.exports.parse = parse | ||
@@ -9,0 +9,0 @@ |
{ | ||
"name": "ndjson", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "streaming line delimited json parser + serializer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# ndjson | ||
#### streaming line delimited json parser + serializer | ||
#### streaming newline delimited json parser + serializer | ||
@@ -10,6 +10,6 @@ [![NPM](https://nodei.co/npm/ndjson.png)](https://nodei.co/npm/ndjson/) | ||
``` | ||
var ldj = require('ndjson') | ||
var ndjson = require('ndjson') | ||
``` | ||
#### ldj.parse() | ||
#### ndjson.parse() | ||
@@ -27,3 +27,3 @@ returns a transform stream that accepts newline delimited json and emits objects | ||
If you want to discard non-valid JSON messages, you can call `ldj.parse({strict: false})` | ||
If you want to discard non-valid JSON messages, you can call `ndjson.parse({strict: false})` | ||
@@ -34,3 +34,3 @@ usage: | ||
fs.createReadStream('data.txt') | ||
.pipe(ldj.parse()) | ||
.pipe(ndjson.parse()) | ||
.on('data', function(obj) { | ||
@@ -41,3 +41,3 @@ // obj is a javascript object | ||
#### ldj.serialize() | ||
#### ndjson.serialize() / ndjson.stringify() | ||
@@ -49,3 +49,3 @@ returns a transform stream that accepts json objects and emits newline delimited json | ||
```js | ||
var serialize = ldj.serialize() | ||
var serialize = ndjson.serialize() | ||
serialize.on('data', function(line) { | ||
@@ -52,0 +52,0 @@ // line is a line of stringified JSON with a newline delimiter at the end |
23
test.js
@@ -28,2 +28,25 @@ var test = require('tape') | ||
test('.parse - strict:true error', function (t) { | ||
var parser = ndj.parse({strict: true}) | ||
try { | ||
parser.write('{"no":"json"\n') | ||
} catch(e) { | ||
t.pass('error thrown') | ||
t.end() | ||
} | ||
}) | ||
test('.parse - strict:false error', function (t) { | ||
var parser = ndj.parse({strict: false}) | ||
parser.once('data', function (data) { | ||
t.ok(data.json, 'parse second one') | ||
t.end() | ||
}) | ||
try { | ||
parser.write('{"json":false\n{"json":true}\n') | ||
} catch(e) { | ||
t.fail('should not call an error') | ||
} | ||
}) | ||
test('.serialize', function(t) { | ||
@@ -30,0 +53,0 @@ var serializer = ndj.serialize() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3843
77
1