From 75bd0c6ad33d33d5d59e57b09082ff10d5dafde5 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Sat, 11 Apr 2020 17:02:59 +0300 Subject: [PATCH] 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 --- doc/api/url.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/api/url.md b/doc/api/url.md index 49f56509fe41e9..6950c92f0980c8 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -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: