node-wordstream
Streams words from a stream, and provides utility streams for filtering through them.
Setup
npm install --save wordstream
var words = ;
Usage
Log every word in a file.
fs; ;
pipe
through a few wordstream utilities.
var stream = fs // Extract words from stream // Remove duplicates // Blacklist some words // Remove every word but these // Sort it alphabetically ; // => 'file', 'is', 'test'... // Using a module like event-stream we can pipe words to a callbackvar es = ; var callback = es; stream;
Methods
The following examples use this example stream:
var stream = fs ;
pick(words)
Remove every word but those listed in an array from a stream. Can use regexps and functions as well, see contained.
stream ; // => "apple", "banana", "banana", "cherry"
without(words)
Remove every word in an array from a stream. Can use regexps and functions as well, see contained.
stream ; // => "apple", "banana", "banana", "cherry", "mango"
unique()
Remove duplicate words from a stream.
stream ; // => "apple", "banana", "cherry", "mango", "pizza"
sort([comparator])
Sort words in a stream, optionally using a comparator.
// Alphabetical sortstream ;
// Sort by length of wordsvar sortByLength = words; stream ; // => "apple", "mango", "banana", "banana", "cherry", "pizza"
filter()
Filter words from a stream using a predicate. Return true
to keep it, false
to remove it.
var removeLongWords = words; stream ; // => "apple", "mango"