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 <daniel.bevenius@gmail.com>
This commit is contained in:
Daniel Bevenius 2020-05-18 14:29:52 +02:00 committed by GitHub
parent cf36a1578a
commit db42ad8d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 11 deletions

View File

@ -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 = {