@steveorevo/node-red-emerge
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -33,2 +33,21 @@ module.exports = function(RED) { | ||
}; | ||
function isObject(item) { | ||
return (item && typeof item === 'object' && !Array.isArray(item)); | ||
} | ||
function mergeDeep(target, source) { | ||
let output = Object.assign({}, target); | ||
if (isObject(target) && isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (isObject(source[key])) { | ||
if (!(key in target)) | ||
Object.assign(output, { [key]: source[key] }); | ||
else | ||
output[key] = mergeDeep(target[key], source[key]); | ||
} else { | ||
Object.assign(output, { [key]: source[key] }); | ||
} | ||
}); | ||
} | ||
return output; | ||
} | ||
@@ -43,3 +62,3 @@ node.on('input', function(msg, send, done) { | ||
} | ||
Object.assign(msgBuffer, msg); | ||
msgBuffer = mergeDeep(msgBuffer, msg); | ||
nodeContext.set('msgBuffer', msgBuffer); | ||
@@ -46,0 +65,0 @@ |
{ | ||
"name": "@steveorevo/node-red-emerge", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "A node that merges msg objects until all defined properties are present / conditions met before passing the combined msg along.", | ||
@@ -5,0 +5,0 @@ "author": "Stephen J. Carnam <steveorevo@gmail.com>", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166393
3264