Skip to content

Commit 002467a

Browse files
committed
feat: add node:string_decoder with global polyfill
1 parent e06358d commit 002467a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Using this preset, we can convert a code that is depending on Node.js to work an
7777
| [node:stream/consumers](https://nodejs.org/api/stream.html) | Mocked | [unenv/node/stream/consumers](./src/runtime/node/stream/consumers) |
7878
| [node:stream/promises](https://nodejs.org/api/stream.html) | Mocked | [unenv/node/stream/promises](./src/runtime/node/stream/promises) |
7979
| [node:stream/web](https://nodejs.org/api/stream.html) | Native | [unenv/node/stream/web](./src/runtime/node/stream/web) |
80-
| [node:string_decoder](https://nodejs.org/api/string_decoder.html) | Mocked | - |
80+
| [node:string_decoder](https://nodejs.org/api/string_decoder.html) | Polyfilled | [unenv/node/string_decoder](./src/runtime/node/string_decoder) |
8181
| [node:sys](https://nodejs.org/api/sys.html) | Mocked | - |
8282
| [node:timers](https://nodejs.org/api/timers.html) | Mocked | - |
8383
| [node:timers/promises](https://nodejs.org/api/timers.html) | Mocked | - |

src/presets/nodeless.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const nodeless: Preset & { alias: Map<string, string> } = {
2424
"stream/promises",
2525
"stream/consumers",
2626
"stream/web",
27+
"string_decoder",
2728
"url",
2829
"util",
2930
"util/types",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// https://nodejs.org/api/string_decoder.html
2+
import type stringDecoder from "node:string_decoder";
3+
import { notImplementedClass } from "src/runtime/_internal/utils";
4+
5+
export const StringDecoder: typeof stringDecoder.StringDecoder =
6+
(globalThis as any).StringDecoder ||
7+
notImplementedClass("string_decoder.StringDecoder");
8+
9+
export default <typeof stringDecoder>{
10+
StringDecoder,
11+
};

0 commit comments

Comments
 (0)