goog.uri.utils
Functions
appendParam( uri, key, opt_value ) → string
string
Appends a single URI parameter.
Repeated calls to this can exhibit quadratic behavior in IE6 due to the way string append works, though it should be limited given the 2kb limit.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
appendParams( uri, ...var_args ) → string
string
Appends URI parameters to an existing URI.
The variable arguments may contain alternating keys and values. Keys are assumed to be already URI encoded. The values should not be URI-encoded, and will instead be encoded by this function.
appendParams('http://www.foo.com?existing=true', 'key1', 'value1', 'key2', 'value?willBeEncoded', 'key3', ['valueA', 'valueB', 'valueC'], 'key4', null); result: 'http://www.foo.com?existing=true&' + 'key1=value1&' + 'key2=value%3FwillBeEncoded&' + 'key3=valueA&key3=valueB&key3=valueC'
A single call to this function will not exhibit quadratic behavior in IE, whereas multiple repeated calls may, although the effect is limited by fact that URL's generally can't exceed 2kb.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
appendParamsFromMap( uri, map ) → string
string
appendPath( baseUri, path ) → string
string
Generates a URI path using a given URI and a path with checks to prevent consecutive "//". The baseUri passed in must not contain query or fragment identifiers. The path to append may not contain query or fragment identifiers.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
buildFromEncodedParts( opt_scheme, opt_userInfo, opt_domain, opt_port, opt_path, opt_queryData, opt_fragment ) → string
string
Builds a URI string from already-encoded parts.
No encoding is performed. Any component may be omitted as either null or undefined.
Parameters |
| ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
buildQueryData( keysAndValues, opt_startIndex ) → string
string
Builds a query data string from a sequence of alternating keys and values. Currently generates "&key&" for empty args.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
buildQueryDataFromMap( map ) → string
string
Builds a query data string from a map. Currently generates "&key&" for empty args.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
getDomain( uri ) → (string|null)
(string|null)
getDomainEncoded( uri ) → (string|null)
(string|null)
getEffectiveScheme( uri ) → string
string
getFragment( uri ) → (string|null)
(string|null)
getFragmentEncoded( uri ) → (string|null)
(string|null)
getHost( uri ) → string
string
getOrigin( uri ) → string
string
getParamValue( uri, keyEncoded ) → (string|null)
(string|null)
getPath( uri ) → (string|null)
(string|null)
getPathAndAfter( uri ) → string
string
getPathEncoded( uri ) → (string|null)
(string|null)
getPort( uri ) → (number|null)
(number|null)
getQueryData( uri ) → (string|null)
(string|null)
getScheme( uri ) → (string|null)
(string|null)
getUserInfo( uri ) → (string|null)
(string|null)
getUserInfoEncoded( uri ) → (string|null)
(string|null)
hasParam( uri, keyEncoded ) → boolean
boolean
haveSameDomain( uri1, uri2 ) → boolean
boolean
Ensures that two URI's have the exact same domain, scheme, and port.
Unlike the version in goog.Uri, this checks protocol, and therefore is suitable for checking against the browser's same-origin policy.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
makeUnique( uri ) → string
string
parseQueryData( encodedQuery, callback ) → void
void
Parses encoded query parameters and calls callback function for every parameter found in the string.
Missing value of parameter (e.g. “…&key&…”) is treated as if the value was an empty string. Keys may be empty strings (e.g. “…&=value&…”) which also means that “…&=&…” and “…&&…” will result in an empty key and value.
Parameters |
|
---|
removeFragment( uri ) → string
string
removeParam( uri, keyEncoded ) → string
string
setFragmentEncoded( uri, fragment ) → string
string
setParam( uri, keyEncoded, value ) → string
string
Replaces all existing definitions of a parameter with a single definition.
Repeated calls to this can exhibit quadratic behavior due to the need to find existing instances and reconstruct the string, though it should be limited given the 2kb limit. Consider using appendParams or setParamsFromMap to update multiple parameters in bulk.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
setParamsFromMap( uri, params ) → string
string
Effeciently set or remove multiple query parameters in a URI. Order of unchanged parameters will not be modified, all updated parameters will be appended to the end of the query. Params with values of null or undefined are removed.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
setPath( uri, path ) → string
string
setUrlPackageSupportLoggingHandler( handler ) → void
void
Parameters |
|
---|
Splits a URI into its component parts.
Each component can be accessed via the component indices; for example:
goog.uri.utils.split(someStr)[goog.uri.utils.ComponentIndex.QUERY_DATA];
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
Properties
QueryArray → Array<*>
Array<*>
An array representing a set of query parameters with alternating keys and values.
Keys are assumed to be URI encoded already and live at even indices. See goog.uri.utils.QueryValue for details on how parameter values are encoded.
Example:
var data = [ // Simple param: ?name=BobBarker 'name', 'BobBarker', // Conditional param -- may be omitted entirely. 'specialDietaryNeeds', hasDietaryNeeds() ? getDietaryNeeds() : null, // Multi-valued param: &house=LosAngeles&house=NewYork&house=null 'house', ['LosAngeles', 'NewYork', null] ];
QueryValue → *
*
Supported query parameter values by the parameter serializing utilities.
If a value is null or undefined, the key-value pair is skipped, as an easy way to omit parameters conditionally. Non-array parameters are converted to a string and URI encoded. Array values are expanded into multiple &key=value pairs, with each element stringized and URI-encoded.