mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-24 01:48:18 +03:00
23 lines
612 B
TypeScript
23 lines
612 B
TypeScript
import { isEmpty } from 'ramda';
|
|
import { stringifyQuery } from './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}`}`;
|
|
};
|