UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

45 lines (44 loc) 1.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const baseClone_1 = __importDefault(require("./.internal/baseClone")); /** Used to compose bitmasks for cloning. */ const CLONE_SYMBOLS_FLAG = 4; /** * This method is like `clone` except that it accepts `customizer` which * is invoked to produce the cloned value. If `customizer` returns `undefined`, * cloning is handled by the method instead. The `customizer` is invoked with * one argument (value). * * @since 5.3.0 * @category Lang * @param {*} value The value to clone. * @param {Function} [customizer] The function to customize cloning. * @returns {*} Returns the cloned value. * @see cloneDeepWith * @example * * ```js * function customizer(value) { * if (isElement(value)) { * return value.cloneNode(false) * } * } * * const el = cloneWith(document.body, customizer) * * console.log(el === document.body) * // => false * console.log(el.nodeName) * // => 'BODY' * console.log(el.childNodes.length) * // => 0 * ``` */ function cloneWith(value, customizer) { customizer = typeof customizer === "function" ? customizer : undefined; return (0, baseClone_1.default)(value, CLONE_SYMBOLS_FLAG, customizer); } exports.default = cloneWith;