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.c
by Markus W. Scherer (IBM)punycode.c
by 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.js
For older Git versions, just use:
git clone https://github.com/bestiejs/punycode.js.git
cd punycode.js
git submodule update --init
Feel free to fork if you see possible improvements!