Skip to content

URL.canParse() #713

@hemanth

Description

@hemanth

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

Today we have to do something like:

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

The proposal is to have something like:

URL.isValid(<URL>, [protocol1, protocol2]);
URL.isValid('https://h3manth.com'); // true
URL.isValid('https://h3manth.com', ['file']); // false 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions