index.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>
  2. // Leon Yu <https://github.com/leonyu>
  3. // BendingBender <https://github.com/BendingBender>
  4. // Maple Miao <https://github.com/mapleeit>
  5. /// <reference types="node" />
  6. import * as stream from 'stream';
  7. import * as http from 'http';
  8. export = FormData;
  9. // Extracted because @types/node doesn't export interfaces.
  10. interface ReadableOptions {
  11. highWaterMark?: number;
  12. encoding?: string;
  13. objectMode?: boolean;
  14. read?(this: stream.Readable, size: number): void;
  15. destroy?(this: stream.Readable, error: Error | null, callback: (error: Error | null) => void): void;
  16. autoDestroy?: boolean;
  17. }
  18. interface Options extends ReadableOptions {
  19. writable?: boolean;
  20. readable?: boolean;
  21. dataSize?: number;
  22. maxDataSize?: number;
  23. pauseStreams?: boolean;
  24. }
  25. declare class FormData extends stream.Readable {
  26. constructor(options?: Options);
  27. append(key: string, value: any, options?: FormData.AppendOptions | string): void;
  28. getHeaders(userHeaders?: FormData.Headers): FormData.Headers;
  29. submit(
  30. params: string | FormData.SubmitOptions,
  31. callback?: (error: Error | null, response: http.IncomingMessage) => void
  32. ): http.ClientRequest;
  33. getBuffer(): Buffer;
  34. setBoundary(boundary: string): void;
  35. getBoundary(): string;
  36. getLength(callback: (err: Error | null, length: number) => void): void;
  37. getLengthSync(): number;
  38. hasKnownLength(): boolean;
  39. }
  40. declare namespace FormData {
  41. interface Headers {
  42. [key: string]: any;
  43. }
  44. interface AppendOptions {
  45. header?: string | Headers;
  46. knownLength?: number;
  47. filename?: string;
  48. filepath?: string;
  49. contentType?: string;
  50. }
  51. interface SubmitOptions extends http.RequestOptions {
  52. protocol?: 'https:' | 'http:';
  53. }
  54. }