punycode.toASCII(domain)


punycode.toASCII() 方法将表示国际化域名的 Unicode 字符串转换为 Punycode。只有域名中非 ASCII 的部分会被转换。对已经仅包含 ASCII 字符的字符串调用 punycode.toASCII() 不会有任何效果。

【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'