Function toValidUrl

  • Attempt to convert the input input a valid URL string via the URL class. If the conversion fails, undefined is returned. Note that this is pretty strict: many values which can be correctly handled by parseUrl will fail this. (For example, the protocol must be included for this to pass.)

    Parameters

    • input:
          | string
          | URL
          | Readonly<
              Pick<
                  Readonly<
                      {
                          fullPath: string;
                          hash: string;
                          host: string;
                          hostname: string;
                          href: string;
                          origin: string;
                          password: string;
                          pathname: string;
                          paths: readonly string[];
                          port: string;
                          protocol: string;
                          search: string;
                          searchParams: Readonly<Record<string, readonly string[]>>;
                          username: string;
                      },
                  >,
                  "href",
              >,
          >

    Returns undefined | string

    Url string if input can be parsed. Otherwise, undefined.