{
- getStyleList(this.state.qrcode).map((style) => {
+ styleList.map((style, index) => {
return
})
@@ -124,8 +143,8 @@ class Qrcode extends React.Component {
diff --git a/src/utils/downloader.js b/src/utils/downloader.js
new file mode 100644
index 0000000..db203fd
--- /dev/null
+++ b/src/utils/downloader.js
@@ -0,0 +1,64 @@
+const svgHead = "\n " +
+ "\n"
+
+export function isChrome() {
+ return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
+}
+
+export function saveSvg(filename, content) {
+ let htmlContent = [svgHead + content]
+ let bl = new Blob(htmlContent, {type: "text/html"})
+ let a = document.createElement("a")
+ filename = "QRcode_" + filename + ".svg"
+
+ a.href = URL.createObjectURL(bl)
+ a.download = filename
+ a.hidden = true
+ a.click()
+}
+
+export function saveImg(filename, content, width, height) {
+ // Finish creating downloadable data
+ filename = "QRcode_" + filename + ".jpg";
+ const wrap = document.createElement('div');
+ wrap.innerHTML = content;
+
+ const $svg = wrap.firstChild
+ const $clone = $svg.cloneNode(true);
+
+ $clone.setAttribute('width', width);
+ $clone.setAttribute('height', height);
+
+ const svgData = new XMLSerializer().serializeToString($clone);
+
+ let canvas = document.createElement('canvas');
+
+ // Image will be scaled to the requested size.
+ // var size = data.requestedSize;
+ canvas.setAttribute('width', width);
+ canvas.setAttribute('height', height);
+
+ let ctx = canvas.getContext('2d');
+
+ let img = document.createElement('img');
+
+ // New window for the image when it's loaded
+ if(!isChrome()) window.open('', 'download');
+
+ img.onload = () => {
+ ctx.fillStyle = 'white'
+ ctx.fillRect(0, 0, width, height)
+ ctx.drawImage(img, 0, 0, width, height);
+ // `download` attr is not well supported
+ // Will result in a download popup for chrome and the
+ // image opening in a new tab for others.
+
+ let a = document.createElement('a');
+ a.setAttribute('href', canvas.toDataURL('image/jpeg', 0.8))
+ a.setAttribute('target', 'download')
+ a.setAttribute('download', filename);
+ a.click();
+ };
+
+ img.setAttribute('src', 'data:image/svg+xml;base64,' + btoa(svgData));
+}
diff --git a/src/utils/qrcode.js b/src/utils/qrcode.js
index 1f8f6b2..3e8ba83 100644
--- a/src/utils/qrcode.js
+++ b/src/utils/qrcode.js
@@ -30,7 +30,7 @@ QR8bitByte.prototype = {
},
write : function(buffer) {
- for (var i = 0; i < this.data.length; i++) {
+ for (let i = 0; i < this.data.length; i++) {
// not JIS ...
buffer.put(this.data.charCodeAt(i), 8);
}
@@ -47,13 +47,13 @@ function QRCode(typeNumber, errorCorrectLevel) {
this.modules = null;
this.moduleCount = 0;
this.dataCache = null;
- this.dataList = new Array();
+ this.dataList = [];
}
QRCode.prototype = {
addData : function(data) {
- var newData = new QR8bitByte(data);
+ let newData = new QR8bitByte(data);
this.dataList.push(newData);
this.dataCache = null;
},
@@ -72,18 +72,18 @@ QRCode.prototype = {
make : function() {
// Calculate automatically typeNumber if provided is < 1
if (this.typeNumber < 1 ){
- var typeNumber = 1;
+ let typeNumber = 1;
for (typeNumber = 1; typeNumber < 40; typeNumber++) {
- var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
+ let rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
- var buffer = new QRBitBuffer();
- var totalDataCount = 0;
- for (var i = 0; i < rsBlocks.length; i++) {
+ let buffer = new QRBitBuffer();
+ let totalDataCount = 0;
+ for (let i = 0; i < rsBlocks.length; i++) {
totalDataCount += rsBlocks[i].dataCount;
}
- for (var i = 0; i < this.dataList.length; i++) {
- var data = this.dataList[i];
+ for (let i = 0; i < this.dataList.length; i++) {
+ let data = this.dataList[i];
buffer.put(data.mode, 4);
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) );
data.write(buffer);
@@ -101,11 +101,11 @@ QRCode.prototype = {
this.moduleCount = this.typeNumber * 4 + 17;
this.modules = new Array(this.moduleCount);
- for (var row = 0; row < this.moduleCount; row++) {
+ for (let row = 0; row < this.moduleCount; row++) {
this.modules[row] = new Array(this.moduleCount);
- for (var col = 0; col < this.moduleCount; col++) {
+ for (let col = 0; col < this.moduleCount; col++) {
this.modules[row][col] = null;//(col + row) % 3;
}
}
@@ -130,11 +130,11 @@ QRCode.prototype = {
setupPositionProbePattern : function(row, col) {
- for (var r = -1; r <= 7; r++) {
+ for (let r = -1; r <= 7; r++) {
if (row + r <= -1 || this.moduleCount <= row + r) continue;
- for (var c = -1; c <= 7; c++) {
+ for (let c = -1; c <= 7; c++) {
if (col + c <= -1 || this.moduleCount <= col + c) continue;
@@ -151,14 +151,14 @@ QRCode.prototype = {
getBestMaskPattern : function() {
- var minLostPoint = 0;
- var pattern = 0;
+ let minLostPoint = 0;
+ let pattern = 0;
- for (var i = 0; i < 8; i++) {
+ for (let i = 0; i < 8; i++) {
this.makeImpl(true, i);
- var lostPoint = QRUtil.getLostPoint(this);
+ let lostPoint = QRUtil.getLostPoint(this);
if (i == 0 || minLostPoint > lostPoint) {
minLostPoint = lostPoint;
@@ -171,19 +171,19 @@ QRCode.prototype = {
createMovieClip : function(target_mc, instance_name, depth) {
- var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
- var cs = 1;
+ let qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
+ let cs = 1;
this.make();
- for (var row = 0; row < this.modules.length; row++) {
+ for (let row = 0; row < this.modules.length; row++) {
- var y = row * cs;
+ let y = row * cs;
- for (var col = 0; col < this.modules[row].length; col++) {
+ for (let col = 0; col < this.modules[row].length; col++) {
- var x = col * cs;
- var dark = this.modules[row][col];
+ let x = col * cs;
+ let dark = this.modules[row][col];
if (dark) {
qr_mc.beginFill(0, 100);
@@ -201,14 +201,14 @@ QRCode.prototype = {
setupTimingPattern : function() {
- for (var r = 8; r < this.moduleCount - 8; r++) {
+ for (let r = 8; r < this.moduleCount - 8; r++) {
if (this.modules[r][6] != null) {
continue;
}
this.modules[r][6] = (r % 2 == 0);
}
- for (var c = 8; c < this.moduleCount - 8; c++) {
+ for (let c = 8; c < this.moduleCount - 8; c++) {
if (this.modules[6][c] != null) {
continue;
}
@@ -218,22 +218,22 @@ QRCode.prototype = {
setupPositionAdjustPattern : function() {
- var pos = QRUtil.getPatternPosition(this.typeNumber);
+ let pos = QRUtil.getPatternPosition(this.typeNumber);
- for (var i = 0; i < pos.length; i++) {
+ for (let i = 0; i < pos.length; i++) {
- for (var j = 0; j < pos.length; j++) {
+ for (let j = 0; j < pos.length; j++) {
- var row = pos[i];
- var col = pos[j];
+ let row = pos[i];
+ let col = pos[j];
if (this.modules[row][col] != null) {
continue;
}
- for (var r = -2; r <= 2; r++) {
+ for (let r = -2; r <= 2; r++) {
- for (var c = -2; c <= 2; c++) {
+ for (let c = -2; c <= 2; c++) {
if (r == -2 || r == 2 || c == -2 || c == 2
|| (r == 0 && c == 0) ) {
@@ -249,28 +249,28 @@ QRCode.prototype = {
setupTypeNumber : function(test) {
- var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
+ let bits = QRUtil.getBCHTypeNumber(this.typeNumber);
- for (var i = 0; i < 18; i++) {
- var mod = (!test && ( (bits >> i) & 1) == 1);
+ for (let i = 0; i < 18; i++) {
+ let mod = (!test && ( (bits >> i) & 1) == 1);
this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
}
- for (var i = 0; i < 18; i++) {
- var mod = (!test && ( (bits >> i) & 1) == 1);
+ for (let i = 0; i < 18; i++) {
+ let mod = (!test && ( (bits >> i) & 1) == 1);
this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
}
},
setupTypeInfo : function(test, maskPattern) {
- var data = (this.errorCorrectLevel << 3) | maskPattern;
- var bits = QRUtil.getBCHTypeInfo(data);
+ let data = (this.errorCorrectLevel << 3) | maskPattern;
+ let bits = QRUtil.getBCHTypeInfo(data);
// vertical
- for (var i = 0; i < 15; i++) {
+ for (let i = 0; i < 15; i++) {
- var mod = (!test && ( (bits >> i) & 1) == 1);
+ let mod = (!test && ( (bits >> i) & 1) == 1);
if (i < 6) {
this.modules[i][8] = mod;
@@ -282,9 +282,9 @@ QRCode.prototype = {
}
// horizontal
- for (var i = 0; i < 15; i++) {
+ for (let i = 0; i < 15; i++) {
- var mod = (!test && ( (bits >> i) & 1) == 1);
+ let mod = (!test && ( (bits >> i) & 1) == 1);
if (i < 8) {
this.modules[8][this.moduleCount - i - 1] = mod;
@@ -302,28 +302,28 @@ QRCode.prototype = {
mapData : function(data, maskPattern) {
- var inc = -1;
- var row = this.moduleCount - 1;
- var bitIndex = 7;
- var byteIndex = 0;
+ let inc = -1;
+ let row = this.moduleCount - 1;
+ let bitIndex = 7;
+ let byteIndex = 0;
- for (var col = this.moduleCount - 1; col > 0; col -= 2) {
+ for (let col = this.moduleCount - 1; col > 0; col -= 2) {
if (col == 6) col--;
while (true) {
- for (var c = 0; c < 2; c++) {
+ for (let c = 0; c < 2; c++) {
if (this.modules[row][col - c] == null) {
- var dark = false;
+ let dark = false;
if (byteIndex < data.length) {
dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1);
}
- var mask = QRUtil.getMask(maskPattern, row, col - c);
+ let mask = QRUtil.getMask(maskPattern, row, col - c);
if (mask) {
dark = !dark;
@@ -358,20 +358,20 @@ QRCode.PAD1 = 0x11;
QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
- var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
+ let rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
- var buffer = new QRBitBuffer();
+ let buffer = new QRBitBuffer();
- for (var i = 0; i < dataList.length; i++) {
- var data = dataList[i];
+ for (let i = 0; i < dataList.length; i++) {
+ let data = dataList[i];
buffer.put(data.mode, 4);
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) );
data.write(buffer);
}
// calc num max data.
- var totalDataCount = 0;
- for (var i = 0; i < rsBlocks.length; i++) {
+ let totalDataCount = 0;
+ for (let i = 0; i < rsBlocks.length; i++) {
totalDataCount += rsBlocks[i].dataCount;
}
@@ -412,59 +412,59 @@ QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
QRCode.createBytes = function(buffer, rsBlocks) {
- var offset = 0;
+ let offset = 0;
- var maxDcCount = 0;
- var maxEcCount = 0;
+ let maxDcCount = 0;
+ let maxEcCount = 0;
- var dcdata = new Array(rsBlocks.length);
- var ecdata = new Array(rsBlocks.length);
+ let dcdata = new Array(rsBlocks.length);
+ let ecdata = new Array(rsBlocks.length);
- for (var r = 0; r < rsBlocks.length; r++) {
+ for (let r = 0; r < rsBlocks.length; r++) {
- var dcCount = rsBlocks[r].dataCount;
- var ecCount = rsBlocks[r].totalCount - dcCount;
+ let dcCount = rsBlocks[r].dataCount;
+ let ecCount = rsBlocks[r].totalCount - dcCount;
maxDcCount = Math.max(maxDcCount, dcCount);
maxEcCount = Math.max(maxEcCount, ecCount);
dcdata[r] = new Array(dcCount);
- for (var i = 0; i < dcdata[r].length; i++) {
+ for (let i = 0; i < dcdata[r].length; i++) {
dcdata[r][i] = 0xff & buffer.buffer[i + offset];
}
offset += dcCount;
- var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
- var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
+ let rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
+ let rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
- var modPoly = rawPoly.mod(rsPoly);
+ let modPoly = rawPoly.mod(rsPoly);
ecdata[r] = new Array(rsPoly.getLength() - 1);
- for (var i = 0; i < ecdata[r].length; i++) {
- var modIndex = i + modPoly.getLength() - ecdata[r].length;
+ for (let i = 0; i < ecdata[r].length; i++) {
+ let modIndex = i + modPoly.getLength() - ecdata[r].length;
ecdata[r][i] = (modIndex >= 0)? modPoly.get(modIndex) : 0;
}
}
- var totalCodeCount = 0;
- for (var i = 0; i < rsBlocks.length; i++) {
+ let totalCodeCount = 0;
+ for (let i = 0; i < rsBlocks.length; i++) {
totalCodeCount += rsBlocks[i].totalCount;
}
- var data = new Array(totalCodeCount);
- var index = 0;
+ let data = new Array(totalCodeCount);
+ let index = 0;
- for (var i = 0; i < maxDcCount; i++) {
- for (var r = 0; r < rsBlocks.length; r++) {
+ for (let i = 0; i < maxDcCount; i++) {
+ for (let r = 0; r < rsBlocks.length; r++) {
if (i < dcdata[r].length) {
data[index++] = dcdata[r][i];
}
}
}
- for (var i = 0; i < maxEcCount; i++) {
- for (var r = 0; r < rsBlocks.length; r++) {
+ for (let i = 0; i < maxEcCount; i++) {
+ for (let r = 0; r < rsBlocks.length; r++) {
if (i < ecdata[r].length) {
data[index++] = ecdata[r][i];
}
@@ -479,7 +479,7 @@ QRCode.createBytes = function(buffer, rsBlocks) {
// QRMode
//---------------------------------------------------------------------
-var QRMode = {
+let QRMode = {
MODE_NUMBER : 1 << 0,
MODE_ALPHA_NUM : 1 << 1,
MODE_8BIT_BYTE : 1 << 2,
@@ -490,7 +490,7 @@ var QRMode = {
// QRErrorCorrectLevel
//---------------------------------------------------------------------
-var QRErrorCorrectLevel = {
+let QRErrorCorrectLevel = {
L : 1,
M : 0,
Q : 3,
@@ -501,7 +501,7 @@ var QRErrorCorrectLevel = {
// QRMaskPattern
//---------------------------------------------------------------------
-var QRMaskPattern = {
+let QRMaskPattern = {
PATTERN000 : 0,
PATTERN001 : 1,
PATTERN010 : 2,
@@ -516,7 +516,7 @@ var QRMaskPattern = {
// QRUtil
//---------------------------------------------------------------------
-var QRUtil = {
+let QRUtil = {
PATTERN_POSITION_TABLE : [
[],
@@ -566,7 +566,7 @@ var QRUtil = {
G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
getBCHTypeInfo : function(data) {
- var d = data << 10;
+ let d = data << 10;
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) );
}
@@ -574,7 +574,7 @@ var QRUtil = {
},
getBCHTypeNumber : function(data) {
- var d = data << 12;
+ let d = data << 12;
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) );
}
@@ -583,7 +583,7 @@ var QRUtil = {
getBCHDigit : function(data) {
- var digit = 0;
+ let digit = 0;
while (data != 0) {
digit++;
@@ -617,9 +617,9 @@ var QRUtil = {
getErrorCorrectPolynomial : function(errorCorrectLength) {
- var a = new QRPolynomial([1], 0);
+ let a = new QRPolynomial([1], 0);
- for (var i = 0; i < errorCorrectLength; i++) {
+ for (let i = 0; i < errorCorrectLength; i++) {
a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0) );
}
@@ -674,26 +674,26 @@ var QRUtil = {
getLostPoint : function(qrCode) {
- var moduleCount = qrCode.getModuleCount();
+ let moduleCount = qrCode.getModuleCount();
- var lostPoint = 0;
+ let lostPoint = 0;
// LEVEL1
- for (var row = 0; row < moduleCount; row++) {
+ for (let row = 0; row < moduleCount; row++) {
- for (var col = 0; col < moduleCount; col++) {
+ for (let col = 0; col < moduleCount; col++) {
- var sameCount = 0;
- var dark = qrCode.isDark(row, col);
+ let sameCount = 0;
+ let dark = qrCode.isDark(row, col);
- for (var r = -1; r <= 1; r++) {
+ for (let r = -1; r <= 1; r++) {
if (row + r < 0 || moduleCount <= row + r) {
continue;
}
- for (var c = -1; c <= 1; c++) {
+ for (let c = -1; c <= 1; c++) {
if (col + c < 0 || moduleCount <= col + c) {
continue;
@@ -717,9 +717,9 @@ var QRUtil = {
// LEVEL2
- for (var row = 0; row < moduleCount - 1; row++) {
- for (var col = 0; col < moduleCount - 1; col++) {
- var count = 0;
+ for (let row = 0; row < moduleCount - 1; row++) {
+ for (let col = 0; col < moduleCount - 1; col++) {
+ let count = 0;
if (qrCode.isDark(row, col ) ) count++;
if (qrCode.isDark(row + 1, col ) ) count++;
if (qrCode.isDark(row, col + 1) ) count++;
@@ -732,8 +732,8 @@ var QRUtil = {
// LEVEL3
- for (var row = 0; row < moduleCount; row++) {
- for (var col = 0; col < moduleCount - 6; col++) {
+ for (let row = 0; row < moduleCount; row++) {
+ for (let col = 0; col < moduleCount - 6; col++) {
if (qrCode.isDark(row, col)
&& !qrCode.isDark(row, col + 1)
&& qrCode.isDark(row, col + 2)
@@ -746,8 +746,8 @@ var QRUtil = {
}
}
- for (var col = 0; col < moduleCount; col++) {
- for (var row = 0; row < moduleCount - 6; row++) {
+ for (let col = 0; col < moduleCount; col++) {
+ for (let row = 0; row < moduleCount - 6; row++) {
if (qrCode.isDark(row, col)
&& !qrCode.isDark(row + 1, col)
&& qrCode.isDark(row + 2, col)
@@ -762,17 +762,17 @@ var QRUtil = {
// LEVEL4
- var darkCount = 0;
+ let darkCount = 0;
- for (var col = 0; col < moduleCount; col++) {
- for (var row = 0; row < moduleCount; row++) {
+ for (let col = 0; col < moduleCount; col++) {
+ for (let row = 0; row < moduleCount; row++) {
if (qrCode.isDark(row, col) ) {
darkCount++;
}
}
}
- var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
+ let ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
lostPoint += ratio * 10;
return lostPoint;
@@ -785,7 +785,7 @@ var QRUtil = {
// QRMath
//---------------------------------------------------------------------
-var QRMath = {
+let QRMath = {
glog : function(n) {
@@ -815,16 +815,16 @@ var QRMath = {
};
-for (var i = 0; i < 8; i++) {
+for (let i = 0; i < 8; i++) {
QRMath.EXP_TABLE[i] = 1 << i;
}
-for (var i = 8; i < 256; i++) {
+for (let i = 8; i < 256; i++) {
QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4]
^ QRMath.EXP_TABLE[i - 5]
^ QRMath.EXP_TABLE[i - 6]
^ QRMath.EXP_TABLE[i - 8];
}
-for (var i = 0; i < 255; i++) {
+for (let i = 0; i < 255; i++) {
QRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i;
}
@@ -838,14 +838,14 @@ function QRPolynomial(num, shift) {
throw new Error(num.length + "/" + shift);
}
- var offset = 0;
+ let offset = 0;
while (offset < num.length && num[offset] == 0) {
offset++;
}
this.num = new Array(num.length - offset + shift);
- for (var i = 0; i < num.length - offset; i++) {
+ for (let i = 0; i < num.length - offset; i++) {
this.num[i] = num[i + offset];
}
}
@@ -862,10 +862,10 @@ QRPolynomial.prototype = {
multiply : function(e) {
- var num = new Array(this.getLength() + e.getLength() - 1);
+ let num = new Array(this.getLength() + e.getLength() - 1);
- for (var i = 0; i < this.getLength(); i++) {
- for (var j = 0; j < e.getLength(); j++) {
+ for (let i = 0; i < this.getLength(); i++) {
+ for (let j = 0; j < e.getLength(); j++) {
num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i) ) + QRMath.glog(e.get(j) ) );
}
}
@@ -879,15 +879,15 @@ QRPolynomial.prototype = {
return this;
}
- var ratio = QRMath.glog(this.get(0) ) - QRMath.glog(e.get(0) );
+ let ratio = QRMath.glog(this.get(0) ) - QRMath.glog(e.get(0) );
- var num = new Array(this.getLength() );
+ let num = new Array(this.getLength() );
- for (var i = 0; i < this.getLength(); i++) {
+ for (let i = 0; i < this.getLength(); i++) {
num[i] = this.get(i);
}
- for (var i = 0; i < e.getLength(); i++) {
+ for (let i = 0; i < e.getLength(); i++) {
num[i] ^= QRMath.gexp(QRMath.glog(e.get(i) ) + ratio);
}
@@ -1155,23 +1155,23 @@ QRRSBlock.RS_BLOCK_TABLE = [
QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
- var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
+ let rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
if (rsBlock == undefined) {
throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
}
- var length = rsBlock.length / 3;
+ let length = rsBlock.length / 3;
- var list = new Array();
+ let list = [];
- for (var i = 0; i < length; i++) {
+ for (let i = 0; i < length; i++) {
- var count = rsBlock[i * 3 + 0];
- var totalCount = rsBlock[i * 3 + 1];
- var dataCount = rsBlock[i * 3 + 2];
+ let count = rsBlock[i * 3 + 0];
+ let totalCount = rsBlock[i * 3 + 1];
+ let dataCount = rsBlock[i * 3 + 2];
- for (var j = 0; j < count; j++) {
+ for (let j = 0; j < count; j++) {
list.push(new QRRSBlock(totalCount, dataCount) );
}
}
@@ -1200,19 +1200,19 @@ QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
//---------------------------------------------------------------------
function QRBitBuffer() {
- this.buffer = new Array();
+ this.buffer = [];
this.length = 0;
}
QRBitBuffer.prototype = {
get : function(index) {
- var bufIndex = Math.floor(index / 8);
+ let bufIndex = Math.floor(index / 8);
return ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
},
put : function(num, length) {
- for (var i = 0; i < length; i++) {
+ for (let i = 0; i < length; i++) {
this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
}
},
@@ -1223,7 +1223,7 @@ QRBitBuffer.prototype = {
putBit : function(bit) {
- var bufIndex = Math.floor(this.length / 8);
+ let bufIndex = Math.floor(this.length / 8);
if (this.buffer.length <= bufIndex) {
this.buffer.push(0);
}