Skip to content

Commit

Permalink
chapter punycode is done
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Sun committed Oct 13, 2016
1 parent 17d8154 commit 7457774
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
| OS | 翻译中... |
| Path | 翻译中... |
| Process | 翻译中... |
| Punycode | 翻译中... |
| Punycode | 已完成 |
| Query Strings | 翻译中... |
| Readline | 翻译中... |
| REPL | 翻译中... |
Expand Down
2 changes: 2 additions & 0 deletions doc/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
模块已锁定,不接受新的 API 建议,后续只会进行安全、性能或 Bug 方面的优化。
</div>

> 本文档不会翻译稳定性为 0 的模块,也不建议使用此类模块。
## 系统调用和 man 页面

类似 [open(2)](http://man7.org/linux/man-pages/man2/open.2.html)[read(2)](http://man7.org/linux/man-pages/man2/read.2.html) 的系统调用命令定义了用户程序与底层操作系统之间的接口。对于 Node.js 简单封装的系统调用命令都会在文档中显式标注,比如 `fs.open()`。对于系统调用命令,文档会直接链接到相应的 man 页面。
Expand Down
71 changes: 3 additions & 68 deletions doc/punycode.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,8 @@
## Punycode

<div class="s s2"></div>
<div class="s s0"></div>

Node.js 自 v0.6.2 版本加入了 [Punycode.js](https://mths.be/punycode),通过 `require('punycode')` 的方式访问。

## punycode.decode(string)

将一个纯 ASCII 的 Punycode 字符串转换为 Unicode 字符串:

```js
// decode domain name parts
punycode.decode('maana-pta'); // 'mañana'
punycode.decode('--dqo34k'); // '☃-⌘'
```

## punycode.encode(string)

将一个 Unicode 字符串转换为纯 ASCII 的 Punycode 字符串:

```js
// encode domain name parts
punycode.encode('mañana'); // 'maana-pta'
punycode.encode('☃-⌘'); // '--dqo34k'
```

## punycode.toASCII(domain)

将一个 Unicode 域名字符串转换为 Punycode 字符串,域名中只有非 ASCII 的部分会被转换:

```js
// encode domain names
punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
punycode.toASCII('☃-⌘.com'); // 'xn----dqo34k.com'
```

## punycode.toUnicode(domain)

将一个 Punycode 的域名字符串转换为 Unicode 字符串,域名中只有 Punycode 的部分会被转换:

```js
// decode domain names
punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
punycode.toUnicode('xn----dqo34k.com'); // '☃-⌘.com'
```

## punycode.ucs2

#### punycode.ucs2.decode(string)

根据传入的 `string` 参数创建一个数值形式的编码数组。由于 JavaScript 内部使用 UCS-2,所以该函数会根据 UTF-16 将一对 surrogate halves 转换为一个编码:

```js
punycode.ucs2.decode('abc'); // [0x61, 0x62, 0x63]
// surrogate pair for U+1D306 tetragram for centre:
punycode.ucs2.decode('\uD834\uDF06'); // [0x1D306]
```

## punycode.ucs2.encode(codePoints)

将编码数组转换为字符串:

```js
punycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc'
punycode.ucs2.encode([0x1D306]); // '\uD834\uDF06'
```

## punycode.version

返回字符串形式的 Punycode 版本号。
punycode 模块已废弃,如果需要使用该模块,可以安装开源社区提供的 [Punycode.js](https://mths.be/punycode)

<style>
.s {
Expand Down Expand Up @@ -105,4 +40,4 @@ punycode.ucs2.encode([0x1D306]); // '\uD834\uDF06'
.s3:before {
content: "接口稳定性: 3 - 已锁定";
}
</style>
</style>

0 comments on commit 7457774

Please sign in to comment.