Skip to content

reergymerej/onmatch

Repository files navigation

onmatch

Build Status

Watch streams for patterns.

import onMatch from 'onmatch'

const pattern = /start.*end/
const handleMatch = (match) => {}

const stream = onMatch(pattern)
stream.on('match', handleMatch)

stream.write('foo')
stream.write('bar', 'ascii')
stream.write(Buffer.from('start')) // assumed to be utf8
stream.write('boop')
stream.write('end') // handleMatch('startboopend')

You'd probably want to pipe the incoming stream in practice.

const stream = onMatch(pattern)
stream.on('match', handleMatch)
readable.pipe(stream)

Releases

No releases published

Packages

No packages published