Skip to content

Commit

Permalink
add node:url to built-in node.js runtime apis (#17070)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 24, 2024
1 parent 5f175e7 commit 7c7a6c3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/content/docs/workers/runtime-apis/nodejs/url.mdx
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
```

0 comments on commit 7c7a6c3

Please sign in to comment.