word-counter-cli-vk 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.
- package/app.js +45 -0
- package/file-1.txt +3 -0
- package/file-2.txt +5 -0
- package/file-3.txt +5 -0
- package/package.json +20 -0
package/app.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
|
|
3
|
+
const filePath = process.argv[2];
|
|
4
|
+
const searchWord = process.argv[3];
|
|
5
|
+
|
|
6
|
+
// console.log(searchWord);
|
|
7
|
+
|
|
8
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
9
|
+
|
|
10
|
+
const wordsArray = fileContent
|
|
11
|
+
.split(/[\W]/)
|
|
12
|
+
.filter(Boolean);
|
|
13
|
+
|
|
14
|
+
const wordCount = {};
|
|
15
|
+
|
|
16
|
+
for (const word of wordsArray) {
|
|
17
|
+
// If word is provided → count only that word
|
|
18
|
+
if (searchWord) {
|
|
19
|
+
if (word === searchWord) {
|
|
20
|
+
wordCount[searchWord] = (wordCount[searchWord] || 0) + 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// If word is NOT provided → count all words
|
|
24
|
+
else {
|
|
25
|
+
wordCount[word] = (wordCount[word] || 0) + 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log(wordCount);
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// let wordCount = {};
|
|
33
|
+
|
|
34
|
+
// if (argWord) {
|
|
35
|
+
// wordCount[argWord] = wordsArray.length;
|
|
36
|
+
// } else {
|
|
37
|
+
// wordsArray.forEach((word) => {
|
|
38
|
+
// if (word in wordsCount) {
|
|
39
|
+
// wordCount[word] += 1;
|
|
40
|
+
// } else {
|
|
41
|
+
// wordCount[word] = 1;
|
|
42
|
+
// }
|
|
43
|
+
// });
|
|
44
|
+
// }
|
|
45
|
+
|
package/file-1.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
Node.js is a powerful, open-source runtime environment that allows developers to run JavaScript code outside of a web browser, primarily on the server side. Built on Google Chrome’s V8 JavaScript engine, Node.js is designed to build scalable network applications. It employs an event-driven, non-blocking I/O model, making it lightweight and efficient for data-intensive real-time applications that run across distributed devices.
|
|
2
|
+
|
|
3
|
+
This architecture allows Node.js to handle multiple requests simultaneously without waiting for a task to complete, which significantly improves performance for applications that require high concurrency. Additionally, its package manager, npm, provides access to a vast ecosystem of open-source libraries and tools, enabling developers to quickly add new features and functionalities to their applications.
|
package/file-2.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features for building web and mobile applications. As the de facto standard for building web servers in Node.js, Express simplifies the process of creating APIs and web applications by providing a thin layer of fundamental web functionalities, such as routing, middleware, and templating. This modularity allows developers to add only the components they need, keeping their applications lean and efficient.
|
|
2
|
+
|
|
3
|
+
Express is known for its simplicity and unopinionated nature, meaning it does not enforce any particular structure or style, giving developers the freedom to design their applications in the way that best fits their needs. Its wide adoption has also led to a rich ecosystem of middleware and plugins that extend its capabilities, enabling everything from authentication to input validation.
|
|
4
|
+
|
|
5
|
+
By using Express, developers can build scalable, high-performance web applications with minimal effort, leveraging its integration with various databases, template engines, and other tools. This flexibility and ease of use make Express.js an ideal choice for both small projects and large-scale enterprise applications, where rapid development and maintainability are crucial.
|
package/file-3.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Networking is the process of connecting computers and other devices to share resources, data, and applications, forming the backbone of modern communication. It enables the exchange of information across local and wide-area networks (LANs and WANs) and is crucial for everything from browsing the web to accessing cloud services. Networking relies on various protocols, such as TCP/IP, which govern how data is transmitted over the internet, ensuring that information sent from one device reaches its destination accurately and securely.
|
|
2
|
+
|
|
3
|
+
The infrastructure of networking includes hardware like routers, switches, and cables, as well as software components that manage the flow of data between devices. With the rise of the Internet of Things (IoT), networking has expanded beyond traditional computers to include a vast array of connected devices, such as smart appliances, sensors, and vehicles, creating new possibilities for automation, data collection, and analysis.
|
|
4
|
+
|
|
5
|
+
Networking is also fundamental to cloud computing, allowing for the seamless integration of distributed resources and services. As technology continues to evolve, networking will remain a critical field, driving innovations in areas like 5G, edge computing, and cybersecurity, ultimately shaping how we live and work in an increasingly connected world.
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "word-counter-cli-vk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple CLI tool to count words in a text file",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"word-count": "./app.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"cli",
|
|
11
|
+
"word-count",
|
|
12
|
+
"nodejs",
|
|
13
|
+
"file-processing"
|
|
14
|
+
],
|
|
15
|
+
"author": "Vikas Kashyap",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
}
|
|
20
|
+
}
|