stream-json
Advanced tools
Comparing version 1.7.5 to 1.8.0
@@ -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'); |
{ | ||
"name": "stream-json", | ||
"version": "1.7.5", | ||
"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.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/uhop/stream-json", |
@@ -116,2 +116,3 @@ # 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).* | ||
@@ -118,0 +119,0 @@ - 1.7.4 *updated dependency (`stream-chain`), bugfix: inconsistent object/array braces. Thx [Xiao Li](https://github.com/xli1000).* |
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
90760
2364
127