Skip to content

Commit 036087a

Browse files
committed
Minor docs improvements
1 parent aface52 commit 036087a

13 files changed

+53
-55
lines changed

documentation/1-promise.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Although in order to support cancelation, [`PCancelable`](https://github.com/sin
1111

1212
**Returns: <code>Promise<[Response](response.md)>**</code>
1313

14-
The most common way is to pass the `URL` as the first argument, then the options as the second.
14+
The most common way is to pass the URL as the first argument, then the options as the second.
1515

1616
```js
1717
import got from 'got';
@@ -30,7 +30,7 @@ const {headers} = await got(
3030

3131
**Returns: <code>Promise<[Response](3-streams.md#response-1)>**</code>
3232

33-
Eventually, you can pass only options containing a `url` property.
33+
Alternatively, you can pass only options containing a `url` property.
3434

3535
```js
3636
import got from 'got';

documentation/10-instances.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The options used for this instance.
2020
(options: Options, next: …) => next(options)
2121
```
2222

23-
An array of handlers. The `next` funtion returns a [`Promise`](1-promise.md) or a [`Request` Got stream](3-streams.md).
23+
An array of handlers. The `next` function returns a [`Promise`](1-promise.md) or a [`Request` Got stream](3-streams.md).
2424

2525
You execute them directly by calling `got(…)`. They are some sort of "global hooks" - these functions are called first. The last handler (it's invisible) is either `asPromise` or `asStream`, depending on the `options.isStream` property.
2626

@@ -29,7 +29,7 @@ You execute them directly by calling `got(…)`. They are some sort of "global h
2929
**Type: `boolean`**\
3030
**Default: `false`**
3131

32-
Determines if `got.defaults.options` can be modified.
32+
Determines whether `got.defaults.options` can be modified.
3333

3434
### `got.extend(…options, …instances)`
3535

@@ -70,21 +70,21 @@ console.log(headers2['x-lorem']); //=> 'impsum'
7070
**Note:**
7171
> - Handlers can be asynchronous and can return a `Promise`, but never a `Promise<Stream>`.
7272
> - Streams must always be handled synchronously.
73-
> - In order to perform async work using streams, `beforeRequest` hook should be used instead.
73+
> - In order to perform async work using streams, the `beforeRequest` hook should be used instead.
7474
7575
The recommended approach for creating handlers that can handle both promises and streams is:
7676

7777
```js
7878
import got from 'got';
7979

80-
// Create a non-async handler, but we can return a Promise later
80+
// Create a non-async handler, but we can return a Promise later.
8181
const handler = (options, next) => {
8282
if (options.isStream) {
8383
// It's a Stream, return synchronously.
8484
return next(options);
8585
}
8686

87-
// For asynchronous work return a Promise
87+
// For asynchronous work, return a Promise.
8888
return (async () => {
8989
try {
9090
const response = await next(options);

documentation/2-options.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ It is made of getters and setters that provide fast option normalization and val
1010
#### Merge behavior explained
1111

1212
When an option is already set, setting it again replaces it with a deep clone by default.\
13-
Otherwise the merge behavior is documented in the correspoding section for the option.
13+
Otherwise the merge behavior is documented in the corresponding section for the option.
1414

1515
#### How to store options
1616

@@ -60,7 +60,7 @@ In the second example, it would throw only when the promise is being executed.
6060
For TypeScript users, `got` exports a dedicated type called `OptionsInit`.\
6161
It is a plain object that can store the same properties as `Options`.
6262

63-
Performance-wise there is no difference which one is used, although the construtor may be prefferred as it automatically validates the data.\
63+
Performance-wise there is no difference which one is used, although the constructor may be preferred as it automatically validates the data.\
6464
The `Options` approach may give a slight boost as it only clones the options, there is no normalization going on.\
6565
It is also useful for storing the base configuration of a custom Got client.
6666

@@ -585,7 +585,7 @@ See [ToughCookie API](https://github.com/salesforce/tough-cookie#getcookiestring
585585
**Default: `false`**
586586

587587
Ignore invalid cookies instead of throwing an error.\
588-
Only useful when the cookieJar option has been set.
588+
Only useful when the `cookieJar` option has been set.
589589

590590
#### **Note:**
591591
> - This is not recommended! Use at your own risk.
@@ -599,7 +599,7 @@ Defines if redirect responses should be followed automatically.
599599

600600
#### **Note:**
601601
> - If a `303` is sent by the server in response to any request type (POST, DELETE, etc.), Got will automatically request the resource pointed to in the location header via GET.\
602-
> This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4).
602+
> This is in accordance with the [specification](https://tools.ietf.org/html/rfc7231#section-6.4.4).
603603
604604
```js
605605
import got from 'got';
@@ -673,7 +673,7 @@ Useful when making lots of requests to different public hostnames.
673673
**Type: `4 | 6`**\
674674
**Default: `undefined`**
675675

676-
The IP version to use. Choosing `undefined` will use the default configuration.
676+
The IP version to use. Specifying `undefined` will use the default configuration.
677677

678678
### `request`
679679

documentation/4-pagination.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ This is where you should do the parsing.
105105

106106
The function takes an object with the following properties:
107107

108-
- `response` - the current response object,
109-
- `currentItems` - items from the current response,
110-
- `allItems` - an empty array, unless `stackAllItems` is `true`, otherwise it contains all emitted items.
108+
- `response` - The current response object,
109+
- `currentItems` - Items from the current response,
110+
- `allItems` - An empty array, unless `stackAllItems` is `true`, otherwise it contains all emitted items.
111111

112112
It should return an object representing Got options pointing to the next page. If there is no next page, `false` should be returned instead.
113113

documentation/5-https.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ This option represents the options used to make HTTPS requests.
1313
**Type: `string[]`**\
1414
**Default: `['http/1.1']`**
1515

16-
Acceptable ALPN protocols.
16+
Acceptable [ALPN](https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation) protocols.
1717

18-
If the `http2` option is `true`, defaults to `['h2', 'http/1.1']`.
18+
If the `http2` option is `true`, this defaults to `['h2', 'http/1.1']`.
1919

2020
#### `rejectUnauthorized`
2121

@@ -35,7 +35,7 @@ The function must return `undefined` if the check succeeded.\
3535
If it failed, an `Error` should be returned.
3636

3737
**Note:**
38-
> - In order to have the function called the certificate must not be expired, self-signed nor with an untrusted-root.
38+
> - In order to have the function called, the certificate must not be expired, self-signed nor with an untrusted-root.
3939
4040
Check [Node.js docs](https://nodejs.org/api/https.html#https_https_request_url_options_callback) for an example.
4141

@@ -46,7 +46,7 @@ Check [Node.js docs](https://nodejs.org/api/https.html#https_https_request_url_o
4646
**Note:**
4747
> - The option has been renamed from the [`ca` TLS option](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) for better readability.
4848
49-
Overrides trusted CA certificates.
49+
Overrides trusted [CA](https://en.wikipedia.org/wiki/Certificate_authority) certificates.
5050

5151
Defaults to CAs provided by [Mozilla](https://ccadb-public.secure.force.com/mozilla/IncludedCACertificateReport).
5252

@@ -115,7 +115,7 @@ Multiple PFX can be be provided as an array of unencrypted buffers or an array o
115115
116116
### Other HTTPS options
117117

118-
The documentation for the options below is at https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
118+
[Documentation for the below options.](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)
119119

120120
- `ciphers`
121121
- `dhparam`

documentation/6-timeout.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ console.log(timings);
5959

6060
**Type: `object`**
6161

62-
This object describes maximum allowed time for particular events.
62+
This object describes the maximum allowed time for particular events.
6363

6464
#### `lookup`
6565

documentation/7-retry.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Retry API
44

55
**Note:**
6-
> If you're looking for retry implemenation using streams, check out the [Retry Stream API](3-streams.md#retry).
6+
> If you're looking for retry implementation using streams, check out the [Retry Stream API](3-streams.md#retry).
77
88
**Tip:**
99
> You can trigger a retry by throwing the [`RetryError`](8-errors.md#retryerror) in any hook.
@@ -85,13 +85,13 @@ The allowed [HTTP status codes](https://developer.mozilla.org/en-US/docs/Web/HTT
8585

8686
The allowed error codes to retry on.
8787

88-
- `ETIMEDOUT` - one of the [timeout limits](6-timeout.md) was reached.
89-
- `ECONNRESET`- the connection was forcibly closed.
90-
- `EADDRINUSE`- could not bind to any free port.
91-
- `ECONNREFUSED`- the connection was refused by the server.
92-
- `EPIPE` - the remote side of the stream being written has been closed.
93-
- `ENOTFOUND` - couldn't resolve the hostname to an IP address.
94-
- `ENETUNREACH` - no internet connection.
88+
- `ETIMEDOUT` - One of the [timeout limits](6-timeout.md) was reached.
89+
- `ECONNRESET`- The connection was forcibly closed.
90+
- `EADDRINUSE`- Could not bind to any free port.
91+
- `ECONNREFUSED`- The connection was refused by the server.
92+
- `EPIPE` - The remote side of the stream being written has been closed.
93+
- `ENOTFOUND` - Could not resolve the hostname to an IP address.
94+
- `ENETUNREACH` - No internet connection.
9595
- `EAI_AGAIN` - DNS lookup timed out.
9696

9797
#### `maxRetryAfter`

documentation/8-errors.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Source code:
99

1010
All Got errors contain various metadata, such as:
1111

12-
- `code` - a string like `ERR_NON_2XX_3XX_RESPONSE`,
13-
- `options` - an instance of [`Options`](`2-options.md`),
14-
- `request` - an instance of Got Stream,
15-
- `response` (optional) - an instance of Got Response,
16-
- `timings` (optional) - points to `response.timings`.
12+
- `code` - A string like `ERR_NON_2XX_3XX_RESPONSE`,
13+
- `options` - An instance of [`Options`](`2-options.md`),
14+
- `request` - An instance of Got Stream,
15+
- `response` (optional) - An instance of Got Response,
16+
- `timings` (optional) - Points to `response.timings`.
1717

1818
**Note:**
19-
> - The `error.stack` property may look incomplete due the execution in async function that is trigerred by a timer.
19+
> - The `error.stack` property may look incomplete due to the execution in an async function that is triggered by a timer.
2020
> - See https://stackoverflow.com/questions/54914770/is-there-a-good-way-to-surface-error-traces-in-production-across-event-emitters
2121
2222
**Note:**

documentation/9-hooks.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ This option represents the hooks to run.
1717
(plainRequestOptions: OptionsInit, options: Options) => void
1818
```
1919

20-
Called with plain request options, right before their normalization.\
20+
Called with the plain request options, right before their normalization.\
2121
The second argument represents the current [`Options`](2-options.md) instance.
2222

2323
**Note:**
24-
> - This is called every time options get merged.
24+
> - This is called every time options are merged.
2525
2626
**Note:**
2727
> - This hook is called when a new instance of `Options` is created.
@@ -32,7 +32,7 @@ The second argument represents the current [`Options`](2-options.md) instance.
3232
3333
This is especially useful in conjunction with `got.extend()` when the input needs custom handling.
3434

35-
For example this can be used to fix typos to migrate from older versions faster.
35+
For example, this can be used to fix typos to migrate from older versions faster.
3636

3737
```js
3838
import got from 'got';
@@ -111,7 +111,7 @@ This hook is especially useful in conjunction with `got.extend()` when you want
111111
> - Got will make no further changes to the request before it is sent.
112112
113113
**Note:**
114-
> - Changing `options.json` or `options.form` has no effect on the request, you should change `options.body` instead. If needed, update the `options.headers` accordingly.
114+
> - Changing `options.json` or `options.form` has no effect on the request. You should change `options.body` instead. If needed, update the `options.headers` accordingly.
115115
116116
```js
117117
import got from 'got';
@@ -134,7 +134,7 @@ const resposne = await got.post(
134134

135135
**Tip:**
136136
> - You can indirectly override the `request` function by early returning a [`ClientRequest`-like](https://nodejs.org/api/http.html#http_class_http_clientrequest) instance or a [`IncomingMessage`-like](https://nodejs.org/api/http.html#http_class_http_incomingmessage) instance. This is very useful when creating a custom cache mechanism.
137-
> - [Read more about this tip](https://github.com/sindresorhus/got/blob/docs-v12/documentation/cache.md#advanced-caching-mechanisms).
137+
> - [Read more about this tip](cache.md#advanced-caching-mechanisms).
138138
139139
#### `beforeRedirect`
140140

@@ -176,15 +176,15 @@ const response = await got('https://example.com', {
176176
```
177177

178178
**Note:**
179-
> - When using Stream API, this hook is ignored.
179+
> - When using the Stream API, this hook is ignored.
180180
181181
**Note:**
182-
> - When retrying, `beforeRequest` hook is called afterwards.
182+
> - When retrying, the `beforeRequest` hook is called afterwards.
183183
184184
**Note:**
185-
> - If no retry occurs, `beforeError` is called instead.
185+
> - If no retry occurs, the `beforeError` hook is called instead.
186186
187-
This hook is especially useful when you want to retrieve the cause of retry.
187+
This hook is especially useful when you want to retrieve the cause of a retry.
188188

189189
```js
190190
import got from 'got';
@@ -211,7 +211,7 @@ await got('https://httpbin.org/status/500', {
211211
```
212212

213213
**Note:**
214-
> - When using Stream API, this hook is ignored.
214+
> - When using the Stream API, this hook is ignored.
215215
216216
**Note:**
217217
> - Calling the retry function will trigger `beforeRetry` hooks.

documentation/cache.md

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ console.log(response.isFromCache);
2323
Got uses [Keyv](https://github.com/lukechilds/keyv) internally to support a wide range of storage adapters. For something more scalable you could use an [official Keyv storage adapter](https://github.com/lukechilds/keyv#official-storage-adapters):
2424

2525
```
26-
$ yarn add @keyv/redis
2726
$ npm install @keyv/redis
2827
```
2928

documentation/lets-make-a-plugin.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ Let's write down the most important information:
2929

3030
Also `X-GitHub-Request-Id` may be useful for debugging.
3131

32-
8. User-Agent is required.
32+
8. The `User-Agent` header is required.
3333

3434
When we have all the necessary info, we can start mixing :cake:
3535

3636
### The root endpoint
3737

38-
Not much to do here, just extend an instance and provide the `prefixUrl` option:
38+
Not much to do here. Just extend an instance and provide the `prefixUrl` option:
3939

4040
```js
4141
import got from 'got';
@@ -206,7 +206,7 @@ The conversion is the last thing here.
206206

207207
### Rate limiting
208208

209-
Umm... `response.headers['x-ratelimit-remaining']` doesn't look good. What about `response.rateLimit.limit` instead?<br>
209+
Umm... `response.headers['x-ratelimit-remaining']` doesn't look good. What about `response.rateLimit.limit` instead?\
210210
Yeah, definitely. Since `response.headers` is an object, we can easily parse these:
211211

212212
```js

documentation/tips.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ In order to specify retriable errors, use the [Retry API](7-retry.md).
3939

4040
### Cookies
4141

42-
Got supports cookies out of box. There is no need for parsing them manually.\
42+
Got supports cookies out of box. There is no need to parse them manually.\
4343
In order to use cookies, pass a `CookieJar` instance from the [`tough-cookie`](https://github.com/salesforce/tough-cookie) package.
4444

4545
```js
@@ -98,8 +98,8 @@ Requests can also be sent via [UNIX Domain Sockets](https://serverfault.com/ques
9898
Use the following URL scheme: `PROTOCOL://unix:SOCKET:PATH`
9999

100100
- `PROTOCOL` - `http` or `https`
101-
- `SOCKET` - absolute path to a unix domain socket, for example: `/var/run/docker.sock`
102-
- `PATH` - request path, for example: `/v2/keys`
101+
- `SOCKET` - Absolute path to a unix domain socket, for example: `/var/run/docker.sock`
102+
- `PATH` - Request path, for example: `/v2/keys`
103103

104104
```js
105105
import got from 'got';
@@ -115,8 +115,8 @@ await got('unix:/var/run/docker.sock:/containers/json');
115115
Got uses the native [`http`](https://nodejs.org/api/http.html) module, which depends on the native [`net`](https://nodejs.org/api/net.html) module.\
116116
This means there are two possible ways to test:
117117

118-
1. use a mocking library like [`nock`](https://github.com/nock/nock),
119-
2. create a server.
118+
1. Use a mocking library like [`nock`](https://github.com/nock/nock),
119+
2. Create a server.
120120

121121
The first approach should cover all common use cases.\
122122
Bear in mind that it overrides the native `http` module, so bugs may occur due to the differences.

readme.md

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ For browser usage, we recommend [Ky](https://github.com/sindresorhus/ky) by the
6363
## Install
6464

6565
```
66-
$ yarn add got
6766
$ npm install got
6867
```
6968

0 commit comments

Comments
 (0)