url.domainToASCII(domain)


返回 domainPunycode 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().

只有在启用 ICU 的情况下编译 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