merge-dictionaries
Advanced tools
Comparing version 0.0.3 to 1.0.0
21
index.js
var _ = require('@sailshq/lodash'); | ||
module.exports = function(dictA, dictB) { | ||
// Create the customized merge function. | ||
var merge = function(dictA, dictB) { | ||
return _.merge(dictA, dictB, function(a, b) { | ||
@@ -13,1 +14,19 @@ // If `a` is not a POJO, or it's an empty POJO, just replace it with `b`. | ||
}; | ||
// Allow variadic usage. | ||
// e.g. mergeDictionarys(dictOne, dictTwo, dictThree, dictFour, ...) | ||
module.exports = function() { | ||
// Special case: if only one arg is provided, just return it. | ||
if (arguments.length === 1) { | ||
return arguments[0]; | ||
} | ||
// Otherwise use `_.reduce` to merge arguments from left to right. | ||
var args = Array.prototype.slice.call(arguments); | ||
var firstArg = args.shift(); | ||
return _.reduce(args, function(memo, arg) { | ||
return merge(memo, arg); | ||
}, firstArg); | ||
}; |
{ | ||
"name": "merge-dictionaries", | ||
"version": "0.0.3", | ||
"version": "1.0.0", | ||
"description": "Recursively merge two dictionaries together", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
18634
90
1