Skip to content

Commit 5e27307

Browse files
committed
New version 3.7.0 release!
# Fixed a version issue + Add binary(hex) data mode support
1 parent 95a40ce commit 5e27307

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

index.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* EasyQRCodeJS-NodeJS
33
*
4-
* NodeJS QRCode generator. Save image to file. Support Dot style, Logo, Background image, Colorful, Title, etc.(Running without DOM on server side)
4+
* NodeJS QRCode generator. Can get standard base64 image data url text or save image to file. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. Support binary(hex) data mode. (Running without DOM on server side)
55
*
6-
* Version 3.6.0
6+
* Version 3.7.0
77
*
88
* @author [ inthinkcolor@gmail.com ]
99
*
@@ -25,7 +25,7 @@ var {
2525

2626
var fs = require('fs');
2727

28-
function QR8bitByte(data) {
28+
function QR8bitByte(data, binary) {
2929
this.mode = QRMode.MODE_8BIT_BYTE;
3030
this.data = data;
3131
this.parsedData = [];
@@ -35,20 +35,24 @@ function QR8bitByte(data) {
3535
var byteArray = [];
3636
var code = this.data.charCodeAt(i);
3737

38-
if (code > 0x10000) {
39-
byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
40-
byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
41-
byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
42-
byteArray[3] = 0x80 | (code & 0x3F);
43-
} else if (code > 0x800) {
44-
byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
45-
byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
46-
byteArray[2] = 0x80 | (code & 0x3F);
47-
} else if (code > 0x80) {
48-
byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
49-
byteArray[1] = 0x80 | (code & 0x3F);
50-
} else {
38+
if (binary) {
5139
byteArray[0] = code;
40+
} else {
41+
if (code > 0x10000) {
42+
byteArray[0] = 0xF0 | ((code & 0x1C0000) >>> 18);
43+
byteArray[1] = 0x80 | ((code & 0x3F000) >>> 12);
44+
byteArray[2] = 0x80 | ((code & 0xFC0) >>> 6);
45+
byteArray[3] = 0x80 | (code & 0x3F);
46+
} else if (code > 0x800) {
47+
byteArray[0] = 0xE0 | ((code & 0xF000) >>> 12);
48+
byteArray[1] = 0x80 | ((code & 0xFC0) >>> 6);
49+
byteArray[2] = 0x80 | (code & 0x3F);
50+
} else if (code > 0x80) {
51+
byteArray[0] = 0xC0 | ((code & 0x7C0) >>> 6);
52+
byteArray[1] = 0x80 | (code & 0x3F);
53+
} else {
54+
byteArray[0] = code;
55+
}
5256
}
5357

5458
this.parsedData.push(byteArray);
@@ -84,8 +88,8 @@ function QRCodeModel(typeNumber, errorCorrectLevel) {
8488
}
8589

8690
QRCodeModel.prototype = {
87-
addData: function(data) {
88-
var newData = new QR8bitByte(data);
91+
addData: function(data, binary) {
92+
var newData = new QR8bitByte(data, binary);
8993
this.dataList.push(newData);
9094
this.dataCache = null;
9195
},
@@ -1046,7 +1050,7 @@ function _getTypeNumber(sText, _htOption) {
10461050

10471051
function _getUTF8Length(sText) {
10481052
var replacedText = encodeURI(sText).toString().replace(/\%[0-9a-fA-F]{2}/g, 'a');
1049-
return replacedText.length + (replacedText.length != sText ? 3 : 0);
1053+
return replacedText.length + (replacedText.length != sText.length ? 3 : 0);
10501054
}
10511055

10521056
/**
@@ -1503,7 +1507,11 @@ function QRCode(vOption) {
15031507
quality: 0.75, // An object specifying the quality (0 to 1). default is 0.75. (JPGs only)
15041508

15051509
// ==== Versions
1506-
version: 0 // The symbol versions of QR Code range from Version 1 to Version 40. default 0 means automatically choose the closest version based on the text length.
1510+
version: 0, // The symbol versions of QR Code range from Version 1 to Version 40. default 0 means automatically choose the closest version based on the text length.
1511+
1512+
// ==== binary(hex) data mode
1513+
binary: false // Whether it is binary mode, default is text mode.
1514+
15071515

15081516
};
15091517
if (typeof vOption === 'string') {
@@ -1555,7 +1563,7 @@ function QRCode(vOption) {
15551563

15561564
this._oQRCode = null;
15571565
this._oQRCode = new QRCodeModel(_getTypeNumber(this._htOption.text, this._htOption), this._htOption.correctLevel);
1558-
this._oQRCode.addData(this._htOption.text);
1566+
this._oQRCode.addData(this._htOption.text, this._htOption.binary);
15591567
this._oQRCode.make();
15601568
}
15611569

0 commit comments

Comments
 (0)