• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# URI String Parsing
2
3> **NOTE**<br>
4> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
5
6
7## Modules to Import
8
9```
10import uri from '@ohos.uri'
11```
12
13## System Capabilities
14
15SystemCapability.Utils.Lang
16
17## URI
18
19
20### Attributes
21
22| Name| Type| Readable| Writable| Description|
23| -------- | -------- | -------- | -------- | -------- |
24| scheme | string | Yes| No| Scheme in the URI.|
25| userInfo | string | Yes| No| User information in the URI.|
26| host | string | Yes| No| Host name (without the port number) in the URI.|
27| port | string | Yes| No| Port number in the URI.|
28| path | string | Yes| No| Path in the URI.|
29| query | string | Yes| No| Query part in the URI.|
30| fragment | string | Yes| No| Fragment part in the URI.|
31| authority | string | Yes| No| Authority part in the URI.|
32| ssp | string | Yes| No| Scheme-specific part in the URI.|
33
34
35### constructor
36
37constructor(uri: string)
38
39A constructor used to create a URI instance.
40
41**Parameters**
42
43| Name| Type.| Readable| Writable| Description|
44| -------- | -------- | -------- | -------- | -------- |
45| uri | string | Yes| Yes| Input object.|
46
47**Example**
48
49```js
50var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
51new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
52```
53```js
54new uri.URI('http://username:password@host:8080'); // Output 'http://username:password@host:8080';
55```
56
57
58### toString
59
60toString(): string
61
62Obtains the query string applicable to this URI.
63
64**Return value**
65
66| Type.| Description|
67| -------- | -------- |
68| string | Website address in a serialized string.|
69
70**Example**
71
72```js
73const uri = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
74uri.toString()
75```
76
77
78### equals
79
80equals(other: URI): boolean
81
82Checks whether this URI is the same as another URI object.
83
84**Parameters**
85
86| Name| Type.| Mandatory| Description|
87| -------- | -------- | -------- | -------- |
88| other | [URI](#uri) | Yes| URI object to compare.|
89
90**Return value**
91
92| Type.| Description|
93| -------- | -------- |
94| boolean | Returns **true** if the two URIs are the same; returns **false** otherwise.|
95
96**Example**
97
98```js
99const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
100const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment');
101uriInstance.equals(uriInstance1);
102```
103
104### checkIsAbsolute
105
106checkIsAbsolute(): boolean
107
108Checks whether this URI is an absolute URI (whether the scheme component is defined).
109
110**Return value**
111
112| Type.| Description|
113| -------- | -------- |
114| boolean | Returns **true** if the URI is an absolute URI; returns **false** otherwise.|
115
116**Example**
117
118```js
119const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080?query=pppppp');
120uriInstance.checkIsAbsolute();
121```
122
123
124### normalize
125
126normalize(): URI
127
128Normalizes the path of this URI.
129
130**Return value**
131
132| Type.| Description|
133| -------- | -------- |
134| URI | URI with the normalized path.|
135
136**Example**
137```js
138const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp');
139let uriInstance1 = uriInstance.normalize();
140uriInstance1.path;
141```
142