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.

70 lines
2.1 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _mergeWith2 = require('lodash/mergeWith');
  6. var _mergeWith3 = _interopRequireDefault(_mergeWith2);
  7. var _isPlainObject2 = require('lodash/isPlainObject');
  8. var _isPlainObject3 = _interopRequireDefault(_isPlainObject2);
  9. var _isFunction2 = require('lodash/isFunction');
  10. var _isFunction3 = _interopRequireDefault(_isFunction2);
  11. var _cloneDeep2 = require('lodash/cloneDeep');
  12. var _cloneDeep3 = _interopRequireDefault(_cloneDeep2);
  13. exports.default = joinArrays;
  14. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15. 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); } }
  16. var isArray = Array.isArray;
  17. function joinArrays() {
  18. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  19. customizeArray = _ref.customizeArray,
  20. customizeObject = _ref.customizeObject,
  21. key = _ref.key;
  22. return function _joinArrays(a, b, k) {
  23. var newKey = key ? key + '.' + k : k;
  24. if ((0, _isFunction3.default)(a) && (0, _isFunction3.default)(b)) {
  25. return function () {
  26. return _joinArrays(a.apply(undefined, arguments), b.apply(undefined, arguments), k);
  27. };
  28. }
  29. if (isArray(a) && isArray(b)) {
  30. var customResult = customizeArray && customizeArray(a, b, newKey);
  31. return customResult || [].concat(_toConsumableArray(a), _toConsumableArray(b));
  32. }
  33. if ((0, _isPlainObject3.default)(a) && (0, _isPlainObject3.default)(b)) {
  34. var _customResult = customizeObject && customizeObject(a, b, newKey);
  35. return _customResult || (0, _mergeWith3.default)({}, a, b, joinArrays({
  36. customizeArray: customizeArray,
  37. customizeObject: customizeObject,
  38. key: newKey
  39. }));
  40. }
  41. if ((0, _isPlainObject3.default)(b)) {
  42. return (0, _cloneDeep3.default)(b);
  43. }
  44. if (isArray(b)) {
  45. return [].concat(_toConsumableArray(b));
  46. }
  47. return b;
  48. };
  49. }