url.domainToASCII(domain)
返回 domain 的 Punycode ASCII 序列化。如果 domain 是无效域名,则返回空字符串。
🌐 Returns the Punycode ASCII serialization of the domain. If domain is an
invalid domain, the empty string is returned.
它执行与 url.domainToUnicode() 相反的操作。
🌐 It performs the inverse operation to url.domainToUnicode().
此功能仅在 node 可执行文件在编译时启用了 重症监护室 的情况下可用。如果未启用,域名将原样传递。
🌐 This feature is only available if the node executable was compiled with
ICU enabled. If not, the domain names are passed through unchanged.
import url from 'node:url';
console.log(url.domainToASCII('español.com'));
// Prints xn--espaol-zwa.com
console.log(url.domainToASCII('中文.com'));
// Prints xn--fiq228c.com
console.log(url.domainToASCII('xn--iñvalid.com'));
// Prints an empty stringconst url = require('node:url');
console.log(url.domainToASCII('español.com'));
// Prints xn--espaol-zwa.com
console.log(url.domainToASCII('中文.com'));
// Prints xn--fiq228c.com
console.log(url.domainToASCII('xn--iñvalid.com'));
// Prints an empty string