+2
-20
@@ -27,23 +27,5 @@ var through = require('through2') | ||
| function serialize (opts) { | ||
| if (!opts) opts = {} | ||
| if (!opts.separator) opts.separator = EOL | ||
| if (!opts.after) opts.after = EOL | ||
| var firstWrite = true | ||
| var serializer = through.obj(function write (obj, enc, cb) { | ||
| var out = "" | ||
| if (firstWrite) { | ||
| if (typeof opts.before !== 'undefined') out += opts.before | ||
| out += JSON.stringify(obj) | ||
| firstWrite = false | ||
| } else { | ||
| out += opts.separator | ||
| out += JSON.stringify(obj) | ||
| } | ||
| cb(null, out) | ||
| }, function end (cb) { | ||
| if (typeof opts.after !== 'undefined') serializer.push(opts.after) | ||
| cb() | ||
| return through.obj(function(obj, enc, cb) { | ||
| cb(null, JSON.stringify(obj) + EOL) | ||
| }) | ||
| return serializer | ||
| } |
+1
-1
| { | ||
| "name": "ndjson", | ||
| "version": "1.4.0", | ||
| "version": "1.4.1", | ||
| "description": "streaming newline delimited json parser + serializer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+1
-30
@@ -38,3 +38,3 @@ # ndjson | ||
| #### ndjson.serialize(opts) / ndjson.stringify(opts) | ||
| #### ndjson.serialize() / ndjson.stringify() | ||
@@ -54,33 +54,4 @@ returns a transform stream that accepts json objects and emits newline delimited json | ||
| ##### Options | ||
| - `before` - a string to put before the stream | ||
| - `after` - a string to put after the stream, defaults to `os.EOL` (e.g. `\n`) | ||
| - `separator` - a string to put between items in the stream, defaults to `os.EOL` (e.g. `\n`) | ||
| ### CLI usage | ||
| You can use the `ndjson` CLI tool to validate ndjson input, and serialize ndjson into a custom JSON output | ||
| ``` | ||
| Usage: ndjson [input] <options> | ||
| ``` | ||
| Install it globally: | ||
| ``` | ||
| npm i ndjson -g | ||
| ``` | ||
| Pass `-` to use STDIN, otherwise pass a file as input | ||
| Example: | ||
| ``` | ||
| echo '{"foo": "bar"}' | ndjson --before=CATS --after=DOGS - | ||
| CATS{"foo":"bar"}DOGS | ||
| ``` | ||
| ### license | ||
| BSD-3-Clause |
+0
-21
@@ -74,22 +74,1 @@ var test = require('tape') | ||
| }) | ||
| test('.serialize custom before after', function(t) { | ||
| var serializer = ndj.serialize({before: 'CATS', after: 'DOGS'}) | ||
| serializer.pipe(concat(function(data) { | ||
| t.equal(data, 'CATS{"hello":"world"}DOGS') | ||
| t.end() | ||
| })) | ||
| serializer.write({hello: 'world'}) | ||
| serializer.end() | ||
| }) | ||
| test('.serialize custom separator', function(t) { | ||
| var serializer = ndj.serialize({separator: 'CATS'}) | ||
| serializer.pipe(concat(function(data) { | ||
| t.equal(data, '{"hello":"world"}CATS{"hej":"verden"}\n') | ||
| t.end() | ||
| })) | ||
| serializer.write({hello: 'world'}) | ||
| serializer.write({hej: 'verden'}) | ||
| serializer.end() | ||
| }) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4958
-25.64%106
-25.35%56
-34.12%