📅  最后修改于: 2023-12-03 15:03:14.462000             🧑  作者: Mango
The URL.domainToASCII
method in Node.js is used to convert a Unicode domain name into an ASCII encoded domain name. This is useful when you need to perform DNS lookups and other operations that require an ASCII domain name.
const url = require('url');
url.domainToASCII(hostname)
The hostname
parameter is a string that contains the Unicode domain name you want to convert to ASCII.
This method returns the ASCII encoded domain name as a string.
const url = require('url');
const hostname = 'سایت.ایران'; // Unicode domain name
const asciiHostname = url.domainToASCII(hostname);
console.log(asciiHostname); // 'xn--mgbh0fb.xn--mgba3a4f16a'
In this example, we convert the Unicode domain name 'سایت.ایران' into its ASCII encoded equivalent using the URL.domainToASCII
method. The resulting ASCII encoded domain name is 'xn--mgbh0fb.xn--mgba3a4f16a'.
URL.domainToASCII
will convert them using the Punycode encoding system.URL.domainToUnicode
, which converts an ASCII encoded domain name into a Unicode domain name.