UNPKG

5.35 kBTypeScriptView Raw
1/**
2 * A class that handles the query portion of a URLBuilder.
3 */
4export declare class URLQuery {
5 private readonly _rawQuery;
6 /**
7 * Get whether or not there any query parameters in this URLQuery.
8 */
9 any(): boolean;
10 /**
11 * Set a query parameter with the provided name and value. If the parameterValue is undefined or
12 * empty, then this will attempt to remove an existing query parameter with the provided
13 * parameterName.
14 */
15 set(parameterName: string, parameterValue: any): void;
16 /**
17 * Get the value of the query parameter with the provided name. If no parameter exists with the
18 * provided parameter name, then undefined will be returned.
19 */
20 get(parameterName: string): string | string[] | undefined;
21 /**
22 * Get the string representation of this query. The return value will not start with a "?".
23 */
24 toString(): string;
25 /**
26 * Parse a URLQuery from the provided text.
27 */
28 static parse(text: string): URLQuery;
29}
30/**
31 * A class that handles creating, modifying, and parsing URLs.
32 */
33export declare class URLBuilder {
34 private _scheme;
35 private _host;
36 private _port;
37 private _path;
38 private _query;
39 /**
40 * Set the scheme/protocol for this URL. If the provided scheme contains other parts of a URL
41 * (such as a host, port, path, or query), those parts will be added to this URL as well.
42 */
43 setScheme(scheme: string | undefined): void;
44 /**
45 * Get the scheme that has been set in this URL.
46 */
47 getScheme(): string | undefined;
48 /**
49 * Set the host for this URL. If the provided host contains other parts of a URL (such as a
50 * port, path, or query), those parts will be added to this URL as well.
51 */
52 setHost(host: string | undefined): void;
53 /**
54 * Get the host that has been set in this URL.
55 */
56 getHost(): string | undefined;
57 /**
58 * Set the port for this URL. If the provided port contains other parts of a URL (such as a
59 * path or query), those parts will be added to this URL as well.
60 */
61 setPort(port: number | string | undefined): void;
62 /**
63 * Get the port that has been set in this URL.
64 */
65 getPort(): string | undefined;
66 /**
67 * Set the path for this URL. If the provided path contains a query, then it will be added to
68 * this URL as well.
69 */
70 setPath(path: string | undefined): void;
71 /**
72 * Append the provided path to this URL's existing path. If the provided path contains a query,
73 * then it will be added to this URL as well.
74 */
75 appendPath(path: string | undefined): void;
76 /**
77 * Get the path that has been set in this URL.
78 */
79 getPath(): string | undefined;
80 /**
81 * Set the query in this URL.
82 */
83 setQuery(query: string | undefined): void;
84 /**
85 * Set a query parameter with the provided name and value in this URL's query. If the provided
86 * query parameter value is undefined or empty, then the query parameter will be removed if it
87 * existed.
88 */
89 setQueryParameter(queryParameterName: string, queryParameterValue: any): void;
90 /**
91 * Get the value of the query parameter with the provided query parameter name. If no query
92 * parameter exists with the provided name, then undefined will be returned.
93 */
94 getQueryParameterValue(queryParameterName: string): string | string[] | undefined;
95 /**
96 * Get the query in this URL.
97 */
98 getQuery(): string | undefined;
99 /**
100 * Set the parts of this URL by parsing the provided text using the provided startState.
101 */
102 private set;
103 toString(): string;
104 /**
105 * If the provided searchValue is found in this URLBuilder, then replace it with the provided
106 * replaceValue.
107 */
108 replaceAll(searchValue: string, replaceValue: string): void;
109 static parse(text: string): URLBuilder;
110}
111declare type URLTokenizerState = "SCHEME" | "SCHEME_OR_HOST" | "HOST" | "PORT" | "PATH" | "QUERY" | "DONE";
112declare type URLTokenType = "SCHEME" | "HOST" | "PORT" | "PATH" | "QUERY";
113export declare class URLToken {
114 readonly text: string;
115 readonly type: URLTokenType;
116 constructor(text: string, type: URLTokenType);
117 static scheme(text: string): URLToken;
118 static host(text: string): URLToken;
119 static port(text: string): URLToken;
120 static path(text: string): URLToken;
121 static query(text: string): URLToken;
122}
123/**
124 * Get whether or not the provided character (single character string) is an alphanumeric (letter or
125 * digit) character.
126 */
127export declare function isAlphaNumericCharacter(character: string): boolean;
128/**
129 * A class that tokenizes URL strings.
130 */
131export declare class URLTokenizer {
132 readonly _text: string;
133 readonly _textLength: number;
134 _currentState: URLTokenizerState;
135 _currentIndex: number;
136 _currentToken: URLToken | undefined;
137 constructor(_text: string, state?: URLTokenizerState);
138 /**
139 * Get the current URLToken this URLTokenizer is pointing at, or undefined if the URLTokenizer
140 * hasn't started or has finished tokenizing.
141 */
142 current(): URLToken | undefined;
143 /**
144 * Advance to the next URLToken and return whether or not a URLToken was found.
145 */
146 next(): boolean;
147}
148export {};
149//# sourceMappingURL=url.d.ts.map
\No newline at end of file