Draw bytes to grids
QRCode assumes the data has already been encoded into codewords. This class handles drawing to a Grid based on mask, version, ecl, and codewords.
new QRCode({ mask, version, ecl, codewords })
mask: number 0-7 specifying which mask to useversion: number 1-40 specifying which version to useecl: number 0-3 specifying which ecl to usecodewords: Uint8Array with each item representing a byteimport { QRCode } from 'qrsart'
let qr = new QRCode({
version: 2,
ecl: 2, //0=low 1=medium 2=quartile 3=high
mask: 6,
codewords: generateCodewords()
})
qr.size
The number of pixels per row and col. size = version * 4 + 17
Each QRCode instance has the following grids:
Useful for splitting encoding and graphics logic.
qr.toBuffer()
Serializes the QR Code into a Uint8Array.
versionmask and eclcodewordsQRCode.fromBuffer(buf)
Returns a new QRCode instance given a Uint8Array. The inverse of toBuffer().
qr.toString()
Converts the result of qr.toBuffer() into a base64 string, useful for compact JSON and HTML storage of QR encodings.
QRCode.fromString()
Returns a new QRCode instance given a base64 string. The inverse of toString().