UNPKG

@sentry/remix

Version:
46 lines (42 loc) • 1.51 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const router = require('@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 = router.matchRoutes(routes, pathname); if (!matches) { return null; } return matches.map((match) => ({ params: match.params, pathname: match.pathname, route: match.route, pathnameBase: match.pathnameBase })); } exports.extractData = extractData; exports.isResponse = isResponse; exports.json = json; exports.matchServerRoutes = matchServerRoutes; //# sourceMappingURL=response.js.map