From db42ad8d54aed44ece9344db95e1d8b4eb65508f Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 18 May 2020 14:29:52 +0200 Subject: [PATCH] lib: remove result variable from asData (#167) 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 f7c9ad4..431280b 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; + ? JSON.parse(data) + : data; - result = isBinary(result) - ? asBase64(result) - : result; - - return result; + return isBinary(maybeJson) + ? asBase64(maybeJson) + : maybeJson; }; module.exports = {