Skip to content

Commit

Permalink
doc: improve WHATWG url constructor code example
Browse files Browse the repository at this point in the history
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 <anna@addaleax.net>
  • Loading branch information
lirantal authored and BridgeAR committed Apr 28, 2020
1 parent 606719f commit ea67a30
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ea67a30

Please sign in to comment.