@vnikhra/word-counter
v1.0.4
Published
A library to count words in a file stream
Downloads
2
Readme
Word Counter
Word Counter is a TypeScript library that provides a function to count the frequency of words in a file stream.
Installation
You can install the Word Counter library via npm:
npm install @vnikhra/word-counter
Usage
Importing
You can import the countWords
function from the Word Counter library in your TypeScript code as follows:
import { countWords } from '@vnikhra/word-counter';
Function Signature
The countWords
function takes a file stream as input and returns an object with the frequency of each word in the stream.
countWords(fileStream: fs.ReadableStream): Promise<{ [word: string]: number }>;
Example
Here's an example of how to use the countWords
function:
import { createReadStream } from 'fs';
import { countWords } from 'word-counter';
const fileStream = createReadStream('example.txt');
countWords(fileStream)
.then(wordFrequency => {
console.log('Word Frequency:', wordFrequency);
})
.catch(error => {
console.error('Error:', error);
});
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on GitHub.
Build Locally
To build this library locally, you will need to have node installed on your system. I would recommend using NVM.
Install dependencies
Install dependencies using
npm i
Build Project
Build project locally using
npm run build
Code will be available at build/index.js
Run tests
Run Tests using
npm test