punycode
**The version of the punycode module bundled in Node.js is being deprecated. **In a future major version of Node.js this module will be removed. Users
currently depending on the punycode module should switch to using the
userland-provided Punycode.js module instead. For punycode-based URL
encoding, see url.domainToASCII or, more generally, the WHATWG URL API.
The punycode module is a bundled version of the Punycode.js module. It
can be accessed using:
import punycode from 'node:punycode';
Punycode is a character encoding scheme defined by RFC 3492 that is
primarily intended for use in Internationalized Domain Names. Because host
names in URLs are limited to ASCII characters only, Domain Names that contain
non-ASCII characters must be converted into ASCII using the Punycode scheme.
For instance, the Japanese character that translates into the English word, 'example' is '例'. The Internationalized Domain Name, '例.com' (equivalent
to 'example.com') is represented by Punycode as the ASCII string 'xn--fsq.com'.
The punycode module provides a simple implementation of the Punycode standard.
The punycode module is a third-party dependency used by Node.js and
made available to developers as a convenience. Fixes or other modifications to
the module must be directed to the Punycode.js project.
Usage in Deno
import * as mod from "node:punycode";
Functions
function decode
Usage in Deno
import { decode } from "node:punycode";
function encode
Usage in Deno
import { encode } from "node:punycode";
function toASCII
Usage in Deno
import { toASCII } from "node:punycode";
#toASCII(domain: string): stringThe punycode.toASCII() method converts a Unicode string representing an
Internationalized Domain Name to Punycode. Only the non-ASCII parts of the
domain name will be converted. Calling punycode.toASCII() on a string that
already only contains ASCII characters will have no effect.
// encode domain names
punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'
punycode.toASCII('example.com'); // 'example.com'
Parameters #
#domain: string Return Type #
string function toUnicode
Usage in Deno
import { toUnicode } from "node:punycode";
#toUnicode(domain: string): stringThe punycode.toUnicode() method converts a string representing a domain name
containing Punycode encoded characters into Unicode. Only the Punycode encoded parts of the domain name are be
converted.
// decode domain names
punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'
punycode.toUnicode('example.com'); // 'example.com'
Parameters #
#domain: string Return Type #
string interface ucs2
Usage in Deno
import { type ucs2 } from "node:punycode";
variable ucs2
since v7.0.0 The version of the punycode module bundled in Node.js is being deprecated. In a future major version of Node.js this module will be removed. Users currently depending on the punycode module should switch to using the userland-provided Punycode.js module instead.
variable version
Usage in Deno
import { version } from "node:punycode";
since v7.0.0 The version of the punycode module bundled in Node.js is being deprecated. In a future major version of Node.js this module will be removed. Users currently depending on the punycode module should switch to using the userland-provided Punycode.js module instead.
Type #
string 