From 7631d344e52a87025cdccbc233d9b6ae44244fcd Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:27:16 +0800 Subject: [PATCH] add response downloading --- scripts/net.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/net.js diff --git a/scripts/net.js b/scripts/net.js new file mode 100644 index 0000000..263d328 --- /dev/null +++ b/scripts/net.js @@ -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; +}