/****************************************
  HTTP Requests (fetch)
*****************************************/ const baseURL = 'http://localhost:3333' ; type Data = { [ key ] : any ; } ; export function get < T > ( path ) { return fetch ( `${ baseURL }${ path }` ) . then ( ( res ) => res . json ( ) ) ; } export function getRaw ( path ) { return fetch ( `${ baseURL }${ path }` ) ; } export function post < T > ( path , data ) { return fetch ( `${ baseURL }${ path }` , { method : 'POST' , body : JSON . stringify ( data ) , headers : { 'Content-Type' : 'application/json' , } , } ) . then ( ( res ) => res . json ( ) ) ; } export function put < T > ( path , data ) { return fetch ( `${ baseURL }${ path }` , { method : 'PUT' , body : JSON . stringify ( data ) , headers : { 'Content-Type' : 'application/json' , } , } ) . then ( ( res ) => res . json ( ) ) ; } export function patch < T > ( path , data ) { return fetch ( `${ baseURL }${ path }` , { method : 'PATCH' , body : JSON . stringify ( data ) , headers : { 'Content-Type' : 'application/json' , } , } ) . then ( ( res ) => res . json ( ) ) ; } export function httpDelete < T > ( path ) { return fetch ( `${ baseURL }${ path }` , { method : 'DELETE' , headers : { 'Content-Type' : 'application/json' , } , } ) . then ( ( res ) => res . json ( ) ) ; } /****************************************
  Arrays
*****************************************/ export function shuffle ( array ) { if ( ! array || array . length === 0 ) return [ ] ; let currentIndex = array . length , temporaryValue , randomIndex ; while ( 0 !== currentIndex ) { randomIndex = Math . floor ( Math . random ( ) * currentIndex ) ; currentIndex -= 1 ; temporaryValue = array [ currentIndex ] ; array [ currentIndex ] = array [ randomIndex ] ; array [ randomIndex ] = temporaryValue ; } return array ; }