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

The primary use case I've encountered for this is really functions like the isValid() in the OP at the top. Specifically, code that wishes to verify that a given input can be handled as a URL (can parse) without incurring the additional cost of creating either a URL object or an Error object with an expensive to generate stack. I've encountered this pattern a number of times.

Most often, I'd say, the check is performed using a regex, which is problematic in that it doesn't match the parsing semantics and can be difficult to make correct. There's an old module on npm called is-url that has over 2.5 million downloads per week to address this specific problem using an incomplete regex approach. 

For me, I would 100% support an API that checks if an input can be parsed as a URL. I have no use case for further validity checks.

Alternatively, I would be good with a `new URL` constructor variation that did not throw on unparseable input so as to avoid the expensive operation to acquire the stack. 

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

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

Received on Saturday, 5 November 2022 12:43:17 UTC