diff --git a/doc/api/url.md b/doc/api/url.md index 857611a0f29e46..a612d0d022f908 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)