Registry / serialization / punycode

punycode

JSON →
library0.2.1jsnpmunverified

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.

npm install punycode
INSTALL
IMPORT
SIG · PUNYCODE
P
punycode
serializationjavascriptv0.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

punycode
const punycode = require('punycode/');
const punycode = require('punycode');
In Node.js, `require('punycode')` refers to the deprecated built-in module. Always use `require('punycode/')` (with the trailing slash) to import the userland npm package.
punycode
import punycode from 'punycode';
import { decode, encode } from 'punycode';
The library primarily exposes a default object with all its methods. While it ships as both CommonJS and ES Modules, direct named imports are not the intended pattern for the main functions.
toASCII
const punycode = require('punycode/'); punycode.toASCII('mañana.com');
import { toASCII } from 'punycode'; toASCII('mañana.com');
Methods like `toASCII` are properties of the default `punycode` object, not direct named exports.

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}`);
Debug
Known issues
breakingVersion 2.0.0 and above dropped support for older JavaScript environments. It targets Node.js v6+ and modern browsers, requiring ES2015+ features.
fix
For compatibility with older runtimes (Rhino, Ringo, Narwhal, older browsers), use `punycode` v1.4.1. Otherwise, ensure your environment supports ES2015+.
affects: >=2.0.0
gotchaIn Node.js, the userland `punycode` package from npm can conflict with Node.js's deprecated built-in `punycode` module.
fix
Always use `require('punycode/')` (with the trailing slash) to explicitly load the npm package. Avoid `require('punycode')` if you intend to use the userland module, as it will load the built-in one.
affects: >=0.6.2
deprecatedThe `punycode` module bundled with Node.js itself has been deprecated (soft-deprecated from v7) and is no longer recommended for new projects. It is advised to use the standalone npm package.
fix
Install the `punycode` npm package via `npm install punycode` and import it using `require('punycode/')` or `import punycode from 'punycode';`.
affects: >=7.0.0
Errors
Common errors & fixes
Error: Cannot find module 'punycode'
Attempting to `require('punycode')` in a Node.js environment where the built-in module is not available or has been overridden by the npm package without the correct import path.
fix
If you've installed the `punycode` npm package, ensure you are importing it with a trailing slash: `const punycode = require('punycode/');`.
SyntaxError: Unexpected token ... (or similar ES2015+ syntax error)
Using `punycode` v2.0.0 or higher in an environment that does not fully support ES2015+ features.
fix
Upgrade your Node.js version to v6 or higher, or use a modern browser. If backward compatibility for older runtimes is essential, downgrade to `punycode` v1.4.1.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
punycode — npm install punycode · libregistry