json-text-sequence
Advanced tools
Comparing version 0.3.0 to 1.0.0
'use strict' | ||
const assert = require('assert') | ||
const stream = require('stream') | ||
const { DelimitedStream } = require('@sovpro/delimited-stream') | ||
const {DelimitedStream} = require('@sovpro/delimited-stream') | ||
@@ -45,7 +44,11 @@ const RS = '\x1e' | ||
class JSONSequenceParser extends stream.Transform { | ||
// @nodoc | ||
/** | ||
* Create a JSONSequenceParser instance. | ||
* | ||
* @param {stream.TransformOptions} [opts] Stream options. | ||
*/ | ||
constructor(opts = {}) { | ||
super({ | ||
...opts, | ||
readableObjectMode: true | ||
readableObjectMode: true, | ||
}) | ||
@@ -56,8 +59,6 @@ this._stream = new DelimitedStream(RS) | ||
// d.length will always be > 0 | ||
assert.ok(d.length > 0) | ||
// assert.ok(d.length > 0) | ||
// if the entry doesn't end with \n, it got truncated | ||
if (d[d.length - 1] !== 0x0a) { | ||
this.emit('truncated', d) | ||
} else { | ||
// If the entry doesn't end with \n, it got truncated | ||
if (d[d.length - 1] === 0x0a) { | ||
try { | ||
@@ -69,2 +70,4 @@ const j = JSON.parse(d) | ||
} | ||
} else { | ||
this.emit('truncated', d) | ||
} | ||
@@ -84,2 +87,4 @@ }) | ||
} | ||
/** @deprecated */ | ||
exports.parser = JSONSequenceParser | ||
@@ -99,7 +104,12 @@ exports.Parser = JSONSequenceParser | ||
class JSONSequenceGenerator extends stream.Transform { | ||
// @nodoc | ||
constructor() { | ||
super() | ||
this._writableState.objectMode = true | ||
this._readableState.objectMode = false | ||
/** | ||
* Create a JSONSequenceGenerator instance. | ||
* | ||
* @param {stream.TransformOptions} [opts] Stream options. | ||
*/ | ||
constructor(opts = {}) { | ||
super({ | ||
...opts, | ||
writableObjectMode: true, | ||
}) | ||
} | ||
@@ -111,4 +121,4 @@ | ||
try { | ||
// this can fail on circular objects, for example | ||
s = JSON.stringify(chunk, 'utf8') | ||
// This can fail on circular objects, for example | ||
s = JSON.stringify(chunk) | ||
} catch (error) { | ||
@@ -122,3 +132,5 @@ return cb(error) | ||
} | ||
/** @deprecated */ | ||
exports.generator = JSONSequenceGenerator | ||
exports.Generator = JSONSequenceGenerator |
{ | ||
"name": "json-text-sequence", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "Parse and generate RS-delimited JSON sequences according to draft-ietf-json-text-sequence", | ||
@@ -9,8 +9,11 @@ "main": "./lib/index.js", | ||
}, | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
"clean": "rm -rf coverage doc man", | ||
"clean": "rm -rf coverage", | ||
"coverage": "nyc -r lcov npm test", | ||
"test": "ava test/*.js", | ||
"release": "npm version patch && git push --follow-tags && npm publish", | ||
"lint": "eslint lib/*.js test/*.js examples/*.js" | ||
"lint": "eslint . --ext js", | ||
"types": "tsc", | ||
"check": "npm run lint && npm run types && npm run coverage && npm pack --dry-run" | ||
}, | ||
@@ -37,12 +40,15 @@ "repository": { | ||
"devDependencies": { | ||
"@cto.af/eslint-config": "^0.0.3", | ||
"@cto.af/eslint-config": "^0.0.10", | ||
"@types/node": "^16.11.0", | ||
"ava": "^3.15.0", | ||
"eslint": "^7.20.0", | ||
"eslint-plugin-ava": "^11.0.0", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-ava": "^13.0.0", | ||
"eslint-plugin-jsdoc": "^36.1.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"nyc": "^15.1.0" | ||
"nyc": "^15.1.0", | ||
"typescript": "^4.4.4" | ||
}, | ||
"engines": { | ||
"node": ">=10.18.0" | ||
"node": ">=12.20.0" | ||
} | ||
} |
@@ -53,2 +53,2 @@ Parse and generate JSON text sequences as defined in [RFC 7464](https://tools.ietf.org/html/rfc7464). | ||
[![Tests](https://github.com/hildjj/json-text-sequence/workflows/Tests/badge.svg)](https://github.com/hildjj/json-text-sequence/actions?query=workflow%3ATests) | ||
[![Coverage Status](https://coveralls.io/repos/hildjj/json-text-sequence/badge.png?branch=master)](https://coveralls.io/r/hildjj/json-text-sequence?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/hildjj/json-text-sequence/badge.png?branch=main)](https://coveralls.io/r/hildjj/json-text-sequence?branch=main) |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8485
5
127
0
0
9