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.
Feel free to fork if you see possible improvements!
Unit tests & code coverage
After cloning this repository, run npm install --dev
to install the dependencies needed for Punycode.js development and testing. You may want to install Istanbul globally using npm install istanbul -g
.
Once that’s done, you can run the unit tests in Node using npm test
or node tests/tests.js
. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use grunt test
.
To generate the code coverage report, use grunt cover
.
Authors
Contributors
License
Punycode.js is dual licensed under the MIT and GPL licenses.