Skip to content

Commit 9c73bd5

Browse files
TrottBethGriggs
authored andcommitted
doc: simplify util.TextDecoder example
This simplifies the example and makes it runnable. (The current example has a magic function.) (This also removes an assignment in a condition which will be flagged if we enable ESLint's no-cond-assign rule.) PR-URL: #41574 Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent f947f72 commit 9c73bd5

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

doc/api/util.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -1187,13 +1187,9 @@ added: v8.3.0
11871187
An implementation of the [WHATWG Encoding Standard][] `TextDecoder` API.
11881188

11891189
```js
1190-
const decoder = new TextDecoder('shift_jis');
1191-
let string = '';
1192-
let buffer;
1193-
while (buffer = getNextChunkSomehow()) {
1194-
string += decoder.decode(buffer, { stream: true });
1195-
}
1196-
string += decoder.decode(); // end-of-stream
1190+
const decoder = new TextDecoder();
1191+
const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
1192+
console.log(decoder.decode(u8arr)); // Hello
11971193
```
11981194

11991195
### WHATWG supported encodings

0 commit comments

Comments
 (0)