forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloneDeepWith.js
38 lines (35 loc) · 1014 Bytes
/
cloneDeepWith.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import baseClone from './.internal/baseClone.js'
/** Used to compose bitmasks for cloning. */
const CLONE_DEEP_FLAG = 1
const CLONE_SYMBOLS_FLAG = 4
/**
* This method is like `cloneWith` except that it recursively clones `value`.
*
* @since 4.0.0
* @category Lang
* @param {*} value The value to recursively clone.
* @param {Function} [customizer] The function to customize cloning.
* @returns {*} Returns the deep cloned value.
* @see cloneWith
* @example
*
* function customizer(value) {
* if (isElement(value)) {
* return value.cloneNode(true)
* }
* }
*
* const el = cloneDeepWith(document.body, customizer)
*
* console.log(el === document.body)
* // => false
* console.log(el.nodeName)
* // => 'BODY'
* console.log(el.childNodes.length)
* // => 20
*/
function cloneDeepWith(value, customizer) {
customizer = typeof customizer == 'function' ? customizer : undefined
return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer)
}
export default cloneDeepWith