type Method = 'get' | 'post' | 'put' | 'delete' ; export function parseEndpoint ( endpoint ) { const parts = endpoint . split ( ' ' ) ; const method = parts [ 0 ] . trim ( ) . toLowerCase ( ) as Method ; const pathname = parts [ 1 ] . trim ( ) ; if ( ! [ 'get' , 'post' , 'put' , 'delete' ] . includes ( method ) ) { throw new Error ( 'Endpoint was not prefixed with a valid HTTP method' ) ; } return { method , pathname } ; }