mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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: https://github.com/nodejs/node/pull/32782 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
bd40a8b3d7
commit
de3ab9f576
1 file changed
+7
@@ -105,6 +105,13 @@ const myURL = new URL('/foo', 'https://example.org/');
|
||||
// https://example.org/foo
|
||||
```
|
||||
|
||||
The URL constructor is accessible as a property on the global object.
|
||||
It can also be imported from the built-in url module:
|
||||
|
||||
```js
|
||||
console.log(URL === require('url').URL); // Prints 'true'.
|
||||
```
|
||||
|
||||
A `TypeError` will be thrown if the `input` or `base` are not valid URLs. Note
|
||||
that an effort will be made to coerce the given values into strings. For
|
||||
instance:
|
||||
|
||||
Reference in new issue
Block a user