UNPKG

word-counter-ac

Version:

A simple word counter CLI package

42 lines (27 loc) 722 B
# Word Counter AC ## A sample word counter CLI package. ```javascript // Code block import fs from 'node:fs/promises' const [,,filePath, word] = process.argv; const textContent = await fs.readFile(filePath, 'utf-8') const wordsCount = {}; const words = textContent.split(/[\W]/).filter(w => w); for (let word of words) { word = word.toLowerCase(); if(!(word in wordsCount)) { wordsCount[word] = 0; } wordsCount[word] += 1; } ``` **Usage** word-counter-ac <\<filename\>> <\<word to search\>> E.g. word-counter-ac ./file-1.txt to **Sample Output** The word 'to' has occured 7 times. --- *Developed with love ❤️ by*, **AC** *thank you!* ---