Home > @opengovsg/validators > UrlValidator > parse
UrlValidator.parse() method
Parses a URL string with a fallback option.
Signature:
typescript
parse(url: any, fallbackUrl: string | URL): URL;Parameters
| Parameter | Type | Description |
|---|---|---|
| url | any | The URL to validate, expects string | URL |
| fallbackUrl | string | URL | The fallback URL to return if the URL is invalid. |
Returns:
URL
The URL object if the URL is valid, else the fallbackUrl (if provided).
Exceptions
UrlValidationError if the URL is invalid and fallbackUrl is not provided.