Replace nested ternary conditions with ramda's cond

This commit is contained in:
Alejandro Celaya 2021-01-24 18:21:04 +01:00
parent e2ba63ff58
commit ecefa22204

View file

@ -1,3 +1,5 @@
import { always, cond } from 'ramda';
export interface QrCodeCapabilities { export interface QrCodeCapabilities {
useSizeInPath: boolean; useSizeInPath: boolean;
svgIsSupported: boolean; svgIsSupported: boolean;
@ -13,7 +15,11 @@ export const buildQrCodeUrl = (
): string => { ): string => {
const sizeFragment = useSizeInPath ? `/${size}` : `?size=${size}`; const sizeFragment = useSizeInPath ? `/${size}` : `?size=${size}`;
const formatFragment = !svgIsSupported ? '' : `format=${format}`; 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}`; return `${shortUrl}/qr-code${sizeFragment}${joinSymbol}${formatFragment}`;
}; };