stream-match
Advanced tools
+7
-2
@@ -1,2 +0,4 @@ | ||
| const streamMatch = async (stream, pattern) => { | ||
| import { abortableSource } from 'abortable-iterator' | ||
| const streamMatch = async (stream, pattern, { signal } = {}) => { | ||
| const match = | ||
@@ -7,3 +9,6 @@ typeof pattern === 'string' | ||
| let buf = '' | ||
| for await (const data of stream) { | ||
| const it = signal | ||
| ? abortableSource(stream, signal) | ||
| : stream | ||
| for await (const data of it) { | ||
| buf += data | ||
@@ -10,0 +15,0 @@ const res = match(buf) |
+4
-1
| { | ||
| "name": "stream-match", | ||
| "version": "4.0.1", | ||
| "version": "4.1.0", | ||
| "license": "MIT", | ||
@@ -17,3 +17,6 @@ "description": "Match a string in a stream. Zero dependencies", | ||
| "test": "^3.2.1" | ||
| }, | ||
| "dependencies": { | ||
| "abortable-iterator": "^5.0.1" | ||
| } | ||
| } |
+5
-2
| # stream-match | ||
| Match a regexp or string in a stream. Zero dependencies. | ||
| Match a regexp or string in a stream. | ||
@@ -26,6 +26,9 @@ ## Usage | ||
| ### res = await match(stream, pattern || string) | ||
| ### res = await match(stream, pattern || string, { signal? }) | ||
| Pass the optional `{ signal }` with an `AbortController#signal` to abort early. | ||
| In this case, an `Error` with `.code = 'ABORT_ERR'` will be thrown. | ||
| ## License | ||
| MIT |
+10
-0
@@ -90,1 +90,11 @@ import test from 'test' | ||
| }) | ||
| test('signal', async () => { | ||
| const stream = new PassThrough() | ||
| const signal = AbortSignal.timeout(1) | ||
| assert.rejects( | ||
| match(stream, 'beep', { signal }), | ||
| { code: 'ABORT_ERR' } | ||
| ) | ||
| }) |
4005
15.48%106
12.77%34
9.68%1
Infinity%+ Added
+ Added
+ Added
+ Added