first
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Pembuat matriks QR Code (Node).
|
||||
*
|
||||
* Memakai core library `qrcode` yang sama dengan proyek awal, hanya tanpa
|
||||
* renderer gambar supaya matriks modulnya bisa digambar sebagai vektor.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const QRCodeCore = require('qrcode/lib/core/qrcode');
|
||||
|
||||
/**
|
||||
* @param {string} text isi QR (payload)
|
||||
* @param {string} [errorCorrectionLevel] L | M | Q | H
|
||||
* @returns {{size:number, version:number, errorCorrectionLevel:object, maskPattern:number, get:function(number,number):boolean}}
|
||||
*/
|
||||
function createMatrix(text, errorCorrectionLevel) {
|
||||
const payload = String(text);
|
||||
if (!payload.length) {
|
||||
throw new Error('Payload QR Code kosong.');
|
||||
}
|
||||
const qr = QRCodeCore.create(payload, {
|
||||
errorCorrectionLevel: String(errorCorrectionLevel || 'M').toUpperCase()
|
||||
});
|
||||
const size = qr.modules.size;
|
||||
return {
|
||||
size: size,
|
||||
version: qr.version,
|
||||
errorCorrectionLevel: qr.errorCorrectionLevel,
|
||||
maskPattern: qr.maskPattern,
|
||||
get: function (row, col) {
|
||||
return qr.modules.get(row, col);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { createMatrix: createMatrix };
|
||||
Reference in New Issue
Block a user