UNPKG

@sentry/remix

Version:
41 lines (38 loc) • 1.35 kB
import { matchRoutes } from '@remix-run/router'; async function extractData(response) { const contentType = response.headers.get("Content-Type"); const responseClone = response.clone(); if (contentType && /\bapplication\/json\b/.test(contentType)) { return responseClone.json(); } return responseClone.text(); } function isResponse(value) { return value != null && /* eslint-disable @typescript-eslint/no-unsafe-member-access */ typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined"; } const json = (data, init = {}) => { const responseInit = typeof init === "number" ? { status: init } : init; const headers = new Headers(responseInit.headers); if (!headers.has("Content-Type")) { headers.set("Content-Type", "application/json; charset=utf-8"); } return new Response(JSON.stringify(data), { ...responseInit, headers }); }; function matchServerRoutes(routes, pathname) { const matches = matchRoutes(routes, pathname); if (!matches) { return null; } return matches.map((match) => ({ params: match.params, pathname: match.pathname, route: match.route, pathnameBase: match.pathnameBase })); } export { extractData, isResponse, json, matchServerRoutes }; //# sourceMappingURL=response.js.map