Parses an URL and returns its individual components.

Parameters:
NameTypeDescription
strstring

The URL to be parsed

componentstring

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
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' );
}