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.

31 lines
649 B

4 years ago
  1. 'use strict';
  2. /**
  3. * Clone helper
  4. *
  5. * Clone an array or object
  6. *
  7. * @param items
  8. * @returns {*}
  9. */
  10. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  11. module.exports = function clone(items) {
  12. var cloned = void 0;
  13. if (Array.isArray(items)) {
  14. var _cloned;
  15. cloned = [];
  16. (_cloned = cloned).push.apply(_cloned, _toConsumableArray(items));
  17. } else {
  18. cloned = {};
  19. Object.keys(items).forEach(function (prop) {
  20. cloned[prop] = items[prop];
  21. });
  22. }
  23. return cloned;
  24. };