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 <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
Trott authored and BethGriggs committed Jan 24, 2022
1 parent f947f72 commit 9c73bd5
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 @@ -1187,13 +1187,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 9c73bd5

Please sign in to comment.