Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

stream-match

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-match - npm Package Compare versions

Comparing version
4.0.0
to
4.0.1
+14
-16
index.js

@@ -1,19 +0,17 @@

const streamMatch = (stream, pattern) =>
new Promise(resolve => {
const match =
typeof pattern === 'string'
? buf => buf.includes(pattern)
: buf => pattern.exec(buf)
let buf = ''
const onData = data => {
buf += data
const res = match(buf)
if (res) {
stream.removeListener('data', onData)
resolve(res)
}
const streamMatch = async (stream, pattern) => {
const match =
typeof pattern === 'string'
? buf => buf.includes(pattern)
: buf => pattern.exec(buf)
let buf = ''
for await (const data of stream) {
buf += data
const res = match(buf)
if (res) {
return res
}
stream.on('data', onData)
})
}
throw new Error('stream ended before pattern matched')
}
export default streamMatch
{
"name": "stream-match",
"version": "4.0.0",
"version": "4.0.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Match a string in a stream. Zero dependencies",

+14
-1

@@ -55,3 +55,3 @@ import test from 'test'

test('string with backslashes', async t => {
test('string with backslashes', async () => {
const stream = new PassThrough()

@@ -78,1 +78,14 @@ let matched = false

})
test('end without match', async () => {
const stream = new PassThrough()
stream.end()
await assert.rejects(
match(stream, 'beep'),
{
name: 'Error',
message: 'stream ended before pattern matched'
}
)
})