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 🙏

© 2024 – Pkg Stats / Ryan Hefner

punycode-esm

v1.0.6

Published

Typescript + ESM version of punycode.js

Downloads

98

Readme

npm package License Quality

Contents

Introduction

ESM/Typescript native version of punycode.js.

ESM native users / Typescript nodenext users may have some issues with the existing punycode library, so this hopefully serves as a viable alternative.

Logically this package should be the same as punycode.js. The only advantage of this library is ease-of-use for modern typescript/ESM.

Credit goes to Mathias Bynens for original implementation of this logic.

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. That means it must be imported. To load from a CJS module, use dynamic import const { encode } = await import('punycode-esm');.

API

decode(string)

Converts a Punycode string of ASCII symbols to a string of Unicode symbols.

// decode domain name parts
Punycode.decode('maana-pta'); // 'mañana'
Punycode.decode('--dqo34k'); // '☃-⌘'

encode(string)

Converts a string of Unicode symbols to a Punycode string of ASCII symbols.

// encode domain name parts
Punycode.encode('mañana'); // 'maana-pta'
Punycode.encode('☃-⌘'); // '--dqo34k'

toUnicode(string)

Converts a Punycode string representing a domain name or an email address to Unicode. Only the Punycoded parts of the input will be converted, i.e. it doesn’t matter if you call it on a string that has already been converted to Unicode.

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

// decode email addresses
Punycode.toUnicode('джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq'); // 'джумла@джpумлатест.bрфa'

toASCII(string)

Converts a lowercased Unicode string representing a domain name or an email address to Punycode. Only the non-ASCII parts of the input will be converted, i.e. it doesn’t matter if you call it with a domain that’s already in ASCII.

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

// encode email addresses
Punycode.toASCII('джумла@джpумлатест.bрфa'); // 'джумла@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq'

ucs2Decode(string)

Creates an array containing the numeric code point values of each Unicode symbol in the string. While JavaScript uses UCS-2 internally, this function will convert a pair of surrogate halves (each of which UCS-2 exposes as separate characters) into a single code point, matching UTF-16.

ucs2Decode('abc'); // [0x61, 0x62, 0x63]
// surrogate pair for U+1D306 TETRAGRAM FOR CENTRE:
punycode.ucs2.decode('\uD834\uDF06'); // [0x1D306]

ucs2Encode(codePoints)

Creates a string based on an array of numeric code point values.

punycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc'
punycode.ucs2.encode([0x1D306]); // '\uD834\uDF06'