Skip to content

Commit

Permalink
Fix #12 by adding a _.mergeWith customizer function
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Arrays are merged, rather than overwritten
  • Loading branch information
moqmar authored and alexlafroscia committed Oct 16, 2020
1 parent 91244a0 commit dde8b24
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -20,7 +20,10 @@ function readAsJSON(fileName) {
function yamlMerge(...from) {
const files = from.map((path) => readAsJSON(path));

const outputJSON = _.merge({}, ...files);
const outputJSON = _.mergeWith({}, ...files, (objValue, srcValue, key, object, source, stack) => {
if (Array.isArray(objValue) && Array.isArray(srcValue)) return [...objValue, ...srcValue];
return undefined; // handle it just like with _.merge
})
return jsYaml.dump(outputJSON);
}

Expand Down

0 comments on commit dde8b24

Please sign in to comment.