large-text-analyzer
v1.0.9
Published
Asynchronously breaks file stream into chunks, and invokes user-supplied function on each chunk
Downloads
8
Maintainers
Readme
Large Text Analyzer
// OPTIONALLY override the word delimiters - this RegEx is the default one:
lta.delimiters = /\s|[^a-zA-Z]|[0-9]/
// OPTIONALLY override the processWord(word) function // to be executed for each word. // NOTE "this.map" - this is the result map, // that gets returned at the end of the stream. // It can be used to store all kinds of results // this here is the default - counts unique // word occurences
lta.processWord = function (word){ word = word.toLowerCase() let count = this.map.get(word) count = count? ++count : 1 this.map.set(word,count) }
// Define async block:
async function processFile (fileName) {
let vocabulary = await lta.processWords(fileName);
console.log(Vocabulary consists of ${vocabulary.size} words
)
console.log(vocabulary);
}
// And execute it. processFile('./test/data/testdata.txt')