- assert - 断言
- async_hooks - 异步钩子
- Buffer - 缓冲器
- child_process - 子进程
- cluster - 集群
- console - 控制台
- crypto - 加密
- debugger - 调试器
- dgram - 数据报
- dns - 域名服务器
- domain - 域
- Error - 错误
- events - 事件触发器
- fs - 文件系统
- global - 全局变量
- http - HTTP
- http2 - HTTP/2
- https - HTTPS
- inspector - 检查器
- module - 模块
- net - 网络
- os - 操作系统
- path - 路径
- perf_hooks - 性能钩子
- process - 进程
- punycode - 域名代码
- querystring - 查询字符串
- readline - 逐行读取
- repl - 交互式解释器
- stream - 流
- string_decoder - 字符串解码器
- timer - 定时器
- tls - 安全传输层
- trace_events - 跟踪事件
- tty - 终端
- url - URL
- util - 实用工具
- v8 - V8引擎
- vm - 虚拟机
- wasi - WASI
- worker_threads - 工作线程
- zlib - 压缩
目录
punycode(域名代码)#
源代码: lib/punycode.js
The version of the punycode module bundled in Node.js is being deprecated.
In a future major version of Node.js this module will be removed. Users
currently depending on the punycode
module should switch to using the
userland-provided Punycode.js module instead.
The punycode
module is a bundled version of the Punycode.js module. It
can be accessed using:
const punycode = require('punycode');
Punycode is a character encoding scheme defined by RFC 3492 that is
primarily intended for use in Internationalized Domain Names. Because host
names in URLs are limited to ASCII characters only, Domain Names that contain
non-ASCII characters must be converted into ASCII using the Punycode scheme.
For instance, the Japanese character that translates into the English word,
'example'
is '例'
. The Internationalized Domain Name, '例.com'
(equivalent
to 'example.com'
) is represented by Punycode as the ASCII string
'xn--fsq.com'
.
The punycode
module provides a simple implementation of the Punycode standard.
The punycode
module is a third-party dependency used by Node.js and
made available to developers as a convenience. Fixes or other modifications to
the module must be directed to the Punycode.js project.
punycode.decode(string)
#
string
<string>
The punycode.decode()
method converts a Punycode string of ASCII-only
characters to the equivalent string of Unicode codepoints.
punycode.decode('maana-pta'); // 'mañana'
punycode.decode('--dqo34k'); // '☃-⌘'
punycode.encode(string)
#
string
<string>
The punycode.encode()
method converts a string of Unicode codepoints to a
Punycode string of ASCII-only characters.
punycode.encode('mañana'); // 'maana-pta'
punycode.encode('☃-⌘'); // '--dqo34k'
punycode.toASCII(domain)
#
domain
<string>
The punycode.toASCII()
method converts a Unicode string representing an
Internationalized Domain Name to Punycode. Only the non-ASCII parts of the
domain name will be converted. Calling punycode.toASCII()
on a string that
already only contains ASCII characters will have no effect.
// encode domain names
punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'
punycode.toASCII('example.com'); // 'example.com'
punycode.toUnicode(domain)
#
domain
<string>
The punycode.toUnicode()
method converts a string representing a domain name
containing Punycode encoded characters into Unicode. Only the Punycode
encoded parts of the domain name are be converted.
// decode domain names
punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'
punycode.toUnicode('example.com'); // 'example.com'
punycode.ucs2
#
punycode.ucs2.decode(string)
#
string
<string>
The punycode.ucs2.decode()
method returns an array containing the numeric
codepoint values of each Unicode symbol in the string.
punycode.ucs2.decode('abc'); // [0x61, 0x62, 0x63]
// surrogate pair for U+1D306 tetragram for centre:
punycode.ucs2.decode('\uD834\uDF06'); // [0x1D306]
punycode.ucs2.encode(codePoints)
#
codePoints
<integer[]>
The punycode.ucs2.encode()
method returns a string based on an array of
numeric code point values.
punycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc'
punycode.ucs2.encode([0x1D306]); // '\uD834\uDF06'
punycode.version
#
Returns a string identifying the current Punycode.js version number.