type AlterURLOptions = { prepend ? : string ; append ? : string ; } | { mutate ? : ( url : string ) => string ; } ; export const alterURL = ( prevFetch , options ) : typeof fetch => { let urlMutator = ( prevURL ) => prevURL ; if ( "mutate" in options ) { urlMutator = options . mutate ; } else if ( "prepend" in options || "append" in options ) { urlMutator = ( prevURL ) => `${ options . prepend || "" }${ prevURL }${ options . append || "" }` ; } return ( ... args ) => { let request = new Request ( ... args ) ; const url = urlMutator ( request . url ) ; request = new Request ( url , request ) ; return prevFetch ( request ) ; } ; } ;