/**
* Class used to represent URI query parameters. It is essentially a hash of
* name-value pairs, though a name can be present more than once.
*
* Has the same interface as the collections in structs.
*
* the object.
* name in #get.
* @class
* @final
*/
export class QueryData {
/**
* Creates a new query data instance from a map of names and values.
*
* @param {!maps.MapLikevar myUri = new Uri(window.location);
*
* Implements RFC 3986 for parsing/formatting URIs.
* http://www.ietf.org/rfc/rfc3986.txt
*
* Some changes have been made to the interface (more like .NETs), though the
* internal representation is now of un-encoded parts, this will change the
* behavior slightly.
*/
/**
* This class contains setters and getters for the parts of the URI.
* The getXyz/setXyz methods return the decoded part
* -- soUri.parse('/foo%20bar').getPath() will return the
* decoded path, /foo bar.
*
* Reserved characters (see RFC 3986 section 2.2) can be present in
* their percent-encoded form in scheme, domain, and path URI components and
* will not be auto-decoded. For example:
* Uri.parse('rel%61tive/path%2fto/resource').getPath() will
* return relative/path%2fto/resource.
*
* The constructor accepts an optional unparsed, raw URI string. The parser
* is relaxed, so special characters that aren't escaped but don't cause
* ambiguities will not cause parse failures.
*
* All setters return this and so may be chained, a la
* Uri.parse('/foo').setFragment('part').toString().
*
* (use Uri.create() to create a URI from parts), or if
* a Uri is passed, a clone is created.
* the case of the parameter name.
*
* @throws URIError If opt_uri is provided and URI is malformed (that is,
* if decodeURIComponent fails on any of the URI components).
* @class
*/
export class Uri {
/**
* Creates a uri from the string form. Basically an alias of new Uri().
* If a Uri object is passed to parse then it will return a clone of the object.
*
* @throws URIError If parsing the URI is malformed. The passed URI components
* should all be parseable by decodeURIComponent.
* @param {*} uri Raw URI string or instance of Uri
* object.
* @param {boolean=} opt_ignoreCase Whether to ignore the case of parameter
* names in #getParameterValue.
* @return {!Uri} The new URI object.
*/
static parse(uri: any, opt_ignoreCase?: boolean | undefined): Uri;
/**
* Creates a new Uri object from unencoded parts.
*
* @param {?string=} opt_scheme Scheme/protocol or full URI to parse.
* @param {?string=} opt_userInfo username:password.
* @param {?string=} opt_domain www.google.com.
* @param {?number=} opt_port 9830.
* @param {?string=} opt_path /some/path/to/a/file.html.
* @param {string|QueryData=} opt_query a=1&b=2.
* @param {?string=} opt_fragment The fragment without the #.
* @param {boolean=} opt_ignoreCase Whether to ignore parameter name case in
* #getParameterValue.
*
* @return {!Uri} The new URI object.
*/
static create(opt_scheme?: (string | null) | undefined, opt_userInfo?: (string | null) | undefined, opt_domain?: (string | null) | undefined, opt_port?: (number | null) | undefined, opt_path?: (string | null) | undefined, opt_query?: (string | QueryData) | undefined, opt_fragment?: (string | null) | undefined, opt_ignoreCase?: boolean | undefined): Uri;
/**
* Resolves a relative Uri against a base Uri, accepting both strings and
* Uri objects.
*
* @param {*} base Base Uri.
* @param {*} rel Relative Uri.
* @return {!Uri} Resolved uri.
*/
static resolve(base: any, rel: any): Uri;
/**
* Removes dot segments in given path component, as described in
* RFC 3986, section 5.2.4.
*
* @param {string} path A non-empty path component.
* @return {string} Path component with removed dot segments.
*/
static removeDotSegments(path: string): string;
/**
* Decodes a value or returns the empty string if it isn't defined or empty.
* @throws URIError If decodeURIComponent fails to decode val.
* @param {string|undefined} val Value to decode.
* @param {boolean=} opt_preserveReserved If true, restricted characters will
* not be decoded.
* @return {string} Decoded value.
* @private
*/
private static decodeOrEmpty_;
/**
* If unescapedPart is non null, then escapes any characters in it that aren't
* valid characters in a url and also escapes any special characters that
* appear in extra.
*
* @param {*} unescapedPart The string to encode.
* @param {?RegExp} extra A character set of characters in [\01-\177].
* @param {boolean=} opt_removeDoubleEncoding If true, remove double percent
* encoding.
* @return {?string} null iff unescapedPart == null.
* @private
*/
private static encodeSpecialChars_;
/**
* Converts a character in [\01-\177] to its unicode character equivalent.
* @param {string} ch One character string.
* @return {string} Encoded string.
* @private
*/
private static encodeChar_;
/**
* Removes double percent-encoding from a string.
* @param {string} doubleEncodedString String
* @return {string} String with double encoding removed.
* @private
*/
private static removeDoubleEncoding_;
/**
* Checks whether two URIs have the same domain.
* @param {string} uri1String First URI string.
* @param {string} uri2String Second URI string.
* @return {boolean} true if the two URIs have the same domain; false otherwise.
*/
static haveSameDomain(uri1String: string, uri2String: string): boolean;
/**
* This class contains setters and getters for the parts of the URI.
* The getXyz/setXyz methods return the decoded part
* -- soUri.parse('/foo%20bar').getPath() will return the
* decoded path, /foo bar.
*
* Reserved characters (see RFC 3986 section 2.2) can be present in
* their percent-encoded form in scheme, domain, and path URI components and
* will not be auto-decoded. For example:
* Uri.parse('rel%61tive/path%2fto/resource').getPath() will
* return relative/path%2fto/resource.
*
* The constructor accepts an optional unparsed, raw URI string. The parser
* is relaxed, so special characters that aren't escaped but don't cause
* ambiguities will not cause parse failures.
*
* All setters return this and so may be chained, a la
* Uri.parse('/foo').setFragment('part').toString().
*
* @param {*=} opt_uri Optional string URI to parse
* (use Uri.create() to create a URI from parts), or if
* a Uri is passed, a clone is created.
* @param {boolean=} opt_ignoreCase If true, #getParameterValue will ignore
* the case of the parameter name.
*
* @throws URIError If opt_uri is provided and URI is malformed (that is,
* if decodeURIComponent fails on any of the URI components).
*/
constructor(opt_uri?: any | undefined, opt_ignoreCase?: boolean | undefined);
/**
* Scheme such as "http".
* @private {string}
*/
private scheme_;
/**
* User credentials in the form "username:password".
* @private {string}
*/
private userInfo_;
/**
* Domain part, e.g. "www.google.com".
* @private {string}
*/
private domain_;
/**
* Port, e.g. 8080.
* @private {?number}
*/
private port_;
/**
* Path, e.g. "/tests/img.png".
* @private {string}
*/
private path_;
/**
* The fragment without the #.
* @private {string}
*/
private fragment_;
/**
* Whether or not this Uri should be treated as Read Only.
* @private {boolean}
*/
private isReadOnly_;
/**
* Whether or not to ignore case when comparing query params.
* @private {boolean}
*/
private ignoreCase_;
queryData_: QueryData | undefined;
/**
* @return {string} The string form of the url.
* @override
*/
toString(): string;
/**
* Resolves the given relative URI (a Uri object), using the URI
* represented by this instance as the base URI.
*
* There are several kinds of relative URIs:
* 1. foo - replaces the last part of the path, the whole query and fragment
* 2. /foo - replaces the path, the query and fragment
* 3. //foo - replaces everything from the domain on. foo is a domain name
* 4. ?foo - replace the query and fragment
* 5. #foo - replace the fragment only
*
* Additionally, if relative URI has a non-empty path, all ".." and "."
* segments will be resolved, as described in RFC 3986.
*
* @param {!Uri} relativeUri The relative URI to resolve.
* @return {!Uri} The resolved URI.
*/
resolve(relativeUri: Uri): Uri;
/**
* Clones the URI instance.
* @return {!Uri} New instance of the URI object.
*/
clone(): Uri;
/**
* @return {string} The encoded scheme/protocol for the URI.
*/
getScheme(): string;
/**
* Sets the scheme/protocol.
* @throws URIError If opt_decode is true and newScheme is malformed (that is,
* if decodeURIComponent fails).
* @param {string} newScheme New scheme value.
* @param {boolean=} opt_decode Optional param for whether to decode new value.
* @return {!Uri} Reference to this URI object.
*/
setScheme(newScheme: string, opt_decode?: boolean | undefined): Uri;
/**
* @return {boolean} Whether the scheme has been set.
*/
hasScheme(): boolean;
/**
* @return {string} The decoded user info.
*/
getUserInfo(): string;
/**
* Sets the userInfo.
* @throws URIError If opt_decode is true and newUserInfo is malformed (that is,
* if decodeURIComponent fails).
* @param {string} newUserInfo New userInfo value.
* @param {boolean=} opt_decode Optional param for whether to decode new value.
* @return {!Uri} Reference to this URI object.
*/
setUserInfo(newUserInfo: string, opt_decode?: boolean | undefined): Uri;
/**
* @return {boolean} Whether the user info has been set.
*/
hasUserInfo(): boolean;
/**
* @return {string} The decoded domain.
*/
getDomain(): string;
/**
* Sets the domain.
* @throws URIError If opt_decode is true and newDomain is malformed (that is,
* if decodeURIComponent fails).
* @param {string} newDomain New domain value.
* @param {boolean=} opt_decode Optional param for whether to decode new value.
* @return {!Uri} Reference to this URI object.
*/
setDomain(newDomain: string, opt_decode?: boolean | undefined): Uri;
/**
* @return {boolean} Whether the domain has been set.
*/
hasDomain(): boolean;
/**
* @return {?number} The port number.
*/
getPort(): number | null;
/**
* Sets the port number.
* @param {*} newPort Port number. Will be explicitly casted to a number.
* @return {!Uri} Reference to this URI object.
*/
setPort(newPort: any): Uri;
/**
* @return {boolean} Whether the port has been set.
*/
hasPort(): boolean;
/**
* @return {string} The decoded path.
*/
getPath(): string;
/**
* Sets the path.
* @throws URIError If opt_decode is true and newPath is malformed (that is,
* if decodeURIComponent fails).
* @param {string} newPath New path value.
* @param {boolean=} opt_decode Optional param for whether to decode new value.
* @return {!Uri} Reference to this URI object.
*/
setPath(newPath: string, opt_decode?: boolean | undefined): Uri;
/**
* @return {boolean} Whether the path has been set.
*/
hasPath(): boolean;
/**
* @return {boolean} Whether the query string has been set.
*/
hasQuery(): boolean;
/**
* Sets the query data.
* @param {QueryData|string|undefined} queryData QueryData object.
* @param {boolean=} opt_decode Optional param for whether to decode new value.
* Applies only if queryData is a string.
* @return {!Uri} Reference to this URI object.
*/
setQueryData(queryData: QueryData | string | undefined, opt_decode?: boolean | undefined): Uri;
/**
* Sets the URI query.
* @param {string} newQuery New query value.
* @param {boolean=} opt_decode Optional param for whether to decode new value.
* @return {!Uri} Reference to this URI object.
*/
setQuery(newQuery: string, opt_decode?: boolean | undefined): Uri;
/**
* @return {string} The encoded URI query, not including the ?.
*/
getEncodedQuery(): string;
/**
* @return {string} The decoded URI query, not including the ?.
*/
getDecodedQuery(): string;
/**
* Returns the query data.
* @return {!QueryData} QueryData object.
*/
getQueryData(): QueryData;
/**
* @return {string} The encoded URI query, not including the ?.
*
* Warning: This method, unlike other getter methods, returns encoded
* value, instead of decoded one.
*/
getQuery(): string;
/**
* Sets the value of the named query parameters, clearing previous values for
* that key.
*
* @param {string} key The parameter to set.
* @param {*} value The new value. Value does not need to be encoded.
* @return {!Uri} Reference to this URI object.
*/
setParameterValue(key: string, value: any): Uri;
/**
* Sets the values of the named query parameters, clearing previous values for
* that key. Not new values will currently be moved to the end of the query
* string.
*
* So, Uri.parse('foo?a=b&c=d&e=f').setParameterValues('c', ['new'])
* yields foo?a=b&e=f&c=new.