A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.
This JavaScript library is the result of comparing, optimizing and documenting different open-source implementations of the Punycode algorithm:
- The C example code from RFC 3492
punycode.cby Markus W. Scherer (IBM)punycode.cby Ben Noordhuis- JavaScript implementation by some
In a browser:
<script src="punycode.js"></script>In Node.js:
var Punycode = require('punycode');var Punycode = require('punycode').Punycode;In Rhino:
load('punycode.js');In RequireJS:
require(['path/to/punycode'], function(Punycode) {
console.log(Punycode);
});Usage example:
// encode/decode domain names
Punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
Punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
Punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'
Punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'
// encode/decode domain name parts
Punycode.encode('mañana'); // 'maana-pta'
Punycode.decode('maana-pta'); // 'mañana'
Punycode.encode('☃-⌘'); // '--dqo34k'
Punycode.decode('--dqo34k'); // '☃-⌘'To clone this repository including all submodules, using Git 1.6.5 or later:
git clone --recursive https://github.com/bestiejs/punycode.js.git
cd punycode.jsFor older Git versions, just use:
git clone https://github.com/bestiejs/punycode.js.git
cd punycode.js
git submodule update --initFeel free to fork if you see possible improvements!