index.d.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. export type XhrCallback = (
  2. error: Error,
  3. response: XhrResponse,
  4. body: any
  5. ) => void;
  6. export interface XhrResponse {
  7. body: Object | string;
  8. statusCode: number;
  9. method: string;
  10. headers: XhrHeaders;
  11. url: string;
  12. rawRequest: XMLHttpRequest;
  13. }
  14. export interface XhrHeaders {
  15. [key: string]: string;
  16. }
  17. export interface XhrBaseConfig {
  18. useXDR?: boolean;
  19. sync?: boolean;
  20. method?: 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'POST' | 'PUT' | 'PATCH';
  21. timeout?: number;
  22. headers?: XhrHeaders;
  23. body?: string | any;
  24. json?: boolean;
  25. username?: string;
  26. password?: string;
  27. withCredentials?: boolean;
  28. responseType?: '' | 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
  29. beforeSend?: (xhrObject: XMLHttpRequest) => void;
  30. xhr?: XMLHttpRequest;
  31. }
  32. export interface XhrUriConfig extends XhrBaseConfig {
  33. uri: string;
  34. }
  35. export interface XhrUrlConfig extends XhrBaseConfig {
  36. url: string;
  37. }
  38. export interface XhrInstance {
  39. (options: XhrUriConfig | XhrUrlConfig, callback: XhrCallback): any;
  40. (url: string, callback: XhrCallback): any;
  41. (url: string, options: XhrBaseConfig, callback: XhrCallback): any;
  42. }
  43. export interface XhrStatic extends XhrInstance {
  44. del: XhrInstance;
  45. get: XhrInstance;
  46. head: XhrInstance;
  47. patch: XhrInstance;
  48. post: XhrInstance;
  49. put: XhrInstance;
  50. }
  51. declare const Xhr: XhrStatic;
  52. export default Xhr;