join-arrays.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. var __read = (this && this.__read) || function (o, n) {
  3. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4. if (!m) return o;
  5. var i = m.call(o), r, ar = [], e;
  6. try {
  7. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  8. }
  9. catch (error) { e = { error: error }; }
  10. finally {
  11. try {
  12. if (r && !r.done && (m = i["return"])) m.call(i);
  13. }
  14. finally { if (e) throw e.error; }
  15. }
  16. return ar;
  17. };
  18. var __spreadArray = (this && this.__spreadArray) || function (to, from) {
  19. for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
  20. to[j] = from[i];
  21. return to;
  22. };
  23. var __importDefault = (this && this.__importDefault) || function (mod) {
  24. return (mod && mod.__esModule) ? mod : { "default": mod };
  25. };
  26. exports.__esModule = true;
  27. var clone_deep_1 = __importDefault(require("clone-deep"));
  28. var merge_with_1 = __importDefault(require("./merge-with"));
  29. var utils_1 = require("./utils");
  30. var isArray = Array.isArray;
  31. function joinArrays(_a) {
  32. var _b = _a === void 0 ? {} : _a, customizeArray = _b.customizeArray, customizeObject = _b.customizeObject, key = _b.key;
  33. return function _joinArrays(a, b, k) {
  34. var newKey = key ? key + "." + k : k;
  35. if (utils_1.isFunction(a) && utils_1.isFunction(b)) {
  36. return function () {
  37. var args = [];
  38. for (var _i = 0; _i < arguments.length; _i++) {
  39. args[_i] = arguments[_i];
  40. }
  41. return _joinArrays(a.apply(void 0, __spreadArray([], __read(args))), b.apply(void 0, __spreadArray([], __read(args))), k);
  42. };
  43. }
  44. if (isArray(a) && isArray(b)) {
  45. var customResult = customizeArray && customizeArray(a, b, newKey);
  46. return customResult || __spreadArray(__spreadArray([], __read(a)), __read(b));
  47. }
  48. if (utils_1.isRegex(b)) {
  49. return b;
  50. }
  51. if (utils_1.isPlainObject(a) && utils_1.isPlainObject(b)) {
  52. var customResult = customizeObject && customizeObject(a, b, newKey);
  53. return (customResult ||
  54. merge_with_1["default"]([a, b], joinArrays({
  55. customizeArray: customizeArray,
  56. customizeObject: customizeObject,
  57. key: newKey
  58. })));
  59. }
  60. if (utils_1.isPlainObject(b)) {
  61. return clone_deep_1["default"](b);
  62. }
  63. if (isArray(b)) {
  64. return __spreadArray([], __read(b));
  65. }
  66. return b;
  67. };
  68. }
  69. exports["default"] = joinArrays;
  70. //# sourceMappingURL=join-arrays.js.map