url.parse

url.parse

url.parse

Function

Parses the current URL into an object.

Syntax

Parameters

None.

Return value

TypeDescription
ObjectReturns the URL parsing object. See "Return Object Fields" below for fields.

Return object fields

FieldTypeMust existDescription
schemeStringYesURL scheme, excluding :, such as http, https.
usernameStringYesURL username. Empty string if there is no username.
passwordString/EmptyYesURL password. empty without password.
hostString/EmptyYesA hostname or IP string. When the URL does not have a host, it is empty.
portInt/EmptyYesExplicit port number. When the URL does not explicitly provide a port, it is empty, and the default port of the scheme will not be returned.
pathStringYesURL path, usually starting with /.
queryString/EmptyYesThe original query string without ?. empty without query string.
fragmentString/EmptyYesURL fragment without #. empty without fragment.
originStringis the ASCII serialization result ofthe URL origin, for example https://btlang.org.
urlStringYesThe complete URL string after normalization.

Code Example

Notes

  • A runtime error is thrown when the URL cannot be parsed.
  • password, host, port, query, and fragment return empty when the corresponding optional URL components are absent.