Skip to content

Commit 8e76f1a

Browse files
lirantalBethGriggs
authored andcommitted
doc: improve WHATWG url constructor code example
Currently, the URL docs for the WHATWG URL spec support are somewhat lacking in their code example of how to access the new URL constructor that lives inside the core url package. PR-URL: #32782 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 191747c commit 8e76f1a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

doc/api/url.md

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ const myURL = new URL('/foo', 'https://example.org/');
105105
// https://example.org/foo
106106
```
107107

108+
The URL constructor is accessible as a property on the global object.
109+
It can also be imported from the built-in url module:
110+
111+
```js
112+
console.log(URL === require('url').URL); // Prints 'true'.
113+
```
114+
108115
A `TypeError` will be thrown if the `input` or `base` are not valid URLs. Note
109116
that an effort will be made to coerce the given values into strings. For
110117
instance:

0 commit comments

Comments
 (0)