A collection of useful static methods to deal with JavaScript URLs.
- Since:
- 3.5.0
Methods
(static) appendQuery(url, name, value) → {String}
Appends a specified key/value pair as a new search parameter.
If the same key is appended multiple times it will appear in the parameter string multiple times for each value.
Parameters:
Name | Type | Description |
---|---|---|
url |
String | The URL to append to. |
name |
String | The name of the parameter to append. |
value |
Object | The value of the parameter to append. |
- Since:
- 3.5.0
- See:
Throws:
-
for Invalid URL or empty arguments
- Type
- TypeError
Returns:
The resulting URL
- Type
- String
(static) getAllHashParameters(url) → {Object|null}
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.
If the same parameter name exists multiple times, only the last parameter value will be returned.
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) → {Object|null}
Returns an object containing the names of the search parameters as properties and values of the search parameters as the property values.
If the same parameter name exists multiple times, only the last parameter value will be returned.
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) → {String|null}
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, name) → {String|null}
Retrieves the first value associated to the given search parameter.
Parameters:
Name | Type | Description |
---|---|---|
url |
String | The URL to retrieve the search parameter from. |
name |
String | The name of the parameter to return. |
- Since:
- 3.6.5
- See:
Throws:
-
for Invalid URL or empty arguments
- Type
- TypeError
Returns:
Returns the first value associated to the given search parameter.
- Type
- String | null
(static) isValidURL(url) → {Boolean}
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