Class: Uri

bp.core. Uri

Constructor

new Uri(uri, optionsopt)

A helper class to interact with and manipulate URI's (or really, URL's).
Parameters:
Name Type Attributes Description
uri string The URI to manipulate.
options object <optional>
Options to apply to the URI manipulation.
Properties:
Name Type Description
uri string The base URI that's being manipulated.
options object The options for the URI manipulation.
Properties
Name Type Description
escapePlus boolean Whether or not + should be escaped or not.
protocol string The protocol (http or https).
hostname string The hostname of the URI.
requestUri string The request portion of the URI (e.g. /path/to/resource).
queryString string The query string of the URI (e.g. ?stuff=poop&things=cool).
hash string The hash portion of the URI (e.g. #things=cool&whatever=stuff).
queryParams object The query string parsed into an object.
hashParams object The hash string parsed into an object.
Examples
var uri = new bp.core.Uri('http://www.blackpulp.com/api/user');
uri.queryParams.userId = 3;
uri.queryParams.showDetails = 1;
uri.toString();  // => 'http://www.blackpulp.com/api/user?userId=3&showDetails=1'
var uri = new bp.core.Uri('http://www.blackpulp.com/api/user?userId=4&asAdmin=0');
uri.hostname;  // => 'www.blackpulp.com'
uri.protocol;  // => 'http'
uri.queryParams.asAdmin;  // => '0'

Methods

decodeString() → {string}

Decodes a string encoded by encodeString()
Returns:
The decoded string.
Type
string

encodeString() → {string}

Encode a string using encodeURIComponent and, if options.escapePlus is set, replaces %20 with +.
Returns:
The encoded string.
Type
string

getHashString()

Get the hash string from the manipulated hashParams.

getJSON() → {string}

Makes the URI JSON friendly. All this really does is call toString().
Returns:
The URI as a string.
Type
string

getQueryString() → {string}

Get the query string of the URI.
Returns:
A query string.
Type
string

getSegment() → {string}

Get a portion of the URI.
Returns:
The URI segment.
Type
string
Example
var uri = new bp.core.Uri('http://www.blackpulp.com/something/cool')
  , segment = uri.getSegment(1);
segment;  // => 'something'

getUri() → {string}

Gets the URI as a string (simply calls toString().
Returns:
The URI as a string.
Type
string

go()

Directs the browser to open the URI.

setSegment() → {bp.core.Uri}

Sets a portion of the URI.
Returns:
The Uri object.
Type
bp.core.Uri
Example
var uri = new bp.core.Uri('http://www.blackpulp.com/something/cool');
uri.setSegment(2, 'else');
uri.toString();  // => 'http://www.blackpulp.com/something/else'

toString() → {string}

Get the URI as a string.
Returns:
The URI as a string.
Type
string