quick-res
Version:
A set of small utilities that makes Response. q.json(), q.text(), q.html(), .... can make your code shorter and more readable while also providing good support for Tree-Shaking.
33 lines (32 loc) • 929 B
JavaScript
// index.ts
function o({ e: i, n: a, s: c } = {}) {
return function(e, n, s) {
if (a && e && (e = a(e)), n && typeof n != "number")
return new Response(e, n);
let u = c ?? n ?? 200, t = new Headers();
if (s)
for (let [r, p] of s instanceof Headers ? s.entries() : Object.entries(s))
if (typeof p == "string")
t.set(r, p);
else
for (let f of p)
t.append(r, f);
return i && t.set("content-type", i), new Response(e, {
status: u,
headers: t
});
};
}
var R = /* @__PURE__ */ o(), l = /* @__PURE__ */ o({
e: "text/plain; charset=UTF-8"
}), d = /* @__PURE__ */ o({
e: "application/json; charset=UTF-8",
n: JSON.stringify
}), x = /* @__PURE__ */ o({ e: "text/html; charset=UTF-8" }), T = () => /* @__PURE__ */ new Response("Not found", { status: 404 });
export {
x as html,
d as json,
T as notFound,
R as resp,
l as text
};