Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ndjson-readablestream

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndjson-readablestream

A small JS package for reading a ReadableStream of NDJSON

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38K
increased by7.51%
Maintainers
1
Weekly downloads
 
Created
Source

ndjson-readablestream

A small JS package for reading a ReadableStream of NDJSON.

readNDJSONStream() accepts a ReadableStream object, and returns an AsyncGenerator where each yielded event is a valid JSON object.

Example usage:

import readNDJSONStream from 'ndjson-readablestream';

const response = await fetch('/chat', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ message: 'Hi, how are you?' }),
});
for await (const event of readNDJSONStream(response.body)) {
  console.log('Received', event);
}

Example usage in a webpage:

<script src="https://cdn.jsdelivr.net/npm/ndjson-readablestream@1.0.1/dist/ndjson-readablestream.umd.js"></script>
<script>
  const response = await fetch("/chat", {
      method: "POST",
      headers: {"Content-Type": "application/json"},
      body: JSON.stringify({message: "Hi, how are you?"})
  });
  for await (const event of readNDJSONStream(response.body)) {
      console.log("Received", event);
  }
</script>

For more details and examples, read my blog post on Fetching JSON over streaming HTTP.

Contributing

Install the development dependencies:

npm install

Run the tests:

npm test

Format the code:

npm run format

Publishing a new version

These instructions are for maintainers only.

  1. Create a branch
  2. Bump the version in package.json using either:
    • npm version patch
    • npm version minor
    • npm version major
  3. Run npm install to update package-lock.json
  4. Update CHANGELOG.md with description of changes in version
  5. Create a pull request
  6. Once merged, checkout main and run:
    1. npm run build
    2. npm login
    3. npm publish

FAQs

Package last updated on 27 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc