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
1.1.1
to
1.2.0
+7
-5
index.js

@@ -5,11 +5,13 @@ 'use strict'

new Promise(resolve => {
const test = typeof pattern === 'string'
? buf => buf.includes(pattern)
: buf => pattern.test(buf)
const match =
typeof pattern === 'string'
? buf => buf.includes(pattern)
: buf => pattern.exec(buf) && pattern.exec(buf)[1]
let buf = ''
const onData = data => {
buf += data
if (test(buf)) {
const res = match(buf)
if (res) {
stream.removeListener('data', onData)
resolve()
resolve(res)
}

@@ -16,0 +18,0 @@ }

{
"name": "stream-match",
"version": "1.1.1",
"version": "1.2.0",
"license": "MIT",
"description": "Match a string in a stream",
"description": "Match a string in a stream. Zero dependencies",
"repository": "juliangruber/stream-match",
"scripts": {
"release": "np",
"test": "prettier-standard '**/*.js' && standard && tap test.js"
},
"devDependencies": {
"np": "^5.2.1",
"prettier-standard": "^15.0.1",

@@ -12,0 +14,0 @@ "standard": "^14.3.1",

# stream-match
Match a regexp or string in a stream.
Match a regexp or string in a stream. Zero dependencies.

@@ -9,4 +9,4 @@ ## Usage

// Given a readable stream,
await match(stream, /pattern/)
// now `pattern` has been emitted by it.
const res = await match(stream, /(p[^n+]n)/)
// `res` will containt `pattern` once it has been emitted.
```

@@ -22,3 +22,3 @@

### await match(stream, pattern || string)
### res = await match(stream, pattern || string)

@@ -25,0 +25,0 @@ ## License

@@ -9,15 +9,14 @@ 'use strict'

const stream = new PassThrough()
let matched = false
let res
await Promise.all([
(async () => {
await match(stream, /beep boop/)
matched = true
res = await match(stream, /(bo+p)/)
})(),
(async () => {
t.notOk(matched)
t.notOk(res)
stream.push('beep ')
t.notOk(matched)
t.notOk(res)
stream.push('boo')
t.notOk(matched)
t.notOk(res)
stream.push('p')

@@ -27,3 +26,3 @@ })()

t.ok(matched)
t.equal(res, 'boop')
stream.push('everything else')

@@ -30,0 +29,0 @@ })