/**
 * A JSON response. Converts `data` to JSON and sets the `Content-Type` header.
 */ export function json < Data > ( data , init = { } ) { let responseInit = init ; if ( typeof init === "number" ) { responseInit = { status : init } ; } let 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 } ) ; } /**
 * A redirect response. Sets the status code and the `Location` header.
 * Defaults to "302 Found".
 */ export function redirect ( url , init = 302 ) { let responseInit = init ; if ( typeof responseInit === "number" ) { responseInit = { status : responseInit } ; } else if ( typeof responseInit . status === "undefined" ) { responseInit . status = 302 ; } let headers = new Headers ( responseInit . headers ) ; headers . set ( "Location" , url ) ; return new Response ( null , { ... responseInit , headers } ) ; } export function isResponse ( value ) { return ( value != null && typeof value . status === "number" && typeof value . statusText === "string" && typeof value . headers === "object" && typeof value . body !== "undefined" ) ; } const redirectStatusCodes = new Set ( [ 301 , 302 , 303 , 307 , 308 ] ) ; export function isRedirectResponse ( response ) { return redirectStatusCodes . has ( response . status ) ; } export function isCatchResponse ( response ) { return response . headers . get ( "X-Remix-Catch" ) != null ; } export function extractData ( response ) { let contentType = response . headers . get ( "Content-Type" ) ; if ( contentType && /\bapplication\/json\b/ . test ( contentType ) ) { return response . json ( ) ; } return response . text ( ) ; }