diff --git a/lib/JSON2CSVTransform.js b/lib/JSON2CSVTransform.js index f7a52f24..773b7959 100644 --- a/lib/JSON2CSVTransform.js +++ b/lib/JSON2CSVTransform.js @@ -19,8 +19,6 @@ class JSON2CSVTransform extends Transform { if (this._readableState.objectMode) { this.initObjectModeParse(); - } else if (this.opts.ndjson) { - this.initNDJSONParse(); } else { this.initJSONParser(); } @@ -52,47 +50,6 @@ class JSON2CSVTransform extends Transform { }; } - /** - * Init the transform with a parser to process NDJSON data. - * It maintains a buffer of received data, parses each line - * as JSON and send it to `pushLine for processing. - */ - initNDJSONParse() { - const transform = this; - - this.parser = { - _data: '', - write(chunk) { - this._data += chunk.toString(); - const lines = this._data - .split('\n') - .map(line => line.trim()) - .filter(line => line !== ''); - - let pendingData = false; - lines - .forEach((line, i) => { - try { - transform.pushLine(JSON.parse(line)); - } catch(e) { - if (i === lines.length - 1) { - pendingData = true; - } else { - e.message = `Invalid JSON (${line})` - transform.emit('error', e); - } - } - }); - this._data = pendingData - ? this._data.slice(this._data.lastIndexOf('\n')) - : ''; - }, - getPendingData() { - return this._data; - } - }; - } - /** * Init the transform with a parser to process JSON data. * It maintains a buffer of received data, parses each as JSON