doc: use global TextDecoder and TextEncoder instead of util

Signed-off-by: LiviaMedeiros <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67461
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
This commit is contained in:
LiviaMedeiros committed 2026-11-16 08:51:57 +08:00
1 parent 8dbdd03581
commit 1260eeea40
3 files changed
+5 -7

No files matched your search

+3 -3
View File
@@ -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
+2 -2
View File
@@ -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
-2
View File
@@ -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!');