@nuintun/qrcode
Version:
A pure JavaScript QRCode encode and decode library.
55 lines (51 loc) • 1.22 kB
JavaScript
/**
* @module QRCode
* @package @nuintun/qrcode
* @license MIT
* @version 5.0.3
* @author nuintun <nuintun@qq.com>
* @description A pure JavaScript QRCode encode and decode library.
* @see https://github.com/nuintun/qrcode#readme
*/
;
/**
* @module ECLevel
*/
const VALUES_TO_ECLEVEL = new Map();
function fromECLevelBits(bits) {
const ecLevel = VALUES_TO_ECLEVEL.get(bits);
if (ecLevel != null) {
return ecLevel;
}
throw new Error('illegal error correction bits');
}
class ECLevel {
#bits;
#level;
#name;
// L = ~7% correction.
static L = new ECLevel('L' /* Level.L */, 0, 0x01);
// M = ~15% correction.
static M = new ECLevel('M' /* Level.M */, 1, 0x00);
// Q = ~25% correction.
static Q = new ECLevel('Q' /* Level.Q */, 2, 0x03);
// H = ~30% correction.
static H = new ECLevel('H' /* Level.H */, 3, 0x02);
constructor(name, level, bits) {
this.#bits = bits;
this.#name = name;
this.#level = level;
VALUES_TO_ECLEVEL.set(bits, this);
}
get bits() {
return this.#bits;
}
get level() {
return this.#level;
}
get name() {
return this.#name;
}
}
exports.ECLevel = ECLevel;
exports.fromECLevelBits = fromECLevelBits;