forked from bryan-hunter/deepmerge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move options stuff to its own file
- Loading branch information
Rebecca Stevens
committed
Nov 16, 2020
1 parent
35340cf
commit b726634
Showing
2 changed files
with
32 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import isPlainObj from "is-plain-obj" | ||
|
||
import { cloneUnlessOtherwiseSpecified } from "./utils" | ||
|
||
function defaultIsMergeable(value) { | ||
return Array.isArray(value) || isPlainObj(value) | ||
} | ||
|
||
function defaultArrayMerge(target, source, options) { | ||
return [...target, ...source].map((element) => | ||
cloneUnlessOtherwiseSpecified(element, options) | ||
) | ||
} | ||
|
||
export function getFullOptions(options) { | ||
const overrides = | ||
options === undefined | ||
? undefined | ||
: (Object.fromEntries( | ||
// Filter out keys explicitly set to undefined. | ||
Object.entries(options).filter(([key, value]) => value !== undefined) | ||
)) | ||
|
||
return { | ||
arrayMerge: defaultArrayMerge, | ||
isMergeable: defaultIsMergeable, | ||
clone: true, | ||
...overrides, | ||
cloneUnlessOtherwiseSpecified | ||
}; | ||
} |