clone.js 892 B

123456789101112131415161718192021222324252627282930
  1. import { clone as objectClone } from '../../utils/object.js';
  2. import { factory } from '../../utils/factory.js';
  3. var name = 'clone';
  4. var dependencies = ['typed'];
  5. export var createClone = /* #__PURE__ */factory(name, dependencies, _ref => {
  6. var {
  7. typed
  8. } = _ref;
  9. /**
  10. * Clone an object. Will make a deep copy of the data.
  11. *
  12. * Syntax:
  13. *
  14. * math.clone(x)
  15. *
  16. * Examples:
  17. *
  18. * math.clone(3.5) // returns number 3.5
  19. * math.clone(math.complex('2-4i')) // returns Complex 2 - 4i
  20. * math.clone(math.unit(45, 'deg')) // returns Unit 45 deg
  21. * math.clone([[1, 2], [3, 4]]) // returns Array [[1, 2], [3, 4]]
  22. * math.clone("hello world") // returns string "hello world"
  23. *
  24. * @param {*} x Object to be cloned
  25. * @return {*} A clone of object x
  26. */
  27. return typed(name, {
  28. any: objectClone
  29. });
  30. });