{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"punycode","path":"/punycode","type":"module","module":"punycode","title":"Punycode","introducedIn":"v0.10.0","sourceLink":{"path":"lib/punycode.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/punycode.js"},"stability":{"index":"0","description":"Deprecated"},"added":[],"deprecated":["v7.0.0"],"removed":[],"napiVersion":[],"changes":[],"description":"**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](https://github.com/bestiejs/punycode.js) module instead. For punycode-based URL\nencoding, see [`url.domainToASCII`](url.html#urldomaintoasciidomain) or, more generally, the\n[WHATWG URL API](url.html#the-whatwg-url-api).\n\nThe `punycode` module is a bundled version of the [Punycode.js](https://github.com/bestiejs/punycode.js) module. It\ncan be accessed using:\n\n```js\nconst punycode = require('node:punycode');\n```\n\n[Punycode](https://tools.ietf.org/html/rfc3492) 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'`.\n\nThe `punycode` module provides a simple implementation of the Punycode standard.\n\nThe `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](https://github.com/bestiejs/punycode.js) project.","summary":"**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.","examples":[{"language":"js","displayName":null,"code":"const punycode = require('node:punycode');"}],"children":[{"kind":"method","id":"punycodedecodestring","name":"decode","title":"`punycode.decode(string)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"string","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `punycode.decode()` method converts a [Punycode](https://tools.ietf.org/html/rfc3492) string of ASCII-only\ncharacters to the equivalent string of Unicode codepoints.\n\n```js\npunycode.decode('maana-pta'); // 'mañana'\npunycode.decode('--dqo34k'); // '☃-⌘'\n```","summary":"The `punycode.decode()` method converts a Punycode string of ASCII-only characters to the equivalent string of Unicode codepoints.","examples":[{"language":"js","displayName":null,"code":"punycode.decode('maana-pta'); // 'mañana'\npunycode.decode('--dqo34k'); // '☃-⌘'"}],"children":[]},{"kind":"method","id":"punycodeencodestring","name":"encode","title":"`punycode.encode(string)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"string","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `punycode.encode()` method converts a string of Unicode codepoints to a\n[Punycode](https://tools.ietf.org/html/rfc3492) string of ASCII-only characters.\n\n```js\npunycode.encode('mañana'); // 'maana-pta'\npunycode.encode('☃-⌘'); // '--dqo34k'\n```","summary":"The `punycode.encode()` method converts a string of Unicode codepoints to a Punycode string of ASCII-only characters.","examples":[{"language":"js","displayName":null,"code":"punycode.encode('mañana'); // 'maana-pta'\npunycode.encode('☃-⌘'); // '--dqo34k'"}],"children":[]},{"kind":"method","id":"punycodetoasciidomain","name":"toASCII","title":"`punycode.toASCII(domain)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.6.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"domain","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `punycode.toASCII()` method converts a Unicode string representing an\nInternationalized Domain Name to [Punycode](https://tools.ietf.org/html/rfc3492). 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.\n\n```js\n// 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```","summary":"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.","examples":[{"language":"js","displayName":null,"code":"// encode domain names\npunycode.toASCII('mañana.com');  // 'xn--maana-pta.com'\npunycode.toASCII('☃-⌘.com');   // 'xn----dqo34k.com'\npunycode.toASCII('example.com'); // 'example.com'"}],"children":[]},{"kind":"method","id":"punycodetounicodedomain","name":"toUnicode","title":"`punycode.toUnicode(domain)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.6.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"domain","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `punycode.toUnicode()` method converts a string representing a domain name\ncontaining [Punycode](https://tools.ietf.org/html/rfc3492) encoded characters into Unicode. Only the [Punycode](https://tools.ietf.org/html/rfc3492)\nencoded parts of the domain name are converted.\n\n```js\n// 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```","summary":"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 converted.","examples":[{"language":"js","displayName":null,"code":"// decode domain names\npunycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'\npunycode.toUnicode('xn----dqo34k.com');  // '☃-⌘.com'\npunycode.toUnicode('example.com');       // 'example.com'"}],"children":[]},{"kind":"property","id":"punycodeucs2","name":"ucs2","title":"`punycode.ucs2`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"punycodeucs2decodestring","name":"decode","title":"`punycode.ucs2.decode(string)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"string","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `punycode.ucs2.decode()` method returns an array containing the numeric\ncodepoint values of each Unicode symbol in the string.\n\n```js\npunycode.ucs2.decode('abc'); // [0x61, 0x62, 0x63]\n// surrogate pair for U+1D306 tetragram for centre:\npunycode.ucs2.decode('\\uD834\\uDF06'); // [0x1D306]\n```","summary":"The `punycode.ucs2.decode()` method returns an array containing the numeric codepoint values of each Unicode symbol in the string.","examples":[{"language":"js","displayName":null,"code":"punycode.ucs2.decode('abc'); // [0x61, 0x62, 0x63]\n// surrogate pair for U+1D306 tetragram for centre:\npunycode.ucs2.decode('\\uD834\\uDF06'); // [0x1D306]"}],"children":[]},{"kind":"method","id":"punycodeucs2encodecodepoints","name":"encode","title":"`punycode.ucs2.encode(codePoints)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"codePoints","type":{"text":"integer[]","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `punycode.ucs2.encode()` method returns a string based on an array of\nnumeric code point values.\n\n```js\npunycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc'\npunycode.ucs2.encode([0x1D306]); // '\\uD834\\uDF06'\n```","summary":"The `punycode.ucs2.encode()` method returns a string based on an array of numeric code point values.","examples":[{"language":"js","displayName":null,"code":"punycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc'\npunycode.ucs2.encode([0x1D306]); // '\\uD834\\uDF06'"}],"children":[]}]},{"kind":"property","id":"punycodeversion","name":"version","title":"`punycode.version`","scope":"module","overloadOf":null,"stability":null,"added":["v0.6.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Returns a string identifying the current [Punycode.js](https://github.com/bestiejs/punycode.js) version number.","summary":"Returns a string identifying the current Punycode.js version number.","examples":[],"children":[]}]}