Class: URL

mindsmine. URL

A collection of useful static methods to deal with JavaScript URLs.


new URL()

Since:
  • 3.5.0

Methods


<static> appendQuery(url, param, value)

Appends content to the query string of a URL, handling logic for whether to place a question mark or ampersand.

Parameters:
Name Type Description
url String

The URL to append to.

param String

The parameter key to append to the URL.

value Object

The parameter value to append to the URL.

Since:
  • 3.5.0
See:
Throws:

for Invalid URL or empty arguments

Type
TypeError
Returns:

The resulting URL

Type
String

<static> getAllHashParameters(url)

Returns an object containing the names of the hash parameters as properties and values of the hash parameters as the property values.

If a hash parameter does not have an associated value, it is provided with a true value.

Parameters:
Name Type Description
url String

The URL to retrieve the hash parameters from.

Since:
  • 3.6.5
See:
Throws:

for Invalid URL or empty arguments

Type
TypeError
Returns:

Returns null if no hash parameters exist.

Type
Object | null

<static> getAllQueryParameters(url)

Returns an object containing the names of the search parameters as properties and values of the search parameters as the property values.

Parameters:
Name Type Description
url String

The URL to retrieve the search parameters from.

Since:
  • 3.6.5
See:
Throws:

for Invalid URL or empty arguments

Type
TypeError
Returns:

Returns null if no search parameters exist.

Type
Object | null

<static> getHashParameter(url, hashParam)

Retrieves the value of the hash parameter.

Parameters:
Name Type Description
url String

The URL to retrieve the hash parameter from.

hashParam String

The hash parameter (case-sensitive) string whose value is to be retrieved.

Since:
  • 3.6.5
See:
Throws:

for Invalid URL or empty arguments

Type
TypeError
Returns:

Returns null if unavailable.

Type
String | null

<static> getQueryParameter(url, queryParam)

Retrieves the value of the query parameter.

Parameters:
Name Type Description
url String

The URL to retrieve the search parameter from.

queryParam String

The query parameter (case-sensitive) string whose value is to be retrieved.

Since:
  • 3.6.5
See:
Throws:

for Invalid URL or empty arguments

Type
TypeError
Returns:

Returns null if unavailable.

Type
String | null

<static> isValidURL(url)

Returns true if the passed string is a valid URL, false otherwise.

Example Usage:

 mindsmine.URL.isValidURL("http://userid@example.com")       //  true
 mindsmine.URL.isValidURL("www.example.com/main.html")       //  false
Parameters:
Name Type Description
url String

to check

Since:
  • 3.5.0
See:
Returns:

if the string is a valid URL

Type
Boolean