Skip to content

Commit 9f8e442

Browse files
Trottdanielleadams
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 <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 2c813d8 commit 9f8e442

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
@@ -1185,13 +1185,9 @@ added: v8.3.0
11851185
An implementation of the [WHATWG Encoding Standard][] `TextDecoder` API.
11861186

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

11971193
### WHATWG supported encodings

0 commit comments

Comments
 (0)