word-counter-cli-sandeep 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/app.js +33 -0
  2. package/package.json +12 -0
package/app.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ console.log("Welcome to the Word Counter CLI By Sandeep Jatav");
4
+
5
+ import fs from 'node:fs/promises'
6
+
7
+ const filePath = process.argv[2];
8
+ const findWord = process.argv[3];
9
+ // console.log(process.argv);
10
+ const a = await fs.readFile(filePath, 'utf-8')
11
+
12
+ const wordCount = 0;
13
+
14
+ const wordsCount = {}
15
+ const wordsArray = a.split(/[\W]/).filter((w) => w);
16
+
17
+ wordsArray.forEach((words) => {
18
+ words = words.toLocaleLowerCase();
19
+ if (!wordsCount[words]) {
20
+ wordsCount[words] = 1;
21
+ } else {
22
+ wordsCount[words]++;
23
+ }
24
+ // console.log(words);
25
+ })
26
+
27
+ if (!findWord) {
28
+ console.log(wordsCount);
29
+
30
+ } else {
31
+ console.log(wordsCount[findWord]);
32
+
33
+ }
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "word-counter-cli-sandeep",
3
+ "version": "1.0.0",
4
+ "description": "A simple CLI tool to count words",
5
+ "main": "count/app.js",
6
+ "bin": {
7
+ "wordcount": "./app.js"
8
+ },
9
+ "keywords": ["word", "counter", "cli"],
10
+ "author": "Sandeep",
11
+ "license": "MIT"
12
+ }