Module punycode
punycode Internationalized Domain Name Conversion Module
Punycode is a character encoding scheme mainly used for internationalized domain names defined by RFC 3492. Because the host name in the URL can only be ASCII characters, the host name including non-ASCII characters must be converted to ASCII using the punycode algorithm.
Instructions:
1var punycode = require('punycode');
Static function
encode
Convert a Unicode string into an equivalent Punycode string containing only ASCII characters
1static String punycode.encode(String domain);
Call parameters:
- domain: String, given Unicode string
Return result:
- String, Returns the encoded Punycode string containing only ASCII characters
decode
Convert a Punycode string into an equivalent Unicode string
1static String punycode.decode(String domain);
Call parameters:
- domain: String, given Unicode string
Return result:
- String, Return the decoded Unicode string
toASCII
Convert a Unicode string representing a domain name to a string containing only ASCII characters. Only the non-ASCII character strings that represent the part of the domain name will be converted. In other words, if you call a string that has been converted to ASCII, there is no problem.
1static String punycode.toASCII(String domain);
Call parameters:
- domain: String, given Unicode string
Return result:
- String, Return the encoded ASCII string
toUnicode
Convert a Punycode string representing a domain name to a Unicode string. Only the Punycode string representing the part of the domain name will be converted. In other words, if you call a string that has been converted to Unicode, there is no problem.
1static String punycode.toUnicode(String domain);
Call parameters:
- domain: String, given ASCII string
Return result:
- String, Return the decoded Unicode string