[whatwg/url] Proposal: URL.isValid (Issue #713)

It would be good to have a `URL.isValid` method? 

Today we have to do something like: 

```js
const isValidUrl = (s) => {
    try {
      new URL(s);
      return true;
    } catch (err) {
      return false;
    }
};
```

The proposal is to have something like:

```js
URL.isValid(<URL>, [protocol1, protocol2]);
```

```js
URL.isValid('https://h3manth.com'); // true
URL.isValid('https://h3manth.com', ['file']); // false 
```


-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/713
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/url/issues/713@github.com>

Received on Monday, 17 October 2022 22:01:50 UTC