• Home
Name
Date
Size
#Lines
LOC

..--

convertxml/12-May-2024-1,1481,002

test_uri/unittest/12-May-2024-548438

test_xml/unittest/12-May-2024-1,126800

uri/12-May-2024-1,232999

url/12-May-2024-3,9163,424

xml/12-May-2024-3,0792,750

LICENSED12-May-202410.1 KiB177150

README.mdD12-May-202425.8 KiB457429

README_zh.mdD12-May-202423.8 KiB456428

build_ts_js.pyD12-May-20242.1 KiB5838

bundle.jsonD12-May-20241.7 KiB6564

mozilla_docs.txtD12-May-20242 KiB5851

README.md

1# js_api_module Subsystem/Component
2
3-   [Introduction](#Introduction)
4-   [Contents](#Contents)
5-   [Illustrate](#Illustrate)
6    -   [Interface Description](#Interface Description)
7    -   [Instructions for use](#Instructions for use)
8
9-   [Related warehouse](#Related warehouse)
10
11## Introduction
12
13The interface of URL is used to parse, construct, normalize, and encode URLs. The constructor of URL creates a new URL object. In order to make changes to the resolved components of the URL or to the URL. The URLSearchParams interface defines some practical methods to process URL query strings.
14
15URI Represents a Uniform Resource Identifier (URI) reference.
16
17XML representation refers to extensible markup language.
18
19The XmlSerializer interface is used to generate an xml file. The constructor of XmlSerializer creates a new XmlSerializer object, and calls the method of the XmlSerializer object to generate an xml file. The XmlPullParser interface is used to parse the existing xml file. The constructor of XmlPullParser creates a new XmlPullParser object, and calls the method of the XmlPullParser object to parse the xml file.
20
21## Contents
22
23```
24base/compileruntime/js_api_module/
25├── Class:URL                                                                # URL class
26│   ├── new URL(input[, base])                                               # Create URL object
27│   ├── hash                                                                 # hash attribute
28│   ├── host                                                                 # host attribute
29│   ├── hostname                                                             # hostname attribute
30│   ├── href                                                                 # href attribute
31│   ├── origin                                                               # origin attribute
32│   ├── password                                                             # password attribute
33│   ├── pathname                                                             # pathname attribute
34│   ├── port                                                                 # port attribute
35│   ├── protocol                                                             # protocol attribute
36│   ├── search                                                               # search attribute
37│   ├── searchParams                                                         # searchParams attribute
38│   ├── username                                                             # username attribute
39│   ├── toString()                                                           # toString method
40│   └── toJSON()                                                             # toJSON method
41├── Class: URLSearchParams                                                   # URLSearchParams class
42│   ├── new URLSearchParams()                                                # Create URLSearchParams object
43│   ├── new URLSearchParams(string)                                          # Create URLSearchParams object
44│   ├── new URLSearchParams(obj)                                             # Create URLSearchParams object
45│   ├── new URLSearchParams(iterable)                                        # Create URLSearchParams object
46│   ├── append(name, value)                                                  # append method
47│   ├── delete(name)                                                         # delete method
48│   ├── entries()                                                            # entries method
49│   ├── forEach(fn[, thisArg])                                               # forEach method
50│   ├── get(name)                                                            # get method
51│   ├── getAll(name)                                                         # getAll method
52│   ├── has(name)                                                            # has method
53│   ├── keys()                                                               # keys method
54│   ├── set(name, value)                                                     # set method
55│   ├── sort()                                                               # sort method
56│   ├── toString()                                                           # toString method
57│   ├── values()                                                             # values method
58│   └── urlSearchParams[Symbol.iterator]()                                   # Create URLSearchParams object
59├── Class:URI                                                                # URI class
60│   ├── URI(str: string)                                                     # Create URI object
61│   ├── scheme                                                               # scheme attribute
62│   ├── authority                                                            # authority attribute
63│   ├── ssp                                                                  # ssp attribute
64│   ├── userinfo                                                             # userinfo attribute
65│   ├── host                                                                 # host attribute
66│   ├── port                                                                 # port attribute
67│   ├── query                                                                # query attribute
68│   ├── fragment                                                             # fragment attribute
69│   ├── path                                                                 # path method
70│   ├── equals(ob: Object)                                                   # equals method
71│   ├── normalize()                                                          # normalize method
72│   ├── checkIsAbsolute()                                                    # checkIsAbsolute method
73│   ├── normalize()                                                          # normalize method
74│   ├── toString()                                                           # toString method
75├── Class:ConvertXml                                                         # ConvertXml class
76│   ├── ConvertXml()                                                         # Create convertxml class object
77│   └── convert(xml: string, options: Object)                                # convert method
78├── Class:XmlSerializer                                                      # XmlSerializer class
79│   ├── new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) # Create XmlSerializer class object
80│   ├── setAttributes(name: string, value: string)                           # Set Attributes method
81│   ├── addEmptyElement(name: string)                                        # Add an empty element method
82│   ├── setDeclaration()                                                     # Set the Declaration method
83│   ├── startElement(name: string)                                           # Set the start element method
84│   ├── endElement()                                                         # Set the end element method
85│   ├── setNamespace(prefix: string, namespace: string)                      # Namespace method
86│   ├── setCommnet(text: string)                                             # Set up Commnet method
87│   ├── setCData(text: string)                                               # Set the CData method
88│   ├── setText(text: string)                                                # Set the Text method
89│   ├── setDocType(text: string)                                             # Set DocType method
90└── Class: XmlPullParser                                                     # XmlPullParser class
91    ├── new (buffer: ArrayBuffer | DataView, encoding?: string)              # Create XmlPullParser object
92    └── parse(option: ParseOptions)                                          # parse method
93```
94
95## Illustrate
96
97### Interface Description
98
99
100| Interface name | Illustrate                                                         |
101| -------- | -------- |
102| new URL(url: string,base?:string \| URL) | Create and return a URL object that references the URL specified by the absolute URL string, the relative URL string, and the basic URL string. |
103| tostring():string | The stringification method returns a USVString containing the complete URL. It is equivalent to the read-only URL.href. |
104| toJSON():string | This method returns a USVString, which contains a serialized URL version. |
105| new URLSearchParams() | The URLSearchParams() constructor has no parameters. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. |
106| new URLSearchParams(string) | The input parameter of URLSearchParams(string) constructor is string data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. |
107| new URLSearchParams(obj) | URLSearchParams(obj) The input parameter of the constructor is the obj data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. |
108| new URLSearchParams(iterable) | URLSearchParams(iterable) The input parameter of the constructor is the iterable data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. |
109| has(name: string): boolean | Retrieve whether the searchParams object contains name. If yes, it returns true, otherwise it returns false. |
110| set(name: string, value string): void |  Retrieve whether the searchParams object contains a key-value pair whose key is name. If not, add the key-value pair, if any, modify the value corresponding to the first key in the object, and delete the remaining key-value pairs whose key is name. |
111| sort(): void | According to the Unicode code point of the key, sort all key/value pairs contained in this object and return undefined. |
112| toString(): string | According to the searchParams object, the query string applicable in the URL is returned. |
113| keys(): iterableIterator\<string> | Return an iterator, which allows iterating through all the key values contained in the object. |
114| values(): iterableIterator\<string> | Returns an iterator, which allows iterating over all the value values contained in the object. |
115| append(name: string, value: string): void | Insert the name, value key-value pair in the searchParams object. |
116| delete(name: string): void | Traverse the searchParams object, find all the names, and delete the corresponding key-value pairs. |
117| get(name: string): string | Retrieve the first name in the searchParams object and return the value corresponding to the name key. |
118| getAll(name: string): string[] | Retrieve all names in the searchParams object and return all the values corresponding to the name key. |
119| entries(): iterableIterator<[string, string]> | Returns an iterator that allows iterating through all key/value pairs contained in the searchParams object. |
120| forEach(): void | Through the callback function to traverse the key-value pairs on the URLSearchParams instance object. |
121| urlSearchParams\[Symbol.iterator]() | Returns an ES6 iterator for each name-value pair in the query string. Each item of the iterator is a JavaScript array. |
122| URI​(str: string) | Construct the URI by parsing the given input parameter (String str). This constructor parses the given string strictly in accordance with the grammatical provisions in RFC 2396 Appendix A. |
123| getScheme​() | Return the scheme component of this URI, or null if the scheme is not defined. |
124| getAuthority​() | Returns the decoded authority component of this URI, or null if authority is not defined. The string returned by this method is the same as the string returned by the getRawAuthority method, except that all escaped octet sequences are decoded. |
125| getSchemeSpecificPart​() |  Returns the decoding scheme-specific part of this URI. The string returned by this method is the same as the string returned by the getRawSchemeSpecificPart method, except that all escaped octet sequences are decoded. |
126| getUserInfo​() | Returns the decoded userinfo component of this URI. The userinfo component of the URI (if defined) only contains characters in unreserved, punctuation, escape, and other categories. |
127| getHost​() | Return the host component of this URI, or null if host is not defined. |
128| getPort​() | Return the port of this URI, or -1 if the port is not defined. The port component of the URI (if defined) is a non-negative integer. |
129| getQuery​() | Returns the decoded query component of this URI, or null if the query is not defined. The string returned by this method is the same as the string returned by the getRawQuery method, except that all escaped octet sequences are decoded. |
130| getFragment​() | Returns the decoded fragment component of this URI, or null if the fragment is not defined. The string returned by this method is the same as the string returned by the getRawFragment method, except that all escaped octet sequences are decoded. |
131| getPath​() | Returns the decoded path component of this URI, or null if path is not defined. The string returned by this method is the same as the string returned by the getRawPath method, except that all escaped octet sequences are decoded. |
132| equals(ob: Object) | Test whether this URI is equal to another object. If the given object is not a URI, this method immediately returns false. |
133| normalize​() | Normalize the path of this URI. If this URI is opaque, or its path is already in normal form, then this URI is returned. Otherwise, a new URI identical to this URI will be constructed. |
134| checkIsAbsolute() | Determine whether this URI is absolute. If and only if it has a scheme component, the URI is absolute and the return value is true, otherwise the return value is false. |
135| toString() | Return the content of this URI as a string. |
136| ConvertXml() | The constructor used to construct the convertxml class object. This constructor does not need to pass in parameters. |
137| convert(xml: string, options: Object)  | Returns a JavaScript object that converts an XML string as required by the option. |
138| XmlSerializer(buffer: ArrayBuffer \| DataView, encoding?: string) | Create and return an XmlSerializer object. The XmlSerializer object passes two parameters. The first parameter is ArrayBuffer or DataView, and the second parameter is the file format (UTF-8 by default). |
139| setAttributes(name: string, value: string): void | Write the Attributes attribute to the xml file. |
140| addEmptyElement(name: string): void | Write an empty element. |
141| setDeclaration(): void | Set the Declaration to use the encoding to write the xml declaration. For example: <? xml version="1.0" encoding="utf-8"> |
142| startElement(name: string): void | Write the elemnet start tag with the given name.|
143| endElement(): void | Write the end tag of the element. |
144| setNamespace(prefix: string, namespace: string): void | Write the namespace of the current element tag. |
145| setCommnet(text: string): void | Write the comment attribute. |
146| setCData(text: string): void | Write the CData attribute. |
147| setText(text: string): void | Write the Text property. |
148| setDocType(text: string): void | Write the DocType attribute. |
149| XmlPullParser(buffer: ArrayBuffer \| DataView, encoding?: string) | Create and return an XmlPullParser object. The XmlPullParser object passes two parameters. The first parameter is ArrayBuffer or DataView, and the second parameter is the file format (default is UTF-8). |
150| parse(option: ParseOptions): void | This interface is used to parse xml. The ParseOptions parameter is an interface containing five optional parameters {supportDoctype?: boolea ignoreNameSpace?: boolean tagValueCallbackFunction?: (name: string, value: string) => boolean attributeValueCallbackFunction?: (name: string, value: string) => boolean) tokenValueCallbackFunction?: (eventType: EventType, value: ParseInfo) => boolean }. The input parameter 1 of the tokenValueCallbackFunction callback function is the event type, and the input parameter 2 is the info interface containing get attributes such as getColumnNumber and getDepth. The user can obtain the depth and other information in the current parsing process through methods such as info.getDepth(). |
151### Instructions for use
152
153The usage of each interface is as follows:
154
155
1561、new URL(url: string,base?:string|URL)
157```
158let b = new URL('https://developer.mozilla.org'); // => 'https://developer.mozilla.org/'
159
160let a = new URL( 'sca/./path/path/../scasa/text', 'http://www.example.com');
161// => 'http://www.example.com/sca/path/scasa/text'
162```
1632、tostring():string
164```
165const url = new URL('http://10.0xFF.O400.235:8080/directory/file?query#fragment');
166url.toString() // => 'http://10.0xff.o400.235:8080/directory/file?query#fragment'
167
168const url = new URL("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html");
169url.toString() // => 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html'
170
171const url = new URL("http://username:password@host:8080/directory/file?query#fragment");
172url.toString() // => 'http://username:password@host:8080/directory/file?query#fragment'
173```
1743、toJSON():string
175```
176const url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/toString");
177url.toJSON(); // =>  'https://developer.mozilla.org/en-US/docs/Web/API/URL/toString'
178```
1794、new URLSearchParams()
180```
181let params = new URLSearchParams('foo=1&bar=2');
182```
1835、new URLSearchParams(string)
184```
185params = new URLSearchParams('user=abc&query=xyz');
186console.log(params.get('user'));
187// Prints 'abc'
188```
1896、new URLSearchParams(obj)
190```
191const params = new URLSearchParams({
192    user: 'abc',
193    query: ['first', 'second']
194});
195console.log(params.getAll('query'));
196// Prints [ 'first,second' ]
197```
1987、new URLSearchParams(iterable)
199```
200let params;
201
202// Using an array
203params = new URLSearchParams([
204    ['user', 'abc'],
205    ['query', 'first'],
206    ['query', 'second'],
207]);
208console.log(params.toString());
209// Prints 'user = abc & query = first&query = second'
210```
2118、has(name: string): boolean
212```
213console.log(params.has('bar')); // =>true
214```
2159、set(name: string, value string): void
216```
217params.set('baz', 3);
218```
21910、sort(): void
220```
221params .sort();
222```
22311、toString(): string
224```
225console.log(params .toString()); // =>bar=2&baz=3&foo=1'
226```
22712、keys(): iterableIterator\<string>
228```
229for(var key of params.keys()) {
230  console.log(key);
231} // =>bar  baz  foo
232```
23313、values(): iterableIterator\<string>
234```
235for(var value of params.values()) {
236  console.log(value);
237} // =>2  3  1
238```
23914、append(name: string, value: string): void
240```
241params.append('foo', 3); // =>bar=2&baz=3&foo=1&foo=3
242```
24315、delete(name: string): void
244```
245params.delete('baz'); // => bar=2&foo=1&foo=3
246```
24716、get(name: string): string
248```
249params.get('foo'); // => 1
250```
25117、getAll(name: string): string[]
252```
253params.getAll('foo'); // =>[ '1', '3' ]
254```
25518、entries(): iterableIterator<[string, string]>
256```
257for(var pair of searchParams.entries()) {
258   console.log(pair[0]+ ', '+ pair[1]);
259} // => bar, 2   foo, 1  foo, 3
260```
26119、forEach(): void
262```
263url.searchParams.forEach((value, name, searchParams) => {
264  console.log(name, value, url.searchParams === searchParams);
265});
266// => foo 1 true
267// => bar 2 true
268```
26920、urlSearchParams[Symbol.iterator] ()
270```
271const params = new URLSearchParams('foo=bar&xyz=baz');
272for (const [name, value] of params) {
273    console.log(name, value);
274}
275// Prints:
276// foo bar
277// xyz bar
278```
279
280
28121、URI​(String str)
282```
283let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
284```
28522、scheme
286```
287let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
288gaogao.scheme        // => "http";
289```
29023、authority
291```
292let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
293gaogao.authority     // => "gg:gaogao@www.baidu.com:99";
294```
29524、ssp
296```
297let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
298gaogao.ssp "         // => gg:gaogao@www.baidu.com:99/path/path?query";
299```
30025、userinfo
301```
302let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
303gaogao.userinfo      // => "gg:gaogao";
304```
30526、host
306```
307let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
308gaogao.host          // => "www.baidu.com";
309```
31027、port
311```
312let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
313gaogao.port          // => "99";
314```
31528、query
316```
317let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
318gaogao.query         // => "query";
319```
32029、fragment
321```
322let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
323gaogao.fragment      // => "fagment";
324```
32530、path
326```
327let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
328gaogao.path          // => "/path/path";
329```
33031、equals(Object ob)
331```
332let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment');
333let gaogao1 = gaogao;
334let res = gaogao.equals(gaogao1);
335console.log(res);      // => true;
336```
33732、normalize​()
338```
339let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment');
340let res = gaogao.normalize();
341console.log(res.path);        // => "/path/path1"
342console.log(res.toString());  // => "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment"
343```
34433、checkIsAbsolute()
345```
346let gaogao = new Uri.URI('f/tp://username:password@www.baidu.com:88/path?query#fagment');
347let res = gaogao.checkIsAbsolute();
348console.log(res);              //=> false;
349```
35034、toString()
351```
352let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment');
353let res = gaogao.toString();
354console.log(res.toString());     // => 'http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment';
355```
356
357
35835、ConvertXml()
359```
360var convertml = new convertXml.ConvertXml();
361```
36236、convert(xml: string, options: Object)
363```
364var result = convertml.convert(xml, {compact: false, spaces: 4});
365```
36637、new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string)
367```
368
369var arrayBuffer = new ArrayBuffer(1024);
370var bufView = new DataView(arrayBuffer);
371var thatSer = new xml.XmlSerializer(bufView);
372```
37338、setDeclaration():void
374```
375var thatSer = new xml.XmlSerializer(bufView);
376thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>;
377```
37839、setCommnet(text: string):void
379```
380var thatSer = new xml.XmlSerializer(bufView);
381thatSer.setCommnet("Hello, World!"); // => <!--Hello, World!-->;
382```
38340、setCData(text: string) :void
384```
385var thatSer = new xml.XmlSerializer(bufView);
386thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); // => <![CDATA[root SYSTEM \“http://www.test.org/test.dtd\”]]>
387```
38841、setDocType(text: string):void
389```
390var thatSer = new xml.XmlSerializer(bufView);
391thatSer.setDocType("foo"); // => <!DOCTYPE foo>
392```
39342、setNamespace(prefix: string, namespace: string): void
39443、startElement(name: string): void
39544、setAttributes(name: string, value: string): void
39645、endElement(): void
39746、setText(text: string): void
398```
399var thatSer = new xml.XmlSerializer(bufView);
400thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
401thatSer.startElement("table");
402thatSer.setAttributes("importance", "high");
403thatSer.setText("Happy");
404endElement(); // => <h:table importance="high" xmlns:h="http://www.w3.org/TR/html4/">Happy</h:table>
405```
40647、addEmptyElement(name: string): void
407```
408var thatSer = new xml.XmlSerializer(bufView);
409thatSer.addEmptyElement("b"); // => <b/>
410```
41148、new (buffer: ArrayBuffer | DataView, encoding?: string)
412```
413var strXml =
414            '<?xml version="1.0" encoding="utf-8"?>' +
415            '<note importance="high" logged="true">' +
416            '    <title>Happy</title>' +
417            '</note>';
418var arrayBuffer = new ArrayBuffer(strXml.length*2);
419var bufView = new Uint8Array(arrayBuffer);
420var strLen = strXml.length;
421for (var i = 0; i < strLen; ++i) {
422    bufView[i] = strXml.charCodeAt(i);//设置arraybuffer 方式
423}
424var that = new xml.XmlPullParser(arrayBuffer);
425
426```
42749、parse(option: ParseOptions): void
428```
429var strXml =
430            '<?xml version="1.0" encoding="utf-8"?>' +
431            '<note importance="high" logged="true">' +
432            '    <title>Happy</title>' +
433            '</note>';
434var arrayBuffer = new ArrayBuffer(strXml.length*2);
435var bufView = new Uint8Array(arrayBuffer);
436var strLen = strXml.length;
437for (var i = 0; i < strLen; ++i) {
438    bufView[i] = strXml.charCodeAt(i);
439}
440var that = new xml.XmlPullParser(arrayBuffer);
441var arrTag = {};
442arrTag[0] = '132';
443var i = 1;
444function func(key, value){
445    arrTag[i] = 'key:'+key+' value:'+ value.getDepth();
446    i++;
447    return true;
448}
449var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func};
450that.parse(options);
451```
452## Related warehouse
453[js_api_module Subsystem](base/compileruntime/js_api_module-readme.md)
454
455## License
456
457URL is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_api_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony/js_api_module/blob/master/LICENSE) for the full license text.

README_zh.md

1# js_api_module子系统/组件
2
3-   [简介](#简介)
4-   [目录](#目录)
5-   [说明](#说明)
6    -   [接口说明](#接口说明)
7    -   [使用说明](#使用说明)
8
9-   [相关仓](#相关仓)
10
11## 简介
12
13URL接口用于解析,构造,规范化和编码 URLs。 URL的构造函数创建新的URL对象。 以便对URL的已解析组成部分或对URL进行更改。URLSearchParams 接口定义了一些实用的方法来处理 URL 的查询字符串。
14
15URI表示统一资源标识符引用。
16
17xml表示指可扩展标记语言。
18
19XmlSerializer接口用于生成一个xml文件。 XmlSerializer的构造函数创建新的XmlSerializer对象,调用XmlSerializer对象的方法生成一个xml文件。XmlPullParser 接口用于解析已有的xml文件,XmlPullParser的构造函数创建新的XmlPullParser对象,调用XmlPullParser对象的方法解析xml。
20
21## 目录
22
23```
24base/compileruntime/js_api_module/
25├── Class:URL                                                                     # URL类
26│   ├── new URL(input[, base])                                                    # 创建URL对象
27│   ├── hash                                                                      # hash属性
28│   ├── host                                                                      # host属性
29│   ├── hostname                                                                  # hostname属性
30│   ├── href                                                                      # href属性
31│   ├── origin                                                                    # origin属性
32│   ├── password                                                                  # password属性
33│   ├── pathname                                                                  # pathname属性
34│   ├── port                                                                      # port属性
35│   ├── protocol                                                                  # protocol属性
36│   ├── search                                                                    # search属性
37│   ├── searchParams                                                              # searchParams属性
38│   ├── username                                                                  # username属性
39│   ├── toString()                                                                # toString方法
40│   └── toJSON()                                                                  # toJSON方法
41├── Class: URLSearchParams                                                        # URLSearchParams类
42│   ├── new URLSearchParams()                                                     # 创建URLSearchParams对象
43│   ├── new URLSearchParams(string)                                               # 创建URLSearchParams对象
44│   ├── new URLSearchParams(obj)                                                  # 创建URLSearchParams对象
45│   ├── new URLSearchParams(iterable)                                             # 创建URLSearchParams对象
46│   ├── append(name, value)                                                       # append方法
47│   ├── delete(name)                                                              # delete方法
48│   ├── entries()                                                                 # entries方法
49│   ├── forEach(fn[, thisArg])                                                    # forEach方法
50│   ├── get(name)                                                                 # get方法
51│   ├── getAll(name)                                                              # getAll方法
52│   ├── has(name)                                                                 # has方法
53│   ├── keys()                                                                    # keys方法
54│   ├── set(name, value)                                                          # set方法
55│   ├── sort()                                                                    # sort方法
56│   ├── toString()                                                                # toString方法
57│   ├── values()                                                                  # values方法
58│   └── urlSearchParams[Symbol.iterator]()                                        # 创建URLSearchParams对象
59├── Class:URI                                                                     # URI类
60│   ├── URI(str: string)                                                          # 创建URI对象
61│   ├── scheme                                                                    # scheme属性
62│   ├── authority                                                                 # authority属性
63│   ├── ssp                                                                       # ssp属性
64│   ├── userinfo                                                                  # userinfo属性
65│   ├── host                                                                      # host属性
66│   ├── port                                                                      # port属性
67│   ├── query                                                                     # query属性
68│   ├── fragment                                                                  # fragment属性
69│   ├── path                                                                      # path属性
70│   ├── equals(ob: Object)                                                        # equals方法
71│   ├── normalize()                                                               # normalize方法
72│   ├── checkIsAbsolute()                                                         # checkIsAbsolute方法
73│   ├── normalize()                                                               # normalize方法
74│   └── toString()                                                                # toString方法
75├── Class:ConvertXml                                                              # ConvertXml类
76│   ├── ConvertXml()                                                              # 创建ConvertXml类对象
77│   └── convert(xml: string, options: Object)                                     # convert方法
78├── Class:XmlSerializer                                                           # XmlSerializer类
79│   ├── new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string)      # 创建XmlSerializer类对象
80│   ├── setAttributes(name: string, value: string)                                # 设置Attributes方法
81│   ├── addEmptyElement(name: string)                                             # 添加一个空元素方法
82│   ├── setDeclaration()                                                          # 设置Declaration方法
83│   ├── startElement(name: string)                                                # 设置开始元素方法
84│   ├── endElement()                                                              # 设置结束元素方法
85│   ├── setNamespace(prefix: string, namespace: string)                           # 设置命名空间方法
86│   ├── setCommnet(text: string)                                                  # 设置Commnet方法
87│   ├── setCData(text: string)                                                    # 设置CData方法
88│   ├── setText(text: string)                                                     # 设置Text方法
89│   └── setDocType(text: string)                                                  # 设置DocType方法
90└── Class: XmlPullParser                                                          # XmlPullParser类
91    ├── new (buffer: ArrayBuffer | DataView, encoding?: string)                   # 创建XmlPullParser对象
92    └── parse(option: ParseOptions)                                               # parse方法
93```
94
95## 说明
96
97### 接口说明
98
99
100| 接口名 | 说明 |
101| -------- | -------- |
102| URL(url: string,base?:string \| URL) | 创建并返回一个URL对象,该URL对象引用使用绝对URL字符串,相对URL字符串和基本URL字符串指定的URL。 |
103| tostring():string | 该字符串化方法返回一个包含完整 URL 的 USVString。它的作用等同于只读的 URL.href。 |
104| toJSON():string | 该方法返回一个USVString,其中包含一个序列化的URL版本。 |
105| new URLSearchParams() | URLSearchParams() 构造器无入参,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 |
106| new URLSearchParams(string) | URLSearchParams(string) 构造器的入参为string数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 |
107| new URLSearchParams(obj) | URLSearchParams(obj) 构造器的入参为obj数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 |
108| new URLSearchParams(iterable) | URLSearchParams(iterable) 构造器的入参为iterable数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 |
109| has(name: string): boolean | 检索searchParams对象中是否含有name。有则返回true,否则返回false。 |
110| set(name: string, value string): void |  检索searchParams对象中是否含有key为name的键值对。没有的话则添加该键值对,有的话则修改对象中第一个key所对应的value,并删除键为name的其余键值对。 |
111| sort(): void | 根据键的Unicode代码点,对包含在此对象中的所有键/值对进行排序,并返回undefined。 |
112| toString(): string | 根据searchParams对象,返回适用在URL中的查询字符串。 |
113| keys(): iterableIterator\<string> | 返回一个iterator,遍历器允许遍历对象中包含的所有key值。 |
114| values(): iterableIterator\<string> | 返回一个iterator,遍历器允许遍历对象中包含的所有value值。 |
115| append(name: string, value: string): void | 在searchParams对象中插入name, value键值对。 |
116| delete(name: string): void | 遍历searchParams对象,查找所有的name,删除对应的键值对。 |
117| get(name: string): string | 检索searchParams对象中第一个name,返回name键对应的值。 |
118| getAll(name: string): string[] | 检索searchParams对象中所有name,返回name键对应的所有值。 |
119| entries(): iterableIterator<[string, string]> | 返回一个iterator,允许遍历searchParams对象中包含的所有键/值对。 |
120| forEach(): void | 通过回调函数来遍历URLSearchParams实例对象上的键值对。 |
121| urlSearchParams\[Symbol.iterator]() | 返回查询字符串中每个名称-值对的ES6迭代器。迭代器的每个项都是一个JavaScript数组。 |
122| URI​(str: string) | 通过解析给定入参(String str)来构造URI。此构造函数严格按照RFC 2396附录A中的语法规定解析给定字符串。 |
123| scheme​ | 返回此 URI 的scheme部分,如果scheme未定义,则返回 null |
124| authority​ | 返回此 URI 的解码authority部分,如果authority未定义,则返回 null。 |
125| ssp​ |  返回此 URI 的解码scheme-specific部分。 |
126| userinfo​ | 返回此 URI 的解码userinfo部分。包含passworld和username。 |
127| host​ | 返回此 URI 的host部分,如果host未定义,则返回 null。 |
128| port​ | 返回此 URI 的port部分,如果port未定义,则返回 -1。URI 的port组件(如果已定义)是一个非负整数。 |
129| query​ | 返回此 URI 的query部分,如果query未定义,则返回 null。 |
130| fragment​ | 返回此 URI 的解码fragment组件,如果fragment未定义,则返回 null。|
131| path​ | 返回此 URI 的解码path组件,如果path未定义,则返回 null。 |
132| equals(ob: Object) | 测试此 URI 是否与另一个对象相等。如果给定的对象不是 URI,则此方法立即返回 false。 |
133| normalize​() | 规范化这个 URI 的路径。如果这个 URI 的path不规范,将规范后构造一个新 URI对象返回。 |
134| checkIsAbsolute​() | 判断这个 URI 是否是绝对的。当且仅当它具有scheme部分时,URI 是绝对的,返回值为true,否则返回值为false。 |
135| ConvertXml() | 用于构造ConvertXml类对象的构造函数。此构造函数无需传入参数。 |
136| convert(xml: string, options: Object)  | 返回按选项要求转化xml字符串的JavaScrip对象。 |
137| XmlSerializer(buffer: ArrayBuffer \| DataView, encoding?: string) | 创建并返回一个XmlSerializer对象,该XmlSerializer对象传参两个第一参数是ArrayBuffer或DataView一段内存,第二个参数为文件格式(默认为UTF-8)。 |
138| setAttributes(name: string, value: string): void | 给xml文件中写入属性Attributes属性。 |
139| addEmptyElement(name: string): void | 写入一个空元素。 |
140| setDeclaration(): void | 设置Declaration使用编码写入xml声明。例如:<?xml version=“1.0”encoding=“utf-8”> |
141| startElement(name: string): void | 写入具有给定名称的elemnet开始标记。|
142| endElement(): void | 写入元素的结束标记。 |
143| setNamespace(prefix: string, namespace: string): void | 写入当前元素标记的命名空间。 |
144| setCommnet(text: string): void | 写入comment属性。 |
145| setCData(text: string): void | 写入CData属性。 |
146| setText(text: string): void | 写入Text属性。 |
147| setDocType(text: string): void | 写入DocType属性。 |
148| XmlPullParser(buffer: ArrayBuffer \| DataView, encoding?: string) | 创建并返回一个XmlPullParser对象,该XmlPullParser对象传参两个第一参数是ArrayBuffer或DataView一段内存,第二个参数为文件格式(默认为UTF-8)。 |
149| parse(option: ParseOptions): void | 该接口用于解析xml,ParseOptions参数为一个接口包含五个可选参{supportDoctype?: boolea ignoreNameSpace?: boolean tagValueCallbackFunction?: (name: string, value: string) => boolean attributeValueCallbackFunction?: (name: string, value: string) => boolean) tokenValueCallbackFunction?: (eventType: EventType, value: ParseInfo) => boolean }。其中tokenValueCallbackFunction回调函数的入参1是事件类型,入参2是包含getColumnNumber、getDepth等get属性的info接口,用户可通过info.getDepth()等方法来获取当前解析过程中的depth等信息。 |
150### 使用说明
151
152各接口使用方法如下:
153
154
1551、new URL(url: string,base?:string|URL)
156```
157let b = new URL('https://developer.mozilla.org'); // => 'https://developer.mozilla.org/'
158
159let a = new URL( 'sca/./path/path/../scasa/text', 'http://www.example.com');
160// => 'http://www.example.com/sca/path/scasa/text'
161```
1622、tostring():string
163```
164const url = new URL('http://10.0xFF.O400.235:8080/directory/file?query#fragment');
165url.toString() // => 'http://10.0xff.o400.235:8080/directory/file?query#fragment'
166
167const url = new URL("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html");
168url.toString() // => 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html'
169
170const url = new URL("http://username:password@host:8080/directory/file?query#fragment");
171url.toString() // => 'http://username:password@host:8080/directory/file?query#fragment'
172```
1733、toJSON():string
174```
175const url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/toString");
176url.toJSON(); // =>  'https://developer.mozilla.org/en-US/docs/Web/API/URL/toString'
177```
1784、new URLSearchParams()
179```
180let params = new URLSearchParams('foo=1&bar=2');
181```
1825、new URLSearchParams(string)
183```
184params = new URLSearchParams('user=abc&query=xyz');
185console.log(params.get('user'));
186// Prints 'abc'
187```
1886、new URLSearchParams(obj)
189```
190const params = new URLSearchParams({
191    user: 'abc',
192    query: ['first', 'second']
193});
194console.log(params.getAll('query'));
195// Prints [ 'first,second' ]
196```
1977、new URLSearchParams(iterable)
198```
199let params;
200
201// Using an array
202params = new URLSearchParams([
203    ['user', 'abc'],
204    ['query', 'first'],
205    ['query', 'second'],
206]);
207console.log(params.toString());
208// Prints 'user = abc & query = first&query = second'
209```
2108、has(name: string): boolean
211```
212console.log(params.has('bar')); // =>true
213```
2149、set(name: string, value string): void
215```
216params.set('baz', 3);
217```
21810、sort(): void
219```
220params .sort();
221```
22211、toString(): string
223```
224console.log(params .toString()); // =>bar=2&baz=3&foo=1'
225```
22612、keys(): iterableIterator\<string>
227```
228for(var key of params.keys()) {
229  console.log(key);
230} // =>bar  baz  foo
231```
23213、values(): iterableIterator\<string>
233```
234for(var value of params.values()) {
235  console.log(value);
236} // =>2  3  1
237```
23814、append(name: string, value: string): void
239```
240params.append('foo', 3); // =>bar=2&baz=3&foo=1&foo=3
241```
24215、delete(name: string): void
243```
244params.delete('baz'); // => bar=2&foo=1&foo=3
245```
24616、get(name: string): string
247```
248params.get('foo'); // => 1
249```
25017、getAll(name: string): string[]
251```
252params.getAll('foo'); // =>[ '1', '3' ]
253```
25418、entries(): iterableIterator<[string, string]>
255```
256for(var pair of searchParams.entries()) {
257   console.log(pair[0]+ ', '+ pair[1]);
258} // => bar, 2   foo, 1  foo, 3
259```
26019、forEach(): void
261```
262url.searchParams.forEach((value, name, searchParams) => {
263  console.log(name, value, url.searchParams === searchParams);
264});
265// => foo 1 true
266// => bar 2 true
267```
26820、urlSearchParams[Symbol.iterator] ()
269```
270const params = new URLSearchParams('foo=bar&xyz=baz');
271for (const [name, value] of params) {
272    console.log(name, value);
273}
274// Prints:
275// foo bar
276// xyz bar
277```
278
279
28021、URI​(str: string)
281```
282let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
283```
28422、scheme
285```
286let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
287gaogao.scheme        // => "http";
288```
28923、authority
290```
291let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
292gaogao.authority     // => "gg:gaogao@www.baidu.com:99";
293```
29424、ssp
295```
296let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
297gaogao.ssp "         // => gg:gaogao@www.baidu.com:99/path/path?query";
298```
29925、userinfo
300```
301let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
302gaogao.userinfo      // => "gg:gaogao";
303```
30426、host
305```
306let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
307gaogao.host          // => "www.baidu.com";
308```
30927、port
310```
311let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
312gaogao.port          // => "99";
313```
31428、query
315```
316let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
317gaogao.query         // => "query";
318```
31929、fragment
320```
321let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
322gaogao.fragment      // => "fagment";
323```
32430、path
325```
326let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment');
327gaogao.path          // => "/path/path";
328```
32931、equals(ob: Object)
330```
331let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment');
332let gaogao1 = gaogao;
333let res = gaogao.equals(gaogao1);
334console.log(res);      // => true;
335```
33632、normalize​()
337```
338let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment');
339let res = gaogao.normalize();
340console.log(res.path);        // => "/path/path1"
341console.log(res.toString());  // => "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment"
342```
34333、checkIsAbsolute​()
344```
345let gaogao = new Uri.URI('f/tp://username:password@www.baidu.com:88/path?query#fagment');
346let res = gaogao.checkIsAbsolute();
347console.log(res);              //=> false;
348```
34934、toString()
350```
351let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment');
352let res = gaogao.toString();
353console.log(res.toString());     // => 'http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment';
354```
355
356
35735、ConvertXml()
358```
359var convertml = new convertXml.ConvertXml();
360```
36136、convert(xml: string, options: Object)
362```
363var result = convertml.convert(xml, {compact: false, spaces: 4});
364```
36537、new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string)
366```
367
368var arrayBuffer = new ArrayBuffer(1024);
369var bufView = new DataView(arrayBuffer);
370var thatSer = new xml.XmlSerializer(bufView);
371```
37238、setDeclaration():void
373```
374var thatSer = new xml.XmlSerializer(bufView);
375thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>;
376```
37739、setCommnet(text: string):void
378```
379var thatSer = new xml.XmlSerializer(bufView);
380thatSer.setCommnet("Hello, World!"); // => <!--Hello, World!-->;
381```
38240、setCData(text: string) :void
383```
384var thatSer = new xml.XmlSerializer(bufView);
385thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); // => <![CDATA[root SYSTEM \“http://www.test.org/test.dtd\”]]>
386```
38741、setDocType(text: string):void
388```
389var thatSer = new xml.XmlSerializer(bufView);
390thatSer.setDocType("foo"); // => <!DOCTYPE foo>
391```
39242、setNamespace(prefix: string, namespace: string): void
39343、startElement(name: string): void
39444、setAttributes(name: string, value: string): void
39545、endElement(): void
39646、setText(text: string): void
397```
398var thatSer = new xml.XmlSerializer(bufView);
399thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
400thatSer.startElement("table");
401thatSer.setAttributes("importance", "high");
402thatSer.setText("Happy");
403endElement(); // => <h:table importance="high" xmlns:h="http://www.w3.org/TR/html4/">Happy</h:table>
404```
40547、addEmptyElement(name: string): void
406```
407var thatSer = new xml.XmlSerializer(bufView);
408thatSer.addEmptyElement("b"); // => <b/>
409```
41048、new (buffer: ArrayBuffer | DataView, encoding?: string)
411```
412var strXml =
413            '<?xml version="1.0" encoding="utf-8"?>' +
414            '<note importance="high" logged="true">' +
415            '    <title>Happy</title>' +
416            '</note>';
417var arrayBuffer = new ArrayBuffer(strXml.length*2);
418var bufView = new Uint8Array(arrayBuffer);
419var strLen = strXml.length;
420for (var i = 0; i < strLen; ++i) {
421    bufView[i] = strXml.charCodeAt(i);//设置arraybuffer 方式
422}
423var that = new xml.XmlPullParser(arrayBuffer);
424
425```
42649、parse(option: ParseOptions): void
427```
428var strXml =
429            '<?xml version="1.0" encoding="utf-8"?>' +
430            '<note importance="high" logged="true">' +
431            '    <title>Happy</title>' +
432            '</note>';
433var arrayBuffer = new ArrayBuffer(strXml.length*2);
434var bufView = new Uint8Array(arrayBuffer);
435var strLen = strXml.length;
436for (var i = 0; i < strLen; ++i) {
437    bufView[i] = strXml.charCodeAt(i);
438}
439var that = new xml.XmlPullParser(arrayBuffer);
440var arrTag = {};
441arrTag[0] = '132';
442var i = 1;
443function func(key, value){
444    arrTag[i] = 'key:'+key+' value:'+ value.getDepth();
445    i++;
446    return true;
447}
448var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
449that.parse(options);
450```
451## 相关仓
452[js_api_module子系统](base/compileruntime/js_api_module/readme.md)
453
454### 许可证
455
456URL在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_api_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony/js_api_module/blob/master/LICENSE)