Skip to content

Commit

Permalink
Use web-encoding pkg instead of TextDecoder from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Feb 20, 2024
1 parent a183bca commit c4dd41c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 49 deletions.
77 changes: 39 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"reconnecting-websocket": "4.4.0",
"uniqid": "5.4.0",
"utf-8-validate": "^5.0.10",
"web-encoding": "^1.1.5",
"ws": "8.4.0",
"xhr2": "0.2.1"
},
Expand Down
13 changes: 2 additions & 11 deletions src/Internal/Types/TokenName.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
/* global BROWSER_RUNTIME */

// `TextDecoder` is not available in `node`, use polyfill in that case
let OurTextDecoder;
if (typeof BROWSER_RUNTIME == "undefined" || !BROWSER_RUNTIME) {
const util = await import("util");
OurTextDecoder = util.TextDecoder;
} else {
OurTextDecoder = TextDecoder;
}
import { TextDecoder } from "web-encoding";

export function _decodeUtf8(buffer) {
return left => right => {
let decoder = new OurTextDecoder("utf-8", { fatal: true }); // Without fatal=true it never fails
let decoder = new TextDecoder("utf-8", { fatal: true }); // Without fatal=true it never fails

try {
return right(decoder.decode(buffer));
Expand Down

0 comments on commit c4dd41c

Please sign in to comment.