Skip to content

Commit 2ba58ac

Browse files
committed
Add utf8WithoutBOM option
Add `utf8WithoutBOM` option
1 parent b6aacdf commit 2ba58ac

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

QRCode.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* React Native QRCode generation component. Can generate standard QRCode image or base64 image data url text. Cross-browser QRCode generator for pure javascript. Support Dot style, Logo, Background image, Colorful, Title etc. settings. support binary mode.
55
*
6-
* Version 4.0.3
6+
* Version 4.0.4
77
*
88
* @author [ [email protected] ]
99
*
@@ -20,7 +20,7 @@ import Canvas, {
2020
Image as CanvasImage
2121
} from 'react-native-canvas';
2222

23-
function QR8bitByte(data, binary) {
23+
function QR8bitByte(data, binary, utf8WithoutBOM) {
2424
this.mode = QRMode.MODE_8BIT_BYTE;
2525
this.data = data;
2626
this.parsedData = [];
@@ -55,7 +55,7 @@ function QR8bitByte(data, binary) {
5555

5656
this.parsedData = Array.prototype.concat.apply([], this.parsedData);
5757

58-
if (this.parsedData.length != this.data.length) {
58+
if (!utf8WithoutBOM && this.parsedData.length != this.data.length) {
5959
this.parsedData.unshift(191);
6060
this.parsedData.unshift(187);
6161
this.parsedData.unshift(239);
@@ -83,8 +83,8 @@ function QRCodeModel(typeNumber, errorCorrectLevel) {
8383
}
8484

8585
QRCodeModel.prototype = {
86-
addData: function(data, binary) {
87-
var newData = new QR8bitByte(data, binary);
86+
addData: function(data, binary, utf8WithoutBOM) {
87+
var newData = new QR8bitByte(data, binary, utf8WithoutBOM);
8888
this.dataList.push(newData);
8989
this.dataCache = null;
9090
},
@@ -1533,8 +1533,10 @@ function QRCode(canvas, vOption) {
15331533
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.
15341534

15351535
// ==== binary(hex) data mode
1536-
binary: false // Whether it is binary mode, default is text mode.
1536+
binary: false, // Whether it is binary mode, default is text mode.
15371537

1538+
// UTF-8 without BOM
1539+
utf8WithoutBOM: true
15381540

15391541
};
15401542
if (typeof vOption === 'string') {
@@ -1631,7 +1633,7 @@ function QRCode(canvas, vOption) {
16311633

16321634
this._oQRCode = null;
16331635
this._oQRCode = new QRCodeModel(_getTypeNumber(this._htOption.text, this._htOption), this._htOption.correctLevel);
1634-
this._oQRCode.addData(this._htOption.text, this._htOption.binary);
1636+
this._oQRCode.addData(this._htOption.text, this._htOption.binary, this._htOption.utf8WithoutBOM);
16351637
this._oQRCode.make();
16361638
this._show();
16371639
}
@@ -1651,7 +1653,7 @@ QRCode.prototype._show = function() {
16511653
QRCode.prototype.makeCode = function(sText) {
16521654

16531655
this._oQRCode = new QRCodeModel(_getTypeNumber(sText, this._htOption), this._htOption.correctLevel);
1654-
this._oQRCode.addData(sText, this._htOption.binary);
1656+
this._oQRCode.addData(sText, this._htOption.binary, this._htOption.utf8WithoutBOM);
16551657
this._oQRCode.make();
16561658
if (this._htOption.tooltip) {
16571659
this._el.title = sText;

QRCode.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": "easyqrcode-react-native",
3-
"version": "4.0.3",
3+
"version": "4.0.4",
44
"description": "React Native QRCode generation component. 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 mode.",
55
"main": "QRCode.min.js",
66
"scripts": {},

readme.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,13 @@ var qrcode = new QRCode(canvas_object, options_object);
252252

253253
// ===== Binary(hex) data mode
254254
/*
255-
binary: false // Whether it is binary mode, default is text mode.
255+
binary: false, // Whether it is binary mode, default is text mode.
256256
*/
257+
258+
// ===== UTF-8 without BOM
259+
/*
260+
utf8WithoutBOM: true
261+
*/
257262
}
258263
```
259264

@@ -327,6 +332,8 @@ var qrcode = new QRCode(canvas_object, options_object);
327332
| **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. |
328333
| Tooltip options| --- | ---|---|---|
329334
| **tooltip** | N | Boolean | `false` | Whether set the QRCode Text as the title attribute value of the QRCode div. |
335+
| UTF-8 options| --- | ---|---|---|
336+
| **utf8WithoutBOM** | N | Boolean | `true` | Use UTF-8 without BOM. set to `false` value will use BOM in UFT-8.|
330337
| Binary(hex) data model options| --- | ---|---|---|
331338
| **binary** | N | Boolean | `false` | Whether it is binary mode, default is text mode. |
332339

0 commit comments

Comments
 (0)