1

GitHub - aralroca/parse-html-stream: During the HTML streaming, capture the DOM...

 3 months ago
source link: https://github.com/aralroca/parse-html-stream
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

parse-html-stream

Overview

parse-html-stream is a JavaScript library designed for client-side applications, specifically tailored for processing HTML streams. The primary objective is to capture and manipulate DOM Nodes as they are received, enabling seamless integration into hypermedia communication paradigms, such as HTMX.

Getting started

bun install parse-html-stream

Usage Example

Utilize the library by leveraging the asynchronous generator for parsing HTML streams. The following TypeScript example demonstrates its usage:

import parseHTMLStream from 'parse-html-stream';

// ...

const reader = res.body.getReader();

for await (const node of parseHTMLStream(reader)) {
  console.log(node);
}

This code snippet showcases how to iterate through the DOM Nodes in a streaming fashion, offering a practical approach for processing HTML streams in real-time.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK