You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
906 B

4 years ago
  1. import _clone from "./internal/_clone.js";
  2. import _curry1 from "./internal/_curry1.js";
  3. /**
  4. * Creates a deep copy of the value which may contain (nested) `Array`s and
  5. * `Object`s, `Number`s, `String`s, `Boolean`s and `Date`s. `Function`s are
  6. * assigned by reference rather than copied
  7. *
  8. * Dispatches to a `clone` method if present.
  9. *
  10. * @func
  11. * @memberOf R
  12. * @since v0.1.0
  13. * @category Object
  14. * @sig {*} -> {*}
  15. * @param {*} value The object or array to clone
  16. * @return {*} A deeply cloned copy of `val`
  17. * @example
  18. *
  19. * const objects = [{}, {}, {}];
  20. * const objectsClone = R.clone(objects);
  21. * objects === objectsClone; //=> false
  22. * objects[0] === objectsClone[0]; //=> false
  23. */
  24. var clone =
  25. /*#__PURE__*/
  26. _curry1(function clone(value) {
  27. return value != null && typeof value.clone === 'function' ? value.clone() : _clone(value, [], [], true);
  28. });
  29. export default clone;