UNPKG

3.27 kBTypeScriptView Raw
1import { PartialJSONObject } from '@lumino/coreutils';
2/**
3 * The namespace for URL-related functions.
4 */
5export declare namespace URLExt {
6 /**
7 * Parse a url into a URL object.
8 *
9 * @param urlString - The URL string to parse.
10 *
11 * @returns A URL object.
12 */
13 function parse(url: string): IUrl;
14 /**
15 * Parse URL and retrieve hostname
16 *
17 * @param url - The URL string to parse
18 *
19 * @return a hostname string value
20 */
21 function getHostName(url: string): string;
22 /**
23 * Normalize a url.
24 */
25 function normalize(url: string): string;
26 function normalize(url: undefined): undefined;
27 function normalize(url: string | undefined): string | undefined;
28 /**
29 * Join a sequence of url components and normalizes as in node `path.join`.
30 *
31 * @param parts - The url components.
32 *
33 * @returns the joined url.
34 */
35 function join(...parts: string[]): string;
36 /**
37 * Encode the components of a multi-segment url.
38 *
39 * @param url - The url to encode.
40 *
41 * @returns the encoded url.
42 *
43 * #### Notes
44 * Preserves the `'/'` separators.
45 * Should not include the base url, since all parts are escaped.
46 */
47 function encodeParts(url: string): string;
48 /**
49 * Return a serialized object string suitable for a query.
50 *
51 * @param object - The source object.
52 *
53 * @returns an encoded url query.
54 *
55 * #### Notes
56 * Modified version of [stackoverflow](http://stackoverflow.com/a/30707423).
57 */
58 function objectToQueryString(value: PartialJSONObject): string;
59 /**
60 * Return a parsed object that represents the values in a query string.
61 */
62 function queryStringToObject(value: string): {
63 [key: string]: string | undefined;
64 };
65 /**
66 * Test whether the url is a local url.
67 *
68 * #### Notes
69 * This function returns `false` for any fully qualified url, including
70 * `data:`, `file:`, and `//` protocol URLs.
71 */
72 function isLocal(url: string): boolean;
73 /**
74 * The interface for a URL object
75 */
76 interface IUrl {
77 /**
78 * The full URL string that was parsed with both the protocol and host
79 * components converted to lower-case.
80 */
81 href: string;
82 /**
83 * Identifies the URL's lower-cased protocol scheme.
84 */
85 protocol: string;
86 /**
87 * The full lower-cased host portion of the URL, including the port if
88 * specified.
89 */
90 host: string;
91 /**
92 * The lower-cased host name portion of the host component without the
93 * port included.
94 */
95 hostname: string;
96 /**
97 * The numeric port portion of the host component.
98 */
99 port: string;
100 /**
101 * The entire path section of the URL.
102 */
103 pathname: string;
104 /**
105 * The "fragment" portion of the URL including the leading ASCII hash
106 * `(#)` character
107 */
108 hash: string;
109 /**
110 * The search element, including leading question mark (`'?'`), if any,
111 * of the URL.
112 */
113 search?: string;
114 }
115}