onmatch
v1.0.0
Published
Watch streams for patterns.
Downloads
2
Maintainers
Readme
onmatch
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)