Skip to content

Commit c1bf8e4

Browse files
committed
Add utf8WithoutBOM option
Add `utf8WithoutBOM` option
1 parent 1c7702e commit c1bf8e4

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

dist/easy.qrcode.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easyqrcodejs",
3-
"version": "4.4.6",
3+
"version": "4.4.7",
44
"description": "Cross-browser QRCode generator for pure javascript. Support Canvas, SVG and Table drawing methods. Support Dot style, Logo, Background image, Colorful, Title etc. settings. Support Angular, Vue.js, React, Next.js, Svelte framework. Support binary(hex) data mode.(Running with DOM on client side)",
55
"main": "dist/easy.qrcode.min.js",
66
"scripts": {},

readme.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@ var qrcode = new QRCode(DOM_object, options_object);
311311

312312
// ===== Drawing method
313313
/*
314-
drawer: 'canvas' // Which drawing method to use. 'canvas', 'svg'. default is 'canvas'
314+
drawer: 'canvas', // Which drawing method to use. 'canvas', 'svg'. default is 'canvas'
315+
*/
316+
317+
// ===== UTF-8 without BOM
318+
/*
319+
utf8WithoutBOM: true
315320
*/
316321

317322
}
@@ -392,11 +397,14 @@ var qrcode = new QRCode(DOM_object, options_object);
392397
| **binary** | N | Boolean | `false` | Whether it is binary mode, default is text mode. |   |
393398
| CORS options| --- | ---|---|---|---|
394399
| **crossOrigin** | N | String | `null` | String which specifies the CORS setting to use when retrieving the image. null means that the crossOrigin attribute is not set. `'anonymous'`, `null`. |   |
400+
| UTF-8 options| --- | ---|---|---|---|
401+
| **utf8WithoutBOM** | N | Boolean | `true` | Use UTF-8 without BOM. set to `false` value will use BOM in UFT-8.|   |
395402
| Drawing method options| --- | ---|---|---|---|
396403
| **drawer** | N | String | `canvas` | Which drawing method to use. `canvas`, `svg`. | Chrome, FF, IE9+. |
397404

398405

399406

407+
400408
### Method
401409

402410

src/easy.qrcode.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Cross-browser QRCode generator for pure javascript. Support Canvas, SVG and Table drawing methods. Support Dot style, Logo, Background image, Colorful, Title etc. settings. Support Angular, Vue.js, React, Next.js, Svelte framework. Support binary(hex) data mode.(Running with DOM on client side)
55
*
6-
* Version 4.4.6
6+
* Version 4.4.7
77
*
88
* @author [ inthinkcolor@gmail.com ]
99
*
@@ -45,7 +45,7 @@
4545

4646
var QRCode;
4747

48-
function QR8bitByte(data, binary) {
48+
function QR8bitByte(data, binary, utf8WithoutBOM) {
4949
this.mode = QRMode.MODE_8BIT_BYTE;
5050
this.data = data;
5151
this.parsedData = [];
@@ -80,8 +80,7 @@
8080
}
8181

8282
this.parsedData = Array.prototype.concat.apply([], this.parsedData);
83-
84-
if (this.parsedData.length != this.data.length) {
83+
if (!utf8WithoutBOM && this.parsedData.length != this.data.length) {
8584
this.parsedData.unshift(191);
8685
this.parsedData.unshift(187);
8786
this.parsedData.unshift(239);
@@ -109,8 +108,8 @@
109108
}
110109

111110
QRCodeModel.prototype = {
112-
addData: function(data, binary) {
113-
var newData = new QR8bitByte(data, binary);
111+
addData: function(data, binary, utf8WithoutBOM) {
112+
var newData = new QR8bitByte(data, binary, utf8WithoutBOM);
114113
this.dataList.push(newData);
115114
this.dataCache = null;
116115
},
@@ -2003,7 +2002,10 @@
20032002
drawer: 'canvas', // Drawing method: canvas, svg(Chrome, FF, IE9+)
20042003

20052004
// ==== CORS
2006-
crossOrigin: null // String which specifies the CORS setting to use when retrieving the image. null means that the crossOrigin attribute is not set.
2005+
crossOrigin: null, // String which specifies the CORS setting to use when retrieving the image. null means that the crossOrigin attribute is not set.
2006+
2007+
// UTF-8 without BOM
2008+
utf8WithoutBOM: true
20072009
};
20082010

20092011
if (typeof vOption === 'string') {
@@ -2128,7 +2130,7 @@
21282130
QRCode.prototype.makeCode = function(sText) {
21292131

21302132
this._oQRCode = new QRCodeModel(_getTypeNumber(sText, this._htOption), this._htOption.correctLevel);
2131-
this._oQRCode.addData(sText, this._htOption.binary);
2133+
this._oQRCode.addData(sText, this._htOption.binary, this._htOption.utf8WithoutBOM);
21322134
this._oQRCode.make();
21332135
if (this._htOption.tooltip) {
21342136
this._el.title = sText;

0 commit comments

Comments
 (0)