From 0d5a180d5628f8d4ddae4a567190f11910583682 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 2 Jun 2022 09:38:56 -0400 Subject: [PATCH] fix: decodehex issue with null string --- src/utils/datalayer-utils.js | 66 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/utils/datalayer-utils.js b/src/utils/datalayer-utils.js index 6ff77ad7..62665dac 100644 --- a/src/utils/datalayer-utils.js +++ b/src/utils/datalayer-utils.js @@ -1,33 +1,33 @@ -export const encodeHex = (str) => { - return Buffer.from(str).toString('hex'); -}; - -export const decodeHex = (str) => { - return Buffer.from(str.replace('0x', ''), 'hex').toString(); -}; - -export const decodeDataLayerResponse = (data) => { - return data.keys_values.map((item) => ({ - key: decodeHex(item.key), - value: decodeHex(item.value), - })); -}; - -export const keyValueToChangeList = (key, value, includeDelete) => { - const changeList = []; - - if (includeDelete) { - changeList.push({ - action: 'delete', - key: encodeHex(key), - }); - } - - changeList.push({ - action: 'insert', - key: encodeHex(key), - value: encodeHex(value), - }); - - return changeList; -}; +export const encodeHex = (str) => { + return Buffer.from(str).toString('hex'); +}; + +export const decodeHex = (str = '') => { + return Buffer.from(str.replace('0x', ''), 'hex').toString(); +}; + +export const decodeDataLayerResponse = (data) => { + return data.keys_values.map((item) => ({ + key: decodeHex(item.key), + value: decodeHex(item.value), + })); +}; + +export const keyValueToChangeList = (key, value, includeDelete) => { + const changeList = []; + + if (includeDelete) { + changeList.push({ + action: 'delete', + key: encodeHex(key), + }); + } + + changeList.push({ + action: 'insert', + key: encodeHex(key), + value: encodeHex(value), + }); + + return changeList; +};