shlink-web-client/src/utils/helpers/qrCodes.ts

24 lines
654 B
TypeScript
Raw Normal View History

import { isEmpty } from 'ramda';
import { stringifyQuery } from '../../../shlink-web-component/utils/helpers/query';
export type QrCodeFormat = 'svg' | 'png';
export type QrErrorCorrection = 'L' | 'M' | 'Q' | 'H';
export interface QrCodeOptions {
size: number;
format: QrCodeFormat;
margin: number;
errorCorrection: QrErrorCorrection;
}
export const buildQrCodeUrl = (shortUrl: string, { margin, ...options }: QrCodeOptions): string => {
const baseUrl = `${shortUrl}/qr-code`;
const query = stringifyQuery({
...options,
margin: margin > 0 ? margin : undefined,
});
return `${baseUrl}${isEmpty(query) ? '' : `?${query}`}`;
};