2021-02-14 11:50:26 +03:00
|
|
|
import { isEmpty } from 'ramda';
|
2023-07-27 23:23:46 +03:00
|
|
|
import { stringifyQuery } from '../../../shlink-web-component/utils/helpers/query';
|
2021-01-24 20:21:04 +03:00
|
|
|
|
2021-01-24 19:37:31 +03:00
|
|
|
export type QrCodeFormat = 'svg' | 'png';
|
|
|
|
|
2021-08-16 18:13:31 +03:00
|
|
|
export type QrErrorCorrection = 'L' | 'M' | 'Q' | 'H';
|
|
|
|
|
2021-02-14 11:50:26 +03:00
|
|
|
export interface QrCodeOptions {
|
|
|
|
size: number;
|
|
|
|
format: QrCodeFormat;
|
|
|
|
margin: number;
|
2021-08-16 18:13:31 +03:00
|
|
|
errorCorrection: QrErrorCorrection;
|
2021-02-14 11:50:26 +03:00
|
|
|
}
|
|
|
|
|
2022-12-23 22:42:47 +03:00
|
|
|
export const buildQrCodeUrl = (shortUrl: string, { margin, ...options }: QrCodeOptions): string => {
|
2022-05-01 11:44:12 +03:00
|
|
|
const baseUrl = `${shortUrl}/qr-code`;
|
2021-02-14 11:50:26 +03:00
|
|
|
const query = stringifyQuery({
|
2022-12-23 22:42:47 +03:00
|
|
|
...options,
|
2022-05-01 11:44:12 +03:00
|
|
|
margin: margin > 0 ? margin : undefined,
|
2021-02-14 11:50:26 +03:00
|
|
|
});
|
2021-01-24 19:37:31 +03:00
|
|
|
|
2021-02-14 11:50:26 +03:00
|
|
|
return `${baseUrl}${isEmpty(query) ? '' : `?${query}`}`;
|
2021-01-24 19:37:31 +03:00
|
|
|
};
|