未验证 提交 eec6b64b 编写于 作者: O openharmony_ci 提交者: Gitee

!9651 Modify the var in the util, uri, url, xml, process module use cases in...

!9651 Modify the var in the util, uri, url, xml, process module use cases in the docs document to let
Merge pull request !9651 from 毕虎/master
...@@ -63,8 +63,8 @@ wait(): Promise<number> ...@@ -63,8 +63,8 @@ wait(): Promise<number>
**示例:** **示例:**
```js ```js
var child = process.runCmd('ls'); let child = process.runCmd('ls');
var result = child.wait(); let result = child.wait();
result.then(val=>{ result.then(val=>{
console.log("result = " + val); console.log("result = " + val);
}) })
...@@ -90,8 +90,8 @@ getOutput(): Promise<Uint8Array> ...@@ -90,8 +90,8 @@ getOutput(): Promise<Uint8Array>
**示例:** **示例:**
```js ```js
var child = process.runCmd('ls'); let child = process.runCmd('ls');
var result = child.wait(); let result = child.wait();
child.getOutput().then(val=>{ child.getOutput().then(val=>{
console.log("child.getOutput = " + val); console.log("child.getOutput = " + val);
}) })
...@@ -117,8 +117,8 @@ getErrorOutput(): Promise<Uint8Array> ...@@ -117,8 +117,8 @@ getErrorOutput(): Promise<Uint8Array>
**示例:** **示例:**
```js ```js
var child = process.runCmd('madir test.text'); let child = process.runCmd('madir test.text');
var result = child.wait(); let result = child.wait();
child.getErrorOutput().then(val=>{ child.getErrorOutput().then(val=>{
console.log("child.getErrorOutput= " + val); console.log("child.getErrorOutput= " + val);
}) })
...@@ -138,7 +138,7 @@ close(): void ...@@ -138,7 +138,7 @@ close(): void
**示例:** **示例:**
```js ```js
var child = process.runCmd('sleep 5; ls'); let child = process.runCmd('sleep 5; ls');
child.close(); child.close();
``` ```
...@@ -162,7 +162,7 @@ kill(signal: number | string): void ...@@ -162,7 +162,7 @@ kill(signal: number | string): void
**示例:** **示例:**
```js ```js
var child = process.runCmd('sleep 5; ls'); let child = process.runCmd('sleep 5; ls');
child.kill(9); child.kill(9);
``` ```
...@@ -184,7 +184,7 @@ isIsolatedProcess(): boolean ...@@ -184,7 +184,7 @@ isIsolatedProcess(): boolean
**示例:** **示例:**
```js ```js
var result = process.isIsolatedProcess(); let result = process.isIsolatedProcess();
``` ```
...@@ -211,7 +211,7 @@ isAppUid(v: number): boolean ...@@ -211,7 +211,7 @@ isAppUid(v: number): boolean
**示例:** **示例:**
```js ```js
var result = process.isAppUid(688); let result = process.isAppUid(688);
``` ```
...@@ -232,7 +232,7 @@ is64Bit(): boolean ...@@ -232,7 +232,7 @@ is64Bit(): boolean
**示例:** **示例:**
```js ```js
var result = process.is64Bit(); let result = process.is64Bit();
``` ```
...@@ -259,7 +259,7 @@ getUidForName(v: string): number ...@@ -259,7 +259,7 @@ getUidForName(v: string): number
**示例:** **示例:**
```js ```js
var pres = process.getUidForName("tool") let pres = process.getUidForName("tool")
``` ```
...@@ -286,8 +286,8 @@ getThreadPriority(v: number): number ...@@ -286,8 +286,8 @@ getThreadPriority(v: number): number
**示例:** **示例:**
```js ```js
var tid = process.tid; let tid = process.tid;
var pres = process.getThreadPriority(tid); let pres = process.getThreadPriority(tid);
``` ```
...@@ -308,7 +308,7 @@ getStartRealtime(): number ...@@ -308,7 +308,7 @@ getStartRealtime(): number
**示例:** **示例:**
```js ```js
var realtime = process.getStartRealtime(); let realtime = process.getStartRealtime();
``` ```
## process.getPastCpuTime<sup>8+</sup> ## process.getPastCpuTime<sup>8+</sup>
...@@ -328,7 +328,7 @@ getPastCpuTime(): number ...@@ -328,7 +328,7 @@ getPastCpuTime(): number
**示例:** **示例:**
```js ```js
var result = process.getPastCpuTime() ; let result = process.getPastCpuTime() ;
``` ```
...@@ -355,8 +355,8 @@ getSystemConfig(name: number): number ...@@ -355,8 +355,8 @@ getSystemConfig(name: number): number
**示例:** **示例:**
```js ```js
var _SC_ARG_MAX = 0 let _SC_ARG_MAX = 0
var pres = process.getSystemConfig(_SC_ARG_MAX) let pres = process.getSystemConfig(_SC_ARG_MAX)
``` ```
...@@ -383,7 +383,7 @@ getEnvironmentVar(name: string): string ...@@ -383,7 +383,7 @@ getEnvironmentVar(name: string): string
**示例:** **示例:**
```js ```js
var pres = process.getEnvironmentVar("PATH") let pres = process.getEnvironmentVar("PATH")
``` ```
...@@ -421,8 +421,8 @@ runCmd(command: string, options?: { timeout?: number, killSignal?: number | stri ...@@ -421,8 +421,8 @@ runCmd(command: string, options?: { timeout?: number, killSignal?: number | stri
**示例:** **示例:**
```js ```js
var child = process.runCmd('ls', { maxBuffer : 2 }); let child = process.runCmd('ls', { maxBuffer : 2 });
var result = child.wait(); let result = child.wait();
child.getOutput.then(val=>{ child.getOutput.then(val=>{
console.log("child.getOutput = " + val); console.log("child.getOutput = " + val);
}) })
...@@ -504,7 +504,7 @@ off(type: string): boolean ...@@ -504,7 +504,7 @@ off(type: string): boolean
process.on("data", (e)=>{ process.on("data", (e)=>{
console.log("data callback"); console.log("data callback");
}) })
var result = process.off("data"); let result = process.off("data");
``` ```
...@@ -544,7 +544,7 @@ cwd(): string ...@@ -544,7 +544,7 @@ cwd(): string
**示例:** **示例:**
```js ```js
var path = process.cwd(); let path = process.cwd();
``` ```
...@@ -588,7 +588,7 @@ uptime(): number ...@@ -588,7 +588,7 @@ uptime(): number
**示例:** **示例:**
```js ```js
var time = process.uptime(); let time = process.uptime();
``` ```
...@@ -616,6 +616,6 @@ kill(signal: number, pid: number): boolean ...@@ -616,6 +616,6 @@ kill(signal: number, pid: number): boolean
**示例:** **示例:**
```js ```js
var pres = process.pid let pres = process.pid
var result = process.kill(28, pres) let result = process.kill(28, pres)
``` ```
...@@ -46,7 +46,7 @@ constructor是URI的构造函数。 ...@@ -46,7 +46,7 @@ constructor是URI的构造函数。
**示例:** **示例:**
```js ```js
var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; let mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
``` ```
```js ```js
......
...@@ -30,11 +30,11 @@ URLSearchParams的构造函数。 ...@@ -30,11 +30,11 @@ URLSearchParams的构造函数。
**示例:** **示例:**
```js ```js
var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); let objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
var objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'}); let objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'});
var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); let objectParams2 = new Url.URLSearchParams('?fod=1&bard=2');
var urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2');
var params = new Url.URLSearchParams(urlObject.search); let params = new Url.URLSearchParams(urlObject.search);
``` ```
...@@ -132,7 +132,7 @@ entries(): IterableIterator<[string, string]> ...@@ -132,7 +132,7 @@ entries(): IterableIterator<[string, string]>
**示例:** **示例:**
```js ```js
var searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); let searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]); console.log(pair[0]+ ', '+ pair[1]);
} }
...@@ -196,9 +196,9 @@ get(name: string): string | null ...@@ -196,9 +196,9 @@ get(name: string): string | null
**示例:** **示例:**
```js ```js
var paramsOject = new Url.URLSearchParams('name=Jonathan&age=18'); let paramsOject = new Url.URLSearchParams('name=Jonathan&age=18');
var name = paramsOject.get("name"); // is the string "Jonathan" let name = paramsOject.get("name"); // is the string "Jonathan"
var age = parseInt(paramsOject.get("age"), 10); // is the number 18 let age = parseInt(paramsOject.get("age"), 10); // is the number 18
``` ```
...@@ -266,7 +266,7 @@ sort(): void ...@@ -266,7 +266,7 @@ sort(): void
**示例:** **示例:**
```js ```js
var searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object let searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object
searchParamsObject.sort(); // Sort the key/value pairs searchParamsObject.sort(); // Sort the key/value pairs
console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4
``` ```
...@@ -289,7 +289,7 @@ keys(): IterableIterator&lt;string&gt; ...@@ -289,7 +289,7 @@ keys(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```js
var searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing let searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var key of searchParamsObject .keys()) { // Output key-value pairs for (var key of searchParamsObject .keys()) { // Output key-value pairs
console.log(key); console.log(key);
} }
...@@ -313,8 +313,8 @@ values(): IterableIterator&lt;string&gt; ...@@ -313,8 +313,8 @@ values(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```js
var searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing let searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var value of searchParams.values()) { for (var value of searchParams.values()) {
console.log(value); console.log(value);
} }
``` ```
...@@ -338,7 +338,7 @@ for (var value of searchParams.values()) { ...@@ -338,7 +338,7 @@ for (var value of searchParams.values()) {
```js ```js
const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap'); const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject) { for (const [name, value] of paramsObject) {
console.log(name, value); console.log(name, value);
} }
``` ```
...@@ -408,11 +408,11 @@ URL的构造函数。 ...@@ -408,11 +408,11 @@ URL的构造函数。
**示例:** **示例:**
```js ```js
var mm = 'http://username:password@host:8080'; let mm = 'http://username:password@host:8080';
var a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; let a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/';
var b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; let b = new Url.URL(mm); // Output 'http://username:password@host:8080/';
new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1';
var c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; let c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1';
new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1';
new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1';
new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1
......
...@@ -31,9 +31,9 @@ XmlSerializer的构造函数。 ...@@ -31,9 +31,9 @@ XmlSerializer的构造函数。
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer); let bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(bufView);
``` ```
...@@ -55,9 +55,9 @@ setAttributes(name: string, value: string): void ...@@ -55,9 +55,9 @@ setAttributes(name: string, value: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer); let bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(bufView);
thatSer.setAttributes("importance", "high"); thatSer.setAttributes("importance", "high");
``` ```
...@@ -79,9 +79,9 @@ addEmptyElement(name: string): void ...@@ -79,9 +79,9 @@ addEmptyElement(name: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer); let bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(bufView);
thatSer.addEmptyElement("b"); // => <b/> thatSer.addEmptyElement("b"); // => <b/>
``` ```
...@@ -97,9 +97,9 @@ setDeclaration(): void ...@@ -97,9 +97,9 @@ setDeclaration(): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer); let bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(bufView);
thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>; thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>;
``` ```
...@@ -121,8 +121,8 @@ startElement(name: string): void ...@@ -121,8 +121,8 @@ startElement(name: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("notel"); thatSer.startElement("notel");
thatSer.endElement();// => '<notel/>'; thatSer.endElement();// => '<notel/>';
``` ```
...@@ -139,9 +139,9 @@ endElement(): void ...@@ -139,9 +139,9 @@ endElement(): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer); let bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(bufView);
thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("table"); thatSer.startElement("table");
thatSer.setAttributes("importance", "high"); thatSer.setAttributes("importance", "high");
...@@ -168,8 +168,8 @@ setNamespace(prefix: string, namespace: string): void ...@@ -168,8 +168,8 @@ setNamespace(prefix: string, namespace: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDeclaration(); thatSer.setDeclaration();
thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("note"); thatSer.startElement("note");
...@@ -193,8 +193,8 @@ setComment(text: string): void ...@@ -193,8 +193,8 @@ setComment(text: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note"); thatSer.startElement("note");
thatSer.setComment("Hi!"); thatSer.setComment("Hi!");
thatSer.endElement(); // => '<note>\r\n <!--Hi!-->\r\n</note>'; thatSer.endElement(); // => '<note>\r\n <!--Hi!-->\r\n</note>';
...@@ -218,8 +218,8 @@ setCDATA(text: string): void ...@@ -218,8 +218,8 @@ setCDATA(text: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1028); let arrayBuffer = new ArrayBuffer(1028);
var thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setCDATA('root SYSTEM') // => '<![CDATA[root SYSTEM]]>'; thatSer.setCDATA('root SYSTEM') // => '<![CDATA[root SYSTEM]]>';
``` ```
...@@ -241,8 +241,8 @@ setText(text: string): void ...@@ -241,8 +241,8 @@ setText(text: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note"); thatSer.startElement("note");
thatSer.setAttributes("importance", "high"); thatSer.setAttributes("importance", "high");
thatSer.setText("Happy1"); thatSer.setText("Happy1");
...@@ -267,8 +267,8 @@ setDocType(text: string): void ...@@ -267,8 +267,8 @@ setDocType(text: string): void
**示例:** **示例:**
```js ```js
var arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(1024);
var thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDocType('root SYSTEM'); // => '<!DOCTYPE root SYSTEM>'; thatSer.setDocType('root SYSTEM'); // => '<!DOCTYPE root SYSTEM>';
``` ```
...@@ -294,20 +294,20 @@ constructor(buffer: ArrayBuffer | DataView, encoding?: string) ...@@ -294,20 +294,20 @@ constructor(buffer: ArrayBuffer | DataView, encoding?: string)
**示例:** **示例:**
```js ```js
var strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' + '<note importance="high" logged="true">' +
' <title>Happy</title>' + ' <title>Happy</title>' +
' <todo>Work</todo>' + ' <todo>Work</todo>' +
' <todo>Play</todo>' + ' <todo>Play</todo>' +
'</note>'; '</note>';
var arrayBuffer = new ArrayBuffer(strXml.length); let arrayBuffer = new ArrayBuffer(strXml.length);
var bufView = new Uint8Array(arrayBuffer); let bufView = new Uint8Array(arrayBuffer);
var strLen = strXml.length; let strLen = strXml.length;
for (var i = 0; i < strLen; ++i) { for (var i = 0; i < strLen; ++i) {
bufView[i] = strXml.charCodeAt(i);//设置arraybuffer方式 bufView[i] = strXml.charCodeAt(i);//设置arraybuffer方式
} }
var that = new xml.XmlPullParser(arrayBuffer); let that = new xml.XmlPullParser(arrayBuffer);
``` ```
...@@ -328,30 +328,30 @@ parse(option: ParseOptions): void ...@@ -328,30 +328,30 @@ parse(option: ParseOptions): void
**示例:** **示例:**
```js ```js
var strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' + '<note importance="high" logged="true">' +
' <title>Happy</title>' + ' <title>Happy</title>' +
' <todo>Work</todo>' + ' <todo>Work</todo>' +
' <todo>Play</todo>' + ' <todo>Play</todo>' +
'</note>'; '</note>';
var arrayBuffer = new ArrayBuffer(strXml.length); let arrayBuffer = new ArrayBuffer(strXml.length);
var bufView = new Uint8Array(arrayBuffer); let bufView = new Uint8Array(arrayBuffer);
var strLen = strXml.length; let strLen = strXml.length;
for (var i = 0; i < strLen; ++i) { for (var i = 0; i < strLen; ++i) {
bufView[i] = strXml.charCodeAt(i); bufView[i] = strXml.charCodeAt(i);
} }
var that = new xml.XmlPullParser(arrayBuffer); let that = new xml.XmlPullParser(arrayBuffer);
var arrTag = {}; let arrTag = {};
var str = ""; let str = "";
var i = 0; let i = 0;
function func(key, value){ function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); arrTag[i] = 'key:'+key+' value:'+ value.getDepth();
str += arrTag[i]; str += arrTag[i];
i++; i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing. return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
} }
var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册