QR code generator written in TypeScript.
Check live demo: https://themanandhisshadow.github.io/qr-code-generator/
Note
qr()
function input not case sensitive. For example:qr(text: "Hello world")
andqr(text: "HELLO WORLD")
returns same qr code!
let qrCode = qr({
text: 'Hello world!',
textOrigin: input,
correction: 'M',
size: 400,
});
Warning
All
qr()
function params are optional, but at least one of two text source params (text
,textOrigin
) should be passed to the params object!
Note
Text sources can only contain allowed letters
[a-zA-Z0-9$%*+-./:]
andwhitespaces
- Create variable that will contains
qr()
function result. Call theqr()
function with the following parameters:
text?: string
- text to convert;textOrigin?: HTMLInputElement
- input, that contains text to convert;correction?: string
- qr code correction level, by default is "M"size?: number
- qr code canvas size in pixels, by default is 400 pixels.
- As result,
qr()
function returns following object:
{
canvas: HTMLCanvasElement, // contains canvas with ready qr code
data: {
blocks: string[],
correction: string,
encodedData: string,
originalData: string,
serviceData: string,
stream: string[],
version: {
number: number,
capacity: number,
},
},
}
Get qrCode.canvas element and make necessary DOM manipulations. For example:
codeContainer.appendChild(qrCode.canvas);