What is punycode?
The punycode npm package is a robust library for encoding and decoding Unicode with Punycode. It's useful for internationalization and handling Unicode domain names and email addresses.
What are punycode's main functionalities?
Encoding to Punycode
Converts a Unicode string to a Punycode string (ASCII). Mainly used for domain names.
punycode.encode('mañana') // => 'maana-pta'
Decoding from Punycode
Converts a Punycode string (ASCII) back to a Unicode string. Useful for displaying human-readable text.
punycode.decode('maana-pta') // => 'mañana'
Unicode to ASCII conversion for domain names
Converts a Unicode domain name to an ASCII-compatible encoding (ACE) domain name.
punycode.toASCII('español.example.com') // => 'xn--espaol-zwa.example.com'
ASCII to Unicode conversion for domain names
Converts an ASCII-compatible encoding (ACE) domain name back to a Unicode domain name.
punycode.toUnicode('xn--espaol-zwa.example.com') // => 'español.example.com'
Other packages similar to punycode
idna-uts46-hx
A library that implements IDNA (Internationalized Domain Names in Applications) to Punycode conversion using the latest Unicode version. It's similar to punycode but follows the IDNA 2008 protocol, which is more up-to-date compared to the IDNA 2003 protocol that punycode follows.
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.