From aa5ff4725bd8b2de8673959b943ff1b8ed130e63 Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Tue, 28 May 2024 18:06:50 +0300 Subject: [PATCH] refactor: optimise object creation & remove spread (#265) --- lib/stringMsg.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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}`