home / documentation / v16 / punycode

Punycode

目录

自 v7.0.0 版本开始弃用

自 v0.10.0 版本开始新增

稳定级别:0 - Deprecated

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. For punycode-based URL encoding, see url.domainToASCII or, more generally, the WHATWG URL API.

The punycode module is a bundled version of the Punycode.js module. It can be accessed using:

JS

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.

M punycode.decode(string)

自 v0.5.1 版本开始新增

The punycode.decode() method converts a Punycode string of ASCII-only characters to the equivalent string of Unicode codepoints.

JS

M punycode.encode(string)

自 v0.5.1 版本开始新增

The punycode.encode() method converts a string of Unicode codepoints to a Punycode string of ASCII-only characters.

JS

M punycode.toASCII(domain)

自 v0.6.1 版本开始新增

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.

JS

M punycode.toUnicode(domain)

自 v0.6.1 版本开始新增

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.

JS

M punycode.ucs2

自 v0.7.0 版本开始新增

M punycode.ucs2.decode(string)

自 v0.7.0 版本开始新增

The punycode.ucs2.decode() method returns an array containing the numeric codepoint values of each Unicode symbol in the string.

JS

M punycode.ucs2.encode(codePoints)

自 v0.7.0 版本开始新增

  • codePoints integer[]

The punycode.ucs2.encode() method returns a string based on an array of numeric code point values.

JS

M punycode.version

自 v0.6.1 版本开始新增

Returns a string identifying the current Punycode.js version number.