You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- options are merged using [`got.mergeOptions()`](#gotmergeoptionsparentoptions-newoptions) (+ hooks are merged too),
1138
+
- options are merged using [`got.mergeOptions()`](#gotmergeoptionsparentoptions-newoptions) (including hooks),
1139
1139
- handlers are stored in an array (you can access them through `instance.defaults.handlers`).
1140
1140
1141
-
#### got.extend(...options, ...instances, ...)
1142
-
1143
-
It's possible to combine options and instances.\
1144
-
It gives the same effect as `got.extend(...options).extend(...instances)`:
1145
-
1146
1141
```js
1147
1142
consta= {headers: {cat:'meow'}};
1148
1143
constb=got.extend({
@@ -1159,7 +1154,7 @@ got.extend(a, b);
1159
1154
//=> {headers: {cat: 'meow', cow: 'moo'}}
1160
1155
```
1161
1156
1162
-
#### got.mergeOptions(parentOptions, newOptions)
1157
+
#### got.mergeOptions(parent, ...sources)
1163
1158
1164
1159
Extends parent options. Avoid using [object spread](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_object_literals) as it doesn't work recursively:
**Note:** Only Got options are merged! Custom user options should be defined via [`options.context`](#context).
1170
+
1174
1171
Options are deeply merged to a new object. The value of each key is determined as follows:
1175
1172
1176
-
- If the new property is set to `undefined`, it keeps the old one.
1177
-
- If both properties are an instances of `URLSearchParams`, a new URLSearchParams instance is created. The values are merged using [`urlSearchParams.append(key, value)`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/append).
1178
-
- If the parent property is an instance of `URL` and the new value is a `string` or `URL`, a new URL instance is created: [`new URL(new, parent)`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#Syntax).
1173
+
- If the new property is not defined, the old value is used.
1174
+
- If the new property is explicitly set to `undefined`:
1175
+
- If the parent property is a plain `object`, the parent value is deeply cloned.
1176
+
- Otherwise, `undefined` is used.
1177
+
- If the parent value is an instance of `URLSearchParams`:
1178
+
- If the new value is a `string`, an `object` or an instance of `URLSearchParams`, a new `URLSearchParams` instance is created. The values are merged using [`urlSearchParams.append(key, value)`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/append).
1179
+
- Otherwise, the only available value is `undefined`.
1179
1180
- If the new property is a plain `object`:
1180
1181
- If the parent property is a plain `object` too, both values are merged recursively into a new `object`.
1181
1182
- Otherwise, only the new value is deeply cloned.
1182
1183
- If the new property is an `Array`, it overwrites the old one with a deep clone of the new property.
1183
1184
- Properties that are not enumerable, such as `context`, `body`, `json`, and `form`, will not be merged.
1185
+
- Otherwise, the new value is assigned to the key.
1186
+
1184
1187
```js
1185
1188
consta= {json: {cat:'meow'}};
1186
1189
constb= {json: {cow:'moo'}};
1187
1190
1188
1191
got.mergeOptions(a, b);
1189
1192
//=> {json: {cow: 'moo'}}
1190
1193
```
1191
-
- Otherwise, the new value is assigned to the key.
1192
1194
1193
1195
#### got.defaults
1194
1196
@@ -1203,7 +1205,7 @@ The Got defaults used in that instance.
1203
1205
Type: `Function[]`\
1204
1206
Default: `[]`
1205
1207
1206
-
An array of functions. You execute them directly by calling `got()`. They are some sort of "global hooks" - these functions are called first. The last handler (*it's hidden*) is either [`asPromise`](source/as-promise.ts) or [`asStream`](source/as-stream.ts), depending on the `options.isStream` property.
1208
+
An array of functions. You execute them directly by calling `got()`. They are some sort of "global hooks" - these functions are called first. The last handler (*it's hidden*) is either [`asPromise`](source/core/as-promise/index.ts) or [`asStream`](source/core/index.ts), depending on the `options.isStream` property.
0 commit comments