Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2022-01-20 08:12:39 +0300
committerGitHub <noreply@github.com>2022-01-20 08:12:39 +0300
commit8e413ff374231924aaf96da39315995ffab02b71 (patch)
tree5115ebae7771628520712f82d71a05a7b3e0f895 /doc/api/util.md
parent25381da6b867a58d2ab8db43e5ebe315c4c6ff46 (diff)
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'doc/api/util.md')
-rw-r--r--doc/api/util.md10
1 files changed, 3 insertions, 7 deletions
diff --git a/doc/api/util.md b/doc/api/util.md
index c9ba27fc39f..801e668ec31 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -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