Namespace: CB_Net

CB_Net

Static class to manage things related to the net. It will return itself if it is tried to be instantiated.

Source:

Namespaces

Fetch
REST
Sockets
XHR

Methods


<static> combineURIParameters()

Source:
See:

<static> combineURLParameters()

Source:
See:

<static> getHashParameters( [URI] [, exclude] [, includeOnly] [, includeIfNotExists] [, trim]) → {string}

Gets all the hash parameters (names and their values) from a given URI or from the current URL.


For example, if the URI provided is "http://whatever.com/index.html?parameter1=value1&parameter2=value2#hash_parameter1=hash_value1&hash_parameter2=hash_value2", it will return
"hash_parameter1=hash_value1&hash_parameter2=hash_value2" (using the default options).

Parameters:
Name Type Argument Default Description
URI string <optional>
window.location.href

The URI that we want to work with. If not provided, it will try to use the current URL (by using window.location.href).

exclude array <optional>

A numeric array containing the name of the parameters that we want to exclude in the returned string. It will exclude them even if they are contained in the given "includeOnly" parameter (if any).

includeOnly array <optional>

A numeric array containing the name of the parameters that we want to include in the returned string. If provided, it will only include these ones to the returned string (unless they are included in the "exclude" parameter).

includeIfNotExists boolean <optional>
false

If it is set to true and an array is given as the "includeOnly" parameter, it will add the parameters in the "includeOnly" array (with empty values) in the returned string even when they did not exist in the original URI provided.

trim boolean <optional>
true

It will use this option when it calls the CB_Net.getURIParameters function internally.

Source:
Returns:

An empty string will be returned if no parameters can be found.

Type
string

<static> getHashValue(index [, trim] [, URI]) → {string}

Gets the value of a specific hash (string after "#") parameter from the current URL or a desired URI.


For example, if the URI provided is "http://whatever.com/index.html?parameter1=value1&parameter2=value2#hash_parameter1=hash_value1&hash_parameter2=hash_value2" and the index given is "hash_parameter1",
it will return "hash_value1" (using the default options).

Parameters:
Name Type Argument Default Description
index string

The name of the parameter whose value we want to get.

trim boolean <optional>
true

It will trim the value (using CB_Net.getParameter internally) before returning it.

URI string <optional>
window.location.href

The URI that we want to work with. If not provided, it will try to use the current URL (by using window.location.href).

Source:
Returns:

An empty string will be returned if the value of the given parameter cannot be found.

Type
string

<static> getParameter(index [, trim] [, URI] [, firstDelimiter] [, lastDelimiter] [, concatenator] [, nameValueSeparator]) → {string}

Gets the value of a specific URI parameter (query or hash), respecting GET/URL rules by default, from the current URL or a desired one (with the given delimiters).


For example, if the URI provided is "http://whatever.com/index.html?parameter1=value1&parameter2=value2#hash_parameter1=hash_value1&hash_parameter2=hash_value2" and the index given is "parameter1", it will return "value1" (using the default options).

Parameters:
Name Type Argument Default Description
index string

The name of the parameter whose value we want to get.

trim boolean <optional>
true

It will trim the value (using CB_trim internally) before returning it.

URI string <optional>
window.location.href

The URI that we want to work with. If not provided, it will try to use the current URL (by using window.location.href).

firstDelimiter string <optional>
'?'

The string that indicates where the parameters start. If it is not provided, it will be "?" as default. If not provided and "lastDelimiter" is not provided either, it will be "?" and "lastDelimiter" will be "#".

lastDelimiter string <optional>
undefined|'#'

The string that indicates where the parameters end. If not provided and "firstDelimiter" is provided, it will stop at the end of the given URI. If it is not provided and "firstDelimiter" is not provided either, "firstDelimiter" will be "?" and "lastDelimiter" will be "#".

concatenator string <optional>
'&'

The string that joints the different parameters.

nameValueSeparator string <optional>
'='

The string that is the separator for the parameters and their values.

Source:
Returns:

An empty string will be returned if the value of the given parameter cannot be found.

Type
string

<static> getURIParameters( [URI] [, exclude] [, includeOnly] [, includeIfNotExists] [, trim] [, firstDelimiter] [, lastDelimiter] [, concatenator] [, nameValueSeparator]) → {string}

Gets all the "GET" (query) parameters (names and their values) from a given URI or from the current URL.


For example, if the URI provided is "http://whatever.com/index.html?parameter1=value1&parameter2=value2#hash_parameter1=hash_value1&hash_parameter2=hash_value2", it will return "parameter1=value1&parameter2=value2" (using the default options).

Parameters:
Name Type Argument Default Description
URI string <optional>
window.location.href

The URI that we want to work with. If not provided, it will try to use the current URL (by using window.location.href).

exclude array <optional>

A numeric array containing the name of the parameters that we want to exclude in the returned string. It will exclude them even if they are contained in the given "includeOnly" parameter (if any).

includeOnly array <optional>

A numeric array containing the name of the parameters that we want to include in the returned string. If provided, it will only include these ones to the returned string (unless they are included in the "exclude" parameter).

includeIfNotExists boolean <optional>
false

If it is set to true and an array is given as the "includeOnly" parameter, it will add the parameters in the "includeOnly" array (with empty values) in the returned string even when they did not exist in the original URI provided.

trim boolean <optional>
true

Defines whether we want to trim the spaces around the values or not.

firstDelimiter string <optional>
'?'

The string that indicates where the parameters start. If it is not provided, it will be "?" as default. If not provided and "lastDelimiter" is not provided either, it will be "?" and "lastDelimiter" will be "#".

lastDelimiter string <optional>
undefined|'#'

The string that indicates where the parameters end. If not provided and "firstDelimiter" is provided, it will stop at the end of the given URI. If it is not provided and "firstDelimiter" is not provided either, "firstDelimiter" will be "?" and "lastDelimiter" will be "#".

concatenator string <optional>
'&'

The string that joints the different parameters.

nameValueSeparator string <optional>
'='

The string that is the separator for the parameters and their values.

Source:
Returns:

An empty string will be returned if no parameters can be found.

Type
string

<static> getURIValue(index [, trim] [, URI]) → {string}

Gets the value of a specific URI "GET" parameter (query) from the current URL or a desired URI.


For example, if the URI provided is "http://whatever.com/index.html?parameter1=value1&parameter2=value2#hash_parameter1=hash_value1&hash_parameter2=hash_value2" and the index given is "parameter1", it will return "value1" (using the default options).

Parameters:
Name Type Argument Default Description
index string

The name of the parameter whose value we want to get.

trim boolean <optional>
true

It will trim the value (using CB_Net.getParameter internally) before returning it.

URI string <optional>
window.location.href

The URI that we want to work with. If not provided, it will try to use the current URL (by using window.location.href).

Source:
Returns:

An empty string will be returned if the value of the given parameter cannot be found.

Type
string

<static> URIDecode(URI) → {string}

Encodes a given URI. Uses the native decodeURI function internally if available or fallbacks to the native unescape function otherwise.

Parameters:
Name Type Description
URI string | number

The URI that we want to decode. Normally, it should be either a string or a number.

Source:
To Do:
  • Think about using another thing since unescape maybe is not a good fallback. Probably a polyfill to simulate the decodeURI function.
Returns:
Type
string

<static> URIEncode(URI) → {string}

Encodes a given URI. Uses the native encodeURI function internally if available or fallbacks to the native escape function otherwise.

Parameters:
Name Type Description
URI string | number

The URI that we want to encode. Normally, it should be either a string or a number.

Source:
To Do:
  • Think about using another thing since escape maybe is not a good fallback. Probably a polyfill to simulate the encodeURI function.
Returns:
Type
string

<static> URIValueDecode(value) → {string}

Decodes a given URI value. Uses the native decodeURIComponent function internally if available or fallbacks to the native unescape function otherwise.

Parameters:
Name Type Description
value string | number

The value that we want to decode. Normally, it should be either a string or a number.

Source:
To Do:
  • Think about using another thing since unescape maybe is not a good fallback. Probably a polyfill to simulate the decodeURIComponent function.
Returns:
Type
string

<static> URIValueEncode(value) → {string}

Encodes a given URI value. Uses the native encodeURIComponent function internally if available or fallbacks to the native escape function otherwise.

Parameters:
Name Type Description
value string | number

The value that we want to encode. Normally, it should be either a string or a number.

Source:
To Do:
  • Think about using another thing since escape maybe is not a good fallback. Probably a polyfill to simulate the encodeURIComponent function.
Returns:
Type
string

<static> URLDecode()

Alias for CB_Net.URIDecode.

Source:
See:

<static> URLEncode()

Alias for CB_Net.URIEncode.

Source:
See:

<static> URLValueDecode()

Source:
See:

<static> URLValueEncode()

Source:
See: