From 1260eeea401606cfe407106690d00bf3d2087f38 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 14 Nov 2026 07:10:26 +0800 Subject: [PATCH] doc: use global `TextDecoder` and `TextEncoder` instead of `util` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LiviaMedeiros PR-URL: https://github.com/nodejs/node/pull/67461 Reviewed-By: Aviv Keller Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Filip Skokan Reviewed-By: Gürgün Dayıoğlu --- doc/api/intl.md | 6 +++--- doc/api/module.md | 4 ++-- doc/api/webstreams.md | 2 -- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/api/intl.md b/doc/api/intl.md index e16c353db14..d073146f92c 100644 --- a/doc/api/intl.md +++ b/doc/api/intl.md @@ -20,7 +20,7 @@ programs. Some of them are: * The [WHATWG URL parser][]'s [internationalized domain names][] (IDNs) support * [`require('node:buffer').transcode()`][] * More accurate [REPL][] line editing -* [`require('node:util').TextDecoder`][] +* [`TextDecoder`][] * [`RegExp` Unicode Property Escapes][] Node.js and the underlying V8 engine use @@ -57,7 +57,7 @@ option: | [WHATWG URL Parser][] | partial (no IDN support) | full | full | full | | [`require('node:buffer').transcode()`][] | none (function does not exist) | full | full | full | | [REPL][] | partial (inaccurate line editing) | full | full | full | -| [`require('node:util').TextDecoder`][] | partial (basic encodings support) | partial/full (depends on OS) | partial (Unicode-only) | full | +| [`TextDecoder`][] | partial (basic encodings support) | partial/full (depends on OS) | partial (Unicode-only) | full | | [`RegExp` Unicode Property Escapes][] | none (invalid `RegExp` error) | full | full | full | The "(not locale-aware)" designation denotes that the function carries out its @@ -231,8 +231,8 @@ to be helpful: [`String.prototype.normalize()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize [`String.prototype.toLowerCase()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase [`String.prototype.toUpperCase()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase +[`TextDecoder`]: globals.md#class-textdecoder [`require('node:buffer').transcode()`]: buffer.md#buffertranscodesource-fromenc-toenc -[`require('node:util').TextDecoder`]: util.md#class-utiltextdecoder [btest402]: https://github.com/srl295/btest402 [full-icu]: https://www.npmjs.com/package/full-icu [internationalized domain names]: https://en.wikipedia.org/wiki/Internationalized_domain_name diff --git a/doc/api/module.md b/doc/api/module.md index 309114f9468..6af6b3d8a7c 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -1036,7 +1036,7 @@ not possible to replace the value of a Node.js builtin (core) module. * The specific {TypedArray} object is a {Uint8Array}. If the source value of a text-based format (i.e., `'json'`, `'module'`) -is not a string, it is converted to a string using [`util.TextDecoder`][]. +is not a string, it is converted to a string using [`TextDecoder`][]. ### Examples @@ -1413,6 +1413,7 @@ returned object contains the following keys: [`NODE_V8_COVERAGE=dir`]: cli.md#node_v8_coveragedir [`Object.freeze()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze [`SourceMap`]: #class-modulesourcemap +[`TextDecoder`]: globals.md#class-textdecoder [`module.constants.compileCacheStatus`]: #moduleconstantscompilecachestatus [`module.enableCompileCache()`]: #moduleenablecompilecacheoptions [`module.flushCompileCache()`]: #moduleflushcompilecache @@ -1421,7 +1422,6 @@ returned object contains the following keys: [`module.registerHooks()`]: #moduleregisterhooksoptions [`module.setSourceMapsSupport()`]: #modulesetsourcemapssupportenabled-options [`os.tmpdir()`]: os.md#ostmpdir -[`util.TextDecoder`]: util.md#class-utiltextdecoder [accepted final formats]: #accepted-final-formats-returned-by-load [deregistration of customization hooks]: #deregistration-of-customization-hooks [hook functions]: #hook-functions-accepted-by-moduleregisterhooks diff --git a/doc/api/webstreams.md b/doc/api/webstreams.md index 45e87152b86..3917d732d8f 100644 --- a/doc/api/webstreams.md +++ b/doc/api/webstreams.md @@ -1634,7 +1634,6 @@ added: v16.7.0 ```mjs import { arrayBuffer } from 'node:stream/consumers'; import { Readable } from 'node:stream'; -import { TextEncoder } from 'node:util'; const encoder = new TextEncoder(); const dataArray = encoder.encode('hello world from consumers!'); @@ -1648,7 +1647,6 @@ console.log(`from readable: ${data.byteLength}`); ```cjs const { arrayBuffer } = require('node:stream/consumers'); const { Readable } = require('node:stream'); -const { TextEncoder } = require('node:util'); const encoder = new TextEncoder(); const dataArray = encoder.encode('hello world from consumers!');