@jsonlines/core
Version:
parse and stringify jsonlines files through streams
46 lines (40 loc) • 1.68 kB
JavaScript
import 'core-js/modules/es.array.iterator';
import 'core-js/modules/es.promise';
import './_chunks/line-sep-6e4e0e79.js';
import 'stream';
import { A as AsyncDuplexBase } from './_chunks/duplex-base-32ed1b65.js';
import { ReadLineStream } from './readline-stream.js';
import 'core-js/modules/es.symbol.description';
import { nullValue } from './null-value.js';
function wrapParseFunc(parse) {
return line => Promise.resolve(parse(line)).then(s => {
if (s === null) return nullValue;else return s;
});
}
class JsonLinesParseStream extends AsyncDuplexBase {
constructor(options) {
var _options$lineSep, _options$parse;
const gzip = options === null || options === void 0 ? void 0 : options.gzip;
const readline = new ReadLineStream({
encoding: options === null || options === void 0 ? void 0 : options.encoding,
lineSep: (_options$lineSep = options === null || options === void 0 ? void 0 : options.lineSep) !== null && _options$lineSep !== void 0 ? _options$lineSep : "lf",
parse: wrapParseFunc((_options$parse = options === null || options === void 0 ? void 0 : options.parse) !== null && _options$parse !== void 0 ? _options$parse : JSON.parse)
});
super({
writable: gzip ? () => import('zlib').then(zlib => {
const gunzip = zlib.createGunzip(gzip === true ? undefined : gzip);
gunzip.pipe(readline);
return gunzip;
}) : readline,
readable: readline
}, {
readableObjectMode: true,
writableObjectMode: false
});
}
}
function parse(...args) {
return new JsonLinesParseStream(...args);
}
export { JsonLinesParseStream, parse };
//# sourceMappingURL=parse.js.map