/** * Common helper functions for working with URLs. These utilities are intended to be simple, * small, and very broadly applicable. * * @alpha */ export default class UrlUtilities { /** * If the provided URL is relative, resolve it under the provided base URL. If the provided URL is absolute, * return it. * * @remarks * Examples: * ``` * resolve('/foo/bar.js', 'http://cdn.com/path/') ---> 'http://cdn.com/path/foo/bar.js' * resolve('http://cdn.com/foo/bar.js', 'http://cdn.com/path/') ---> 'http://cdn.com/foo/bar.js' * resolve('/foo/bar.js', 'path/') ---> 'path/foo/bar.js' * ``` * @param url - the URL to be resolved * @param baseUrl - the base URL to use if the URL is relative */ static resolve(url: string, baseUrl: string): string; /** * Removes any slash characters from the end of the URL. * * @remarks * This function assumes that the input is already a valid absolute or server-relative URL. * * Examples: * ``` * removeEndSlash('http://example.com/') ---> 'http://example.com' * removeEndSlash('/example') ---> '/example' * removeEndSlash('/') ---> '' * ``` * @param url - the URL to be normalized */ static removeEndSlash(url: string): string; /** * Removes any slash characters from the beginning of the URL. * * @remarks * This function assumes that the input is already a valid absolute or server-relative URL. * * Examples: * ``` * removeLeadingSlash('/example/path.js') ---> 'example/path.js' * removeLeadingSlash('example/') ---> 'example/' * removeLeadingSlash('/') ---> '' * ``` * @param url - the URL to be normalized */ static removeLeadingSlash(url: string): string; /** * Converts a variable to an OData string literal suitable for usage in a REST URL. * * @remarks * The returned string will be enclosed in single quotes, and any single quotes * will be escaped. * * Example usage: * * ``` * const url = "/_api/web/GetFolderByServerRelativeUrl(" * + UrlUtilities.convertToODataStringLiteral("/SitePages/Alice's%20Page") * + ")/Files"; * * // Produces this URL: * // "/_api/web/GetFolderByServerRelativeUrl('/SitePages/Alice''s%20Page')/Files" * ``` * * @privateRemarks * Standard reference: * https://tools.oasis-open.org/version-control/ * browse/wsvn/odata/trunk/spec/ABNF/odata-abnf-construction-rules.txt * SQUOTE-in-string = SQUOTE SQUOTE ; two consecutive single quotes represent * one within a string literal */ static convertToODataStringLiteral(value: string): string; /** * Detects if a string represents a correctly formatted data URL. * * @remarks * * Examples: * ``` * isDataUrl('data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D') ---> true * isDataUrl('data:,Hello%2C%20World!') ---> true * isDataUrl('data:image/png;base64,iVBORw0KGgoAA') ---> true * isDataUrl('http://contoso.com') ---> false * isDataUrl('/foo/bar') ---> false * ``` * * Information on data URLs can be found at https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs */ static isDataUrl(url: string): boolean; /** * Detects if a url is relative * * @remarks * This function assumes that the input is already a valid absolute or server-relative URL. * * Examples: * ``` * isRelativeUrl('/example/path.aspx') ---> true * isRelativeUrl('http://contoso.com') ---> false * ``` */ static isRelativeUrl(url: string): boolean; /** * Detects if a url is absolute url * * Examples: * ``` * isAbsoluteUrl('http://example.com') ---> true * isAbsoluteUrl('/test/123') ---> false * ``` */ static isAbsoluteUrl(url: string): boolean; /** * Creates an absolute URL from a relative URL and decodes it if needed. */ static absolutizeUrl(url: string, decode?: boolean): string; /** * Creates a relative URL from an absolute URL. */ static relativizeUrl(url: string, removeQueryString?: boolean): string; } //# sourceMappingURL=UrlUtilities.d.ts.map