Socket
Socket
Sign inDemoInstall

stream-json

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-json - npm Package Compare versions

Comparing version 1.7.3 to 1.8.0

45

jsonl/Parser.js

@@ -10,2 +10,11 @@ 'use strict';

static checkedParse(input, reviver, errorIndicator) {
try {
return JSON.parse(input, reviver);
} catch (error) {
if (typeof errorIndicator == 'function') return errorIndicator(error);
}
return errorIndicator;
}
constructor(options) {

@@ -16,2 +25,3 @@ super(Object.assign({}, options, {readableObjectMode: true}));

this._reviver = options && options.reviver;
this._errorIndicator = options && options.errorIndicator;
if (options && options.checkErrors) {

@@ -21,2 +31,6 @@ this._processBuffer = this._checked_processBuffer;

}
if (options && 'errorIndicator' in options) {
this._processBuffer = this._suppressed_processBuffer;
this._flush = this._suppressed_flush;
}
}

@@ -49,2 +63,33 @@

_suppressed_processBuffer(callback) {
const lines = this._buffer.split('\n');
this._rest += lines[0];
if (lines.length > 1) {
if (this._rest) {
const value = JsonlParser.checkedParse(this._rest, this._reviver, this._errorIndicator);
value !== undefined && this.push({key: this._counter++, value});
}
this._rest = lines.pop();
for (let i = 1; i < lines.length; ++i) {
if (!lines[i]) continue;
const value = JsonlParser.checkedParse(lines[i], this._reviver, this._errorIndicator);
value !== undefined && this.push({key: this._counter++, value});
}
}
this._buffer = '';
callback(null);
}
_suppressed_flush(callback) {
super._flush(error => {
if (error) return callback(error);
if (this._rest) {
const value = JsonlParser.checkedParse(this._rest, this._reviver, this._errorIndicator);
value !== undefined && this.push({key: this._counter++, value});
this._rest = '';
}
callback(null);
});
}
_checked_processBuffer(callback) {

@@ -51,0 +96,0 @@ const lines = this._buffer.split('\n');

4

package.json
{
"name": "stream-json",
"version": "1.7.3",
"version": "1.8.0",
"description": "stream-json is the micro-library of Node.js stream components for creating custom JSON processing pipelines with a minimal memory footprint. It can parse JSON files far exceeding available memory streaming individual primitives using a SAX-inspired API. Includes utilities to stream JSON database dumps.",

@@ -12,3 +12,3 @@ "homepage": "http://github.com/uhop/stream-json",

"dependencies": {
"stream-chain": "^2.2.4"
"stream-chain": "^2.2.5"
},

@@ -15,0 +15,0 @@ "devDependencies": {

@@ -306,2 +306,5 @@ 'use strict';

} else if (value === '}' || value === ']') {
if (value === '}' ? this._expect === 'arrayStop' : this._expect !== 'arrayStop') {
return callback(new Error("Parser cannot parse input: expected '" + (this._expect === 'arrayStop' ? ']' : '}') + "'"));
}
this.push({name: value === '}' ? 'endObject' : 'endArray'});

@@ -308,0 +311,0 @@ this._parent = this._stack.pop();

@@ -116,4 +116,7 @@ # stream-json [![NPM version][npm-image]][npm-url]

- 1.8.0 *added an option to indicate/ignore JSONL errors. Thx, [AK](https://github.com/ak--47).*
- 1.7.5 *fixed a stringer bug with ASCII control symbols. Thx, [Kraicheck](https://github.com/Kraicheck).*
- 1.7.4 *updated dependency (`stream-chain`), bugfix: inconsistent object/array braces. Thx [Xiao Li](https://github.com/xli1000).*
- 1.7.3 *added an assembler option to treat numbers as strings.*
- 1.7.2 *added an error check for JSONL parsing. Thx [Marc-Andre Boily](https://github.com/maboily)!*
- 1.7.2 *added an error check for JSONL parsing. Thx [Marc-Andre Boily](https://github.com/maboily).*
- 1.7.1 *minor bugfix and improved error reporting.*

@@ -123,38 +126,3 @@ - 1.7.0 *added `utils/Utf8Stream` to sanitize `utf8` input, all parsers support it automatically. Thx [john30](https://github.com/john30) for the suggestion.*

- 1.6.0 *added `jsonl/Parser` and `jsonl/Stringer`.*
- 1.5.0 *`Disassembler` and streamers now follow `JSON.stringify()` and `JSON.parse()` protocols respectively including `replacer` and `reviver`.*
- 1.4.1 *bugfix: `Stringer` with `makeArray` should produce empty array if no input.*
- 1.4.0 *added `makeArray` functionality to `Stringer`. Thx all who asked for it!*
- 1.3.3 *bugfix: very large/infinite streams with garbage didn't fail. Thx [Arne Marschall](https://github.com/Disco1267)!*
- 1.3.2 *bugfix: filters could fail with packed-only token streams. Thx [Trey Brisbane](https://github.com/treybrisbane)!*
- 1.3.1 *bugfix: reverted the last bugfix in `Verifier`, a bugfix in tests, thx [Guillermo Ares](https://github.com/guillermoares).*
- 1.3.0 *added `Batch`, a bugfix in `Verifier`.*
- 1.2.1 *the technical release.*
- 1.2.0 *added `Verifier`.*
- 1.1.4 *fixed `Filter` going haywire, thx [@codebling](https://github.com/codebling)!*
- 1.1.3 *fixed `Parser` streaming numbers when shouldn't, thx [Grzegorz Lachowski](https://github.com/gregolsky)!*
- 1.1.2 *fixed `Stringer` not escaping some symbols, thx [Pavel Bardov](https://github.com/pbardov)!*
- 1.1.1 *minor updates in docs and comments.*
- 1.1.0 *added `Disassembler`.*
- 1.0.3 *minor tweaks, added TypeScript typings and the badge.*
- 1.0.2 *minor tweaks, documentation improvements.*
- 1.0.1 *reorg to fix export problems.*
- 1.0.0 *the first 1.0 release.*
- 0.6.1 *the technical release.*
- 0.6.0 *added Stringer to convert event streams back to JSON.*
- 0.5.3 *bug fix to allow empty JSON Streaming.*
- 0.5.2 *bug fixes in `Filter`.*
- 0.5.1 *corrected README.*
- 0.5.0 *added support for [JSON Streaming](https://en.wikipedia.org/wiki/JSON_Streaming).*
- 0.4.2 *refreshed dependencies.*
- 0.4.1 *added `StreamObject` by [Sam Noedel](https://github.com/delta62).*
- 0.4.0 *new high-performant Combo component, switched to the previous parser.*
- 0.3.0 *new even faster parser, bug fixes.*
- 0.2.2 *refreshed dependencies.*
- 0.2.1 *added utilities to filter objects on the fly.*
- 0.2.0 *new faster parser, formal unit tests, added utilities to assemble objects on the fly.*
- 0.1.0 *bug fixes, more documentation.*
- 0.0.5 *bug fixes.*
- 0.0.4 *improved grammar.*
- 0.0.3 *the technical release.*
- 0.0.2 *bug fixes.*
- 0.0.1 *the initial release.*
The rest can be consulted in the project's wiki [Release history](https://github.com/uhop/stream-json/wiki/Release-history).

@@ -29,3 +29,3 @@ 'use strict';

const skipValue = endName =>
function(chunk, encoding, callback) {
function (chunk, encoding, callback) {
if (chunk.name === endName) {

@@ -38,3 +38,6 @@ this._transform = this._prev_transform;

const replaceSymbols = {'\b': '\\b', '\f': '\\f', '\n': '\\n', '\r': '\\r', '\t': '\\t', '"': '\\"', '\\': '\\\\'};
const sanitizeString = value => value.replace(/[\b\f\n\r\t\"\\]/g, match => replaceSymbols[match]);
const sanitizeString = value =>
value.replace(/[\b\f\n\r\t\"\\\u0000-\u001F\u007F-\u009F]/g, match =>
replaceSymbols.hasOwnProperty(match) ? replaceSymbols[match] : '\\u' + ('0000' + match.charCodeAt(0).toString(16)).slice(-4)
);

@@ -92,3 +95,3 @@ const doNothing = () => {};

case 'stringValue':
this.push('"' + sanitizeString(chunk.value)+ '"');
this.push('"' + sanitizeString(chunk.value) + '"');
break;

@@ -95,0 +98,0 @@ case 'numberValue':

@@ -260,2 +260,5 @@ 'use strict';

} else if (value === '}' || value === ']') {
if (value === '}' ? this._expect === 'arrayStop' : this._expect !== 'arrayStop') {
return callback(this._makeError("Verifier cannot parse input: expected '" + (this._expect === 'arrayStop' ? ']' : '}') + "'"));
}
this._parent = this._stack.pop();

@@ -262,0 +265,0 @@ this._expect = expected[this._parent];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc