Files
kit-ui/lib/qrcode/qrcodeService.ts

40 lines
866 B
TypeScript
Raw Normal View History

import QRCode from 'qrcode';
import type { ErrorCorrectionLevel } from '@/types/qrcode';
export async function generateSvg(
text: string,
errorCorrection: ErrorCorrectionLevel,
foregroundColor: string,
backgroundColor: string,
margin: number,
): Promise<string> {
return QRCode.toString(text, {
type: 'svg',
errorCorrectionLevel: errorCorrection,
color: {
dark: foregroundColor,
light: backgroundColor,
},
margin,
});
}
export async function generateDataUrl(
text: string,
errorCorrection: ErrorCorrectionLevel,
foregroundColor: string,
backgroundColor: string,
margin: number,
size: number,
): Promise<string> {
return QRCode.toDataURL(text, {
errorCorrectionLevel: errorCorrection,
color: {
dark: foregroundColor,
light: backgroundColor,
},
margin,
width: size,
});
}