UNPKG

3.39 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 url - 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 * @returns 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 value 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 * @param allowRoot - Whether the paths starting at Unix-style filesystem root (`/`) are permitted.
69 *
70 * #### Notes
71 * This function returns `false` for any fully qualified url, including
72 * `data:`, `file:`, and `//` protocol URLs.
73 */
74 function isLocal(url: string, allowRoot?: boolean): boolean;
75 /**
76 * The interface for a URL object
77 */
78 interface IUrl {
79 /**
80 * The full URL string that was parsed with both the protocol and host
81 * components converted to lower-case.
82 */
83 href: string;
84 /**
85 * Identifies the URL's lower-cased protocol scheme.
86 */
87 protocol: string;
88 /**
89 * The full lower-cased host portion of the URL, including the port if
90 * specified.
91 */
92 host: string;
93 /**
94 * The lower-cased host name portion of the host component without the
95 * port included.
96 */
97 hostname: string;
98 /**
99 * The numeric port portion of the host component.
100 */
101 port: string;
102 /**
103 * The entire path section of the URL.
104 */
105 pathname: string;
106 /**
107 * The "fragment" portion of the URL including the leading ASCII hash
108 * `(#)` character
109 */
110 hash: string;
111 /**
112 * The search element, including leading question mark (`'?'`), if any,
113 * of the URL.
114 */
115 search?: string;
116 }
117}