UNPKG

5.48 kBTypeScriptView Raw
1/**
2 * **The version of the punycode module bundled in Node.js is being deprecated**.
3 * In a future major version of Node.js this module will be removed. Users
4 * currently depending on the `punycode` module should switch to using the
5 * userland-provided [Punycode.js](https://github.com/bestiejs/punycode.js) module instead. For punycode-based URL
6 * encoding, see `url.domainToASCII` or, more generally, the `WHATWG URL API`.
7 *
8 * The `punycode` module is a bundled version of the [Punycode.js](https://github.com/bestiejs/punycode.js) module. It
9 * can be accessed using:
10 *
11 * ```js
12 * const punycode = require('punycode');
13 * ```
14 *
15 * [Punycode](https://tools.ietf.org/html/rfc3492) is a character encoding scheme defined by RFC 3492 that is
16 * primarily intended for use in Internationalized Domain Names. Because host
17 * names in URLs are limited to ASCII characters only, Domain Names that contain
18 * non-ASCII characters must be converted into ASCII using the Punycode scheme.
19 * For instance, the Japanese character that translates into the English word,`'example'` is `'例'`. The Internationalized Domain Name, `'例.com'` (equivalent
20 * to `'example.com'`) is represented by Punycode as the ASCII string`'xn--fsq.com'`.
21 *
22 * The `punycode` module provides a simple implementation of the Punycode standard.
23 *
24 * The `punycode` module is a third-party dependency used by Node.js and
25 * made available to developers as a convenience. Fixes or other modifications to
26 * the module must be directed to the [Punycode.js](https://github.com/bestiejs/punycode.js) project.
27 * @deprecated Since v7.0.0 - Deprecated
28 * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/punycode.js)
29 */
30declare module 'punycode' {
31 /**
32 * The `punycode.decode()` method converts a [Punycode](https://tools.ietf.org/html/rfc3492) string of ASCII-only
33 * characters to the equivalent string of Unicode codepoints.
34 *
35 * ```js
36 * punycode.decode('maana-pta'); // 'mañana'
37 * punycode.decode('--dqo34k'); // '☃-⌘'
38 * ```
39 * @since v0.5.1
40 */
41 function decode(string: string): string;
42 /**
43 * The `punycode.encode()` method converts a string of Unicode codepoints to a[Punycode](https://tools.ietf.org/html/rfc3492) string of ASCII-only characters.
44 *
45 * ```js
46 * punycode.encode('mañana'); // 'maana-pta'
47 * punycode.encode('☃-⌘'); // '--dqo34k'
48 * ```
49 * @since v0.5.1
50 */
51 function encode(string: string): string;
52 /**
53 * The `punycode.toUnicode()` method converts a string representing a domain name
54 * containing [Punycode](https://tools.ietf.org/html/rfc3492) encoded characters into Unicode. Only the [Punycode](https://tools.ietf.org/html/rfc3492)encoded parts of the domain name are be
55 * converted.
56 *
57 * ```js
58 * // decode domain names
59 * punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
60 * punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'
61 * punycode.toUnicode('example.com'); // 'example.com'
62 * ```
63 * @since v0.6.1
64 */
65 function toUnicode(domain: string): string;
66 /**
67 * The `punycode.toASCII()` method converts a Unicode string representing an
68 * Internationalized Domain Name to [Punycode](https://tools.ietf.org/html/rfc3492). Only the non-ASCII parts of the
69 * domain name will be converted. Calling `punycode.toASCII()` on a string that
70 * already only contains ASCII characters will have no effect.
71 *
72 * ```js
73 * // encode domain names
74 * punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
75 * punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'
76 * punycode.toASCII('example.com'); // 'example.com'
77 * ```
78 * @since v0.6.1
79 */
80 function toASCII(domain: string): string;
81 /**
82 * @deprecated since v7.0.0
83 * The version of the punycode module bundled in Node.js is being deprecated.
84 * In a future major version of Node.js this module will be removed.
85 * Users currently depending on the punycode module should switch to using
86 * the userland-provided Punycode.js module instead.
87 */
88 const ucs2: ucs2;
89 interface ucs2 {
90 /**
91 * @deprecated since v7.0.0
92 * The version of the punycode module bundled in Node.js is being deprecated.
93 * In a future major version of Node.js this module will be removed.
94 * Users currently depending on the punycode module should switch to using
95 * the userland-provided Punycode.js module instead.
96 */
97 decode(string: string): number[];
98 /**
99 * @deprecated since v7.0.0
100 * The version of the punycode module bundled in Node.js is being deprecated.
101 * In a future major version of Node.js this module will be removed.
102 * Users currently depending on the punycode module should switch to using
103 * the userland-provided Punycode.js module instead.
104 */
105 encode(codePoints: ReadonlyArray<number>): string;
106 }
107 /**
108 * @deprecated since v7.0.0
109 * The version of the punycode module bundled in Node.js is being deprecated.
110 * In a future major version of Node.js this module will be removed.
111 * Users currently depending on the punycode module should switch to using
112 * the userland-provided Punycode.js module instead.
113 */
114 const version: string;
115}
116declare module 'node:punycode' {
117 export * from 'punycode';
118}