clone.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import _clone from "./internal/_clone.js";
  2. import _curry1 from "./internal/_curry1.js";
  3. /**
  4. * Creates a deep copy of the source that can be used in place of the source
  5. * object without retaining any references to it.
  6. * The source object may contain (nested) `Array`s and `Object`s,
  7. * `Number`s, `String`s, `Boolean`s and `Date`s.
  8. * `Function`s are assigned by reference rather than copied.
  9. *
  10. * Dispatches to a `clone` method if present.
  11. *
  12. * Note that if the source object has multiple nodes that share a reference,
  13. * the returned object will have the same structure, but the references will
  14. * be pointed to the location within the cloned value.
  15. *
  16. * @func
  17. * @memberOf R
  18. * @since v0.1.0
  19. * @category Object
  20. * @sig {*} -> {*}
  21. * @param {*} value The object or array to clone
  22. * @return {*} A deeply cloned copy of `val`
  23. * @example
  24. *
  25. * const objects = [{}, {}, {}];
  26. * const objectsClone = R.clone(objects);
  27. * objects === objectsClone; //=> false
  28. * objects[0] === objectsClone[0]; //=> false
  29. */
  30. var clone =
  31. /*#__PURE__*/
  32. _curry1(function clone(value) {
  33. return value != null && typeof value.clone === 'function' ? value.clone() : _clone(value, true);
  34. });
  35. export default clone;