diff --git a/README.md b/README.md index e9ff0fd..1421b00 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,7 @@ Makes a GET request. `options` can have any properties from the [`http.request() ``` Given encodings will be added to the `Accept-Encoding` header, and the response will be decoded if the server responds with encoded content. -If you'd like a concatenated response, use `miniget(url).text()`. - -```js -let body = await miniget('http://yourwebsite.com').text(); -``` +Defaults are held in `miniget.defaultOptions` and can be adjusted globally. Miniget returns a readable stream, errors will then be emitted on the stream. Returned stream has additional methods added, and can emit the following events. @@ -63,6 +59,10 @@ Aborts the request. Returns a promise that resolves to the concatenated contents of the response. +```js +let body = await miniget('http://yourwebsite.com').text(); +``` + #### Event: redirect * `string` - URL redirected to. diff --git a/src/index.ts b/src/index.ts index 45c926d..9f16b9e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,7 +29,7 @@ namespace Miniget { acceptEncoding?: { [key: string]: () => Transform }; } - export type Defaults = Miniget.Options; + export type defaultOptions = Miniget.Options; export type MinigetError = Error; export interface Stream extends PassThrough { @@ -48,7 +48,7 @@ Miniget.MinigetError = class MinigetError extends Error { } }; -Miniget.Defaults = Miniget.Options = { +Miniget.defaultOptions = { maxRedirects: 10, maxRetries: 2, maxReconnects: 0, @@ -56,7 +56,7 @@ Miniget.Defaults = Miniget.Options = { }; function Miniget(url: string, options: Miniget.Options = {}): Miniget.Stream { - const opts: Miniget.Options = Object.assign({}, Miniget.Defaults, options); + const opts: Miniget.Options = Object.assign({}, Miniget.defaultOptions, options); const stream = new PassThrough({ highWaterMark: opts.highWaterMark }) as Miniget.Stream; let activeRequest: ClientRequest | null; let activeDecodedStream: Transform | null; diff --git a/test/request-test.ts b/test/request-test.ts index bc734c5..2defcc0 100644 --- a/test/request-test.ts +++ b/test/request-test.ts @@ -786,3 +786,12 @@ describe('Make a request', () => { stream.resume(); }); }); + +describe('Importing the module', () => { + it('Exposes default options', () => { + assert.ok(miniget.defaultOptions); + }); + it('Exposes MinigetError', () => { + assert.ok(miniget.MinigetError); + }); +});