A robust Punycode converter that fully complies to \href{http://tools.ietf.org/html/rfc3492}{\texttt{ RFC 3492}} and \href{http://tools.ietf.org/html/rfc5891}{\texttt{ RFC 5891}}, and works on nearly all Java\+Script platforms.

This Java\+Script library is the result of comparing, optimizing and documenting different open-\/source implementations of the Punycode algorithm\+:


\begin{DoxyItemize}
\item \href{http://tools.ietf.org/html/rfc3492\#appendix-C}{\texttt{ The C example code from RFC 3492}}
\item \href{http://opensource.apple.com/source/ICU/ICU-400.42/icuSources/common/punycode.c}{\texttt{ {\ttfamily punycode.\+c} by {\itshape Markus W. Scherer} (IBM)}}
\item \href{https://github.com/bnoordhuis/punycode/blob/master/punycode.c}{\texttt{ {\ttfamily punycode.\+c} by {\itshape Ben Noordhuis}}}
\item \href{http://stackoverflow.com/questions/183485/can-anyone-recommend-a-good-free-javascript-for-punycode-to-unicode-conversion/301287\#301287}{\texttt{ Java\+Script implementation by {\itshape some}}}
\item \href{https://github.com/joyent/node/blob/426298c8c1c0d5b5224ac3658c41e7c2a3fe9377/lib/punycode.js}{\texttt{ {\ttfamily punycode.\+js} by {\itshape Ben Noordhuis}}} (note\+: \href{https://github.com/joyent/node/issues/2072}{\texttt{ not fully compliant}})
\end{DoxyItemize}

This project is \href{https://github.com/joyent/node/blob/master/lib/punycode.js}{\texttt{ bundled}} with \href{https://github.com/joyent/node/compare/975f1930b1...61e796decc}{\texttt{ Node.\+js v0.\+6.\+2+}}.\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31592}{}\doxysection{Installation}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31592}
Via \href{http://npmjs.org/}{\texttt{ npm}} (only required for Node.\+js releases older than v0.\+6.\+2)\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install punycode }

\end{DoxyCode}


Via \href{http://bower.io/}{\texttt{ Bower}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{bower install punycode }

\end{DoxyCode}


Via \href{https://github.com/component/component}{\texttt{ Component}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{component install bestiejs/punycode.js }

\end{DoxyCode}


In a browser\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{<script src="{}punycode.js"{}></script> }

\end{DoxyCode}


In \href{http://narwhaljs.org/}{\texttt{ Narwhal}}, \href{http://nodejs.org/}{\texttt{ Node.\+js}}, and \href{http://ringojs.org/}{\texttt{ Ringo\+JS}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var punycode = require('punycode'); }

\end{DoxyCode}


In \href{http://www.mozilla.org/rhino/}{\texttt{ Rhino}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{load('punycode.js'); }

\end{DoxyCode}


Using an AMD loader like \href{http://requirejs.org/}{\texttt{ Require\+JS}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{require(}
\DoxyCodeLine{  \{}
\DoxyCodeLine{    'paths': \{}
\DoxyCodeLine{      'punycode': 'path/to/punycode'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  ['punycode'],}
\DoxyCodeLine{  function(punycode) \{}
\DoxyCodeLine{    console.log(punycode);}
\DoxyCodeLine{  \}}
\DoxyCodeLine{); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31593}{}\doxysection{API}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31593}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31594}{}\doxysubsection{$<$tt$>$punycode.\+decode(string)$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31594}
Converts a Punycode string of ASCII symbols to a string of Unicode symbols.


\begin{DoxyCode}{0}
\DoxyCodeLine{// decode domain name parts}
\DoxyCodeLine{punycode.decode('maana-\/pta'); // 'mañana'}
\DoxyCodeLine{punycode.decode('-\/-\/dqo34k'); // '☃-\/⌘' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31595}{}\doxysubsection{$<$tt$>$punycode.\+encode(string)$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31595}
Converts a string of Unicode symbols to a Punycode string of ASCII symbols.


\begin{DoxyCode}{0}
\DoxyCodeLine{// encode domain name parts}
\DoxyCodeLine{punycode.encode('mañana'); // 'maana-\/pta'}
\DoxyCodeLine{punycode.encode('☃-\/⌘'); // '-\/-\/dqo34k' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31596}{}\doxysubsection{$<$tt$>$punycode.\+to\+Unicode(input)$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31596}
Converts a Punycode string representing a domain name or an email address to Unicode. Only the Punycoded parts of the input will be converted, i.\+e. it doesn’t matter if you call it on a string that has already been converted to Unicode.


\begin{DoxyCode}{0}
\DoxyCodeLine{// decode domain names}
\DoxyCodeLine{punycode.toUnicode('xn-\/-\/maana-\/pta.com');}
\DoxyCodeLine{// → 'mañana.com'}
\DoxyCodeLine{punycode.toUnicode('xn-\/-\/-\/-\/dqo34k.com');}
\DoxyCodeLine{// → '☃-\/⌘.com'}
\DoxyCodeLine{}
\DoxyCodeLine{// decode email addresses}
\DoxyCodeLine{punycode.toUnicode('джумла@xn-\/-\/p-\/8sbkgc5ag7bhce.xn-\/-\/ba-\/lmcq');}
\DoxyCodeLine{// → 'джумла@джpумлатест.bрфa' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31597}{}\doxysubsection{$<$tt$>$punycode.\+to\+ASCII(input)$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31597}
Converts a Unicode string representing a domain name or an email address to Punycode. Only the non-\/\+ASCII parts of the input will be converted, i.\+e. it doesn’t matter if you call it with a domain that\textquotesingle{}s already in ASCII.


\begin{DoxyCode}{0}
\DoxyCodeLine{// encode domain names}
\DoxyCodeLine{punycode.toASCII('mañana.com');}
\DoxyCodeLine{// → 'xn-\/-\/maana-\/pta.com'}
\DoxyCodeLine{punycode.toASCII('☃-\/⌘.com');}
\DoxyCodeLine{// → 'xn-\/-\/-\/-\/dqo34k.com'}
\DoxyCodeLine{}
\DoxyCodeLine{// encode email addresses}
\DoxyCodeLine{punycode.toASCII('джумла@джpумлатест.bрфa');}
\DoxyCodeLine{// → 'джумла@xn-\/-\/p-\/8sbkgc5ag7bhce.xn-\/-\/ba-\/lmcq' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31598}{}\doxysubsection{$<$tt$>$punycode.\+ucs2$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31598}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31599}{}\doxysubsubsection{$<$tt$>$punycode.\+ucs2.\+decode(string)$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31599}
Creates an array containing the numeric code point values of each Unicode symbol in the string. While \href{https://mathiasbynens.be/notes/javascript-encoding}{\texttt{ Java\+Script uses UCS-\/2 internally}}, this function will convert a pair of surrogate halves (each of which UCS-\/2 exposes as separate characters) into a single code point, matching UTF-\/16.


\begin{DoxyCode}{0}
\DoxyCodeLine{punycode.ucs2.decode('abc');}
\DoxyCodeLine{// → [0x61, 0x62, 0x63]}
\DoxyCodeLine{// surrogate pair for U+1D306 TETRAGRAM FOR CENTRE:}
\DoxyCodeLine{punycode.ucs2.decode('\(\backslash\)uD834\(\backslash\)uDF06');}
\DoxyCodeLine{// → [0x1D306] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31600}{}\doxysubsubsection{$<$tt$>$punycode.\+ucs2.\+encode(code\+Points)$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31600}
Creates a string based on an array of numeric code point values.


\begin{DoxyCode}{0}
\DoxyCodeLine{punycode.ucs2.encode([0x61, 0x62, 0x63]);}
\DoxyCodeLine{// → 'abc'}
\DoxyCodeLine{punycode.ucs2.encode([0x1D306]);}
\DoxyCodeLine{// → '\(\backslash\)uD834\(\backslash\)uDF06' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31601}{}\doxysubsection{$<$tt$>$punycode.\+version$<$/tt$>$}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31601}
A string representing the current Punycode.\+js version number.\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31602}{}\doxysection{Unit tests \& code coverage}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31602}
After cloning this repository, run {\ttfamily npm install -\/-\/dev} to install the dependencies needed for Punycode.\+js development and testing. You may want to install Istanbul {\itshape globally} using {\ttfamily npm install istanbul -\/g}.

Once that’s done, you can run the unit tests in Node using {\ttfamily npm test} or {\ttfamily node tests/tests.\+js}. To run the tests in Rhino, Ringo, Narwhal, Phantom\+JS, and web browsers as well, use {\ttfamily grunt test}.

To generate the code coverage report, use {\ttfamily grunt cover}.

Feel free to fork if you see possible improvements!\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31603}{}\doxysection{Author}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31603}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{1}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ \href{https://twitter.com/mathias}{\texttt{ }}    }\\\cline{1-1}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ \href{https://twitter.com/mathias}{\texttt{ }}    }\\\cline{1-1}
\endhead
\href{https://mathiasbynens.be/}{\texttt{ Mathias Bynens}}   \\\cline{1-1}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31604}{}\doxysection{Contributors}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31604}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{1}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ \href{https://twitter.com/jdalton}{\texttt{ }}    }\\\cline{1-1}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ \href{https://twitter.com/jdalton}{\texttt{ }}    }\\\cline{1-1}
\endhead
\href{http://allyoucanleet.com/}{\texttt{ John-\/\+David Dalton}}   \\\cline{1-1}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31605}{}\doxysection{License}\label{md_sfcode_node_modules_url_node_modules_punycode_README_autotoc_md31605}
Punycode.\+js is available under the \href{https://mths.be/mit}{\texttt{ MIT}} license. 