hi_viral 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/me.js +66 -13
  2. package/package.json +10 -3
package/me.js CHANGED
@@ -1,22 +1,75 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import https from 'https';
4
4
  import chalk from 'chalk';
5
+ import readline from 'readline';
5
6
 
6
- const url = 'https://viralvaghela.com/hi.txt';
7
+ // Readline interface setup for user input
8
+ const rl = readline.createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout
11
+ });
12
+
13
+ // Function to clear the terminal screen
14
+ function clearScreen() {
15
+ process.stdout.write('\x1B[2J\x1B[3J\x1B[H');
16
+ }
17
+
18
+ // Function to print a single frame of the progress bar with rocket
19
+ function printProgressBar(progress, rocketPosition) {
20
+ const progressBarWidth = 20;
21
+ const progressBar = '▇'.repeat(Math.floor(progress * progressBarWidth));
22
+ const emptySpace = ' '.repeat(progressBarWidth - progressBar.length);
23
+ let progressBarWithRocket = progressBar.slice(0, rocketPosition) + '🚀' + progressBar.slice(rocketPosition);
24
+ console.log(chalk.green(`[${progressBarWithRocket}${emptySpace}] ${Math.floor(progress * 100)}%`));
25
+ }
7
26
 
8
- https.get(url, (response) => {
9
- let data = '';
27
+ // Function to update the progress and print the progress bar with rocket
28
+ function updateProgress(progress) {
29
+ clearScreen();
30
+ const rocketPosition = Math.floor(progress * 20); // 20 is the width of the progress bar
31
+ printProgressBar(progress, rocketPosition);
32
+ }
10
33
 
11
- // A chunk of data has been received.
12
- response.on('data', (chunk) => {
13
- data += chunk;
34
+ // Function to fetch and print the data
35
+ function fetchData() {
36
+ const url = 'https://viralvaghela.com/hi.txt';
37
+ https.get(url, (response) => {
38
+ let data = '';
39
+ response.on('data', (chunk) => {
40
+ data += chunk;
41
+ });
42
+ response.on('end', () => {
43
+ clearScreen();
44
+ console.log(chalk.green(data));
45
+ rl.close(); // Close the readline interface after displaying the data
46
+ });
47
+ }).on('error', (err) => {
48
+ console.log(chalk.red('Error: ' + err.message));
14
49
  });
50
+ }
15
51
 
16
- // The whole response has been received. Print out the result.
17
- response.on('end', () => {
18
- console.log(chalk.green(data));
52
+ // Function to simulate fetching data with progress
53
+ function simulateFetchData() {
54
+ const totalTime = 1000; // 10 seconds
55
+ const interval = 100; // 100 milliseconds
56
+ let currentTime = 0;
57
+ const timer = setInterval(() => {
58
+ const progress = currentTime / totalTime;
59
+ updateProgress(progress);
60
+ currentTime += interval;
61
+ if (currentTime >= totalTime) {
62
+ clearInterval(timer);
63
+ fetchData();
64
+ }
65
+ }, interval);
66
+
67
+ // Ask user if they want to stop the fetching process
68
+ rl.question(chalk.yellow('Press Enter to stop fetching...\n'), (answer) => {
69
+ clearInterval(timer);
70
+ fetchData();
19
71
  });
20
- }).on('error', (err) => {
21
- console.log(chalk.red('Error: ' + err.message));
22
- });
72
+ }
73
+
74
+ // Start fetching data
75
+ simulateFetchData();
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "hi_viral",
3
- "version": "1.0.1",
4
- "description": "this is my intro",
3
+ "version": "1.0.3",
4
+ "description": "This is my introduction package",
5
5
  "main": "me.js",
6
+ "url": "https://viralvaghela.com",
6
7
  "type": "module",
7
8
  "scripts": {
8
9
  "start": "node me.js"
@@ -15,5 +16,11 @@
15
16
  "dependencies": {
16
17
  "axios": "^1.3.4",
17
18
  "chalk": "^5.3.0"
18
- }
19
+ },
20
+ "keywords": [
21
+ "viral",
22
+ "vaghela",
23
+ "viralvaghela",
24
+ "viral vaghela"
25
+ ]
19
26
  }