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 * @file 18 * @kit ArkTS 19 */ 20 21/** 22 * The uri module provides utilities for URI resolution and parsing. 23 * 24 * @namespace uri 25 * @syscap SystemCapability.Utils.Lang 26 * @since 8 27 */ 28/** 29 * The uri module provides utilities for URI resolution and parsing. 30 * 31 * @namespace uri 32 * @syscap SystemCapability.Utils.Lang 33 * @crossplatform 34 * @since 10 35 */ 36/** 37 * The uri module provides utilities for URI resolution and parsing. 38 * 39 * @namespace uri 40 * @syscap SystemCapability.Utils.Lang 41 * @crossplatform 42 * @atomicservice 43 * @since 11 44 */ 45declare namespace uri { 46 /** 47 * URI Represents a Uniform Resource Identifier (URI) reference. 48 * 49 * @syscap SystemCapability.Utils.Lang 50 * @since 8 51 * @name URI 52 */ 53 /** 54 * URI Represents a Uniform Resource Identifier (URI) reference. 55 * 56 * @syscap SystemCapability.Utils.Lang 57 * @crossplatform 58 * @since 10 59 * @name URI 60 */ 61 /** 62 * URI Represents a Uniform Resource Identifier (URI) reference. 63 * 64 * @syscap SystemCapability.Utils.Lang 65 * @crossplatform 66 * @atomicservice 67 * @since 11 68 * @name URI 69 */ 70 class URI { 71 /** 72 * URI constructor, which is used to instantiate a URI object. 73 * uri: Constructs a URI by parsing a given string. 74 * 75 * @param { string } uri - uri uri 76 * @throws { BusinessError } 401 - Parameter error. Possible causes: 77 * 1.Mandatory parameters are left unspecified; 78 * 2.Incorrect parameter types; 79 * 3.Parameter verification failed. 80 * @throws { BusinessError } 10200002 - Invalid uri string. 81 * @syscap SystemCapability.Utils.Lang 82 * @since 8 83 */ 84 /** 85 * URI constructor, which is used to instantiate a URI object. 86 * uri: Constructs a URI by parsing a given string. 87 * 88 * @param { string } uri - uri uri 89 * @throws { BusinessError } 401 - Parameter error. Possible causes: 90 * 1.Mandatory parameters are left unspecified; 91 * 2.Incorrect parameter types; 92 * 3.Parameter verification failed. 93 * @throws { BusinessError } 10200002 - Invalid uri string. 94 * @syscap SystemCapability.Utils.Lang 95 * @crossplatform 96 * @since 10 97 */ 98 /** 99 * URI constructor, which is used to instantiate a URI object. 100 * uri: Constructs a URI by parsing a given string. 101 * 102 * @param { string } uri - uri uri 103 * @throws { BusinessError } 401 - Parameter error. Possible causes: 104 * 1.Mandatory parameters are left unspecified; 105 * 2.Incorrect parameter types; 106 * 3.Parameter verification failed. 107 * @throws { BusinessError } 10200002 - Invalid uri string. 108 * @syscap SystemCapability.Utils.Lang 109 * @crossplatform 110 * @atomicservice 111 * @since 11 112 */ 113 constructor(uri: string); 114 /** 115 * Returns the serialized URI as a string. 116 * 117 * @returns { string } Returns the serialized URI as a string. 118 * @syscap SystemCapability.Utils.Lang 119 * @since 8 120 */ 121 /** 122 * Returns the serialized URI as a string. 123 * 124 * @returns { string } Returns the serialized URI as a string. 125 * @syscap SystemCapability.Utils.Lang 126 * @crossplatform 127 * @since 10 128 */ 129 /** 130 * Returns the serialized URI as a string. 131 * 132 * @returns { string } Returns the serialized URI as a string. 133 * @syscap SystemCapability.Utils.Lang 134 * @crossplatform 135 * @atomicservice 136 * @since 11 137 */ 138 toString(): string; 139 140 /** 141 * Check whether this URI is equivalent to other URI objects. 142 * 143 * @param { URI } other - other other URI object to be compared 144 * @returns { boolean } boolean Tests whether this URI is equivalent to other URI objects. 145 * @syscap SystemCapability.Utils.Lang 146 * @since 8 147 * @deprecated since 9 148 * @useinstead ohos.uri.URI.equalsTo 149 */ 150 equals(other: URI): boolean; 151 152 /** 153 * Check whether this URI is equivalent to other URI objects. 154 * 155 * @param { URI } other - other other URI object to be compared 156 * @returns { boolean } boolean Tests whether this URI is equivalent to other URI objects. 157 * @throws { BusinessError } 401 - Parameter error. Possible causes: 158 * 1.Mandatory parameters are left unspecified; 159 * 2.Incorrect parameter types. 160 * @syscap SystemCapability.Utils.Lang 161 * @since 9 162 */ 163 /** 164 * Check whether this URI is equivalent to other URI objects. 165 * 166 * @param { URI } other - other other URI object to be compared 167 * @returns { boolean } boolean Tests whether this URI is equivalent to other URI objects. 168 * @throws { BusinessError } 401 - Parameter error. Possible causes: 169 * 1.Mandatory parameters are left unspecified; 170 * 2.Incorrect parameter types. 171 * @syscap SystemCapability.Utils.Lang 172 * @crossplatform 173 * @since 10 174 */ 175 /** 176 * Check whether this URI is equivalent to other URI objects. 177 * 178 * @param { URI } other - other other URI object to be compared 179 * @returns { boolean } boolean Tests whether this URI is equivalent to other URI objects. 180 * @throws { BusinessError } 401 - Parameter error. Possible causes: 181 * 1.Mandatory parameters are left unspecified; 182 * 2.Incorrect parameter types. 183 * @syscap SystemCapability.Utils.Lang 184 * @crossplatform 185 * @atomicservice 186 * @since 11 187 */ 188 equalsTo(other: URI): boolean; 189 190 /** 191 * Indicates whether this URI is an absolute URI. 192 * 193 * @returns { boolean } boolean Indicates whether the URI is an absolute URI (whether the scheme component is defined). 194 * @syscap SystemCapability.Utils.Lang 195 * @since 8 196 */ 197 /** 198 * Indicates whether this URI is an absolute URI. 199 * 200 * @returns { boolean } boolean Indicates whether the URI is an absolute URI (whether the scheme component is defined). 201 * @syscap SystemCapability.Utils.Lang 202 * @crossplatform 203 * @since 10 204 */ 205 /** 206 * Indicates whether this URI is an absolute URI. 207 * 208 * @returns { boolean } boolean Indicates whether the URI is an absolute URI (whether the scheme component is defined). 209 * @syscap SystemCapability.Utils.Lang 210 * @crossplatform 211 * @atomicservice 212 * @since 11 213 */ 214 checkIsAbsolute(): boolean; 215 216 /** 217 * Normalize the path of this URI, It is not safe to call the normalize interface with URI. 218 * 219 * @returns { URI } URI Used to normalize the path of this URI and return a URI object whose path has been normalized. 220 * @syscap SystemCapability.Utils.Lang 221 * @since 8 222 */ 223 /** 224 * Normalize the path of this URI, It is not safe to call the normalize interface with URI. 225 * 226 * @returns { URI } URI Used to normalize the path of this URI and return a URI object whose path has been normalized. 227 * @syscap SystemCapability.Utils.Lang 228 * @crossplatform 229 * @since 10 230 */ 231 /** 232 * Normalize the path of this URI, It is not safe to call the normalize interface with URI. 233 * 234 * @returns { URI } URI Used to normalize the path of this URI and return a URI object whose path has been normalized. 235 * @syscap SystemCapability.Utils.Lang 236 * @crossplatform 237 * @atomicservice 238 * @since 11 239 */ 240 normalize(): URI; 241 /** 242 * Searches the query string for the first value with the given key. 243 * 244 * @param { string } key - Given the first value of the key. 245 * @returns { string } Return decoded value. 246 * @throws { BusinessError } 401 - Parameter error. Possible causes: 247 * 1.Mandatory parameters are left unspecified; 248 * 2.Incorrect parameter types. 249 * @syscap SystemCapability.Utils.Lang 250 * @crossplatform 251 * @atomicservice 252 * @since 12 253 */ 254 getQueryValue(key: string): string; 255 /** 256 * Encodes the key and value and then appends the result to the query string. 257 * 258 * @param { string } [key] - The key it will be encoded with. 259 * @param { string } [value] - The value it will be encoded with. 260 * @returns { URI } Return URI object. 261 * @throws { BusinessError } 401 - Parameter error. Possible causes: 262 * 1.Mandatory parameters are left unspecified; 263 * 2.Incorrect parameter types. 264 * @syscap SystemCapability.Utils.Lang 265 * @crossplatform 266 * @atomicservice 267 * @since 12 268 */ 269 addQueryValue(key: string, value: string): URI; 270 /** 271 * Returns a set of the unique names of all query parameters. 272 * 273 * @returns { string[] } Return a set of decoded names. 274 * @syscap SystemCapability.Utils.Lang 275 * @crossplatform 276 * @atomicservice 277 * @since 12 278 */ 279 getQueryNames(): string[]; 280 /** 281 * Searches the query string for parameter values with the given key. 282 * 283 * @param { string } key - The key it will be encoded with. 284 * @returns { string[] } Return a set of decoded values. 285 * @throws { BusinessError } 401 - Parameter error. Possible causes: 286 * 1.Mandatory parameters are left unspecified; 287 * 2.Incorrect parameter types. 288 * @syscap SystemCapability.Utils.Lang 289 * @crossplatform 290 * @atomicservice 291 * @since 12 292 */ 293 getQueryValues(key: string): string[]; 294 /** 295 * Searches the query string for the first value with the given key and interprets it as a boolean value. 296 * 297 * @param { string } key - Indicates the key value to be queried. 298 * @param { boolean } defaultValue - The default value returned when the key has no query parameters. 299 * @returns { boolean } Query with key value returns true, otherwise returns false. 300 * @throws { BusinessError } 401 - Parameter error. Possible causes: 301 * 1.Mandatory parameters are left unspecified; 302 * 2.Incorrect parameter types. 303 * @syscap SystemCapability.Utils.Lang 304 * @crossplatform 305 * @atomicservice 306 * @since 12 307 */ 308 getBooleanQueryValue(key: string, defaultValue: boolean): boolean; 309 /** 310 * Clears the the previously set query. 311 * 312 * @returns { URI } After clearing, return the URI object. 313 * @syscap SystemCapability.Utils.Lang 314 * @crossplatform 315 * @atomicservice 316 * @since 12 317 */ 318 clearQuery(): URI; 319 /** 320 * Gets the decoded last path segment. 321 * 322 * @returns { string } Returns the last decoded segment, or null if the path is empty. 323 * @syscap SystemCapability.Utils.Lang 324 * @crossplatform 325 * @atomicservice 326 * @since 12 327 */ 328 getLastSegment(): string; 329 /** 330 * Gets the decoded path segments. 331 * 332 * @returns { string[] } Return decoded path segments, each without a leading or trailing "/". 333 * @syscap SystemCapability.Utils.Lang 334 * @crossplatform 335 * @atomicservice 336 * @since 12 337 */ 338 getSegment(): string[]; 339 /** 340 * Encodes the given path segment and appends it to the path. 341 * 342 * @param { string } [pathSegment] - path segment to be added. 343 * @returns { URI } After adding, return the URI object. 344 * @throws { BusinessError } 401 - Parameter error. Possible causes: 345 * 1.Mandatory parameters are left unspecified; 346 * 2.Incorrect parameter types. 347 * @syscap SystemCapability.Utils.Lang 348 * @crossplatform 349 * @atomicservice 350 * @since 12 351 */ 352 addSegment(pathSegment: string): URI; 353 /** 354 * Creates a new Uri by appending an already-encoded path segment to a base Uri. 355 * 356 * @param { string } pathSegment - Encoding path segment to be added. 357 * @returns { URI } After adding, return the URI object. 358 * @throws { BusinessError } 401 - Parameter error. Possible causes: 359 * 1.Mandatory parameters are left unspecified; 360 * 2.Incorrect parameter types. 361 * @syscap SystemCapability.Utils.Lang 362 * @crossplatform 363 * @atomicservice 364 * @since 12 365 */ 366 addEncodedSegment(pathSegment: string): URI; 367 /** 368 * Determine whether URI is hierarchical. 369 * 370 * @returns { boolean } Return true as Hierarchical, otherwise return false. 371 * @syscap SystemCapability.Utils.Lang 372 * @crossplatform 373 * @atomicservice 374 * @since 12 375 */ 376 checkHierarchical(): boolean; 377 /** 378 * Determine whether URI is Opaque. 379 * 380 * @returns { boolean } Return true as Opaque, otherwise return false. 381 * @syscap SystemCapability.Utils.Lang 382 * @crossplatform 383 * @atomicservice 384 * @since 12 385 */ 386 checkOpaque(): boolean; 387 /** 388 * Determine whether URI is Relative. 389 * 390 * @returns { boolean } Return true as Relative, otherwise return false. 391 * @syscap SystemCapability.Utils.Lang 392 * @crossplatform 393 * @atomicservice 394 * @since 12 395 */ 396 checkRelative(): boolean; 397 /** 398 * Creates an opaque Uri from the given components. 399 * 400 * @param { string } scheme - of the URI. 401 * @param { string } ssp -scheme-specific-part, everything between the scheme separator (':') and the fragment 402 * separator ('#'), which will get encoded. 403 * @param { string } fragment - fragment, everything after the '#', null if undefined, will get encoded. 404 * @returns { URI } Return Uri consisting of a given scheme, SSP, and fragment. 405 * @throws { BusinessError } 401 - Parameter error. Possible causes: 406 * 1.Mandatory parameters are left unspecified; 407 * 2.Incorrect parameter types. 408 * @syscap SystemCapability.Utils.Lang 409 * @crossplatform 410 * @atomicservice 411 * @since 12 412 */ 413 static createFromParts(scheme: string, ssp: string, fragment: string): URI; 414 /** 415 * Gets the protocol part of the URI. 416 * 417 * @syscap SystemCapability.Utils.Lang 418 * @since 8 419 */ 420 /** 421 * Gets the protocol part of the URI. 422 * 423 * @syscap SystemCapability.Utils.Lang 424 * @crossplatform 425 * @since 10 426 */ 427 /** 428 * Gets the protocol part of the URI. 429 * 430 * @syscap SystemCapability.Utils.Lang 431 * @crossplatform 432 * @atomicservice 433 * @since 11 434 */ 435 /** 436 * Gets/Sets the protocol part of the URI. 437 * 438 * @syscap SystemCapability.Utils.Lang 439 * @crossplatform 440 * @atomicservice 441 * @since 12 442 */ 443 scheme: string; 444 445 /** 446 * Obtains the user information part of the URI. 447 * 448 * @syscap SystemCapability.Utils.Lang 449 * @since 8 450 */ 451 /** 452 * Obtains the user information part of the URI. 453 * 454 * @syscap SystemCapability.Utils.Lang 455 * @crossplatform 456 * @since 10 457 */ 458 /** 459 * Obtains the user information part of the URI. 460 * 461 * @syscap SystemCapability.Utils.Lang 462 * @crossplatform 463 * @atomicservice 464 * @since 11 465 */ 466 /** 467 * Gets/Sets Obtains the user information part of the URI. 468 * 469 * @syscap SystemCapability.Utils.Lang 470 * @crossplatform 471 * @atomicservice 472 * @since 12 473 */ 474 userInfo: string; 475 476 /** 477 * Gets the hostname portion of the URI without a port. 478 * 479 * @syscap SystemCapability.Utils.Lang 480 * @since 8 481 */ 482 /** 483 * Gets the hostname portion of the URI without a port. 484 * 485 * @syscap SystemCapability.Utils.Lang 486 * @crossplatform 487 * @since 10 488 */ 489 /** 490 * Gets the hostname portion of the URI without a port. 491 * 492 * @syscap SystemCapability.Utils.Lang 493 * @crossplatform 494 * @atomicservice 495 * @since 11 496 */ 497 host: string; 498 499 /** 500 * Gets the port portion of the URI. 501 * 502 * @syscap SystemCapability.Utils.Lang 503 * @since 8 504 */ 505 /** 506 * Gets the port portion of the URI. 507 * 508 * @syscap SystemCapability.Utils.Lang 509 * @crossplatform 510 * @since 10 511 */ 512 /** 513 * Gets the port portion of the URI. 514 * 515 * @syscap SystemCapability.Utils.Lang 516 * @crossplatform 517 * @atomicservice 518 * @since 11 519 */ 520 port: string; 521 522 /** 523 * Gets the path portion of the URI. 524 * 525 * @syscap SystemCapability.Utils.Lang 526 * @since 8 527 */ 528 /** 529 * Gets the path portion of the URI. 530 * 531 * @syscap SystemCapability.Utils.Lang 532 * @crossplatform 533 * @since 10 534 */ 535 /** 536 * Gets the path portion of the URI. 537 * 538 * @syscap SystemCapability.Utils.Lang 539 * @crossplatform 540 * @atomicservice 541 * @since 11 542 */ 543 /** 544 * Gets/Sets the path portion of the URI. 545 * 546 * @syscap SystemCapability.Utils.Lang 547 * @crossplatform 548 * @atomicservice 549 * @since 12 550 */ 551 path: string; 552 553 /** 554 * Gets the query portion of the URI 555 * 556 * @syscap SystemCapability.Utils.Lang 557 * @since 8 558 */ 559 /** 560 * Gets the query portion of the URI 561 * 562 * @syscap SystemCapability.Utils.Lang 563 * @crossplatform 564 * @since 10 565 */ 566 /** 567 * Gets the query portion of the URI 568 * 569 * @syscap SystemCapability.Utils.Lang 570 * @crossplatform 571 * @atomicservice 572 * @since 11 573 */ 574 /** 575 * Gets/Sets the query portion of the URI 576 * 577 * @syscap SystemCapability.Utils.Lang 578 * @crossplatform 579 * @atomicservice 580 * @since 12 581 */ 582 query: string; 583 584 /** 585 * Gets the fragment part of the URI. 586 * 587 * @syscap SystemCapability.Utils.Lang 588 * @since 8 589 */ 590 /** 591 * Gets the fragment part of the URI. 592 * 593 * @syscap SystemCapability.Utils.Lang 594 * @crossplatform 595 * @since 10 596 */ 597 /** 598 * Gets the fragment part of the URI. 599 * 600 * @syscap SystemCapability.Utils.Lang 601 * @crossplatform 602 * @atomicservice 603 * @since 11 604 */ 605 /** 606 * Gets/Sets the fragment part of the URI. 607 * 608 * @syscap SystemCapability.Utils.Lang 609 * @crossplatform 610 * @atomicservice 611 * @since 12 612 */ 613 fragment: string; 614 615 /** 616 * Gets the decoding permission component part of this URI. 617 * 618 * @syscap SystemCapability.Utils.Lang 619 * @since 8 620 */ 621 /** 622 * Gets the decoding permission component part of this URI. 623 * 624 * @syscap SystemCapability.Utils.Lang 625 * @crossplatform 626 * @since 10 627 */ 628 /** 629 * Gets the decoding permission component part of this URI. 630 * 631 * @syscap SystemCapability.Utils.Lang 632 * @crossplatform 633 * @atomicservice 634 * @since 11 635 */ 636 /** 637 * Gets/Sets the decoding permission component part of this URI. 638 * 639 * @syscap SystemCapability.Utils.Lang 640 * @crossplatform 641 * @atomicservice 642 * @since 12 643 */ 644 authority: string; 645 646 /** 647 * Gets the decoding scheme-specific part of the URI. 648 * 649 * @syscap SystemCapability.Utils.Lang 650 * @since 8 651 */ 652 /** 653 * Gets the decoding scheme-specific part of the URI. 654 * 655 * @syscap SystemCapability.Utils.Lang 656 * @crossplatform 657 * @since 10 658 */ 659 /** 660 * Gets the decoding scheme-specific part of the URI. 661 * 662 * @syscap SystemCapability.Utils.Lang 663 * @crossplatform 664 * @atomicservice 665 * @since 11 666 */ 667 /** 668 * Gets/Sets the decoding scheme-specific part of the URI. 669 * 670 * @type { string } 671 * @syscap SystemCapability.Utils.Lang 672 * @crossplatform 673 * @atomicservice 674 * @since 12 675 */ 676 ssp: string; 677 /** 678 * Gets/Sets Obtains the encoded user information part of the URI. 679 * 680 * @type { string } 681 * @syscap SystemCapability.Utils.Lang 682 * @crossplatform 683 * @atomicservice 684 * @since 12 685 */ 686 encodedUserInfo: string; 687 /** 688 * Gets/Sets the encoded path portion of the URI. 689 * 690 * @type { string } 691 * @syscap SystemCapability.Utils.Lang 692 * @crossplatform 693 * @atomicservice 694 * @since 12 695 */ 696 encodedPath: string; 697 /** 698 * Gets/Sets the encoded query component from this URI. 699 * 700 * @type { string } 701 * @syscap SystemCapability.Utils.Lang 702 * @crossplatform 703 * @atomicservice 704 * @since 12 705 */ 706 encodedQuery: string; 707 /** 708 * Gets/Sets the encoded fragment part of this URI, everything after the '#'. 709 * 710 * @type { string } 711 * @syscap SystemCapability.Utils.Lang 712 * @crossplatform 713 * @atomicservice 714 * @since 12 715 */ 716 encodedFragment: string; 717 /** 718 * Gets/Sets the encoded authority part of this URI. 719 * 720 * @type { string } 721 * @syscap SystemCapability.Utils.Lang 722 * @crossplatform 723 * @atomicservice 724 * @since 12 725 */ 726 encodedAuthority: string; 727 /** 728 * Gets/Sets the scheme-specific part of this URI, i.e. everything between the scheme separator ':' and 729 * the fragment separator '#'. 730 * 731 * @type { string } 732 * @syscap SystemCapability.Utils.Lang 733 * @crossplatform 734 * @atomicservice 735 * @since 12 736 */ 737 encodedSSP: string; 738 } 739} 740export default uri; 741