{ "type": "module", "source": "doc/api/punycode.md", "modules": [ { "textRaw": "Punycode", "name": "punycode", "introduced_in": "v0.10.0", "type": "module", "meta": { "changes": [], "deprecated": [ "v7.0.0" ] }, "stability": 0, "stabilityText": "Deprecated", "desc": "
The version of the punycode module bundled in Node.js is being deprecated.\nIn a future major version of Node.js this module will be removed. Users\ncurrently depending on the punycode module should switch to using the\nuserland-provided Punycode.js module instead. For punycode-based URL\nencoding, see url.domainToASCII or, more generally, the\nWHATWG URL API.
The punycode module is a bundled version of the Punycode.js module. It\ncan be accessed using:
const punycode = require('node:punycode');\n\nPunycode is a character encoding scheme defined by RFC 3492 that is\nprimarily intended for use in Internationalized Domain Names. Because host\nnames in URLs are limited to ASCII characters only, Domain Names that contain\nnon-ASCII characters must be converted into ASCII using the Punycode scheme.\nFor instance, the Japanese character that translates into the English word,\n'example' is 'ä¾'. The Internationalized Domain Name, 'ä¾.com' (equivalent\nto 'example.com') is represented by Punycode as the ASCII string\n'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\nmade available to developers as a convenience. Fixes or other modifications to\nthe module must be directed to the Punycode.js project.
The punycode.decode() method converts a Punycode string of ASCII-only\ncharacters to the equivalent string of Unicode codepoints.
punycode.decode('maana-pta'); // 'mañana'\npunycode.decode('--dqo34k'); // 'â-â'\n"
},
{
"textRaw": "`punycode.encode(string)`",
"name": "encode",
"type": "method",
"meta": {
"added": [
"v0.5.1"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`string` {string}",
"name": "string",
"type": "string"
}
]
}
],
"desc": "The punycode.encode() method converts a string of Unicode codepoints to a\nPunycode string of ASCII-only characters.
punycode.encode('mañana'); // 'maana-pta'\npunycode.encode('â-â'); // '--dqo34k'\n"
},
{
"textRaw": "`punycode.toASCII(domain)`",
"name": "toASCII",
"type": "method",
"meta": {
"added": [
"v0.6.1"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`domain` {string}",
"name": "domain",
"type": "string"
}
]
}
],
"desc": "The punycode.toASCII() method converts a Unicode string representing an\nInternationalized Domain Name to Punycode. Only the non-ASCII parts of the\ndomain name will be converted. Calling punycode.toASCII() on a string that\nalready only contains ASCII characters will have no effect.
// encode domain names\npunycode.toASCII('mañana.com'); // 'xn--maana-pta.com'\npunycode.toASCII('â-â.com'); // 'xn----dqo34k.com'\npunycode.toASCII('example.com'); // 'example.com'\n"
},
{
"textRaw": "`punycode.toUnicode(domain)`",
"name": "toUnicode",
"type": "method",
"meta": {
"added": [
"v0.6.1"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`domain` {string}",
"name": "domain",
"type": "string"
}
]
}
],
"desc": "The punycode.toUnicode() method converts a string representing a domain name\ncontaining Punycode encoded characters into Unicode. Only the Punycode\nencoded parts of the domain name are converted.
// decode domain names\npunycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'\npunycode.toUnicode('xn----dqo34k.com'); // 'â-â.com'\npunycode.toUnicode('example.com'); // 'example.com'\n"
}
],
"properties": [
{
"textRaw": "`punycode.ucs2`",
"name": "ucs2",
"type": "property",
"meta": {
"added": [
"v0.7.0"
],
"changes": []
},
"methods": [
{
"textRaw": "`punycode.ucs2.decode(string)`",
"name": "decode",
"type": "method",
"meta": {
"added": [
"v0.7.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`string` {string}",
"name": "string",
"type": "string"
}
]
}
],
"desc": "The punycode.ucs2.decode() method returns an array containing the numeric\ncodepoint values of each Unicode symbol in the string.
punycode.ucs2.decode('abc'); // [0x61, 0x62, 0x63]\n// surrogate pair for U+1D306 tetragram for centre:\npunycode.ucs2.decode('\\uD834\\uDF06'); // [0x1D306]\n"
},
{
"textRaw": "`punycode.ucs2.encode(codePoints)`",
"name": "encode",
"type": "method",
"meta": {
"added": [
"v0.7.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`codePoints` {integer[]}",
"name": "codePoints",
"type": "integer[]"
}
]
}
],
"desc": "The punycode.ucs2.encode() method returns a string based on an array of\nnumeric code point values.
punycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc'\npunycode.ucs2.encode([0x1D306]); // '\\uD834\\uDF06'\n"
}
]
},
{
"textRaw": "Type: {string}",
"name": "version",
"type": "string",
"meta": {
"added": [
"v0.6.1"
],
"changes": []
},
"desc": "Returns a string identifying the current Punycode.js version number.
" } ], "displayName": "Punycode" } ] }