QRLite is QRCode(8bit mode) generator written in TypeScript only.
npm install qrlitesh
npm i qrlite
`
Sample
Output Bitmap(Node.js sample)
` js
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' ) );
`
Browser sample
`html
`
QRCode WebComponents(Browser sample2)
https://github.com/HirokiMiyaoka/QRCodeComponent
QRCodeComponent is QRCode generate and draw Webcomponents uses QRLite.
TypeScript sample
`ts
import * as QRLite from 'qrlite';
`
Debug
` js
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.
QRLite.convert(data: string, option: QRLiteConvertOption): QRLiteBitCanvas
`
type QRLiteLevel = 'L' | 'M' | 'Q' | 'H';
interface QRLiteConvertOption {
level?: QRLiteLevel;
version?: number;
mask?: number;
}
`
QRLite.Generator
$3
$3
$3
$3
$3
$3
`
interface QRLiteRating {
calc: (canvas: QRLiteBitCanvas) => number;
}
`
$3
$3
[ 0 ] ... Data code
[ 1 ] ... EC code.
$3
$3
Return masked QR code.
Mask has 8 types.
$3
$3
QRLiteBitCanvas
$3
$3
$3
$3
$3
$3
$3
$3
$3
$3
Write code Buffer.from( canvas.outputBitmapByte( frame ) ) if you want to get Buffer.
Test
Build
` sh
npm run build
`
Run
All test.
` sh
npm run test
`
Options.
` sh
npm run test -- OPTION FILES...
`
* OPTION
* --binary
* -b
* Binary mode.
* --debug
* -d
* Text mode.
* FILES
* Set test dir.
* npm run test -- 0000_1_H
Add
$3
`text
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.
* VERSION
* QRCode version. ( 1 ~ 40 )
* LEVEL
* QRCode level. ( L M Q H )
* test.txt
* QRCode data.
* sample.png
* Only sample.
#### Binary
Binary mode test use Microsoft monochrome bitmap.
You create min QRCode and rename sample.bmp .
#### Text
Text mode test use sample.txt .
This answer set White = [ ], Black = [██`].