From c7d1a26dfbc286748500bef1d8c0e35975253572 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 18 May 2020 06:09:41 +0200 Subject: [PATCH] lib: remove result variable from asData This commit removes the 'result' variable form the utility function asData. The motivation is to improve readability. Signed-off-by: Daniel Bevenius --- lib/utils/fun.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/utils/fun.js b/lib/utils/fun.js index f7c9ad4c..431280b9 100644 --- a/lib/utils/fun.js +++ b/lib/utils/fun.js @@ -53,20 +53,16 @@ const isJsonContentType = (contentType) => contentType && contentType.match(/(json)/i); const asData = (data, contentType) => { - let result = data; - // pattern matching alike - result = isString(result) && - !isBase64(result) && + const maybeJson = isString(data) && + !isBase64(data) && isJsonContentType(contentType) - ? JSON.parse(result) - : result; - - result = isBinary(result) - ? asBase64(result) - : result; + ? JSON.parse(data) + : data; - return result; + return isBinary(maybeJson) + ? asBase64(maybeJson) + : maybeJson; }; module.exports = {