Skip to content

Commit

Permalink
doc: document WHATWG IDNA methods' error handling
Browse files Browse the repository at this point in the history
PR-URL: #11549
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
TimothyGu authored and addaleax committed Mar 5, 2017
1 parent 6a5d961 commit b968491
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -876,22 +876,48 @@ for (const [name, value] of params) {
// xyz baz
```

### require('url').domainToAscii(domain)
### require('url').domainToASCII(domain)

* `domain` {String}
* Returns: {String}

Returns the [Punycode][] ASCII serialization of the `domain`.
Returns the [Punycode][] ASCII serialization of the `domain`. If `domain` is an
invalid domain, the empty string is returned.

*Note*: The `require('url').domainToAscii()` method is introduced as part of
It performs the inverse operation to [`require('url').domainToUnicode()`][].

```js
const url = require('url');
console.log(url.domainToASCII('español.com'));
// Prints xn--espaol-zwa.com
console.log(url.domainToASCII('中文.com'));
// Prints xn--fiq228c.com
console.log(url.domainToASCII('xn--iñvalid.com'));
// Prints an empty string
```

*Note*: The `require('url').domainToASCII()` method is introduced as part of
the new `URL` implementation but is not part of the WHATWG URL standard.

### require('url').domainToUnicode(domain)

* `domain` {String}
* Returns: {String}

Returns the Unicode serialization of the `domain`.
Returns the Unicode serialization of the `domain`. If `domain` is an invalid
domain, the empty string is returned.

It performs the inverse operation to [`require('url').domainToASCII()`][].

```js
const url = require('url');
console.log(url.domainToUnicode('xn--espaol-zwa.com'));
// Prints español.com
console.log(url.domainToUnicode('xn--fiq228c.com'));
// Prints 中文.com
console.log(url.domainToUnicode('xn--iñvalid.com'));
// Prints an empty string
```

*Note*: The `require('url').domainToUnicode()` API is introduced as part of the
the new `URL` implementation but is not part of the WHATWG URL standard.
Expand Down Expand Up @@ -956,6 +982,8 @@ console.log(myURL.origin);
[`URLSearchParams`]: #url_class_urlsearchparams
[`urlSearchParams.entries()`]: #url_urlsearchparams_entries
[`urlSearchParams@@iterator()`]: #url_urlsearchparams_iterator
[`require('url').domainToASCII()`]: #url_require_url_domaintoascii_domain
[`require('url').domainToUnicode()`]: #url_require_url_domaintounicode_domain
[stable sorting algorithm]: https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
[`JSON.stringify()`]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
[`url.toJSON()`]: #url_url_tojson

0 comments on commit b968491

Please sign in to comment.