From ecefa222047f47a35beff5189c775f9fa567ee3c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 24 Jan 2021 18:21:04 +0100 Subject: [PATCH] Replace nested ternary conditions with ramda's cond --- src/utils/helpers/qrCodes.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/helpers/qrCodes.ts b/src/utils/helpers/qrCodes.ts index 06e81b4d..13b298ca 100644 --- a/src/utils/helpers/qrCodes.ts +++ b/src/utils/helpers/qrCodes.ts @@ -1,3 +1,5 @@ +import { always, cond } from 'ramda'; + export interface QrCodeCapabilities { useSizeInPath: boolean; svgIsSupported: boolean; @@ -13,7 +15,11 @@ export const buildQrCodeUrl = ( ): string => { const sizeFragment = useSizeInPath ? `/${size}` : `?size=${size}`; const formatFragment = !svgIsSupported ? '' : `format=${format}`; - const joinSymbol = useSizeInPath && svgIsSupported ? '?' : !useSizeInPath && svgIsSupported ? '&' : ''; + const joinSymbolResolver = cond([ + [ () => useSizeInPath && svgIsSupported, always('?') ], + [ () => !useSizeInPath && svgIsSupported, always('&') ], + ]); + const joinSymbol = joinSymbolResolver() ?? ''; return `${shortUrl}/qr-code${sizeFragment}${joinSymbol}${formatFragment}`; };