UNPKG

2.37 kBMarkdownView Raw
1# Text Search in Node.JS Streams
2
3[![Circle CI](https://circleci.com/gh/kevgo/node-text-stream-search.svg?style=shield)](https://circleci.com/gh/kevgo/node-text-stream-search)
4[![Code Coverage](https://coveralls.io/repos/github/kevgo/node-text-stream-search/badge.svg?branch=master)](https://coveralls.io/github/kevgo/node-text-stream-search?branch=master)
5[![0 dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](https://github.com/kevgo/node-text-stream-search/blob/master/package.json)
6[![install size](https://packagephobia.now.sh/badge?p=text-stream-search)](https://packagephobia.now.sh/result?p=text-stream-search)
7[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/kevgo/node-text-stream-search.svg)](https://lgtm.com/projects/g/kevgo/node-text-stream-search/context:javascript)
8
9This micro-library (no dependencies) searches for occurrences of a given search
10term (string or Regex) in a Node.js stream, i.e. anything that emits `data`
11events with Buffers or strings.
12
13```javascript
14import { TextStreamSearch } from "text-stream-search"
15
16const streamSearch = new TextStreamSearch(myStream)
17
18// wait until myStream contains "hello"
19await streamSearch.waitForText("hello")
20
21// capture data from the stream
22const matchText = await streamSearch.waitForRegex("listening at port \\d+.")
23// matchingText contains something like "listening at port 3000."
24
25// access the captured stream content
26const text = streamSearch.fullText()
27```
28
29## Related projects
30
31- [StreamSnitch](https://github.com/dmotz/stream-snitch): does the same thing
32 with regular expressions, but is buggy and blocks the event queue
33
34## Development
35
36All contributions and feedback, no matter how big or small, is welcome. Please
37submit bugs, ideas, or improvements via
38[an issue](https://github.com/kevgo/node-text-stream-accumulator/issues/new) or
39pull request.
40
41- run all tests: <code textrun="verify-make-command">make test</code>
42- run unit tests: <code textrun="verify-make-command">make unit</code>
43- run linters: <code textrun="verify-make-command">make lint</code>
44- fix formatting issues: <code textrun="verify-make-command">make lint</code>
45- see all available make commands: <code textrun="verify-make-command">make
46 help</code>
47
48#### Deploy a new version
49
50- update the version in `package.json` and commit to `master`
51- run `npm publish`