-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.js
40 lines (35 loc) · 833 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Useful functions.
*
* Authors : Corentin Forler, Pierre Sibut-Bourde, 2021.
*/
const got = require('got');
const { JSDOM } = require('jsdom');
/**
* @param {string} url
* @returns {string} html
*/
module.exports.fetchHtml = async (url) => {
const response = await got(url);
return response.body;
};
/**
* @param {string} html
* @returns {Document} document
*/
module.exports.parseHtml = (html) => {
return (new JSDOM(html)).window.document;
};
/**
* @param {unknown[][]} arrays
* @returns {unknown[]}
*/
module.exports.flatten = (arrays) => {
return Array.prototype.concat(...arrays);
};
/**
* The zip() function takes arrays and aggregates them in a list of tuples
* @param {any[][]} rows
* @returns {any[][]}
*/
module.exports.zip = (...rows) => rows[0].map((_, c) => rows.map(row => row[c]));