From 9c73bd56102c18c62e0da9947164ceb49bd0ba28 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 c9ba27fc39f4c4..801e668ec3106f 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