Simple JSONLines parser that works with streams for web runtime.
npm install jsonl-parser-webSimple JSONLines parser (`.jsonl) that works with streams for web runtime, with Typescript support. The goal was to have a simple API for a specific use case.
Current only supports stream inputs.
npm install jsonlines-p
yarn add jsonlines-p
pnpm add jsonlines-p
`Usage
$3
Pass the respones body to the parser.
`typescript
import { JsonLines, JsonLineStream } from 'jsonlines-p';const response = await fetch("/remote/items.jsonl");
// Aggregates the lines into an array.
const items = await JsonLines- (response.body);
// or if you want to access the stream directly
const stream = JsonLineStream- (response.body);
`$3
Use a custom line parser and error handler.
`typescript
// Usage
JsonLines(response.body, options)export type ParserOptions = {
/**
* Parse each JSON line.
*/
parser?: (line: string) => T,
/**
* Callback for errors thrown by the parser.
* If not provided, errors will be silently ignored.
*
* Note that this might be called multiple times for a stream, for each line.
*/
onError?: (error: Error, line: string) => void;
}
`$3
These are also exported if you need more control.
`typescript
export function createLineStreamTransformer(
options: ParserOptions = {}
): TransformStream
``The MIT License.