From 1729ad5dc7b49747280baee75c84bf158a1f3403 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 18 Oct 2023 15:06:57 +1300 Subject: [PATCH 1/2] remove use of `this` with TextDecoder this fixes issues with ESM bundlers such as rollup --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 8274f6c..24c4d90 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -464,7 +464,7 @@ const decoders = { if (typeof data === 'string') data = Buffer.from(data, 'latin1'); try { - const decoder = new TextDecoder(this); + const decoder = new TextDecoder(); return decoder.decode(data); } catch {} }, From 8313824d9e443bf49f03a5b3687389ae861fe3dd Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 18 Oct 2023 16:05:22 +1300 Subject: [PATCH 2/2] make charset an explicit argument to decoders.other --- lib/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 24c4d90..2f79654 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -413,7 +413,7 @@ function getDecoder(charset) { charset = charset.toLowerCase(); continue; } - return decoders.other.bind(charset); + return decoders.other(charset); } } } @@ -458,13 +458,13 @@ const decoders = { return data.base64Slice(0, data.length); }, - other: (data, hint) => { + other: (charset) => (data, hint) => { if (data.length === 0) return ''; if (typeof data === 'string') data = Buffer.from(data, 'latin1'); try { - const decoder = new TextDecoder(); + const decoder = new TextDecoder(charset); return decoder.decode(data); } catch {} },