copier.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.copy = copy;
  6. var _copy_map = _interopRequireDefault(require("./copy_map.js"));
  7. var _detector = require("./detector.js");
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * no operation
  11. */
  12. function noop() {}
  13. /**
  14. * copy value
  15. *
  16. * @param {*} value
  17. * @param {string} [type=null]
  18. * @param {Function} [customizer=noop]
  19. * @return {*}
  20. */
  21. function copy(value, type = null, customizer = noop) {
  22. if (arguments.length === 2 && typeof type === 'function') {
  23. customizer = type;
  24. type = null;
  25. }
  26. const valueType = type || (0, _detector.detectType)(value);
  27. const copyFunction = _copy_map.default.get(valueType);
  28. if (valueType === 'Object') {
  29. const result = customizer(value, valueType);
  30. if (result !== undefined) {
  31. return result;
  32. }
  33. } // NOTE: TypedArray needs pass type to argument
  34. return copyFunction ? copyFunction(value, valueType) : value;
  35. }
  36. //# sourceMappingURL=copier.js.map