sse-line-parser 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +50 -50
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,21 +1,21 @@
1
1
  # SSE Stream Parser
2
2
 
3
- 一个**轻量、纯粹、可用于生产环境的 SSEServer-Sent Events)流解析工具**,基于标准的 SSE 协议实现,与具体应用场景无关,可广泛应用于各类 SSE 数据流解析,不掺杂请求管理、不中断连接、只做一件事:**把流解析干净**。
3
+ A **lightweight, pure, production-ready SSE (Server-Sent Events) stream parser**, implemented based on the standard SSE protocol. It is independent of specific application scenarios and can be widely used in various SSE data stream parsing tasks. It does not involve request management or connection interruption, focusing solely on doing one thing: **parsing streams cleanly**.
4
4
 
5
5
  ---
6
6
 
7
- ## ✨ 特性亮点
7
+ ## ✨ Features
8
8
 
9
- - ✅ **纯 SSE 流解析**,不关心请求生命周期
10
- - ✅ 支持标准 `data:` 协议格式,兼容所有基于 SSE 的服务
11
- - ✅ 内置 `[DONE]` 提前识别与快速跳过
12
- - ✅ GC 压力,避免不必要对象创建
13
- - ✅ 可运行于 **Node.js ≥ 18**(原生 `fetch` + `ReadableStream`)
14
- - ✅ TypeScript 原生支持,类型清晰
9
+ - ✅ **Pure SSE stream parsing**, no concern for request lifecycle
10
+ - ✅ Supports standard `data:` protocol format, compatible with all SSE-based services
11
+ - ✅ Built-in `[DONE]` early identification and quick skipping
12
+ - ✅ Low GC pressure, avoiding unnecessary object creation
13
+ - ✅ Runs on **Node.js ≥ 18** (native `fetch` + `ReadableStream`)
14
+ - ✅ Native TypeScript support with clear types
15
15
 
16
16
  ---
17
17
 
18
- ## 📦 安装
18
+ ## 📦 Installation
19
19
 
20
20
  ```bash
21
21
  pnpm add sse-stream-parser
@@ -27,29 +27,29 @@ yarn add sse-stream-parser
27
27
 
28
28
  ---
29
29
 
30
- ## 🧠 设计理念
30
+ ## 🧠 Design Philosophy
31
31
 
32
- > **只做流解析,不做控制逻辑**
32
+ > **Parse streams only, no control logic**
33
33
 
34
- 本插件**不会**:
34
+ This plugin will **NOT**:
35
35
 
36
- - ❌ 管理请求中断 / abort
37
- - ❌ 包装 fetch
38
- - ❌ 维护连接状态
39
- - ❌ 引入 EventEmitter / Rx / class 抽象
36
+ - ❌ Manage request interruption/abort
37
+ - ❌ Wrap fetch
38
+ - ❌ Maintain connection status
39
+ - ❌ Introduce EventEmitter/Rx/class abstractions
40
40
 
41
- 本插件**只负责**:
41
+ This plugin is **only responsible for**:
42
42
 
43
- - ✔ 解析 `ReadableStreamDefaultReader<Uint8Array<ArrayBuffer>>`
44
- - ✔ 拆分 SSE
45
- - ✔ 解析 `data:` 内容
46
- - ✔ 识别 `[DONE]`
43
+ - ✔ Parse `ReadableStreamDefaultReader<Uint8Array<ArrayBuffer>>`
44
+ - ✔ Split SSE lines
45
+ - ✔ Parse `data:` content
46
+ - ✔ Identify `[DONE]`
47
47
 
48
48
  ---
49
49
 
50
- ## 🚀 基本用法
50
+ ## 🚀 Basic Usage
51
51
 
52
- ### 1️⃣ 基础示例(Node.js / Edge
52
+ ### 1️⃣ Basic Example (Node.js / Edge)
53
53
 
54
54
  ```ts
55
55
  import { parseSSEStream } from "sse-stream-parser";
@@ -64,7 +64,7 @@ await parseSSEStream({
64
64
  renderStream: reader,
65
65
  options: {
66
66
  onMessage(data) {
67
- // data 是解析后的 SSE 消息
67
+ // data is the parsed SSE message
68
68
  console.log(data);
69
69
  },
70
70
  onDone() {
@@ -79,56 +79,56 @@ await parseSSEStream({
79
79
 
80
80
  ---
81
81
 
82
- ## 🔍 `[DONE]` 的处理逻辑
82
+ ## 🔍 `[DONE]` Processing Logic
83
83
 
84
- 插件内部对以下情况做了优化:
84
+ Plugin internally optimizes for the following case:
85
85
 
86
86
  ```txt
87
87
  data: [DONE]
88
88
  ```
89
89
 
90
- - 提前识别 `[DONE]`
91
- - **不再进入 JSON.parse**
92
- - 立即触发 `onDone`
93
- - 后续数据直接跳过
90
+ - Early identification of `[DONE]`
91
+ - **Skip JSON.parse**
92
+ - Immediately trigger `onDone`
93
+ - Subsequent data is skipped directly
94
94
 
95
- 避免无意义的解析和异常捕获。
95
+ Avoid meaningless parsing and exception catching.
96
96
 
97
97
  ---
98
98
 
99
- ## ⚙️ API 说明
99
+ ## ⚙️ API Documentation
100
100
 
101
101
  ### `parseSSEStream(options)`
102
102
 
103
- #### 参数
103
+ #### Parameters
104
104
 
105
- | 参数 | 类型 | 说明 |
106
- | ------------------- | ----------------------------------------- | ---------------------------- |
107
- | `renderStream` | `ReadableStreamDefaultReader<Uint8Array>` | SSE 响应体的 Reader |
108
- | `options` | `StreamOptions` | 包含回调函数的选项对象 |
109
- | `options.onMessage` | `(data: T) => void` | 每条消息回调 |
110
- | `options.onDone` | `() => void` | 收到 `[DONE]` 时触发(可选) |
111
- | `options.onError` | `(err: Error) => void` | 解析错误回调(可选) |
105
+ | Parameter | Type | Description |
106
+ | ------------------- | ----------------------------------------- | ---------------------------------------------- |
107
+ | `renderStream` | `ReadableStreamDefaultReader<Uint8Array>` | Reader for SSE response body |
108
+ | `options` | `StreamOptions` | Options object containing callbacks |
109
+ | `options.onMessage` | `(data: T) => void` | Callback for each message |
110
+ | `options.onDone` | `() => void` | Triggered when `[DONE]` is received (optional) |
111
+ | `options.onError` | `(err: Error) => void` | Parsing error callback (optional) |
112
112
 
113
113
  ---
114
114
 
115
- ## 🌍 运行环境
115
+ ## 🌍 Runtime Environment
116
116
 
117
117
  - Node.js **>= 18**
118
118
  - Bun / Deno / Edge Runtime
119
- - 浏览器(需要支持 `ReadableStream`)
119
+ - Browser (requires `ReadableStream` support)
120
120
 
121
121
  ---
122
122
 
123
- ## 🧱 适用场景
123
+ ## 🧱 Use Cases
124
124
 
125
- - OpenAI / Claude / Gemini 等 AI 服务 SSE
126
- - 实时数据推送服务
127
- - 股票行情、天气数据等实时更新
128
- - 日志流实时监控
129
- - 自定义 SSE 服务
130
- - Web / Node / Edge 流式消费
131
- - Infra / SDK / 中间层
125
+ - SSE for AI services like OpenAI/Claude/Gemini
126
+ - Real-time data push services
127
+ - Real-time updates for stock quotes, weather data, etc.
128
+ - Real-time log stream monitoring
129
+ - Custom SSE services
130
+ - Streaming consumption on Web/Node/Edge
131
+ - Infrastructure / SDK / Middleware layers
132
132
 
133
133
  ---
134
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sse-line-parser",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A simple parser for Server-Sent Events (SSE) streams",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",