The punycode.decode() method converts a Punycode string of ASCII-only characters to the equivalent string of Unicode codepoints.
punycode.decode('maana-pta'); // 'mañana'
punycode.decode('--dqo34k'); // '☃-⌘'
Node.js module
The 'node:punycode' module provides utilities for converting Unicode strings to ASCII using Punycode encoding, as defined by RFC 3492. It enables safe handling of Internationalized Domain Names (IDNs).
Functions include encode, decode, toASCII, and toUnicode.
Fully implemented. 100% of Node.js's test suite passes. Note: This module is deprecated by Node.js.
The 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'
The 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'