Skip to content

Commit

Permalink
doc: simplify util.TextDecoder example
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Trott authored and danielleadams committed Mar 14, 2022
1 parent 2c813d8 commit 9f8e442
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -1185,13 +1185,9 @@ added: v8.3.0
An implementation of the [WHATWG Encoding Standard][] `TextDecoder` API.

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

### WHATWG supported encodings
Expand Down

0 comments on commit 9f8e442

Please sign in to comment.