Node.js v18.12.1 documentation


Table of contents

Punycode#

Stability: 0 - Deprecated已弃用

Source Code: lib/punycode.js

The version of the punycode module bundled in Node.js is being deprecated.Node.js中捆绑的punycode模块版本正在被弃用。 In a future major version of Node.js this module will be removed. 在Node.js的未来主要版本中,此模块将被删除。Users currently depending on the punycode module should switch to using the userland-provided Punycode.js module instead. 当前依赖punycode模块的用户应该改用userland提供的Punycode.js模块。For punycode-based URL encoding, see url.domainToASCII or, more generally, the WHATWG URL API.有关基于punycode的URL编码,请参阅url.domainToASCII,或者更一般地,WHATWG URL API

The punycode module is a bundled version of the Punycode.js module. punycode模块是Punycode.js模块的捆绑版本。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. 是RFC 3492定义的字符编码方案,主要用于国际化域名。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. 由于URL中的主机名仅限于ASCII字符,因此必须使用Punycode方案将包含非ASCII字符的域名转换为ASCII。For instance, the Japanese character that translates into the English word, 'example' is '例'. 例如,翻译成英语单词'example'的日语字符是'例'The Internationalized Domain Name, '例.com' (equivalent to 'example.com') is represented by Punycode as the ASCII string 'xn--fsq.com'.国际化域名'例.com'(相当于'example.com')由Punycode表示为ASCII字符串'xn--fsq.com'

The punycode module provides a simple implementation of the Punycode standard.punycode模块提供了punycode标准的简单实现。

The punycode module is a third-party dependency used by Node.js and made available to developers as a convenience. punycode模块是Node.js使用的第三方依赖项,为开发人员提供方便。Fixes or other modifications to the module must be directed to the Punycode.js project.对模块的修复或其他修改必须指向Punycode.js项目。