Skip to content

Commit

Permalink
fix: decodehex issue with null string
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Jun 2, 2022
1 parent 9fb3426 commit 0d5a180
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/utils/datalayer-utils.js
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 0d5a180

Please sign in to comment.