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:
parent
cf36a1578a
commit
db42ad8d54
|
@ -53,20 +53,16 @@ const isJsonContentType = (contentType) =>
|
||||||
contentType && contentType.match(/(json)/i);
|
contentType && contentType.match(/(json)/i);
|
||||||
|
|
||||||
const asData = (data, contentType) => {
|
const asData = (data, contentType) => {
|
||||||
let result = data;
|
|
||||||
|
|
||||||
// pattern matching alike
|
// pattern matching alike
|
||||||
result = isString(result) &&
|
const maybeJson = isString(data) &&
|
||||||
!isBase64(result) &&
|
!isBase64(data) &&
|
||||||
isJsonContentType(contentType)
|
isJsonContentType(contentType)
|
||||||
? JSON.parse(result)
|
? JSON.parse(data)
|
||||||
: result;
|
: data;
|
||||||
|
|
||||||
result = isBinary(result)
|
return isBinary(maybeJson)
|
||||||
? asBase64(result)
|
? asBase64(maybeJson)
|
||||||
: result;
|
: maybeJson;
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in New Issue