From 9f8e442dc71b44f40aae2a7d783846c212ebdedb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 19 Jan 2022 21:12:39 -0800 Subject: [PATCH] doc: simplify util.TextDecoder example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca --- doc/api/util.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/doc/api/util.md b/doc/api/util.md index 0e90b2892ffc5a..04a7acfaf5de6b 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -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