stack-analyze 1.2.0 → 1.2.1

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/index.cjs CHANGED
@@ -11,15 +11,24 @@ const {
11
11
  const Wappalyzer = require("wappalyzer");
12
12
  const cheerio = require("cheerio");
13
13
 
14
+ const gigabyteConvert = (size, base=1073741824) => (size / base).toFixed(2);
15
+
16
+ const wappalyzer = new Wappalyzer();
17
+
18
+ const pagespeedApi = async (url, strategy) => await axios.get("https://www.googleapis.com/pagespeedonline/v5/runPagespeed", {
19
+ params: {
20
+ url,
21
+ key: "AIzaSyBEDaW4FxSZ2s1vz5CdD5Ai6PGZGdAzij0",
22
+ strategy
23
+ }
24
+ });
25
+
14
26
  const animeSearch = async ({ query, results, failed }) => {
15
27
  /* error manager */
16
28
  try {
17
29
  // call api
18
30
  const { data } = await axios.get("https://api.jikan.moe/v/anime", {
19
- params: {
20
- q: query,
21
- limit: 10
22
- }
31
+ params: { q: query }
23
32
  });
24
33
 
25
34
  results(data.results);
@@ -31,9 +40,7 @@ const bitlyInfo = async ({ link, token, results, failed }) => {
31
40
  try {
32
41
  const { data } = await axios.post(
33
42
  "https://api-ssl.bitly.com/v4/expand",
34
- {
35
- bitlink_id: link
36
- },
43
+ { bitlink_id: link },
37
44
  {
38
45
  headers: {
39
46
  Authorization: `Bearer ${token}`,
@@ -112,11 +119,11 @@ async function ramMemInfo(callback) {
112
119
 
113
120
  // show results
114
121
  callback({
115
- total_mem: `${(total / 1073741824).toFixed(2)} GB`,
116
- free_mem: `${(free / 1073741824).toFixed(2)} GB`,
117
- used_mem: `${(used / 1073741824).toFixed(2)} GB`,
118
- active_mem: `${(active / 1073741824).toFixed(2)} GB`,
119
- available_mem: `${(available / 1073741824).toFixed(2)} GB`
122
+ total_mem: `${gigabyteConvert(total)} GB`,
123
+ free_mem: `${gigabyteConvert(free)} GB`,
124
+ used_mem: `${gigabyteConvert(used)} GB`,
125
+ active_mem: `${gigabyteConvert(active)} GB`,
126
+ available_mem: `${gigabyteConvert(available)} GB`
120
127
  });
121
128
  } catch (err) { callback(err); }
122
129
  }
@@ -162,7 +169,7 @@ async function diskInfo(callback) {
162
169
  type,
163
170
  name,
164
171
  vendor,
165
- diskSize: `${(size / 1073741824).toFixed(2)} GB`,
172
+ diskSize: `${gigabyteConvert(size)} GB`,
166
173
  interfaceType
167
174
  }));
168
175
 
@@ -184,7 +191,7 @@ async function controllerInfo(callback) {
184
191
  vendor,
185
192
  vramSize: vram < 1024
186
193
  ? `${vram} MB`
187
- : `${(vram / 1024).toFixed(2)} GB`
194
+ : `${gigabyteConvert(vram, 1024)} GB`
188
195
  }));
189
196
 
190
197
  callback(controllersList);
@@ -229,11 +236,7 @@ async function biosInfo(callback) {
229
236
  const movieDB = async ({ api_key, query, results, failed }) => {
230
237
  try {
231
238
  const { data } = await axios.get("https://api.themoviedb.org/3/search/movie", {
232
- params: {
233
- api_key,
234
- query,
235
- page: 1
236
- }
239
+ params: { api_key, query }
237
240
  });
238
241
 
239
242
  const movieData = data.results
@@ -257,7 +260,7 @@ const movieDB = async ({ api_key, query, results, failed }) => {
257
260
 
258
261
  return primaryDate.getTime() - secondaryDate.getTime();
259
262
  })
260
- .filter(({ release_date }) => release_date !== undefined && release_date !== "");
263
+ .filter((data) => data?.release_date);
261
264
 
262
265
  results(movieData);
263
266
  } catch (err) { failed(err); }
@@ -265,7 +268,6 @@ const movieDB = async ({ api_key, query, results, failed }) => {
265
268
 
266
269
  async function multipleStack({ urls, results, failed }) {
267
270
  let result;
268
- const wappalyzer = new Wappalyzer();
269
271
  try {
270
272
  await wappalyzer.init();
271
273
  result = await Promise.all(
@@ -284,21 +286,9 @@ async function multipleStack({ urls, results, failed }) {
284
286
 
285
287
  const pageSpeed = async ({ url, results, failed }) => {
286
288
  try {
287
- const resMobile = await axios.get("https://www.googleapis.com/pagespeedonline/v5/runPagespeed", {
288
- params: {
289
- url,
290
- key: "AIzaSyBEDaW4FxSZ2s1vz5CdD5Ai6PGZGdAzij0",
291
- strategy: "mobile"
292
- }
293
- });
289
+ const resMobile = await pagespeedApi(url, "mobile");
294
290
 
295
- const resDesktop = await axios.get("https://www.googleapis.com/pagespeedonline/v5/runPagespeed", {
296
- params: {
297
- url,
298
- key: "AIzaSyBEDaW4FxSZ2s1vz5CdD5Ai6PGZGdAzij0",
299
- strategy: "desktop"
300
- }
301
- });
291
+ const resDesktop = await pagespeedApi(url, "desktop");
302
292
 
303
293
  // extract results
304
294
  const mobile = Math.round(resMobile.data.lighthouseResult.categories.performance.score * 100);
@@ -309,9 +299,8 @@ const pageSpeed = async ({ url, results, failed }) => {
309
299
  };
310
300
 
311
301
  async function singleStack({ url, results, failed }) {
312
- const wappalyzer = await new Wappalyzer;
313
-
314
302
  let result;
303
+
315
304
  try {
316
305
  await wappalyzer.init();
317
306
 
@@ -334,8 +323,9 @@ async function singleStack({ url, results, failed }) {
334
323
 
335
324
  async function twitchInfo({ query, token, clientID, results, failed }) {
336
325
  try {
337
- const { data: twitchData } = await axios.get(`https://api.twitch.tv/helix/users?login=${query}`,
326
+ const { data: twitchData } = await axios.get("https://api.twitch.tv/helix/users",
338
327
  {
328
+ params: { login: query },
339
329
  headers: {
340
330
  Authorization: `Bearer ${token}`,
341
331
  "Client-Id": clientID
@@ -346,131 +336,95 @@ async function twitchInfo({ query, token, clientID, results, failed }) {
346
336
  } catch (err) { failed(err); }
347
337
  }
348
338
 
349
- function scrape(url) {
350
- let $;
351
-
352
- const scraping = axios.create({
353
- baseURL: url
354
- });
355
-
356
- const title = async ({results, failed}) => {
357
- try {
358
- const { data } = await scraping.get(url);
359
- $ = cheerio.load(data);
360
-
361
- results($("title").text());
362
- } catch (err) { failed(err); }
363
- };
364
-
365
- const images = async ({results, failed}) => {
366
- try {
367
- const { data } = await scraping.get(url);
368
- $ = cheerio.load(data);
369
-
370
- const imgs = $("img").map((i, el) => ({
371
- imagePath: $(el).attr("src"),
372
- imageTitle: $(el).attr("alt")
373
- })).toArray();
374
-
375
- results(imgs);
376
- } catch (err) { failed(err); }
377
- };
378
-
379
- const metadata = async ({results, failed}) => {
380
- try {
381
- const { data } = await scraping.get(url);
382
- $ = cheerio.load(data);
383
-
384
- const metadataList = $("meta").map((i, el) => ({
385
- metaInfo: $(el).attr("name"),
386
- metaContent: $(el).attr("content")
387
- })).toArray()
388
- .filter(({ metaInfo }) => metaInfo !== undefined);
389
-
390
- results(metadataList);
391
- } catch (err) { failed(err); }
392
- };
393
-
394
- const headings = async ({results, failed}) => {
395
- try {
396
- const { data } = await scraping.get(url);
397
- $ = cheerio.load(data);
398
-
399
- const headingList = $("h1, h2, h3, h4, h5, h6").map((i, el) => ({
400
- headingTag: $(el).prop("tagName"),
401
- headingText: $(el).text()
402
- })).toArray();
403
-
404
- results(headingList);
405
- } catch (err) { failed(err); }
406
- };
407
-
408
- const table_heading = async ({results, failed}) => {
409
- try {
410
- const { data } = await scraping.get(url);
411
- $ = cheerio.load(data);
412
-
413
- const tableHeadList = $("th").map((i, el) => ({
414
- headingRow: i,
415
- text: $(el).text()
416
- })).toArray();
417
-
418
- results(tableHeadList);
419
- } catch (err) { failed(err); }
420
- };
421
-
422
- const table_data = async ({results, failed}) => {
423
- try {
424
- const { data } = await scraping.get(url);
425
- $ = cheerio.load(data);
426
-
427
- const tableColumnList = $("td").map((i, el) => $(el).text()).toArray();
428
-
429
- results(tableColumnList);
430
- } catch (err) { failed(err); }
431
- };
432
-
433
-
434
- const links = async ({results, failed}) => {
435
- try {
436
- const { data } = await scraping.get(url);
437
- $ = cheerio.load(data);
438
-
439
- const linkList = $("a").map((i, el) => ({
440
- url: $(el).attr("href"),
441
- text: $(el).text()
442
- })).toArray()
443
- .filter(({ url }) => url.indexOf("#") !== 0);
444
-
445
- results(linkList);
446
- } catch (err) { failed(err); }
447
- };
448
-
449
- const cites = async ({results, failed}) => {
450
- try {
451
- const { data } = await scraping.get(url);
452
- $ = cheerio.load(data);
453
-
454
- const citeList = $("q, blockquote").map((i, el) => ({
455
- citeTag: $(el).prop("tagName"),
456
- citeLink: $(el).attr("cite"),
457
- citeText: $(el).text()
458
- })).toArray();
459
-
460
- results(citeList);
461
- } catch (err) { failed(err); }
462
- };
463
-
464
- return {
465
- title,
466
- images,
467
- metadata,
468
- headings,
469
- table_heading,
470
- table_data,
471
- links,
472
- cites
473
- };
339
+ async function scrape({url, options, results, failed}) {
340
+ let scrapingResult;
341
+
342
+ try {
343
+ const { data } = await axios.get(url);
344
+ const $ = cheerio.load(data);
345
+
346
+ const scraping = {
347
+ title() {
348
+ results($("title").text());
349
+ },
350
+ images() {
351
+ const imageList = $("img").map((i, el) => ({
352
+ imagePath: $(el).attr("src"),
353
+ imageTitle: $(el).attr("alt")
354
+ })).toArray();
355
+
356
+ scrapingResult = imageList.length === 0
357
+ ? "no found images"
358
+ : imageList;
359
+
360
+ results(scrapingResult);
361
+ },
362
+ metadata() {
363
+ const metadataList = $("meta").map((i, el) => ({
364
+ metaInfo: $(el).attr("name"),
365
+ metaContent: $(el).attr("content")
366
+ })).toArray()
367
+ .filter((data) => data?.metaInfo);
368
+
369
+ results(metadataList);
370
+ },
371
+ headings() {
372
+ const headingList = $("h1, h2, h3, h4, h5, h6").map((i, el) => ({
373
+ headingTag: $(el).prop("tagName"),
374
+ headingText: $(el).text()
375
+ })).toArray();
376
+
377
+ results(headingList);
378
+ },
379
+ tableHead() {
380
+ const tableHeadList = $("th").map((i, el) => ({
381
+ headingRow: i,
382
+ text: $(el).text()
383
+ })).toArray();
384
+
385
+ scrapingResult = tableHeadList.length === 0
386
+ ? "no found th tags" : tableHeadList;
387
+
388
+ results(scrapingResult);
389
+ },
390
+ tableData() {
391
+ const tableColumnList = $("td").map((i, el) => ({
392
+ tableRow: i + 1,
393
+ tableData: $(el).text(),
394
+ })).toArray();
395
+
396
+ scrapingResult = tableColumnList.length === 0
397
+ ? "no found td tags" : tableColumnList;
398
+
399
+ results(scrapingResult);
400
+ },
401
+ links() {
402
+ const linkList = $("a").map((i, el) => ({
403
+ url: $(el).attr("href"),
404
+ text: $(el).text()
405
+ })).toArray()
406
+ .filter(({ url }) => url.indexOf("#") !== 0);
407
+
408
+ results(linkList);
409
+ },
410
+ cites() {
411
+ const citeList = $("q, blockquote").map((i, el) => ({
412
+ citeTag: $(el).prop("tagName"),
413
+ citeLink: $(el).attr("cite"),
414
+ citeText: $(el).text()
415
+ })).toArray();
416
+
417
+ scrapingResult = citeList.length === 0
418
+ ? "no found q and/or blockquote tags" : citeList;
419
+
420
+ results(scrapingResult);
421
+ }
422
+ };
423
+
424
+ scraping[options]();
425
+ } catch (err) {
426
+ failed(err.message);
427
+ }
474
428
  }
475
429
 
476
430
  const password = () => {