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 danielleadams committed Mar 2, 2022
1 parent 31db297 commit e4ecbed
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 e4ecbed

Please sign in to comment.