Punycode Converter

2.3.1 · active · verified Sun Apr 19

Punycode.js is a robust JavaScript library for converting Unicode strings to Punycode and vice-versa, strictly adhering to RFC 3492 (Punycode) and RFC 5891 (IDNA2008). It provides low-level functions for encoding and decoding individual string parts, as well as higher-level utilities for processing entire domain names and email addresses. The current stable version is 2.3.1. While previously bundled with Node.js up to v7, the userland module (`npm install punycode`) now specifically targets modern Node.js v6+ environments and browsers supporting ES2015+ features. Version 1.4.1 remains available for broader compatibility with older runtimes like Rhino, Ringo, and Narwhal, offering the same functionality with a UMD build. The project is actively maintained with periodic releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to encode and decode internationalized domain names (IDN) and individual Unicode string parts using `punycode.js`.

const punycode = require('punycode/');

// Encode a Unicode domain name to Punycode
const unicodeDomain = 'mañana.com';
const punycodeDomain = punycode.toASCII(unicodeDomain);
console.log(`Unicode domain: ${unicodeDomain}`);
console.log(`Punycode domain: ${punycodeDomain}`);

// Decode a Punycode domain name back to Unicode
const decodedUnicodeDomain = punycode.toUnicode(punycodeDomain);
console.log(`Decoded Unicode domain: ${decodedUnicodeDomain}`);

// Encode/decode individual string parts
const unicodePart = '☃-⌘';
const punycodePart = punycode.encode(unicodePart);
console.log(`Unicode part: ${unicodePart}`);
console.log(`Punycode part: ${punycodePart}`);

const decodedUnicodePart = punycode.decode(punycodePart);
console.log(`Decoded Unicode part: ${decodedUnicodePart}`);

view raw JSON →