stack-analyze 1.3.4 → 1.3.6

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,72 +1,72 @@
1
- // modules
2
- import axios from "axios";
3
- import { format } from "timeago.js";
4
- import { printTable } from "console-table-printer";
5
- import colors from "colors";
6
-
7
- // save twitch users
8
- import { stackSave } from "../utils.js";
9
-
10
- /**
11
- * types for twitch info
12
- *
13
- * @typedef {Object} Twitch
14
- * @property {string} Twitch.twitchUsers
15
- * @property {string} Twitch.twitchSeparator
16
- * @property {string} Twitch.twitchToken
17
- * @property {string} Twitch.twitchClient
18
- */
19
-
20
- /**
21
- * @description twitch user info
22
- * @async
23
- * @param {Twitch} param
24
- * @returns { Promise<void> } - return twitch results
25
- */
26
- export default async function twitchInfo({
27
- twitchUsers,
28
- twitchSeparator,
29
- twitchToken,
30
- twitchClient
31
- }) {
32
-
33
- const userList = twitchUsers.split(twitchSeparator);
34
-
35
- if(userList.length === 10) {
36
- console.error("twitch users must be 10".bgRed);
37
- }
38
-
39
- const params = new URLSearchParams();
40
-
41
- userList.forEach((item) => {
42
- params.append("login", item);
43
- });
44
-
45
- try {
46
- const { data: twitchData } = await axios.get("https://api.twitch.tv/helix/users", {
47
- params,
48
- headers: {
49
- Authorization: `Bearer ${twitchToken}`,
50
- "Client-Id": twitchClient
51
- }
52
- });
53
-
54
- const result = twitchData.data.map(({
55
- display_name,
56
- broadcaster_type,
57
- view_count,
58
- created_at
59
- }) => ({
60
- username: display_name,
61
- broadcaster: broadcaster_type || "user",
62
- viewCount: view_count,
63
- accountDate: new Date(created_at).toLocaleDateString(),
64
- accountAge: format(created_at)
65
- }));
66
-
67
- printTable(result);
68
- stackSave("twitch-users.json", JSON.stringify(result, null, 2));
69
- } catch (err) {
70
- console.error(colors.red(err));
71
- }
72
- }
1
+ // modules
2
+ import axios from "axios";
3
+ import { format } from "timeago.js";
4
+ import { printTable } from "console-table-printer";
5
+ import colors from "colors";
6
+
7
+ // save twitch users
8
+ import { stackSave } from "../utils.js";
9
+
10
+ /**
11
+ * types for twitch info
12
+ *
13
+ * @typedef {Object} Twitch
14
+ * @property {string} Twitch.twitchUsers
15
+ * @property {string} Twitch.twitchSeparator
16
+ * @property {string} Twitch.twitchToken
17
+ * @property {string} Twitch.twitchClient
18
+ */
19
+
20
+ /**
21
+ * @description twitch user info
22
+ * @async
23
+ * @param {Twitch} param
24
+ * @returns { Promise<void> } - return twitch results
25
+ */
26
+ export default async function twitchInfo({
27
+ twitchUsers,
28
+ twitchSeparator,
29
+ twitchToken,
30
+ twitchClient
31
+ }) {
32
+
33
+ const userList = twitchUsers.split(twitchSeparator);
34
+
35
+ if(userList.length === 10) {
36
+ console.error("twitch users must be 10".bgRed);
37
+ }
38
+
39
+ const params = new URLSearchParams();
40
+
41
+ userList.forEach((item) => {
42
+ params.append("login", item);
43
+ });
44
+
45
+ try {
46
+ const { data: twitchData } = await axios.get("https://api.twitch.tv/helix/users", {
47
+ params,
48
+ headers: {
49
+ Authorization: `Bearer ${twitchToken}`,
50
+ "Client-Id": twitchClient
51
+ }
52
+ });
53
+
54
+ const result = twitchData.data.map(({
55
+ display_name,
56
+ broadcaster_type,
57
+ view_count,
58
+ created_at
59
+ }) => ({
60
+ username: display_name,
61
+ broadcaster: broadcaster_type || "user",
62
+ viewCount: view_count,
63
+ accountDate: new Date(created_at).toLocaleDateString(),
64
+ accountAge: format(created_at)
65
+ }));
66
+
67
+ printTable(result);
68
+ stackSave("twitch-users.json", JSON.stringify(result, null, 2));
69
+ } catch (err) {
70
+ console.error(colors.red(err.message));
71
+ }
72
+ }
package/hash/infoTools.js CHANGED
@@ -1,57 +1,61 @@
1
- // inquirer
2
- import inquirer from "inquirer";
3
-
4
- // functions
5
- import bitlyInfo from "../functions/bitly.js";
6
- import cryptoMarket from "../functions/cryptoList.js";
7
- import githubInfo from "../functions/gitUser.js";
8
- import bundlephobia from "../functions/bundlephobia.js";
9
-
10
- // fields
11
- import {
12
- bitlyQuery,
13
- promptParams,
14
- promptKey
15
- } from "../validations/infoValidations.js";
16
-
17
- const infoTools = {
18
- github_info(refreshCallback) {
19
- console.clear();
20
- inquirer.prompt([
21
- promptParams("gitUser", "enter a github user for search")
22
- ])
23
- .then(({ gitUser }) => {
24
- githubInfo(gitUser);
25
- setTimeout(refreshCallback, 2e3);
26
- });
27
- },
28
- bitly_info(refreshCallback) {
29
- console.clear();
30
- inquirer.prompt([
31
- bitlyQuery,
32
- promptKey("token", "enter a bitly token")
33
- ])
34
- .then(({ bitlyLink, token }) => {
35
- bitlyInfo(bitlyLink, token);
36
- setTimeout(refreshCallback, 2e3);
37
- });
38
- },
39
- crypto_market(refreshCallback) {
40
- console.clear();
41
- cryptoMarket();
42
- setTimeout(refreshCallback, 5e3);
43
- },
44
- bundlephobia_info(refreshCallback) {
45
- console.clear();
46
- inquirer.prompt([
47
- promptParams("pkgName", "enter a npm package name for search info size")
48
- ])
49
- .then(({ pkgName }) => {
50
- console.info(pkgName);
51
- bundlephobia(pkgName);
52
- setTimeout(refreshCallback, 5e3);
53
- });
54
- },
55
- };
56
-
57
- export default infoTools;
1
+ // inquirer
2
+ import { input, password } from "@inquirer/prompts";
3
+
4
+ // functions
5
+ import bitlyInfo from "../functions/bitly.js";
6
+ import cryptoMarket from "../functions/cryptoList.js";
7
+ import githubInfo from "../functions/gitUser.js";
8
+ import bundlephobia from "../functions/bundlephobia.js";
9
+
10
+ // bitly regexp
11
+ const bitlyRegexp = /bit\.ly\//g;
12
+
13
+ const infoTools = {
14
+ async github_info(refreshCallback) {
15
+ console.clear();
16
+
17
+ const gitUser = await input({
18
+ message: "enter a github user for search",
19
+ required: true
20
+ });
21
+
22
+ githubInfo(gitUser);
23
+ setTimeout(refreshCallback, 2e3);
24
+ },
25
+ async bitly_info(refreshCallback) {
26
+ console.clear();
27
+
28
+ const { bitlyLink, token } = {
29
+ bitlyLink: await input({
30
+ message: "enter a short link:",
31
+ validate: input => bitlyRegexp.test(input) || "only bitly link".yellow
32
+ }),
33
+ token: await password({
34
+ message: "enter a bitly token",
35
+ required: true,
36
+ mask: true
37
+ })
38
+ };
39
+
40
+ bitlyInfo(bitlyLink, token);
41
+ setTimeout(refreshCallback, 2e3);
42
+ },
43
+ crypto_market(refreshCallback) {
44
+ console.clear();
45
+ cryptoMarket();
46
+ setTimeout(refreshCallback, 5e3);
47
+ },
48
+ async bundlephobia_info(refreshCallback) {
49
+ console.clear();
50
+
51
+ const pkgName = await input({
52
+ message: "enter a npm package name for search info size"
53
+ });
54
+
55
+ console.info(pkgName);
56
+ bundlephobia(pkgName);
57
+ setTimeout(refreshCallback, 5e3);
58
+ },
59
+ };
60
+
61
+ export default infoTools;
@@ -1,119 +1,116 @@
1
- // inquirer
2
- import inquirer from "inquirer";
3
-
4
- // functions
5
- import animeSearch from "../functions/animeInfo.js";
6
- import movieDB from "../functions/moviesInfo.js";
7
- import pokemonInfo from "../functions/pokemon.js";
8
- import twitchInfo from "../functions/twitch.js";
9
- import deezer from "../functions/deezer.js";
10
- import potterSearch from "../functions/potterSearch.js";
11
-
12
- // fields
13
- import {
14
- promptParams,
15
- promptKey
16
- } from "../validations/infoValidations.js";
17
-
18
- /** query tools */
19
- const queryTools = {
20
- anime_Search(refreshCallback) {
21
- console.clear();
22
- inquirer.prompt([promptParams("query", "")])
23
- .then(({ query }) => {
24
- animeSearch(query);
25
- setTimeout(refreshCallback, 2e3);
26
- });
27
- },
28
- movie_info(refreshCallback) {
29
- console.clear();
30
- inquirer.prompt([
31
- promptParams("query", "enter movie for search DB"),
32
- promptKey("token", "enter a token key")
33
- ])
34
- .then(({ query, token }) => {
35
- movieDB(query, token);
36
- setTimeout(refreshCallback, 2e3);
37
- });
38
- },
39
- pokemon_info(refreshCallback) {
40
- console.clear();
41
- inquirer.prompt([
42
- {
43
- type: "list",
44
- name: "pokeOpt",
45
- message: "enter a opt for start search",
46
- choices: ["ID", "Name"],
47
- },
48
- {
49
- type: "number",
50
- name: "pokeId",
51
- message: "enter a poekmon ID:",
52
- validate: value => value > 0 || "this field not allowed empty values, NaN or number less or equal to 0",
53
- filter(value) {
54
- if(!value) return "";
55
-
56
- const int = parseInt(value);
57
-
58
- if(isNaN(int)) return "";
59
-
60
- return int <= 0 ? "" : int;
61
- },
62
- when: ({pokeOpt}) => pokeOpt === "ID",
63
- },
64
- {
65
- type: "input",
66
- name: "pokeName",
67
- message: "enter a poekmon name:",
68
- validate(input) {
69
- const excludeNumbers = /[^0-9]/;
70
-
71
- return excludeNumbers.test(input) || "the pokemon name is required";
72
- },
73
- when: ({pokeOpt}) => pokeOpt === "Name",
74
- },
75
- ])
76
- .then(anw => {
77
- pokemonInfo(anw?.pokeName || anw?.pokeId);
78
- setTimeout(refreshCallback, 6e3);
79
- });
80
- },
81
- twitch_info(refreshCallback) {
82
- console.clear();
83
-
84
- inquirer.prompt([
85
- promptParams("twitchSeparator", "enter a separator for split example ',':"),
86
- promptParams("twitchUsers", "enter a twitch users example 'a,b,c'"),
87
- promptKey("twitchClient", "enter a twitch client ID"),
88
- promptKey("twitchToken", "enter a twitch token"),
89
- ])
90
- .then(({ twitchSeparator, twitchUsers, twitchClient, twitchToken }) => {
91
- twitchInfo({ twitchSeparator, twitchUsers, twitchClient, twitchToken });
92
- setTimeout(refreshCallback, 2e3);
93
- });
94
- },
95
- deezer(refreshCallback) {
96
- console.clear();
97
-
98
- inquirer.prompt([
99
- promptParams("query", "enter a query for search")
100
- ])
101
- .then(({ query }) => {
102
- deezer(query);
103
- setTimeout(refreshCallback, 5e3);
104
- });
105
- },
106
- potter_search(refreshCallback) {
107
- console.clear();
108
-
109
- inquirer.prompt([
110
- promptParams("search", "enter a keyword or name for search")
111
- ])
112
- .then(({ search }) => {
113
- potterSearch(search);
114
- setTimeout(refreshCallback, 5e3);
115
- });
116
- }
117
- };
118
-
119
- export default queryTools;
1
+ // inquirer
2
+ import { input, password, select, number } from "@inquirer/prompts";
3
+
4
+ // functions
5
+ import animeSearch from "../functions/animeInfo.js";
6
+ import movieDB from "../functions/moviesInfo.js";
7
+ import pokemonInfo from "../functions/pokemon.js";
8
+ import twitchInfo from "../functions/twitch.js";
9
+ import deezer from "../functions/deezer.js";
10
+ import potterSearch from "../functions/potterSearch.js";
11
+
12
+ /** query tools */
13
+ const queryTools = {
14
+ async anime_Search(refreshCallback) {
15
+ console.clear();
16
+
17
+ const query = await input({
18
+ message: "enter a anime keyword for search",
19
+ required: true
20
+ });
21
+
22
+ animeSearch(query);
23
+ setTimeout(refreshCallback, 2e3);
24
+ },
25
+ async movie_info(refreshCallback) {
26
+ console.clear();
27
+
28
+ const { query, token } = {
29
+ query: await input({
30
+ message: "enter movie for search DB",
31
+ required: true
32
+ }),
33
+ token: await password({
34
+ message: "enter a token key",
35
+ required: true,
36
+ mask: true
37
+ })
38
+ };
39
+
40
+ movieDB(query, token);
41
+ setTimeout(refreshCallback, 2e3);
42
+ },
43
+ async pokemon_info(refreshCallback) {
44
+ console.clear();
45
+
46
+ const pokeSelect = await select({
47
+ message: "enter a opt for start search",
48
+ choices: ["id", "name"],
49
+ });
50
+
51
+ const opt = pokeSelect === "id"
52
+ ? await number({
53
+ message: "enter a poekmon ID:",
54
+ min: 1,
55
+ required: true
56
+ }) : await input({
57
+ message: "enter a poekmon name:",
58
+ required: true,
59
+ validate: input => /[^0-9]/.test(input) || "the pokemon name is required"
60
+ });
61
+
62
+ pokemonInfo(opt);
63
+ setTimeout(refreshCallback, 6e3);
64
+ },
65
+ async twitch_info(refreshCallback) {
66
+ console.clear();
67
+
68
+ const { twitchSeparator, twitchUsers, twitchClient, twitchToken } = {
69
+ twitchSeparator: await input({
70
+ message: "enter a separator for split example ',':",
71
+ required: true
72
+ }),
73
+ twitchUsers: await input({
74
+ message: "enter a twitch users example 'a,b,c'",
75
+ required: true
76
+ }),
77
+ twitchClient: await password({
78
+ message: "enter a twitch client ID:",
79
+ required: true,
80
+ mask: true
81
+ }),
82
+ twitchToken: await password({
83
+ message: "enter a twitch token:",
84
+ required: true,
85
+ mask: true
86
+ })
87
+ };
88
+
89
+ twitchInfo({ twitchSeparator, twitchUsers, twitchClient, twitchToken });
90
+ setTimeout(refreshCallback, 2e3);
91
+ },
92
+ async deezer(refreshCallback) {
93
+ console.clear();
94
+
95
+ const query = await input({
96
+ message: "enter a query for search",
97
+ required: true
98
+ });
99
+
100
+ setTimeout(refreshCallback, 5e3);
101
+ deezer(query);
102
+ },
103
+ async potter_search(refreshCallback) {
104
+ console.clear();
105
+
106
+ const search = await input({
107
+ message: "enter a keyword or name for search",
108
+ required: true
109
+ });
110
+
111
+ potterSearch(search);
112
+ setTimeout(refreshCallback, 5e3);
113
+ }
114
+ };
115
+
116
+ export default queryTools;
@@ -1,19 +1,32 @@
1
- // functions
2
- import genPassword from "../functions/password.js";
3
- import hardware from "../functions/hardware.js";
4
-
5
-
6
- const utilityTools = {
7
- password(refreshCallback) {
8
- console.clear();
9
- genPassword();
10
- setTimeout(refreshCallback, 3e3);
11
- },
12
- async hardware(refreshCallback) {
13
- console.clear();
14
- hardware();
15
- setTimeout(refreshCallback, 3e3);
16
- }
17
- };
18
-
19
- export default utilityTools;
1
+ // menu
2
+ import { stackMenu } from "../menu.js";
3
+ import { pokerGameOpts } from "../utils.js";
4
+
5
+ // functions
6
+ import genPassword from "../functions/password.js";
7
+ import hardware from "../functions/hardware.js";
8
+ import pokerGame from "../functions/poker.js";
9
+
10
+ const utilityTools = {
11
+ password(refreshCallback) {
12
+ console.clear();
13
+ genPassword();
14
+ setTimeout(refreshCallback, 3e3);
15
+ },
16
+ async hardware(refreshCallback) {
17
+ console.clear();
18
+ hardware();
19
+ setTimeout(refreshCallback, 3e3);
20
+ },
21
+ async poker_game(refreshCallback) {
22
+ const pokeOpt = await stackMenu({
23
+ message: "select a poker game for view instructions:",
24
+ choices: pokerGameOpts
25
+ });
26
+
27
+ pokerGame(pokeOpt);
28
+ setTimeout(refreshCallback, 5e3);
29
+ }
30
+ };
31
+
32
+ export default utilityTools;