parseUrl
Parse a URL string into a structured object of protocol, host, pathname, query, and hash, returning null when the input is invalid.
Usage
parseUrl parses a URL string into a structured object.
import { parseUrl } from '@movk/core'
parseUrl('https://example.com:8080/path?query=1#hash')
// {
// href: 'https://example.com:8080/path?query=1#hash',
// protocol: 'https:',
// host: 'example.com:8080',
// hostname: 'example.com',
// port: '8080',
// pathname: '/path',
// search: '?query=1',
// hash: '#hash',
// auth: '',
// origin: 'https://example.com:8080'
// }
parseUrl('/path', 'https://example.com')
// parse a relative URL against a base
API
parseUrl(url, base?)
Parse a URL string into a structured object.
Parameters
url
string required
The URL string to parse.
base
string
An optional base URL used to resolve relative paths.
Returns
returns
ParsedUrl | null
The parsed URL object, or
null if parsing fails.Changelog
No recent changes