From 11c2ee62c365321c074137c1e34d6b6ee41ae426 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 17 Jan 2022 20:23:51 -0800 Subject: [PATCH] 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.) --- 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