stack-analyze 1.1.6 → 1.1.9

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.
@@ -1,8 +1,8 @@
1
1
  // modules
2
- const axios = require("axios").default;
3
- const { format } = require("timeago.js");
4
- const { red } = require("colors");
5
- const { Table } = require("console-table-printer");
2
+ import { default as axios } from "axios";
3
+ import { format } from "timeago.js";
4
+ import colors from "colors";
5
+ import { printTable } from "console-table-printer";
6
6
 
7
7
  /**
8
8
  *
@@ -22,36 +22,6 @@ const animeSearch = async (query) => {
22
22
  }
23
23
  });
24
24
 
25
- const animeList = new Table({
26
- columns: [
27
- {
28
- name: "title",
29
- alignment: "left",
30
- color: "green"
31
- },
32
- {
33
- name: "type",
34
- alignment: "left",
35
- color: "magenta"
36
- },
37
- {
38
- name: "episodes",
39
- alignment: "left",
40
- color: "magenta"
41
- },
42
- {
43
- name: "debutDate",
44
- alignment: "left",
45
- color: "magenta"
46
- },
47
- {
48
- name: "finalDate",
49
- alignment: "left",
50
- color: "green"
51
- }
52
- ]
53
- });
54
-
55
25
  const animeData = data.results.map(({
56
26
  title,
57
27
  episodes,
@@ -62,18 +32,15 @@ const animeSearch = async (query) => {
62
32
  type,
63
33
  episodes,
64
34
  debutDate: format(start_date),
65
- finalDate: end_date !== null
66
- ? format(end_date)
35
+ finalDate: end_date !== null
36
+ ? format(end_date)
67
37
  : "current date"
68
38
  }));
69
-
70
-
71
- animeList.addRows(animeData);
72
39
 
73
- animeList.printTable();
74
40
 
75
- } catch (err) { console.error(red(err.message)); }
41
+ printTable(animeData);
42
+ } catch (err) { console.error(colors.red(err.message)); }
76
43
  };
77
44
 
78
45
  // exports module
79
- module.exports = animeSearch;
46
+ export default animeSearch;
@@ -1,13 +1,12 @@
1
1
  // modules
2
- const axios = require("axios").default;
3
- const { format } = require("timeago.js");
4
- const { red } = require("colors");
2
+ import { default as axios } from "axios";
3
+ import { format } from "timeago.js";
4
+ import colors from "colors";
5
5
 
6
6
  /**
7
7
  *
8
8
  * @description call the bitly info data
9
9
  * @param { string } link - link for search info
10
- * @param { string } token - token for using tool
11
10
  * @returns { Promise<void> } - return results serach
12
11
  *
13
12
  */
@@ -34,10 +33,9 @@ const bitlyInfo = async (link, token) => {
34
33
  link: data.long_url
35
34
  });
36
35
  } catch (err) {
37
- console.error(red(err.message));
36
+ console.error(colors.red(err.message));
38
37
  }
39
38
  };
40
39
 
41
40
  // export
42
- module.exports = bitlyInfo;
43
-
41
+ export default bitlyInfo;
@@ -1,13 +1,14 @@
1
1
  // modules
2
- const CoinGecko = require("coingecko-api");
3
- const { format } = require("timeago.js");
4
- const { red, green } = require("colors");
5
- const { Table } = require("console-table-printer");
2
+ import {default as axios} from "axios";
3
+ import { format } from "timeago.js";
4
+ import colors from "colors";
6
5
 
7
- // init coingecko api
8
- const CoinGeckoClient = new CoinGecko();
6
+ import { printTable } from "console-table-printer";
9
7
 
10
- /*
8
+ // currency format
9
+ import { currency } from "../utils.js";
10
+
11
+ /**
11
12
  *
12
13
  * @descripiton call the crypto market list
13
14
  * @returns { Promise<void> } - return results search
@@ -16,12 +17,17 @@ const CoinGeckoClient = new CoinGecko();
16
17
  const cryptoMarket = async () => {
17
18
  try {
18
19
  // start crypto
19
- const coinData = await CoinGeckoClient.coins.markets({
20
- per_page: 10
21
- });
20
+ const { data } = await axios.get(
21
+ "https://api.coingecko.com/api/v3/coins/markets", {
22
+ params: {
23
+ vs_currency: "usd",
24
+ per_page: 10
25
+ }
26
+ }
27
+ );
22
28
 
23
29
  // map coinData
24
- const coinList = coinData.data.map(({
30
+ const coinList = data.map(({
25
31
  symbol,
26
32
  name,
27
33
  current_price,
@@ -30,51 +36,19 @@ const cryptoMarket = async () => {
30
36
  }) => ({
31
37
  symbol,
32
38
  name,
33
- price: current_price,
39
+ price: currency.format(current_price),
34
40
  priceChanged: price_change_percentage_24h > 0
35
- ? green(price_change_percentage_24h)
36
- : red(price_change_percentage_24h),
41
+ ? colors.green(price_change_percentage_24h)
42
+ : colors.red(price_change_percentage_24h),
37
43
  lastUpdated: format(last_updated)
38
44
  }));
39
45
 
40
- // init table
41
- const coinTable = new Table({
42
- columns: [
43
- {
44
- name: "symbol",
45
- alignment: "left",
46
- color: "green"
47
- },
48
- {
49
- name: "name",
50
- alignment: "left",
51
- color: "white_bold"
52
- },
53
- {
54
- name: "price",
55
- alignment: "left",
56
- color: "yellow"
57
- },
58
- {
59
- name: "priceChanged",
60
- alignment: "left"
61
- },
62
- {
63
- name: "lastUpdated",
64
- alignment: "left",
65
- color: "magenta"
66
- }
67
- ]
68
- });
69
-
70
- coinTable.addRows(coinList);
71
-
72
46
  // print table
73
- coinTable.printTable();
47
+ printTable(coinList);
74
48
  } catch (err) {
75
49
  // print err message
76
- console.error(red(err.message));
50
+ console.error(colors.red(err.message));
77
51
  }
78
52
  };
79
53
 
80
- module.exports = cryptoMarket;
54
+ export default cryptoMarket;
@@ -1,7 +1,7 @@
1
1
  // modules
2
- const axios = require("axios").default;
3
- const { format } = require("timeago.js");
4
- const { red, yellow } = require("colors");
2
+ import { default as axios } from "axios";
3
+ import { format } from "timeago.js";
4
+ import colors from "colors";
5
5
 
6
6
  /**
7
7
  *
@@ -10,7 +10,7 @@ const { red, yellow } = require("colors");
10
10
  * @returns { Promise<void> } - return results info
11
11
  *
12
12
  */
13
- async function githubInfo(user) {
13
+ export default async function githubInfo(user) {
14
14
  try {
15
15
  const res = await axios.get(`https://api.github.com/users/${user}`);
16
16
 
@@ -30,12 +30,9 @@ async function githubInfo(user) {
30
30
 
31
31
  console.table(info);
32
32
  } else {
33
- console.info(yellow(res.status.toString()));
33
+ console.info(colors.yellow(res.status.toString()));
34
34
  }
35
35
  } catch(err) {
36
- console.error(red(err.message));
36
+ console.error(colors.red(err.message));
37
37
  }
38
38
  }
39
-
40
- module.exports = githubInfo;
41
-
@@ -1,241 +1,201 @@
1
1
  // modules
2
- const {
2
+ import {
3
3
  cpu,
4
4
  mem,
5
5
  osInfo,
6
6
  diskLayout,
7
7
  graphics,
8
8
  bios
9
- } = require("systeminformation");
10
- const { printTable } = require("console-table-printer");
11
- const { red } = require("colors");
12
-
13
-
14
- /**
15
- *
16
- * @description call the async function cpuinfo
17
- * @return { Promise<void> } - return cpu results
18
- *
19
- */
20
- async function cpuInfo() {
21
- try {
22
- const {
23
- manufacturer,
24
- brand,
25
- speed,
26
- cores,
27
- physicalCores,
28
- processors,
29
- vendor,
30
- family,
31
- model
32
- } = await cpu();
33
-
34
- // show results
35
- console.table({
36
- manufacturer,
37
- brand,
38
- speed,
39
- cores,
40
- physicalCores,
41
- processors,
42
- vendor,
43
- family,
44
- model
45
- });
46
- } catch (err) {
47
- console.error(red(err.message));
48
- }
49
- }
50
-
51
- /**
52
- *
53
- * @description call the async function ram memory
54
- * @return { Promise<void> } - return ram memory results
55
- *
56
- */
57
- async function ramMemInfo() {
58
- try {
59
- const {
60
- total,
61
- free,
62
- used,
63
- active,
64
- available
65
- } = await mem();
66
-
67
- // show results
68
- console.table({
69
- total_mem: `${(total / 1073741824).toFixed(2)} GB`,
70
- free_mem: `${(free / 1073741824).toFixed(2)} GB`,
71
- used_mem: `${(used / 1073741824).toFixed(2)} GB`,
72
- active_mem: `${(active / 1073741824).toFixed(2)} GB`,
73
- available_mem: `${(available / 1073741824).toFixed(2)} GB`
74
- });
75
- } catch (err) {
76
- console.error(red(err.message));
77
- }
78
- }
79
-
80
- /**
81
- *
82
- * @description call the async function osinfo
83
- * @return { Promise<void> } - return os results results
84
- *
85
- */
86
- async function osDetail() {
87
- try {
88
- const {
89
- hostname,
90
- platform,
91
- distro,
92
- release,
93
- kernel,
94
- arch,
95
- serial,
96
- uefi
97
- } = await osInfo();
98
-
99
- // show results
100
- console.table({
101
- hostname,
102
- platform,
103
- distro,
104
- release,
105
- kernel,
106
- arch,
107
- serial,
108
- uefi
109
- });
110
- } catch (err) {
111
- console.error(red(err.message));
112
- }
113
- }
114
-
115
- /**
116
- *
117
- * @description call the async function diskinfo
118
- * @return { Promise<void> } - return disks results
119
- *
120
- */
121
- async function diskInfo() {
122
- try {
123
- const disks = await diskLayout();
124
-
125
- const disksList = disks.map(({
126
- type,
127
- name,
128
- vendor,
129
- size,
130
- interfaceType
131
- }) => ({
132
- type,
133
- name,
134
- vendor,
135
- diskSize: `${(size / 1073741824).toFixed(2)} GB`,
136
- interfaceType
137
- }));
138
-
139
- printTable(disksList);
140
-
141
- } catch (err) {
142
- console.error(red(err.message));
9
+ } from "systeminformation";
10
+ import colors from "colors";
11
+ import { printTable } from "console-table-printer";
12
+
13
+ /** @type {Object.<string, function(): Promise<void>>} */
14
+ const hardwareTools = {
15
+ async cpuInfo() {
16
+ console.clear();
17
+
18
+ try {
19
+ const {
20
+ manufacturer,
21
+ brand,
22
+ speed,
23
+ cores,
24
+ physicalCores,
25
+ processors,
26
+ vendor,
27
+ family,
28
+ model
29
+ } = await cpu();
30
+
31
+ // show results
32
+ console.table({
33
+ manufacturer,
34
+ brand,
35
+ speed,
36
+ cores,
37
+ physicalCores,
38
+ processors,
39
+ vendor,
40
+ family,
41
+ model
42
+ });
43
+ } catch (err) {
44
+ console.error(colors.red(err.message));
45
+ }
46
+ },
47
+ async ramMemInfo() {
48
+ console.clear();
49
+
50
+ try {
51
+ const {
52
+ total,
53
+ free,
54
+ used,
55
+ active,
56
+ available
57
+ } = await mem();
58
+
59
+ // show results
60
+ console.table({
61
+ total_mem: `${(total / 1073741824).toFixed(2)} GB`,
62
+ free_mem: `${(free / 1073741824).toFixed(2)} GB`,
63
+ used_mem: `${(used / 1073741824).toFixed(2)} GB`,
64
+ active_mem: `${(active / 1073741824).toFixed(2)} GB`,
65
+ available_mem: `${(available / 1073741824).toFixed(2)} GB`
66
+ });
67
+ } catch (err) {
68
+ console.error(colors.red(err.message));
69
+ }
70
+ },
71
+ async osDetail() {
72
+ console.clear();
73
+
74
+ try {
75
+ const {
76
+ hostname,
77
+ platform,
78
+ distro,
79
+ release,
80
+ kernel,
81
+ arch,
82
+ serial,
83
+ uefi
84
+ } = await osInfo();
85
+
86
+ // show results
87
+ console.table({
88
+ hostname,
89
+ platform,
90
+ distro,
91
+ release,
92
+ kernel,
93
+ arch,
94
+ serial,
95
+ uefi
96
+ });
97
+ } catch (err) {
98
+ console.error(colors.red(err.message));
99
+ }
100
+ },
101
+ async diskInfo() {
102
+ console.clear();
103
+
104
+ try {
105
+ const disks = await diskLayout();
106
+
107
+ const disksList = disks.map(({
108
+ type,
109
+ name,
110
+ vendor,
111
+ size,
112
+ interfaceType
113
+ }) => ({
114
+ type,
115
+ name,
116
+ vendor,
117
+ diskSize: `${(size / 1073741824).toFixed(2)} GB`,
118
+ interfaceType
119
+ }));
120
+
121
+ printTable(disksList);
122
+
123
+ } catch (err) {
124
+ console.error(colors.red(err.message));
125
+ }
126
+ },
127
+ async controllerInfo() {
128
+ console.clear();
129
+
130
+ try {
131
+ const { controllers } = await graphics();
132
+
133
+ const controllersList = controllers.map(({
134
+ model,
135
+ vendor,
136
+ vram
137
+ }) => ({
138
+ model,
139
+ vendor,
140
+ vramSize: vram < 1024
141
+ ? `${vram} MB`
142
+ : `${(vram / 1024).toFixed(2)} GB`
143
+ }));
144
+
145
+ // show results
146
+ printTable(controllersList);
147
+ } catch (err) {
148
+ console.error(colors.red(err.message));
149
+ }
150
+ },
151
+ async displayInfo() {
152
+ console.clear();
153
+
154
+ try {
155
+ const { displays } = await graphics();
156
+
157
+ const displayList = displays.map(({
158
+ model,
159
+ main,
160
+ connection,
161
+ resolutionX,
162
+ resolutionY
163
+ }) => ({
164
+ model,
165
+ main,
166
+ connection,
167
+ resolutionX,
168
+ resolutionY
169
+ }));
170
+
171
+ // show results
172
+ printTable(displayList);
173
+ } catch (err) {
174
+ console.error(colors.red(err.message));
175
+ }
176
+ },
177
+ async biosInfo() {
178
+ console.clear();
179
+
180
+ try {
181
+ const {
182
+ releaseDate,
183
+ vendor,
184
+ revision,
185
+ version
186
+ } = await bios();
187
+
188
+ console.table({
189
+ releaseDate,
190
+ vendor,
191
+ bios_revision: revision === "" ? "no info" : revision,
192
+ version
193
+ });
194
+ } catch (err) {
195
+ console.error(colors.red(err.message));
196
+ }
143
197
  }
144
- }
145
-
146
- /**
147
- *
148
- * @description call the async function graphic card
149
- * @return { Promise<void> } - return graphic controller results
150
- *
151
- */
152
- async function controllerInfo() {
153
- try {
154
- const { controllers } = await graphics();
155
-
156
- const controllersList = controllers.map(({
157
- model,
158
- vendor,
159
- vram
160
- }) => ({
161
- model,
162
- vendor,
163
- vramSize: vram < 1024
164
- ? `${vram} MB`
165
- : `${(vram / 1024).toFixed(2)} GB`
166
- }));
167
-
168
- // show results
169
- printTable(controllersList);
170
- } catch (err) {
171
- console.error(red(err.message));
172
- }
173
- }
174
-
175
- /**
176
- *
177
- * @description call the async function display info
178
- * @return { Promise<void> } - return display results
179
- *
180
- */
181
- async function displayInfo() {
182
- try {
183
- const { displays } = await graphics();
184
-
185
- const displayList = displays.map(({
186
- model,
187
- main,
188
- connection,
189
- resolutionX,
190
- resolutionY
191
- }) => ({
192
- model,
193
- main,
194
- connection,
195
- resolutionX,
196
- resolutionY
197
- }));
198
-
199
- // show results
200
- printTable(displayList);
201
- } catch (err) {
202
- console.error(red(err.message));
203
- }
204
- }
205
-
206
- /**
207
- *
208
- * @description call the async function biosinfo
209
- * @return { Promise<void> } - return bios info results
210
- *
211
- */
212
- async function biosInfo() {
213
- try {
214
- const {
215
- releaseDate,
216
- vendor,
217
- revision,
218
- version
219
- } = await bios();
220
-
221
- console.table({
222
- releaseDate,
223
- vendor,
224
- bios_revision: revision === "" ? "no info": revision,
225
- version
226
- });
227
- } catch (err) {
228
- console.error(red(err.message));
229
- }
230
- }
198
+ };
231
199
 
232
200
  // exports modules
233
- module.exports = {
234
- cpuInfo,
235
- ramMemInfo,
236
- osDetail,
237
- diskInfo,
238
- controllerInfo,
239
- displayInfo,
240
- biosInfo
241
- };
201
+ export default hardwareTools;