mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-07-25 13:11:52 +00:00
Replace nested ternary conditions with ramda's cond
This commit is contained in:
@@ -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}`;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user