From 3a0058cd4aedbd2b0a981cbc4595b63b2af29d4f Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Wed, 26 Apr 2017 18:04:30 -0700 Subject: [PATCH] doc: document url.domainTo* methods separately PR-URL: https://github.com/nodejs/node/pull/12683 Reviewed-By: James M Snell Reviewed-By: Daijiro Wachi Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung --- doc/api/url.md | 94 ++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/doc/api/url.md b/doc/api/url.md index 934e65fabc664f..f6f562af4fdb7d 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -131,6 +131,50 @@ The `slashes` property is a `boolean` with a value of `true` if two ASCII forward-slash characters (`/`) are required following the colon in the `protocol`. +## url.domainToASCII(domain) + +> Stability: 1 - Experimental + +* `domain` {string} +* Returns: {string} + +Returns the [Punycode][] ASCII serialization of the `domain`. If `domain` is an +invalid domain, the empty string is returned. + +It performs the inverse operation to [`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 +``` + +## url.domainToUnicode(domain) + +> Stability: 1 - Experimental + +* `domain` {string} +* Returns: {string} + +Returns the Unicode serialization of the `domain`. If `domain` is an invalid +domain, the empty string is returned. + +It performs the inverse operation to [`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 +``` + ## url.format(urlObject)