-
-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d369b08
commit af5c3fd
Showing
6 changed files
with
70 additions
and
61 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 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 |
---|---|---|
@@ -1,36 +1,32 @@ | ||
'use strict'; | ||
const {URL} = require('url'); | ||
const is = require('@sindresorhus/is'); | ||
|
||
module.exports = (defaults, options = {}) => { | ||
return merge({}, defaults, options); | ||
}; | ||
|
||
function merge(target, ...sources) { | ||
const 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]; | ||
for (const [key, sourceValue] of Object.entries(source)) { | ||
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) | ||
)) { | ||
|
||
const targetValue = target[key]; | ||
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 if (is.array(sourceValue)) { | ||
target[key] = merge([], sourceValue); | ||
} else { | ||
target[key] = sourceValue; | ||
} | ||
} | ||
} | ||
|
||
return target; | ||
} | ||
}; | ||
|
||
module.exports = merge; |
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