Punycode.js
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:
This project is bundled with Node.js v0.6.2+.
Installation and usage
In a browser:
<script src="punycode.js"></script>
Via npm (only required for Node.js releases older than v0.6.2):
npm install punycode
In Narwhal, Node.js, and RingoJS:
var punycode = require('punycode');
In Rhino:
load('punycode.js');
Using an AMD loader like RequireJS:
require(
{
'paths': {
'punycode': 'path/to/punycode'
}
},
['punycode'],
function(punycode) {
console.log(punycode);
}
);
Usage example:
punycode.toASCII('mañana.com');
punycode.toUnicode('xn--maana-pta.com');
punycode.toASCII('☃-⌘.com');
punycode.toUnicode('xn----dqo34k.com');
punycode.encode('mañana');
punycode.decode('maana-pta');
punycode.encode('☃-⌘');
punycode.decode('--dqo34k');
Full API documentation is available.
Cloning this repo
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!
Authors
Contributors
License
Punycode.js is dual licensed under the MIT and GPL licenses.