项目作者: javascript-studio

项目描述 :
☯️ Transforms to parse and stringify ndjson
高级语言: JavaScript
项目地址: git://github.com/javascript-studio/studio-ndjson.git
创建时间: 2017-05-30T16:46:51Z
项目社区:https://github.com/javascript-studio/studio-ndjson

开源协议:MIT License

下载


Studio ndjson

☯️ Transforms to parse and stringify ndjson.

This module also works in the browser using a naive stream shim for
small Browserify bundles.

Usage

To stringify an object stream into ndjson:

  1. const StringifyTransform = require('@studio/ndjson/stringify');
  2. object_stream.pipe(new StringifyTransform()).pipe(process.stdout);

To parse ndjson into an object stream:

  1. const ParseTransform = require('@studio/ndjson/parse');
  2. process.stdin.pipe(new ParseTransform()).pipe(object_stream);

Install

  1. npm i @studio/ndjson

API

Require the transform you need:

  • @studio/ndjson/stringify: Exports the StringifyTransform class which
    reads objects and writes strings.
  • @studio/ndjson/parse: Exports the ParseTransform class which reads
    strings and writes objects.

The module main exports StringifyTransform and ParseTransform if you need
both:

  1. const { StringifyTransform, ParseTransform } = require('@studio/ndjson');

ParseTransform options

The ParseTransform constructor accepts an options object with these
properties:

  • loose: Whether to ignore data before the first { in each line.
  • loose_out: A stream to receive data that was found before the first { in
    each line. Implies loose.

Error handling

If JSON.parse or JSON.stringify throw an error, the transform emits an
error event with the error object having a code property with
ERR_JSON_PARSE or ERR_JSON_STRINGIFY. For parse errors, the line property
on the error is the string that could not be parsed.

License

MIT

Made with ❤️ on 🌍