From 46f5fd860d761e422602a8c851b9da5626f3996b Mon Sep 17 00:00:00 2001 From: "yw.hao" Date: Fri, 16 Aug 2024 16:40:12 +0800 Subject: [PATCH 1/2] fix: fix hermes don't support textencoder --- lib/core/byte-data.js | 8 ++++++-- package.json | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/core/byte-data.js b/lib/core/byte-data.js index d562fcc9..8342f3d9 100644 --- a/lib/core/byte-data.js +++ b/lib/core/byte-data.js @@ -1,9 +1,13 @@ +const encodeUtf8 = require('encode-utf8') const Mode = require('./mode') function ByteData (data) { this.mode = Mode.BYTE - if (typeof (data) === 'string') { - this.data = new TextEncoder().encode(data) + if (typeof (data) === 'string' && typeof TextEncoder !== 'undefined') { + this.data = encodeUtf8(data); + this.data = new Uint8Array(data) + } else if (typeof (data) === 'string') { + this.data = new TextEncoder().encode(data); } else { this.data = new Uint8Array(data) } diff --git a/package.json b/package.json index 6e97c936..66509e7a 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "dependencies": { "dijkstrajs": "^1.0.1", + "encode-utf8": "^1.0.3", "pngjs": "^5.0.0", "yargs": "^15.3.1" }, From cc4a8738c69295866ab555f61e2dfec9ba1b3549 Mon Sep 17 00:00:00 2001 From: "yw.hao" Date: Mon, 26 Aug 2024 19:10:29 +0800 Subject: [PATCH 2/2] fix: fix logic error --- lib/core/byte-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/byte-data.js b/lib/core/byte-data.js index 8342f3d9..a1e5db89 100644 --- a/lib/core/byte-data.js +++ b/lib/core/byte-data.js @@ -3,7 +3,7 @@ const Mode = require('./mode') function ByteData (data) { this.mode = Mode.BYTE - if (typeof (data) === 'string' && typeof TextEncoder !== 'undefined') { + if (typeof (data) === 'string' && typeof TextEncoder === 'undefined') { this.data = encodeUtf8(data); this.data = new Uint8Array(data) } else if (typeof (data) === 'string') {