add response downloading
This commit is contained in:
parent
3930e06f2b
commit
7631d344e5
1 changed files with 19 additions and 0 deletions
19
scripts/net.js
Normal file
19
scripts/net.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* net.js
|
||||||
|
This script provides network utilities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export async function download(URL, type) {
|
||||||
|
let connect = await fetch(URL),
|
||||||
|
data;
|
||||||
|
|
||||||
|
if (connect.ok) {
|
||||||
|
if (type ? type.includes(`json`) || type.includes(`dictionary`) : false) {
|
||||||
|
data = connect.json();
|
||||||
|
} else {
|
||||||
|
data = connect.text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the filter.
|
||||||
|
return data;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue