npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

punycode-esm

v2.0.2

Published

Typescript + ESM version of punycode.js

Readme

punycode-esm

ESM and TypeScript port of the punycode.js library.

npm package License

Contents

Install

npm i punycode-esm

Example

import { toASCII, toUnicode } from 'punycode-esm';

// encode domain names
toASCII('mañana.com');  // 'xn--maana-pta.com'
toASCII('☃-⌘.com');    // 'xn----dqo34k.com'

// decode domain names
toUnicode('xn--maana-pta.com'); // 'mañana.com'
toUnicode('xn----dqo34k.com');  // '☃-⌘.com'

Usage

punycode-esm is an ESM module. It must be imported. To load from a CJS module, use dynamic import: const { encode } = await import('punycode-esm').

Functions throw RangeError for malformed Punycode: decode and toUnicode for input that is not ASCII (Invalid input), is not valid Punycode, or needs wider integers than JavaScript numbers hold (Overflow: input needs wider integers to process); encode and toASCII for the overflow case only. toASCII and toUnicode only convert labels, and do none of the other IDNA processing: no case folding, no Unicode normalization and no length checks. They split on . and the other full-stop characters 。, . and 。 (all written as . in the result), and only recognise the lowercase xn-- prefix.

API

encode(string)

Converts a string of Unicode symbols (a single domain label) to a Punycode string of ASCII-only symbols.

Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | string | string | — | Required. A Unicode domain label (no dots). |

Returns string — the Punycode-encoded ASCII label.

encode('mañana'); // 'maana-pta'
encode('☃-⌘');   // '--dqo34k'

decode(string)

Converts a Punycode string of ASCII-only symbols (a single domain label) to a string of Unicode symbols.

Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | string | string | — | Required. A Punycode-encoded ASCII label (no dots). |

Returns string — the decoded Unicode label.

decode('maana-pta'); // 'mañana'
decode('--dqo34k');  // '☃-⌘'

toASCII(string)

Converts a Unicode domain name or email address to its Punycode (ASCII) representation. Only non-ASCII labels are converted; already-ASCII labels are left unchanged.

Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | string | string | — | Required. A Unicode domain name or email address. |

Returns string — the ASCII-compatible encoding of the domain or email.

toASCII('mañana.com');                     // 'xn--maana-pta.com'
toASCII('☃-⌘.com');                       // 'xn----dqo34k.com'
toASCII('джумла@джpумлатест.bрфa');        // 'джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq'

toUnicode(string)

Converts a Punycode domain name or email address to Unicode. Only Punycode-encoded labels (prefixed with xn--) are converted; others are left unchanged.

Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | string | string | — | Required. A Punycode domain name or email address. |

Returns string — the Unicode representation of the domain or email.

toUnicode('xn--maana-pta.com');                          // 'mañana.com'
toUnicode('xn----dqo34k.com');                           // '☃-⌘.com'
toUnicode('джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq');   // 'джумла@джpумлатест.bрфa'

ucs2Decode(string)

Creates an array of Unicode code point values from a string. Surrogate pairs (as used internally by JavaScript's UCS-2 encoding) are combined into a single code point, matching UTF-16 semantics.

Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | string | string | — | Required. A UCS-2 encoded string. |

Returns number[] — array of Unicode code point integers.

ucs2Decode('abc');           // [0x61, 0x62, 0x63]
ucs2Decode('\uD834\uDF06');  // [0x1D306]

ucs2Encode(codePoints)

Creates a string from an array of Unicode code point values.

Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | codePoints | readonly number[] | — | Required. Array of Unicode code point integers. |

Returns string — the UCS-2 encoded string.

ucs2Encode([0x61, 0x62, 0x63]); // 'abc'
ucs2Encode([0x1D306]);          // '\uD834\uDF06'

Credit

This is a direct ESM/TypeScript port of punycode.js by Mathias Bynens. The logic is identical; this package exists for compatibility with TypeScript moduleResolution: nodenext and pure-ESM projects. Logic is in sync with punycode v2.3.1.