From 2bdd1084fadcb418089818101b824c80506aea86 Mon Sep 17 00:00:00 2001 From: Joe Clark Date: Thu, 16 Jan 2025 16:22:16 +0000 Subject: [PATCH] common: typo --- packages/common/src/util/base64.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/common/src/util/base64.js b/packages/common/src/util/base64.js index 86db0ff9d..a90ca403b 100644 --- a/packages/common/src/util/base64.js +++ b/packages/common/src/util/base64.js @@ -17,21 +17,21 @@ import _ from 'lodash'; * @example To skip the JSON stringification step * const encodedObject = encode('Hello World', {parseJson: false}) */ -export const encode = (data, options = {parseJson: true}) => { +export const encode = (data, options = { parseJson: true }) => { let str = data; - if(typeof data !== "string" && options.parseJson){ + if (typeof data !== 'string' && options.parseJson) { try { str = JSON.stringify(str); - } catch (e){ + } catch (e) { console.log(e.message); } } return Buffer.from(str, 'utf-8').toString('base64'); -} +}; -/**4 +/** * Decodes a Base64 encoded string back to its original format. * @function * @public @@ -47,10 +47,13 @@ export const encode = (data, options = {parseJson: true}) => { * @example To skip the JSON stringification step * const decodedString = decode('Hello World', {parseJson: false}) */ -export const decode = (base64Data, options = {parseJson: true}) =>{ +export const decode = (base64Data, options = { parseJson: true }) => { let decodedValue = Buffer.from(base64Data, 'base64').toString('utf-8'); - if((_.startsWith(decodedValue, '[') || _.startsWith(decodedValue, '{')) && options.parseJson) { + if ( + (_.startsWith(decodedValue, '[') || _.startsWith(decodedValue, '{')) && + options.parseJson + ) { try { decodedValue = JSON.parse(decodedValue); } catch (e) { @@ -59,5 +62,4 @@ export const decode = (base64Data, options = {parseJson: true}) =>{ } return decodedValue; -} - +};