Skip to content

Commit e2ddd20

Browse files
committed
Add utf8WithoutBOM option
Add `utf8WithoutBOM` option
1 parent a2dc6e6 commit e2ddd20

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

index.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* NodeJS QRCode generator. Can save image or svg to file, get standard base64 image data url text or get SVG serialized text. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. support binary mode.(Running without DOM on server side)
55
*
6-
* Version 4.4.0
6+
* Version 4.4.1
77
*
88
* @author [ [email protected] ]
99
*
@@ -35,7 +35,7 @@ const {
3535
} = jsdom;
3636
const win = new JSDOM().window;
3737

38-
function QR8bitByte(data, binary) {
38+
function QR8bitByte(data, binary, utf8WithoutBOM) {
3939
this.mode = QRMode.MODE_8BIT_BYTE;
4040
this.data = data;
4141
this.parsedData = [];
@@ -70,7 +70,7 @@ function QR8bitByte(data, binary) {
7070

7171
this.parsedData = Array.prototype.concat.apply([], this.parsedData);
7272

73-
if (this.parsedData.length != this.data.length) {
73+
if (!utf8WithoutBOM && this.parsedData.length != this.data.length) {
7474
this.parsedData.unshift(191);
7575
this.parsedData.unshift(187);
7676
this.parsedData.unshift(239);
@@ -98,8 +98,8 @@ function QRCodeModel(typeNumber, errorCorrectLevel) {
9898
}
9999

100100
QRCodeModel.prototype = {
101-
addData: function(data, binary) {
102-
var newData = new QR8bitByte(data, binary);
101+
addData: function(data, binary, utf8WithoutBOM) {
102+
var newData = new QR8bitByte(data, binary, utf8WithoutBOM);
103103
this.dataList.push(newData);
104104
this.dataCache = null;
105105
},
@@ -1461,7 +1461,7 @@ Drawing.prototype.draw = function(oQRCode) {
14611461
// console.error(e);
14621462
t.reject(e);
14631463
}
1464-
img.originalSrc=_htOption.logo;
1464+
img.originalSrc = _htOption.logo;
14651465
img.src = _htOption.logo;
14661466
// if (img.complete) {
14671467
// img.onload = null;
@@ -1548,14 +1548,14 @@ Drawing.prototype.makeImage = function() {
15481548
if (this._htOption.onRenderingStart) {
15491549
this._htOption.onRenderingStart(this._htOption);
15501550
}
1551-
1551+
15521552
if (this._htOption.format == 'PNG') {
15531553
// dataUrl = this._canvas.toDataURL()
15541554
t.resolve(this._canvas.createPNGStream());
15551555
} else {
15561556
t.resolve(this._canvas.createJPEGStream());
15571557
}
1558-
1558+
15591559
}
15601560
};
15611561

@@ -1660,7 +1660,10 @@ function QRCode(vOption) {
16601660
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.
16611661

16621662
// ==== binary(hex) data mode
1663-
binary: false // Whether it is binary mode, default is text mode.
1663+
binary: false, // Whether it is binary mode, default is text mode.
1664+
1665+
// UTF-8 without BOM
1666+
utf8WithoutBOM: true
16641667
};
16651668
if (typeof vOption === 'string') {
16661669
vOption = {
@@ -1776,7 +1779,7 @@ function QRCode(vOption) {
17761779

17771780
this._oQRCode = null;
17781781
this._oQRCode = new QRCodeModel(_getTypeNumber(this._htOption.text, this._htOption), this._htOption.correctLevel);
1779-
this._oQRCode.addData(this._htOption.text, this._htOption.binary);
1782+
this._oQRCode.addData(this._htOption.text, this._htOption.binary, this._htOption.utf8WithoutBOM);
17801783
this._oQRCode.make();
17811784
}
17821785

@@ -1828,7 +1831,7 @@ QRCode.prototype.saveSVG = function(saveOptions) {
18281831
// Get Base64 or SVG text
18291832
QRCode.prototype._toData = function(drawer, makeType) {
18301833
var defOptions = {
1831-
makeType: makeType?makeType:'URL'
1834+
makeType: makeType ? makeType : 'URL'
18321835
}
18331836
this._htOption._drawer = drawer;
18341837

index.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easyqrcodejs-nodejs",
3-
"version": "4.4.0",
3+
"version": "4.4.1",
44
"description": "NodeJS QRCode generator. Can save image or svg to file, get standard base64 image data url text or get SVG serialized text. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. support binary mode.(Running without DOM on server side)",
55
"main": "index.min.js",
66
"scripts": {},

readme.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,13 @@ var qrcode = new QRCode(options);
258258

259259
// ===== Binary(hex) data mode
260260
/*
261-
binary: false // Whether it is binary mode, default is text mode.
261+
binary: false, // Whether it is binary mode, default is text mode.
262262
*/
263+
264+
// ===== UTF-8 without BOM
265+
/*
266+
utf8WithoutBOM: true
267+
*/
263268
}
264269
```
265270

@@ -333,6 +338,8 @@ var qrcode = new QRCode(options);
333338
| **quality** | N | Number | `0.75` | An object specifying the quality (0 to 1). (**JPGs only**) |
334339
| Version options| --- | ---|---|---|
335340
| **version** | N | Number | `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. [Information capacity and versions of QR Codes](https://www.qrcode.com/en/about/version.html) **NOTE**: If you set a value less than the minimum version available for text, the minimum version is automatically used. |
341+
| UTF-8 options| --- | ---|---|---|
342+
| **utf8WithoutBOM** | N | Boolean | `true` | Use UTF-8 without BOM. set to `false` value will use BOM in UFT-8.|
336343
| Binary(hex) data model options| --- | ---|---|---|
337344
| **binary** | N | Boolean | `false` | Whether it is binary mode, default is text mode. |
338345

0 commit comments

Comments
 (0)