unified-stream

Streaming interface for unified processors

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
unified-stream
3.0.06 months ago7 years agoMinified + gzip package size for unified-stream in KB

Readme

unified-stream
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
Streaming interface for unifiedunified.

Contents

*   [`stream(processor)`](#streamprocessor)
*   [`MinimalDuplex`](#minimalduplex)

What is this?

This package turns a unified processor into a (duplex) Node.js stream.
👉 Note: the interface is streaming but the code buffers.

When should I use this?

You can use this if you have to use Node streams and are integrating with unified. As the code actually buffers, in almost all cases, you can use unified itself.

Install

This package is ESM onlyesm. In Node.js (version 16+), install with npm:
npm install unified-stream

In Deno with esm.shesm-sh:
import {stream} from 'https://esm.sh/unified-stream@3'

In browsers with esm.shesm-sh:
<script type="module">
  import {stream} from 'https://esm.sh/unified-stream@3?bundle'
</script>

Use

import process from 'node:process'
import rehypeFormat from 'rehype-format'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'
import {stream} from 'unified-stream'

// Pipe stdin, into an HTML formatter, to stdout.
process.stdin
  .pipe(
    stream(unified().use(rehypeParse).use(rehypeFormat).use(rehypeStringify))
  )
  .pipe(process.stdout)

API

This package exports the identifier streamapi-stream. There is no default export.

stream(processor)

Create a duplex (readable and writable) stream that transforms with processor.
Parameters
— unified processor
Returns
Duplex stream (MinimalDuplexapi-minimal-duplex).

MinimalDuplex

Simple readable and writable (duplex) stream (TypeScript type).

Types

This package is fully typed with TypeScript. It exports the additional type MinimalDuplexapi-minimal-duplex.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, unified-stream@^3, compatible with Node.js 16.

Contribute

See contributing.mdcontributing in unifiedjs/.githubhealth for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor