Module punycode
punycode international domain name conversion module
Punycode is a character encoding scheme defined by RFC 3492 mainly used for internationalized domain names. Because the host name in the URL is limited to ASCII characters, host names 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 to an equivalent Punycode string containing only ASCII characters
1static String punycode.encode(String domain);
Call parameters:
- domain: String, given Unicode string
Return results:
- String, returns the encoded Punycode string containing only ASCII characters.
decode
Convert a Punycode string to the equivalent Unicode string
1static String punycode.decode(String domain);
Call parameters:
- domain: String, given Unicode string
Return results:
- String, returns the decoded Unicode string
toASCII
Converts a Unicode string representing a domain name to a string containing only ASCII characters. Only non-ASCII strings representing portions of domain names are 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 results:
- String, returns the encoded ASCII string
toUnicode
Converts a Punycode string representing a domain name to a Unicode string. Only the Punycode string representing the portion 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 results:
- String, returns the decoded Unicode string