• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2021 Huawei Device Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16/**
17 * The url module provides utilities for URL resolution and parsing.
18 * @since 7
19 * @sysCap SystemCapability.CCRuntime
20 * @devices phone, tablet
21 * @import import url from '@ohos.url';
22 * @permission N/A
23 */
24
25declare namespace url {
26    class URLSearchParams {
27        /**
28         * A parameterized constructor used to create an URLSearchParams instance.
29         * As the input parameter of the constructor function, init supports four types.
30         * The input parameter is a character string two-dimensional array.
31         * The input parameter is the object list.
32         * The input parameter is a character string.
33         * The input parameter is the URLSearchParams object.
34         */
35        constructor(init?: string[][] | Record<string, string> | string | URLSearchParams);
36
37        /**
38         * Appends a specified key/value pair as a new search parameter.
39         * @since 7
40         * @sysCap SystemCapability.CCRuntime
41         * @param name Key name of the search parameter to be inserted.
42         * @param value Values of search parameters to be inserted.
43         */
44        append(name: string, value: string): void;
45
46        /**
47         * Deletes the given search parameter and its associated value,from the list of all search parameters.
48         * @since 7
49         * @sysCap SystemCapability.CCRuntime
50         * @param Name of the key-value pair to be deleted.
51         */
52        delete(name: string): void;
53
54        /**
55         * Returns all key-value pairs associated with a given search parameter as an array.
56         * @since 7
57         * @sysCap SystemCapability.CCRuntime
58         * @param Name Specifies the name of a key value.
59         * @return string[] Returns all key-value pairs with the specified name.
60         */
61        getAll(name: string): string[];
62
63        /**
64         * Returns an ES6 iterator. Each item of the iterator is a JavaScript Array.
65         * The first item of Array is name, and the second item of Array is value.
66         * @since 7
67         * @sysCap SystemCapability.CCRuntime
68         * @return Returns an iterator for ES6.
69         */
70         entries(): IterableIterator<[string, string]>;
71
72        /**
73         * Callback functions are used to traverse key-value pairs on the URLSearchParams instance object.
74         * @since 7
75         * @sysCap SystemCapability.CCRuntime
76         * @param value Current traversal key value.
77         * @param key Indicates the name of the key that is traversed.
78         * @param searchParams The instance object that is currently calling the forEach method.
79         */
80        forEach(callbackfn: (value: string, key: string, searchParams: this) => void): void;
81
82        /**
83         * Returns the first value associated to the given search parameter.
84         * @since 7
85         * @sysCap SystemCapability.CCRuntime
86         * @param name Specifies the name of a key-value pair.
87         * @return Returns the first value found by name. If no value is found, null is returned.
88         */
89        get(name: string): string | null;
90
91        /**
92         * Returns a Boolean that indicates whether a parameter with the specified name exists.
93         * @since 7
94         * @sysCap SystemCapability.CCRuntime
95         * @param name Specifies the name of a key-value pair.
96         * @return Returns a Boolean value that indicates whether a found
97         */
98        has(name: string): boolean;
99
100        /**
101         * Sets the value associated with a given search parameter to the
102         * given value. If there were several matching values, this method
103         * deletes the others. If the search parameter doesn't exist, this
104         * method creates it.
105         * @since 7
106         * @sysCap SystemCapability.CCRuntime
107         * @param name Key name of the parameter to be set.
108         * @param value Indicates the parameter value to be set.
109         */
110        set(name: string, value: string): void;
111
112        /**
113        * Sort all key/value pairs contained in this object in place and return undefined.
114        * @since 7
115        * @sysCap SystemCapability.CCRuntime
116        */
117        sort(): void;
118
119        /**
120         * Returns an iterator allowing to go through all keys contained in this object.
121         * @since 7
122         * @sysCap SystemCapability.CCRuntime
123         * @return Returns an ES6 Iterator over the names of each name-value pair.
124         */
125        keys(): IterableIterator<string>;
126
127        /**
128         * Returns an iterator allowing to go through all values contained in this object.
129         * @since 7
130         * @sysCap SystemCapability.CCRuntime
131         * @return Returns an ES6 Iterator over the values of each name-value pair.
132         */
133        values(): IterableIterator<string>;
134
135        /**
136         * Returns an iterator allowing to go through all key/value
137         * pairs contained in this object.
138         * @since 7
139         * @sysCap SystemCapability.CCRuntime
140         * @return Returns an ES6 iterator. Each item of the iterator is a JavaScript Array.
141         * The first item of Array is name, and the second item of Array is value.
142         */
143        [Symbol.iterator](): IterableIterator<[string, string]>;
144
145        /**
146         * Returns a query string suitable for use in a URL.
147         * @since 7
148         * @sysCap SystemCapability.CCRuntime
149         * @return Returns a search parameter serialized as a string, percent-encoded if necessary.
150         */
151        toString(): string;
152    }
153
154    class URL {
155        /**
156         * URL constructor, which is used to instantiate a URL object.
157         * url: Absolute or relative input URL to resolve. Base is required if input is relative.
158         * If input is an absolute value, base ignores the value.
159         * base: Base URL to parse if input is not absolute.
160         */
161        constructor(url: string, base?: string | URL);
162
163        /**
164         * Returns the serialized URL as a string.
165         * @since 7
166         * @sysCap SystemCapability.CCRuntime
167         * @return Returns the serialized URL as a string.
168         */
169        toString(): string;
170
171        /**
172         * Returns the serialized URL as a string.
173         * @since 7
174         * @sysCap SystemCapability.CCRuntime
175         * @return Returns the serialized URL as a string.
176         */
177        toJSON(): string;
178
179        /**
180         * Gets and sets the fragment portion of the URL.
181         * @since 7
182         * @sysCap SystemCapability.CCRuntime
183         */
184        hash: string;
185
186        /**
187         * Gets and sets the host portion of the URL.
188         * @since 7
189         * @sysCap SystemCapability.CCRuntime
190         */
191        host: string;
192
193        /**
194         * Gets and sets the host name portion of the URL,not include the port.
195         * @since 7
196         * @sysCap SystemCapability.CCRuntime
197         */
198        hostname: string;
199
200        /**
201         * Gets and sets the serialized URL.
202         * @since 7
203         * @sysCap SystemCapability.CCRuntime
204         */
205        href: string;
206
207        /**
208         * Gets the read-only serialization of the URL's origin.
209         * @since 7
210         * @sysCap SystemCapability.CCRuntime
211         */
212        readonly origin: string;
213
214        /**
215         * Gets and sets the password portion of the URL.
216         * @since 7
217         * @sysCap SystemCapability.CCRuntime
218         */
219        password: string;
220
221        /**
222         * Gets and sets the path portion of the URL.
223         * @since 7
224         * @sysCap SystemCapability.CCRuntime
225         */
226        pathname: string;
227
228        /**
229         * Gets and sets the port portion of the URL.
230         * @since 7
231         * @sysCap SystemCapability.CCRuntime
232         */
233        port: string;
234
235        /**
236         * Gets and sets the protocol portion of the URL.
237         * @since 7
238         * @sysCap SystemCapability.CCRuntime
239         */
240        protocol: string;
241
242        /**
243         * Gets and sets the serialized query portion of the URL.
244         * @since 7
245         * @sysCap SystemCapability.CCRuntime
246         */
247        search: string;
248
249        /**
250         * Gets the URLSearchParams object that represents the URL query parameter.
251         * This property is read-only, but URLSearchParams provides an object that can be used to change
252         * the URL instance. To replace the entire query parameter for a URL, use url.searchsetter.
253         * @since 7
254         * @sysCap SystemCapability.CCRuntime
255         * @note Be careful when modifying with .searchParams, because the URLSearchParams
256         * object uses different rules to determine which characters to
257         * percent-encode according to the WHATWG specification.
258         */
259        readonly searchParams: URLSearchParams;
260
261        /**
262         * Gets and sets the username portion of the URL.
263         * @since 7
264         * @sysCap SystemCapability.CCRuntime
265         */
266        username: string;
267    }
268}
269export default url;