const payloadMethods = new Set ( Object . freeze ( [ 'PATCH' , 'POST' , 'PUT' , 'DELETE' ] ) ) ; export function isPayloadMethod ( method = 'GET' ) { return payloadMethods . has ( method . toUpperCase ( ) ) ; } export function isJSONSerializable ( val ) { if ( val === undefined ) { return false ; } const t = typeof val ; if ( t === 'string' || t === 'number' || t === 'boolean' || t === null ) { return true ; } if ( t !== 'object' ) { return false ; } if ( Array . isArray ( val ) ) { return true ; } return ( val . constructor && val . constructor . name === 'Object' ) || typeof val . toJSON === 'function' ; } const textTypes = new Set ( [ 'image/svg' , 'application/xml' , 'application/xhtml' , 'application/html' ] ) ; const jsonTypes = new Set ( [ 'application/json' , 'application/ld+json' ] ) ; interface ResponseMap { blob : Blob ; text : string ; arrayBuffer : ArrayBuffer ; } export type ResponseType = keyof ResponseMap | 'json' ; export type MappedType < R extends ResponseType , JsonType = any > = R extends keyof ResponseMap ? ResponseMap [ R ] : JsonType ; export function detectResponseType ( _contentType = '' ) { if ( ! _contentType ) { return 'json' ; } const contentType = _contentType . split ( ';' ) . shift ( ) ! ; if ( jsonTypes . has ( contentType ) ) { return 'json' ; } if ( textTypes . has ( contentType ) || contentType . startsWith ( 'text/' ) ) { return 'text' ; } return 'blob' ; }