import { TraeSettings } from './types' ; import { isValidBody } from './guards' ; function isJSON ( { headers } ) { const header = new Headers ( headers ) . get ( 'Content-Type' ) || '' ; return header . toLowerCase ( ) . includes ( 'application/json' ) ; } function createRequestBody ( content , config ) { if ( isJSON ( config ) ) { return JSON . stringify ( content ) ; } if ( isValidBody ( content ) ) { return content ; } throw new Error ( `Invalid body type: ${ typeof content }` ) ; } export default createRequestBody ;