Skip to content

Commit

Permalink
feat: document miniget.defaultOptions
Browse files Browse the repository at this point in the history
BREAKING CHANGES: `miniget.Defaults` -> `miniget.defaultOptions`
  • Loading branch information
fent committed Nov 7, 2020
1 parent e5b5041 commit c2d7614
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -48,15 +48,15 @@ Miniget.MinigetError = class MinigetError extends Error {
}
};

Miniget.Defaults = Miniget.Options = {
Miniget.defaultOptions = {
maxRedirects: 10,
maxRetries: 2,
maxReconnects: 0,
backoff: { inc: 100, max: 10000 },
};

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;
Expand Down
9 changes: 9 additions & 0 deletions test/request-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit c2d7614

Please sign in to comment.