-
-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
got.mergeOptions()
behavior more obvious and document its beha…
…vior (#538)
- Loading branch information
1 parent
6d654fa
commit d369b08
Showing
9 changed files
with
110 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const {URL} = require('url'); | ||
const is = require('@sindresorhus/is'); | ||
|
||
module.exports = (defaults, options = {}) => { | ||
return merge({}, defaults, options); | ||
}; | ||
|
||
function merge(target, ...sources) { | ||
for (const source of sources) { | ||
const sourceIter = is.array(source) ? | ||
source.entries() : | ||
Object.entries(source); | ||
for (const [key, sourceValue] of sourceIter) { | ||
const targetValue = target[key]; | ||
if (is.undefined(sourceValue)) { | ||
continue; | ||
} | ||
if (is.array(sourceValue)) { | ||
target[key] = merge(new Array(sourceValue.length), sourceValue); | ||
} else if (is.urlInstance(targetValue) && ( | ||
is.urlInstance(sourceValue) || is.string(sourceValue) | ||
)) { | ||
target[key] = new URL(sourceValue, targetValue); | ||
} else if (is.plainObject(sourceValue)) { | ||
if (is.plainObject(targetValue)) { | ||
target[key] = merge({}, targetValue, sourceValue); | ||
} else { | ||
target[key] = merge({}, sourceValue); | ||
} | ||
} else { | ||
target[key] = sourceValue; | ||
} | ||
} | ||
} | ||
return target; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters