Parses an URL and returns its individual components.
Parameters:
Name | Type | Description |
---|---|---|
str | string | The URL to be parsed |
component | string | Determines which URL component to be returned. If ommitted, an associative array with all URL components is returned. Possible values: ( scheme, user, pass, host, path, query, fragment, source ). |
- Since
- 1.0.0
- Source
Returns:
Returns the specified URL component. If the component parameter is ommitted, returns an associative array with all URL components.
- Type:
- string |
object
Example
import { parseUrl } from "@gravityforms/utils";
function Example() {
const url = 'http://username:password@hostname/path?arg=value#anchor';
const allComponents = parseUrl( url );
const hostname = parseUrl( url, 'host' );
}