-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add node:url to built-in node.js runtime apis
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
pcx_content_type: configuration | ||
title: url | ||
|
||
--- | ||
|
||
import { Render } from "~/components" | ||
|
||
<Render file="nodejs-compat-howto" /> | ||
|
||
## domainToASCII | ||
|
||
Returns the Punycode ASCII serialization of the domain. If domain is an invalid domain, the empty string is returned. | ||
|
||
```js | ||
import { domainToASCII } from 'node:url'; | ||
|
||
console.log(domainToASCII('español.com')); | ||
// Prints xn--espaol-zwa.com | ||
console.log(domainToASCII('中文.com')); | ||
// Prints xn--fiq228c.com | ||
console.log(domainToASCII('xn--iñvalid.com')); | ||
// Prints an empty string | ||
``` | ||
|
||
## domainToUnicode | ||
|
||
Returns the Unicode serialization of the domain. If domain is an invalid domain, the empty string is returned. | ||
|
||
It performs the inverse operation to `domainToASCII()`. | ||
|
||
```js | ||
import { domainToUnicode } from 'node:url'; | ||
|
||
console.log(domainToUnicode('xn--espaol-zwa.com')); | ||
// Prints español.com | ||
console.log(domainToUnicode('xn--fiq228c.com')); | ||
// Prints 中文.com | ||
console.log(domainToUnicode('xn--iñvalid.com')); | ||
// Prints an empty string | ||
``` |