Skip to content

Commit

Permalink
lib: remove result variable from asData (#167)
Browse files Browse the repository at this point in the history
This commit removes the 'result' variable form the utility function
asData. The motivation is to improve readability.

Signed-off-by: Daniel Bevenius <daniel.bevenius@gmail.com>
  • Loading branch information
danbev authored May 18, 2020
1 parent cf36a15 commit db42ad8
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/utils/fun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit db42ad8

Please sign in to comment.