5
<title>punycode Node.js v0.10.15 Manual & Documentation</title>
6
<link rel="stylesheet" href="assets/style.css">
7
<link rel="stylesheet" href="assets/sh.css">
8
<link rel="canonical" href="http://nodejs.org/api/punycode.html">
10
<body class="alt apidoc" id="api-section-punycode">
11
<div id="intro" class="interior">
12
<a href="/" title="Go back to the home page">
13
<img id="logo" src="http://nodejs.org/images/logo-light.png" alt="node.js">
16
<div id="content" class="clearfix">
17
<div id="column2" class="interior">
19
<li><a href="/" class="home">Home</a></li>
20
<li><a href="/download/" class="download">Download</a></li>
21
<li><a href="/about/" class="about">About</a></li>
22
<li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
23
<li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
24
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
25
<li><a href="/community/" class="community">Community</a></li>
26
<li><a href="/logos/" class="logos">Logos</a></li>
27
<li><a href="http://jobs.nodejs.org/" class="jobs">Jobs</a></li>
29
<p class="twitter"><a href="http://twitter.com/nodejs">@nodejs</a></p>
32
<div id="column1" class="interior">
34
<h1>Node.js v0.10.15 Manual & Documentation</h1>
37
<a href="index.html" name="toc">Index</a> |
38
<a href="all.html">View on single page</a> |
39
<a href="punycode.json">View as JSON</a>
46
<h2>Table of Contents</h2>
48
<li><a href="#punycode_punycode">punycode</a><ul>
49
<li><a href="#punycode_punycode_decode_string">punycode.decode(string)</a></li>
50
<li><a href="#punycode_punycode_encode_string">punycode.encode(string)</a></li>
51
<li><a href="#punycode_punycode_tounicode_domain">punycode.toUnicode(domain)</a></li>
52
<li><a href="#punycode_punycode_toascii_domain">punycode.toASCII(domain)</a></li>
53
<li><a href="#punycode_punycode_ucs2">punycode.ucs2</a><ul>
54
<li><a href="#punycode_punycode_ucs2_decode_string">punycode.ucs2.decode(string)</a></li>
55
<li><a href="#punycode_punycode_ucs2_encode_codepoints">punycode.ucs2.encode(codePoints)</a></li>
58
<li><a href="#punycode_punycode_version">punycode.version</a></li>
66
<h1>punycode<span><a class="mark" href="#punycode_punycode" id="punycode_punycode">#</a></span></h1>
67
<pre class="api_stability_2">Stability: 2 - Unstable</pre><p><a href="http://mths.be/punycode">Punycode.js</a> is bundled with Node.js v0.6.2+. Use
68
<code>require('punycode')</code> to access it. (To use it with other Node.js versions,
69
use npm to install the <code>punycode</code> module first.)
72
<h2>punycode.decode(string)<span><a class="mark" href="#punycode_punycode_decode_string" id="punycode_punycode_decode_string">#</a></span></h2>
73
<p>Converts a Punycode string of ASCII code points to a string of Unicode code
77
<pre><code>// decode domain name parts
78
punycode.decode('maana-pta'); // 'mañana'
79
punycode.decode('--dqo34k'); // '☃-⌘'</code></pre>
80
<h2>punycode.encode(string)<span><a class="mark" href="#punycode_punycode_encode_string" id="punycode_punycode_encode_string">#</a></span></h2>
81
<p>Converts a string of Unicode code points to a Punycode string of ASCII code
85
<pre><code>// encode domain name parts
86
punycode.encode('mañana'); // 'maana-pta'
87
punycode.encode('☃-⌘'); // '--dqo34k'</code></pre>
88
<h2>punycode.toUnicode(domain)<span><a class="mark" href="#punycode_punycode_tounicode_domain" id="punycode_punycode_tounicode_domain">#</a></span></h2>
89
<p>Converts a Punycode string representing a domain name to Unicode. Only the
90
Punycoded parts of the domain name will be converted, i.e. it doesn't matter if
91
you call it on a string that has already been converted to Unicode.
94
<pre><code>// decode domain names
95
punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
96
punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'</code></pre>
97
<h2>punycode.toASCII(domain)<span><a class="mark" href="#punycode_punycode_toascii_domain" id="punycode_punycode_toascii_domain">#</a></span></h2>
98
<p>Converts a Unicode string representing a domain name to Punycode. Only the
99
non-ASCII parts of the domain name will be converted, i.e. it doesn't matter if
100
you call it with a domain that's already in ASCII.
103
<pre><code>// encode domain names
104
punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
105
punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'</code></pre>
106
<h2>punycode.ucs2<span><a class="mark" href="#punycode_punycode_ucs2" id="punycode_punycode_ucs2">#</a></span></h2>
107
<h3>punycode.ucs2.decode(string)<span><a class="mark" href="#punycode_punycode_ucs2_decode_string" id="punycode_punycode_ucs2_decode_string">#</a></span></h3>
108
<p>Creates an array containing the decimal code points of each Unicode character
109
in the string. While <a href="http://mathiasbynens.be/notes/javascript-encoding">JavaScript uses UCS-2
110
internally</a>, this function
111
will convert a pair of surrogate halves (each of which UCS-2 exposes as
112
separate characters) into a single code point, matching UTF-16.
115
<pre><code>punycode.ucs2.decode('abc'); // [97, 98, 99]
116
// surrogate pair for U+1D306 tetragram for centre:
117
punycode.ucs2.decode('\uD834\uDF06'); // [0x1D306]</code></pre>
118
<h3>punycode.ucs2.encode(codePoints)<span><a class="mark" href="#punycode_punycode_ucs2_encode_codepoints" id="punycode_punycode_ucs2_encode_codepoints">#</a></span></h3>
119
<p>Creates a string based on an array of decimal code points.
122
<pre><code>punycode.ucs2.encode([97, 98, 99]); // 'abc'
123
punycode.ucs2.encode([0x1D306]); // '\uD834\uDF06'</code></pre>
124
<h2>punycode.version<span><a class="mark" href="#punycode_punycode_version" id="punycode_punycode_version">#</a></span></h2>
125
<p>A string representing the current Punycode.js version number.
132
<a href="http://joyent.com" class="joyent-logo">Joyent</a>
133
<ul class="clearfix">
134
<li><a href="/">Node.js</a></li>
135
<li><a href="/download/">Download</a></li>
136
<li><a href="/about/">About</a></li>
137
<li><a href="http://npmjs.org/">npm Registry</a></li>
138
<li><a href="http://nodejs.org/api/">Docs</a></li>
139
<li><a href="http://blog.nodejs.org">Blog</a></li>
140
<li><a href="/community/">Community</a></li>
141
<li><a href="/logos/">Logos</a></li>
142
<li><a href="http://jobs.nodejs.org/">Jobs</a></li>
143
<li><a href="http://twitter.com/nodejs" class="twitter">@nodejs</a></li>
146
<p>Copyright <a href="http://joyent.com/">Joyent, Inc</a>, Node.js is a <a href="/trademark-policy.pdf">trademark</a> of Joyent, Inc. View <a href="https://raw.github.com/joyent/node/v0.10.15/LICENSE">license</a>.</p>
149
<script src="../sh_main.js"></script>
150
<script src="../sh_javascript.min.js"></script>
151
<script>highlight(undefined, undefined, 'pre');</script>
153
window._gaq = [['_setAccount', 'UA-10874194-2'], ['_trackPageview']];
155
var g = d.createElement(t),
156
s = d.getElementsByTagName(t)[0];
157
g.src = '//www.google-analytics.com/ga.js';
158
s.parentNode.insertBefore(g, s);
159
}(document, 'script'));