@vkontakte/vk-qr
v3.1.0
Published
QR Code generator
Maintainers
Keywords
Readme
VK-QR
JavaScript library for generating SVG code of VK-style QR codes.
Usage
Install via yarn
yarn add @vkontakte/vk-qror npm
npm install @vkontakte/vk-qrAnd use in your code
import * as vkQr from '@vkontakte/vk-qr';
// Returns SVG code of generated 256x256 QR code with VK logo
const qrSvg = vkQr.createQR('Text to encode', {
qrSize: 256,
isShowLogo: true,
});Customize the background frame thickness and corner radius in pixels:
const qrSvg = vkQr.createQR('Text to encode', {
qrSize: 256,
isShowBackground: true,
backgroundPadding: 12,
backgroundRadius: 16,
});API Reference
Syntax
generatedSvgCode = vkQr.createQR(text[, qrOptions]);Parameters
textrequired String to generate a QR codeoptionsoptional An options object containing any custom settings that you want to apply to the generated QR code. The possible options are:qrSize: Size of QR code. Default is 128className: Class name of root SVG elementisShowLogo: Show VK logo in center of QR code Default is falseisShowBackground: Show QR background. Default is falsebackgroundColor: QR code background HEX color. Works ifisShowBackgroundis enabled. Default is "#ffffff"backgroundPadding: Background frame thickness (padding on each side) in output pixels. Works ifisShowBackgroundis enabled. Default is 20backgroundRadius: Background corner radius in output pixels. Works ifisShowBackgroundis enabled. Default is 36foregroundColor: QR code HEX colorlogoColor: Color of logo. Default is "#4680c2"logoData: Reference to logo as a reference IRIsuffix: SVG elements id postfixecc: ECC level in range [0-3] (0 - low, 3 - high)
backgroundPadding and backgroundRadius accept finite, non-negative numbers, including 0.
Invalid values use the defaults. Both are limited to half of qrSize.
The outer SVG size stays qrSize × qrSize; padding reduces the space available to the QR code
equally on all sides. If padding fills the entire image, only the background is rendered.
Return value
A string with SVG code.
License
The code is available under the MIT license.
