Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
WIP: merge arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed May 9, 2019
1 parent 85e2028 commit 71fa89b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/functions/mergePure.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const uniq = require('lodash/uniq');

// NOTE: repeated because #656 isn't merged yet
function objectHasKeys(obj) {
return Object.keys(Object(obj)) > -1;
// should be more "object can have keys (object / function)"
return Object.keys(Object(obj)) > 0;
}

// NOTE: this behaves like lodash/merge, but doesn't mutate the target
Expand All @@ -18,7 +17,9 @@ module.exports = function mergeDeep() {

if (Array.isArray(previousValue)) {
var nextArray = Array.isArray(nextValue) ? nextValue : [nextValue];
acc[key] = uniq([].concat(previousValue, nextArray));
acc[key] = previousValue.map(function(v, i) {
return mergeDeep(v, nextArray[i]);
});
} else if (objectHasKeys(nextValue)) {
acc[key] = mergeDeep(previousValue, nextValue);
} else {
Expand All @@ -31,4 +32,4 @@ module.exports = function mergeDeep() {
};

// TODO: make this removable
module.exports = require('lodash/merge');
// module.exports = require('lodash/merge');

0 comments on commit 71fa89b

Please sign in to comment.