json-text-sequence
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -5,5 +5,6 @@ 'use strict' | ||
const stream = require('stream') | ||
const DelimitStream = require('delimit-stream') | ||
const { DelimitedStream } = require('@sovpro/delimited-stream') | ||
const RS = (this.RS = '\x1e') | ||
const RS = '\x1e' | ||
exports.RS = RS | ||
@@ -34,3 +35,3 @@ // Parse a JSON text sequence stream as defined in | ||
// var p = new parser() | ||
// .on('json', function(obj) { | ||
// .on('data', function(obj) { | ||
// console.log('Valid', obj); | ||
@@ -47,10 +48,10 @@ // }) | ||
// @nodoc | ||
constructor() { | ||
super() | ||
this._readableState.objectMode = true | ||
this._stream = new DelimitStream(RS) | ||
// I can't figure out how to make 'error' happen. Maybe it can't? | ||
.on('error', /* istanbul ignore next */ e => this.emit('error', e)) | ||
constructor(opts = {}) { | ||
super({ | ||
...opts, | ||
readableObjectMode: true | ||
}) | ||
this._stream = new DelimitedStream(RS) | ||
.on('data', d => { | ||
// NOTE: delimit-stream will deal with repeated delimiters. | ||
// NOTE: delimited-stream will deal with repeated delimiters. | ||
// d.length will always be > 0 | ||
@@ -61,7 +62,7 @@ assert.ok(d.length > 0) | ||
if (d[d.length - 1] !== 0x0a) { | ||
return this.emit('truncated', d) | ||
this.emit('truncated', d) | ||
} else { | ||
try { | ||
const j = JSON.parse(d) | ||
return this.push(j) | ||
this.push(j) | ||
} catch (ignored) { | ||
@@ -76,11 +77,12 @@ this.emit('invalid', d) | ||
_transform(chunk, encoding, cb) { | ||
return this._stream._transform(chunk, encoding, cb) | ||
this._stream.write(chunk, encoding, cb) | ||
} | ||
// @nodoc | ||
_flush(cb) { | ||
return this._stream._flush(cb) | ||
_final(cb) { | ||
this._stream.end(null, null, cb) | ||
} | ||
} | ||
exports.parser = JSONSequenceParser | ||
exports.Parser = JSONSequenceParser | ||
@@ -120,1 +122,2 @@ // Generate a JSON text sequence stream as defined in | ||
exports.generator = JSONSequenceGenerator | ||
exports.Generator = JSONSequenceGenerator |
{ | ||
"name": "json-text-sequence", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Parse and generate RS-delimited JSON sequences according to draft-ietf-json-text-sequence", | ||
@@ -13,3 +13,4 @@ "main": "./lib/index.js", | ||
"test": "ava test/*.js", | ||
"release": "npm version patch && git push --follow-tags && npm publish" | ||
"release": "npm version patch && git push --follow-tags && npm publish", | ||
"lint": "eslint lib/*.js test/*.js examples/*.js" | ||
}, | ||
@@ -33,6 +34,10 @@ "repository": { | ||
"dependencies": { | ||
"delimit-stream": "0.1.0" | ||
"@sovpro/delimited-stream": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@cto.af/eslint-config": "^0.0.3", | ||
"ava": "^3.15.0", | ||
"eslint": "^7.20.0", | ||
"eslint-plugin-ava": "^11.0.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"nyc": "^15.1.0" | ||
@@ -39,0 +44,0 @@ }, |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
0
7660
6
4
108
+ Added@sovpro/delimited-stream@1.1.0(transitive)
- Removeddelimit-stream@0.1.0
- Removeddelimit-stream@0.1.0(transitive)