UNPKG

1.06 kBJavaScriptView Raw
1var baseClone = require('./_baseClone');
2
3/** Used to compose bitmasks for cloning. */
4var CLONE_SYMBOLS_FLAG = 4;
5
6/**
7 * Creates a shallow clone of `value`.
8 *
9 * **Note:** This method is loosely based on the
10 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
11 * and supports cloning arrays, array buffers, booleans, date objects, maps,
12 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
13 * arrays. The own enumerable properties of `arguments` objects are cloned
14 * as plain objects. An empty object is returned for uncloneable values such
15 * as error objects, functions, DOM nodes, and WeakMaps.
16 *
17 * @static
18 * @memberOf _
19 * @since 0.1.0
20 * @category Lang
21 * @param {*} value The value to clone.
22 * @returns {*} Returns the cloned value.
23 * @see _.cloneDeep
24 * @example
25 *
26 * var objects = [{ 'a': 1 }, { 'b': 2 }];
27 *
28 * var shallow = _.clone(objects);
29 * console.log(shallow[0] === objects[0]);
30 * // => true
31 */
32function clone(value) {
33 return baseClone(value, CLONE_SYMBOLS_FLAG);
34}
35
36module.exports = clone;