QRLite is QRCode(8bit mode) generator written in TypeScript only.
QRlite can output QRLite bitmap canvas, text, and Monochrome bitmap.
npm i qrlite
const QRLite = require( 'qrlite' );
function OutputBitmapFile( name, canvas, frame ) {
if ( frame === undefined ) { frame = 4; }
var fs = require('fs');
var buf = Buffer.from( canvas.outputBitmapByte( frame ) );
fs.writeFileSync( name, buf );
}
OutputBitmapFile( 'test.bmp', QRLite.convert( 'test' ) );
<script src="./qrlite.js"></script>
<script>console.log(QRLite);</script>
https://github.com/HirokiMiyaoka/QRCodeComponent
QRCodeComponent is QRCode generate and draw Webcomponents uses QRLite.
import * as QRLite from 'qrlite';
const qr = new QRLite.Generator();
// Set level.
qr.setLevel( 'Q' );
// Set data.
qr.setData( 'test' );
// datacode[ 0 ] = Data block, datacode[ 1 ] = EC Block
const datacode = qr.createDataCode();
// Raw QR Code.
qr.drawData( datacode[ 0 ], datacode[ 1 ] );
const rawcanvas = qr.get();
// Get masked canvases.(masked[ 0-7 ] = QRLite.Canvas)
const masked = qr.createMaskedQRCode();
// Print QRCode points.
// console.log( qr.evaluateQRCode( masked ) );
// Select mask number.
const masknum = qr.selectQRCode( masked );
// QR Code.
const canvas = masked[ masknum ];
// Output to console.
canvas.print();
Black = 1
or true
, White = 0
or false
.
type QRLiteLevel = 'L' | 'M' | 'Q' | 'H';
interface QRLiteConvertOption {
level?: QRLiteLevel;
version?: number;
mask?: number;
}
interface QRLiteRating {
calc: (canvas: QRLiteBitCanvas) => number;
}
[ 0 ] ... Data code
[ 1 ] ... EC code.
Return masked QR code.
Mask has 8 types.
drawQRByte( byte: Uint8Array, cursor?: { x: number, y: number, up: boolean, right: boolean } ) => { x: number, y: number, up: boolean, right: boolean }
Write code Buffer.from( canvas.outputBitmapByte( frame ) )
if you want to get Buffer.
npm run build
All test.
npm run test
Options.
npm run test -- OPTION FILES...
- OPTION
--binary
-b
- Binary mode.
--debug
-d
- Text mode.
- FILES
- Set test dir.
npm run test -- 0000_1_H
- Set test dir.
test/
NNNN_VERSION_LEVEL/ ... Test case
test.txt ... QRCode text.
sample.png ... Sample for human.
sample.bmp ... Binary mode sample.
sample.txt ... Text mode sample.
- NNNN
- Test number. Start
0000
.
- Test number. Start
- VERSION
- QRCode version. (
1
~40
)
- QRCode version. (
- LEVEL
- QRCode level. (
L
M
Q
H
)
- QRCode level. (
- test.txt
- QRCode data.
- sample.png
- Only sample.
Binary mode test use Microsoft monochrome bitmap.
You create min QRCode and rename sample.bmp
.
Text mode test use sample.txt
.
This answer set White = [
], Black = [██
].