Function parseUrl

  • Converts a string or URL instance into UrlParts.

    • Partial URLs are valid. Whatever you don't provide will be empty in the returned object.
    • Encoding options are only applied to pathname, search, and hash url parts.

    Parameters

    • url: string | URL
    • Optionaloptions: Readonly<Pick<PartialWithUndefined<{
          encoding: UrlEncoding;
          searchParamStrategy: SearchParamStrategy;
      }>, "encoding">>

    Returns UrlParts

    import {parseUrl} from 'url-vir';

    let result = parseUrl('https://example.com:123/hello/there');

    // output
    result = {
    protocol: 'https',
    username: '',
    password: '',
    host: 'example.com:123',
    hostname: 'example.com',
    port: '123',
    origin: 'https://example.com:123',
    pathname: '/hello/there',
    paths: [
    'hello',
    'there',
    ],
    search: '',
    searchParams: {},
    hash: '',
    fullPath: '/hello/there',
    href: 'https://example.com:123/hello/there',
    };