Skip to content

Commit

Permalink
feat: add isValidUrl function
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadam committed Jul 11, 2023
1 parent 22beb41 commit e15e14b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/url/is-valid-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* A valid URL (Uniform Resource Locator) in the web typically consists of several components:
* 1. Protocol: This is the type of protocol used for communication, such as "http://" or "https://".
* 2. Domain: This is the unique address of a website, like "example.com" or "google.com".
* 3. Path: This is the specific location or file on the website, such as "/products" or "/about-us.html".
* 4. Query Parameters: These are optional parameters that can be added to a URL to provide additional information to the website, like "?category=books".
*
*
* @param url - the given url string
* @returns true if the URL is valid, false otherwise.
*
* @public
*/
export function isValidUrl(url: string): boolean {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}

0 comments on commit e15e14b

Please sign in to comment.