diff --git a/lib/stringMsg.js b/lib/stringMsg.js index 6ae357a..80a5a5c 100644 --- a/lib/stringMsg.js +++ b/lib/stringMsg.js @@ -19,13 +19,17 @@ const { * @param {Object} [rest={}] Anything else to be added like len, timestamp, direction. * @return {Object} All canId fields with format and data props added. */ -function buildMsg(canIdInfo, format, data, rest = {}) { - return { - ...canIdInfo, +function buildMsg(_canIdInfo, format, data, rest = {}) { + const canIdInfo = Object.assign({}, _canIdInfo, { format, - data, - ...rest, + data + }) + for (const property in rest) { + if (canIdInfo[property] === undefined) { + canIdInfo[property] = rest[property] + } } + return canIdInfo } function buildErrMsg(msg, input) { if (input && isString(input)) return `${msg} - ${input}`