1/* 2 * Copyright (c) 2021-2022 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.Utils.Lang 20 * @permission N/A 21 */ 22declare namespace url { 23 /** 24 * The URLSearchParams interface defines some practical methods to process URL query strings. 25 * @name URLSearchParams 26 * @since 7 27 * @deprecated since 9 28 * @useinstead ohos.url.URLParams 29 * @syscap SystemCapability.Utils.Lang 30 */ 31 class URLSearchParams { 32 /** 33 * A parameterized constructor used to create an URLSearchParams instance. 34 * As the input parameter of the constructor function, init supports four types. 35 * The input parameter is a character string two-dimensional array. 36 * The input parameter is the object list. 37 * The input parameter is a character string. 38 * The input parameter is the URLSearchParams object. 39 * @deprecated since 9 40 * @useinstead ohos.url.URLParams.constructor 41 */ 42 constructor(init?: string[][] | Record<string, string> | string | URLSearchParams); 43 44 /** 45 * Appends a specified key/value pair as a new search parameter. 46 * @since 7 47 * @deprecated since 9 48 * @useinstead ohos.url.URLParams.append 49 * @syscap SystemCapability.Utils.Lang 50 * @param name Key name of the search parameter to be inserted. 51 * @param value Values of search parameters to be inserted. 52 */ 53 append(name: string, value: string): void; 54 55 /** 56 * Deletes the given search parameter and its associated value,from the list of all search parameters. 57 * @since 7 58 * @deprecated since 9 59 * @useinstead ohos.url.URLParams.delete 60 * @syscap SystemCapability.Utils.Lang 61 * @param name Name of the key-value pair to be deleted. 62 */ 63 delete(name: string): void; 64 65 /** 66 * Returns all key-value pairs associated with a given search parameter as an array. 67 * @since 7 68 * @deprecated since 9 69 * @useinstead ohos.url.URLParams.getAll 70 * @syscap SystemCapability.Utils.Lang 71 * @param name Specifies the name of a key value. 72 * @returns string[] Returns all key-value pairs with the specified name. 73 */ 74 getAll(name: string): string[]; 75 76 /** 77 * Returns an ES6 iterator. Each item of the iterator is a JavaScript Array. 78 * The first item of Array is name, and the second item of Array is value. 79 * @since 7 80 * @deprecated since 9 81 * @useinstead ohos.url.URLParams.entries 82 * @syscap SystemCapability.Utils.Lang 83 * @returns Returns an iterator for ES6. 84 */ 85 entries(): IterableIterator<[string, string]>; 86 87 /** 88 * Callback functions are used to traverse key-value pairs on the URLSearchParams instance object. 89 * @since 7 90 * @deprecated since 9 91 * @useinstead ohos.url.URLParams.forEach 92 * @syscap SystemCapability.Utils.Lang 93 * @param value Current traversal key value. 94 * @param key Indicates the name of the key that is traversed. 95 * @param searchParams The instance object that is currently calling the forEach method. 96 * @param thisArg to be used as this value for when callbackFn is called 97 */ 98 forEach(callbackFn: (value: string, key: string, searchParams: this) => void, thisArg?: Object): void; 99 100 /** 101 * Returns the first value associated to the given search parameter. 102 * @since 7 103 * @deprecated since 9 104 * @useinstead ohos.url.URLParams.get 105 * @syscap SystemCapability.Utils.Lang 106 * @param name Specifies the name of a key-value pair. 107 * @returns Returns the first value found by name. If no value is found, null is returned. 108 */ 109 get(name: string): string | null; 110 111 /** 112 * Returns a Boolean that indicates whether a parameter with the specified name exists. 113 * @since 7 114 * @deprecated since 9 115 * @useinstead ohos.url.URLParams.has 116 * @syscap SystemCapability.Utils.Lang 117 * @param name Specifies the name of a key-value pair. 118 * @returns Returns a Boolean value that indicates whether a found 119 */ 120 has(name: string): boolean; 121 122 /** 123 * Sets the value associated with a given search parameter to the 124 * given value. If there were several matching values, this method 125 * deletes the others. If the search parameter doesn't exist, this 126 * method creates it. 127 * @since 7 128 * @deprecated since 9 129 * @useinstead ohos.url.URLParams.set 130 * @syscap SystemCapability.Utils.Lang 131 * @param name Key name of the parameter to be set. 132 * @param value Indicates the parameter value to be set. 133 */ 134 set(name: string, value: string): void; 135 136 /** 137 * Sort all key/value pairs contained in this object in place and return undefined. 138 * @since 7 139 * @deprecated since 9 140 * @useinstead ohos.url.URLParams.sort 141 * @syscap SystemCapability.Utils.Lang 142 */ 143 sort(): void; 144 145 /** 146 * Returns an iterator allowing to go through all keys contained in this object. 147 * @since 7 148 * @deprecated since 9 149 * @useinstead ohos.url.URLParams.keys 150 * @syscap SystemCapability.Utils.Lang 151 * @returns Returns an ES6 Iterator over the names of each name-value pair. 152 */ 153 keys(): IterableIterator<string>; 154 155 /** 156 * Returns an iterator allowing to go through all values contained in this object. 157 * @since 7 158 * @deprecated since 9 159 * @useinstead ohos.url.URLParams.values 160 * @syscap SystemCapability.Utils.Lang 161 * @returns Returns an ES6 Iterator over the values of each name-value pair. 162 */ 163 values(): IterableIterator<string>; 164 165 /** 166 * Returns an iterator allowing to go through all key/value 167 * pairs contained in this object. 168 * @since 7 169 * @deprecated since 9 170 * @useinstead ohos.url.URLParams.[Symbol.iterator] 171 * @syscap SystemCapability.Utils.Lang 172 * @returns Returns an ES6 iterator. Each item of the iterator is a JavaScript Array. 173 * The first item of Array is name, and the second item of Array is value. 174 */ 175 [Symbol.iterator](): IterableIterator<[string, string]>; 176 177 /** 178 * Returns a query string suitable for use in a URL. 179 * @since 7 180 * @deprecated since 9 181 * @useinstead ohos.url.URLParams.toString 182 * @syscap SystemCapability.Utils.Lang 183 * @returns Returns a search parameter serialized as a string, percent-encoded if necessary. 184 */ 185 toString(): string; 186 } 187 188 /** 189 * The URLParams interface defines some practical methods to process URL query strings. 190 * @name URLParams 191 * @since 9 192 * @syscap SystemCapability.Utils.Lang 193 */ 194 class URLParams { 195 /** 196 * A parameterized constructor used to create an URLParams instance. 197 * As the input parameter of the constructor function, init supports four types. 198 * The input parameter is a character string two-dimensional array. 199 * The input parameter is the object list. 200 * The input parameter is a character string. 201 * The input parameter is the URLParams object. 202 * @since 9 203 * @throws {BusinessError} 401 - The type of init must be string two-dimensional array or object list 204 * or string or URLParams object. 205 */ 206 constructor(init?: string[][] | Record<string, string> | string | URLParams); 207 208 /** 209 * Appends a specified key/value pair as a new search parameter. 210 * @since 9 211 * @syscap SystemCapability.Utils.Lang 212 * @param name Key name of the search parameter to be inserted. 213 * @param value Values of search parameters to be inserted. 214 * @throws {BusinessError} 401 - if the input parameters are invalid. 215 */ 216 append(name: string, value: string): void; 217 218 /** 219 * Deletes the given search parameter and its associated value,from the list of all search parameters. 220 * @since 9 221 * @syscap SystemCapability.Utils.Lang 222 * @param name Name of the key-value pair to be deleted. 223 * @throws {BusinessError} 401 - The type of name must be string. 224 */ 225 delete(name: string): void; 226 227 /** 228 * Returns all key-value pairs associated with a given search parameter as an array. 229 * @since 9 230 * @syscap SystemCapability.Utils.Lang 231 * @param name Specifies the name of a key value. 232 * @returns string[] Returns all key-value pairs with the specified name. 233 * @throws {BusinessError} 401 - The type of name must be string. 234 */ 235 getAll(name: string): string[]; 236 237 /** 238 * Returns an ES6 iterator. Each item of the iterator is a JavaScript Array. 239 * The first item of Array is name, and the second item of Array is value. 240 * @since 9 241 * @syscap SystemCapability.Utils.Lang 242 * @returns Returns an iterator for ES6. 243 */ 244 entries(): IterableIterator<[string, string]>; 245 246 /** 247 * Callback functions are used to traverse key-value pairs on the URLParams instance object. 248 * @since 9 249 * @syscap SystemCapability.Utils.Lang 250 * @param value Current traversal key value. 251 * @param key Indicates the name of the key that is traversed. 252 * @param searchParams The instance object that is currently calling the forEach method. 253 * @param thisArg to be used as this value for when callbackFn is called 254 * @throws {BusinessError} 401 - if the input parameters are invalid. 255 */ 256 forEach(callbackFn: (value: string, key: string, searchParams: this) => void, thisArg?: Object): void; 257 258 /** 259 * Returns the first value associated to the given search parameter. 260 * @since 9 261 * @syscap SystemCapability.Utils.Lang 262 * @param name Specifies the name of a key-value pair. 263 * @returns Returns the first value found by name. If no value is found, null is returned. 264 * @throws {BusinessError} 401 - The type of name must be string. 265 */ 266 get(name: string): string | null; 267 268 /** 269 * Returns a Boolean that indicates whether a parameter with the specified name exists. 270 * @since 9 271 * @syscap SystemCapability.Utils.Lang 272 * @param name Specifies the name of a key-value pair. 273 * @returns Returns a Boolean value that indicates whether a found 274 * @throws {BusinessError} 401 - The type of name must be string. 275 */ 276 has(name: string): boolean; 277 278 /** 279 * Sets the value associated with a given search parameter to the 280 * given value. If there were several matching values, this method 281 * deletes the others. If the search parameter doesn't exist, this 282 * method creates it. 283 * @since 9 284 * @syscap SystemCapability.Utils.Lang 285 * @param name Key name of the parameter to be set. 286 * @param value Indicates the parameter value to be set. 287 * @throws {BusinessError} 401 - if the input parameters are invalid. 288 */ 289 set(name: string, value: string): void; 290 291 /** 292 * Sort all key/value pairs contained in this object in place and return undefined. 293 * @since 9 294 * @syscap SystemCapability.Utils.Lang 295 */ 296 sort(): void; 297 298 /** 299 * Returns an iterator allowing to go through all keys contained in this object. 300 * @since 9 301 * @syscap SystemCapability.Utils.Lang 302 * @returns Returns an ES6 Iterator over the names of each name-value pair. 303 */ 304 keys(): IterableIterator<string>; 305 306 /** 307 * Returns an iterator allowing to go through all values contained in this object. 308 * @since 9 309 * @syscap SystemCapability.Utils.Lang 310 * @returns Returns an ES6 Iterator over the values of each name-value pair. 311 */ 312 values(): IterableIterator<string>; 313 314 /** 315 * Returns an iterator allowing to go through all key/value 316 * pairs contained in this object. 317 * @since 9 318 * @syscap SystemCapability.Utils.Lang 319 * @returns Returns an ES6 iterator. Each item of the iterator is a JavaScript Array. 320 * The first item of Array is name, and the second item of Array is value. 321 */ 322 [Symbol.iterator](): IterableIterator<[string, string]>; 323 324 /** 325 * Returns a query string suitable for use in a URL. 326 * @since 9 327 * @syscap SystemCapability.Utils.Lang 328 * @returns Returns a search parameter serialized as a string, percent-encoded if necessary. 329 */ 330 toString(): string; 331 } 332 333 /** 334 * The interface of URL is used to parse, construct, normalize, and encode URLs. 335 * @name URL 336 * @since 7 337 * @syscap SystemCapability.Utils.Lang 338 */ 339 class URL { 340 /** 341 * URL constructor, which is used to instantiate a URL object. 342 * url: Absolute or relative input URL to resolve. Base is required if input is relative. 343 * If input is an absolute value, base ignores the value. 344 * base: Base URL to parse if input is not absolute. 345 * @since 7 346 * @deprecated since 9 347 * @useinstead ohos.url.URL.parseURL 348 */ 349 constructor(url: string, base?: string | URL); 350 351 /** 352 * URL constructor, which is used to instantiate a URL object. 353 * @since 9 354 */ 355 constructor(); 356 357 /** 358 * Replaces the original constructor to process arguments and return a url object. 359 * @since 9 360 * @syscap SystemCapability.Utils.Lang 361 * @param url Absolute or relative input URL to resolve. Base is required if input is relative. 362 * If input is an absolute value, base ignores the value. 363 * @param base Base URL to parse if input is not absolute. 364 * @throws {BusinessError} 401 - if the input parameters are invalid. 365 * @throws {BusinessError} 10200002 - Invalid url string. 366 */ 367 static parseURL(url: string, base?: string | URL): URL; 368 369 /** 370 * Returns the serialized URL as a string. 371 * @since 7 372 * @syscap SystemCapability.Utils.Lang 373 * @returns Returns the serialized URL as a string. 374 */ 375 toString(): string; 376 377 /** 378 * Returns the serialized URL as a string. 379 * @since 7 380 * @syscap SystemCapability.Utils.Lang 381 * @returns Returns the serialized URL as a string. 382 */ 383 toJSON(): string; 384 385 /** 386 * Gets and sets the fragment portion of the URL. 387 * @since 7 388 * @syscap SystemCapability.Utils.Lang 389 */ 390 hash: string; 391 392 /** 393 * Gets and sets the host portion of the URL. 394 * @since 7 395 * @syscap SystemCapability.Utils.Lang 396 */ 397 host: string; 398 399 /** 400 * Gets and sets the host name portion of the URL,not include the port. 401 * @since 7 402 * @syscap SystemCapability.Utils.Lang 403 */ 404 hostname: string; 405 406 /** 407 * Gets and sets the serialized URL. 408 * @since 7 409 * @syscap SystemCapability.Utils.Lang 410 */ 411 href: string; 412 413 /** 414 * Gets the read-only serialization of the URL's origin. 415 * @since 7 416 * @syscap SystemCapability.Utils.Lang 417 */ 418 readonly origin: string; 419 420 /** 421 * Gets and sets the password portion of the URL. 422 * @since 7 423 * @syscap SystemCapability.Utils.Lang 424 */ 425 password: string; 426 427 /** 428 * Gets and sets the path portion of the URL. 429 * @since 7 430 * @syscap SystemCapability.Utils.Lang 431 */ 432 pathname: string; 433 434 /** 435 * Gets and sets the port portion of the URL. 436 * @since 7 437 * @syscap SystemCapability.Utils.Lang 438 */ 439 port: string; 440 441 /** 442 * Gets and sets the protocol portion of the URL. 443 * @since 7 444 * @syscap SystemCapability.Utils.Lang 445 */ 446 protocol: string; 447 448 /** 449 * Gets and sets the serialized query portion of the URL. 450 * @since 7 451 * @syscap SystemCapability.Utils.Lang 452 */ 453 search: string; 454 455 /** 456 * Gets the URLSearchParams object that represents the URL query parameter. 457 * This property is read-only, but URLSearchParams provides an object that can be used to change 458 * the URL instance. To replace the entire query parameter for a URL, use url.searchsetter. 459 * @since 7 460 * @deprecated since 9 461 * @useinstead ohos.url.URL.params 462 * @syscap SystemCapability.Utils.Lang 463 */ 464 readonly searchParams: URLSearchParams; 465 466 /** 467 * Gets the URLParams object that represents the URL query parameter. 468 * This property is read-only, but URLParams provides an object that can be used to change 469 * the URL instance. To replace the entire query parameter for a URL, use url.searchsetter. 470 * @since 9 471 * @syscap SystemCapability.Utils.Lang 472 */ 473 readonly params: URLParams; 474 475 /** 476 * Gets and sets the username portion of the URL. 477 * @since 7 478 * @syscap SystemCapability.Utils.Lang 479 */ 480 username: string; 481 } 482} 483export default url;