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 * @type { string } 418 * @syscap SystemCapability.Utils.Lang 419 * @since 8 420 */ 421 /** 422 * Gets the protocol part of the URI. 423 * 424 * @type { string } 425 * @syscap SystemCapability.Utils.Lang 426 * @crossplatform 427 * @since 10 428 */ 429 /** 430 * Gets the protocol part of the URI. 431 * 432 * @type { string } 433 * @syscap SystemCapability.Utils.Lang 434 * @crossplatform 435 * @atomicservice 436 * @since 11 437 */ 438 /** 439 * Gets/Sets the protocol part of the URI. 440 * 441 * @type { string } 442 * @syscap SystemCapability.Utils.Lang 443 * @crossplatform 444 * @atomicservice 445 * @since 12 446 */ 447 scheme: string; 448 449 /** 450 * Obtains the user information part of the URI. 451 * 452 * @type { string } 453 * @syscap SystemCapability.Utils.Lang 454 * @since 8 455 */ 456 /** 457 * Obtains the user information part of the URI. 458 * 459 * @type { string } 460 * @syscap SystemCapability.Utils.Lang 461 * @crossplatform 462 * @since 10 463 */ 464 /** 465 * Obtains the user information part of the URI. 466 * 467 * @type { string } 468 * @syscap SystemCapability.Utils.Lang 469 * @crossplatform 470 * @atomicservice 471 * @since 11 472 */ 473 /** 474 * Gets/Sets Obtains the user information part of the URI. 475 * 476 * @type { string } 477 * @syscap SystemCapability.Utils.Lang 478 * @crossplatform 479 * @atomicservice 480 * @since 12 481 */ 482 userInfo: string; 483 484 /** 485 * Gets the hostname portion of the URI without a port. 486 * 487 * @type { string } 488 * @syscap SystemCapability.Utils.Lang 489 * @since 8 490 */ 491 /** 492 * Gets the hostname portion of the URI without a port. 493 * 494 * @type { string } 495 * @syscap SystemCapability.Utils.Lang 496 * @crossplatform 497 * @since 10 498 */ 499 /** 500 * Gets the hostname portion of the URI without a port. 501 * 502 * @type { string } 503 * @syscap SystemCapability.Utils.Lang 504 * @crossplatform 505 * @atomicservice 506 * @since 11 507 */ 508 host: string; 509 510 /** 511 * Gets the port portion of the URI. 512 * 513 * @type { string } 514 * @syscap SystemCapability.Utils.Lang 515 * @since 8 516 */ 517 /** 518 * Gets the port portion of the URI. 519 * 520 * @type { string } 521 * @syscap SystemCapability.Utils.Lang 522 * @crossplatform 523 * @since 10 524 */ 525 /** 526 * Gets the port portion of the URI. 527 * 528 * @type { string } 529 * @syscap SystemCapability.Utils.Lang 530 * @crossplatform 531 * @atomicservice 532 * @since 11 533 */ 534 port: string; 535 536 /** 537 * Gets the path portion of the URI. 538 * 539 * @type { string } 540 * @syscap SystemCapability.Utils.Lang 541 * @since 8 542 */ 543 /** 544 * Gets the path portion of the URI. 545 * 546 * @type { string } 547 * @syscap SystemCapability.Utils.Lang 548 * @crossplatform 549 * @since 10 550 */ 551 /** 552 * Gets the path portion of the URI. 553 * 554 * @type { string } 555 * @syscap SystemCapability.Utils.Lang 556 * @crossplatform 557 * @atomicservice 558 * @since 11 559 */ 560 /** 561 * Gets/Sets the path portion of the URI. 562 * 563 * @type { string } 564 * @syscap SystemCapability.Utils.Lang 565 * @crossplatform 566 * @atomicservice 567 * @since 12 568 */ 569 path: string; 570 571 /** 572 * Gets the query portion of the URI 573 * 574 * @type { string } 575 * @syscap SystemCapability.Utils.Lang 576 * @since 8 577 */ 578 /** 579 * Gets the query portion of the URI 580 * 581 * @type { string } 582 * @syscap SystemCapability.Utils.Lang 583 * @crossplatform 584 * @since 10 585 */ 586 /** 587 * Gets the query portion of the URI 588 * 589 * @type { string } 590 * @syscap SystemCapability.Utils.Lang 591 * @crossplatform 592 * @atomicservice 593 * @since 11 594 */ 595 /** 596 * Gets/Sets the query portion of the URI 597 * 598 * @type { string } 599 * @syscap SystemCapability.Utils.Lang 600 * @crossplatform 601 * @atomicservice 602 * @since 12 603 */ 604 query: string; 605 606 /** 607 * Gets the fragment part of the URI. 608 * 609 * @type { string } 610 * @syscap SystemCapability.Utils.Lang 611 * @since 8 612 */ 613 /** 614 * Gets the fragment part of the URI. 615 * 616 * @type { string } 617 * @syscap SystemCapability.Utils.Lang 618 * @crossplatform 619 * @since 10 620 */ 621 /** 622 * Gets the fragment part of the URI. 623 * 624 * @type { string } 625 * @syscap SystemCapability.Utils.Lang 626 * @crossplatform 627 * @atomicservice 628 * @since 11 629 */ 630 /** 631 * Gets/Sets the fragment part of the URI. 632 * 633 * @type { string } 634 * @syscap SystemCapability.Utils.Lang 635 * @crossplatform 636 * @atomicservice 637 * @since 12 638 */ 639 fragment: string; 640 641 /** 642 * Gets the decoding permission component part of this URI. 643 * 644 * @type { string } 645 * @syscap SystemCapability.Utils.Lang 646 * @since 8 647 */ 648 /** 649 * Gets the decoding permission component part of this URI. 650 * 651 * @type { string } 652 * @syscap SystemCapability.Utils.Lang 653 * @crossplatform 654 * @since 10 655 */ 656 /** 657 * Gets the decoding permission component part of this URI. 658 * 659 * @type { string } 660 * @syscap SystemCapability.Utils.Lang 661 * @crossplatform 662 * @atomicservice 663 * @since 11 664 */ 665 /** 666 * Gets/Sets the decoding permission component part of this URI. 667 * 668 * @type { string } 669 * @syscap SystemCapability.Utils.Lang 670 * @crossplatform 671 * @atomicservice 672 * @since 12 673 */ 674 authority: string; 675 676 /** 677 * Gets the decoding scheme-specific part of the URI. 678 * 679 * @type { string } 680 * @syscap SystemCapability.Utils.Lang 681 * @since 8 682 */ 683 /** 684 * Gets the decoding scheme-specific part of the URI. 685 * 686 * @type { string } 687 * @syscap SystemCapability.Utils.Lang 688 * @crossplatform 689 * @since 10 690 */ 691 /** 692 * Gets the decoding scheme-specific part of the URI. 693 * 694 * @type { string } 695 * @syscap SystemCapability.Utils.Lang 696 * @crossplatform 697 * @atomicservice 698 * @since 11 699 */ 700 /** 701 * Gets/Sets the decoding scheme-specific part of the URI. 702 * 703 * @type { string } 704 * @syscap SystemCapability.Utils.Lang 705 * @crossplatform 706 * @atomicservice 707 * @since 12 708 */ 709 ssp: string; 710 /** 711 * Gets/Sets Obtains the encoded user information part of the URI. 712 * 713 * @type { string } 714 * @syscap SystemCapability.Utils.Lang 715 * @crossplatform 716 * @atomicservice 717 * @since 12 718 */ 719 encodedUserInfo: string; 720 /** 721 * Gets/Sets the encoded path portion of the URI. 722 * 723 * @type { string } 724 * @syscap SystemCapability.Utils.Lang 725 * @crossplatform 726 * @atomicservice 727 * @since 12 728 */ 729 encodedPath: string; 730 /** 731 * Gets/Sets the encoded query component from this URI. 732 * 733 * @type { string } 734 * @syscap SystemCapability.Utils.Lang 735 * @crossplatform 736 * @atomicservice 737 * @since 12 738 */ 739 encodedQuery: string; 740 /** 741 * Gets/Sets the encoded fragment part of this URI, everything after the '#'. 742 * 743 * @type { string } 744 * @syscap SystemCapability.Utils.Lang 745 * @crossplatform 746 * @atomicservice 747 * @since 12 748 */ 749 encodedFragment: string; 750 /** 751 * Gets/Sets the encoded authority part of this URI. 752 * 753 * @type { string } 754 * @syscap SystemCapability.Utils.Lang 755 * @crossplatform 756 * @atomicservice 757 * @since 12 758 */ 759 encodedAuthority: string; 760 /** 761 * Gets/Sets the scheme-specific part of this URI, i.e. everything between the scheme separator ':' and 762 * the fragment separator '#'. 763 * 764 * @type { string } 765 * @syscap SystemCapability.Utils.Lang 766 * @crossplatform 767 * @atomicservice 768 * @since 12 769 */ 770 encodedSSP: string; 771 } 772} 773export default uri; 774