提交 2d019435 编写于 作者: G Gloria

Update docs against 8302+8786+9246+9345+9687+9651

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 11a50470
...@@ -64,8 +64,8 @@ This is a system API and cannot be called by third-party applications. ...@@ -64,8 +64,8 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
```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);
}) })
...@@ -91,8 +91,8 @@ This is a system API and cannot be called by third-party applications. ...@@ -91,8 +91,8 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
```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);
}) })
...@@ -118,8 +118,8 @@ This is a system API and cannot be called by third-party applications. ...@@ -118,8 +118,8 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
```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);
}) })
...@@ -139,7 +139,7 @@ This is a system API and cannot be called by third-party applications. ...@@ -139,7 +139,7 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
```js ```js
var child = process.runCmd('sleep 5; ls'); let child = process.runCmd('sleep 5; ls');
child.close(); child.close();
``` ```
...@@ -163,7 +163,7 @@ This is a system API and cannot be called by third-party applications. ...@@ -163,7 +163,7 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
```js ```js
var child = process.runCmd('sleep 5; ls'); let child = process.runCmd('sleep 5; ls');
child.kill(9); child.kill(9);
``` ```
...@@ -185,7 +185,7 @@ Checks whether this process is isolated. ...@@ -185,7 +185,7 @@ Checks whether this process is isolated.
**Example** **Example**
```js ```js
var result = process.isIsolatedProcess(); let result = process.isIsolatedProcess();
``` ```
...@@ -212,7 +212,7 @@ Checks whether a UID belongs to this app. ...@@ -212,7 +212,7 @@ Checks whether a UID belongs to this app.
**Example** **Example**
```js ```js
var result = process.isAppUid(688); let result = process.isAppUid(688);
``` ```
...@@ -233,7 +233,7 @@ Checks whether this process is running in a 64-bit environment. ...@@ -233,7 +233,7 @@ Checks whether this process is running in a 64-bit environment.
**Example** **Example**
```js ```js
var result = process.is64Bit(); let result = process.is64Bit();
``` ```
...@@ -260,7 +260,7 @@ Obtains the process UID based on the process name. ...@@ -260,7 +260,7 @@ Obtains the process UID based on the process name.
**Example** **Example**
```js ```js
var pres = process.getUidForName("tool") let pres = process.getUidForName("tool")
``` ```
...@@ -287,8 +287,8 @@ Obtains the thread priority based on the specified TID. ...@@ -287,8 +287,8 @@ Obtains the thread priority based on the specified TID.
**Example** **Example**
```js ```js
var tid = process.tid; let tid = process.tid;
var pres = process.getThreadPriority(tid); let pres = process.getThreadPriority(tid);
``` ```
...@@ -309,7 +309,7 @@ Obtains the duration, in milliseconds, from the time the system starts to the ti ...@@ -309,7 +309,7 @@ Obtains the duration, in milliseconds, from the time the system starts to the ti
**Example** **Example**
```js ```js
var realtime = process.getStartRealtime(); let realtime = process.getStartRealtime();
``` ```
## process.getPastCpuTime<sup>8+</sup> ## process.getPastCpuTime<sup>8+</sup>
...@@ -329,7 +329,7 @@ Obtains the CPU time (in milliseconds) from the time the process starts to the c ...@@ -329,7 +329,7 @@ Obtains the CPU time (in milliseconds) from the time the process starts to the c
**Example** **Example**
```js ```js
var result = process.getPastCpuTime() ; let result = process.getPastCpuTime() ;
``` ```
...@@ -356,8 +356,8 @@ Obtains the system configuration. ...@@ -356,8 +356,8 @@ Obtains the system configuration.
**Example** **Example**
```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)
``` ```
...@@ -384,7 +384,7 @@ Obtains the value of an environment variable. ...@@ -384,7 +384,7 @@ Obtains the value of an environment variable.
**Example** **Example**
```js ```js
var pres = process.getEnvironmentVar("PATH") let pres = process.getEnvironmentVar("PATH")
``` ```
...@@ -422,8 +422,8 @@ This is a system API and cannot be called by third-party applications. ...@@ -422,8 +422,8 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
```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);
}) })
...@@ -505,7 +505,7 @@ This is a system API and cannot be called by third-party applications. ...@@ -505,7 +505,7 @@ This is a system API and cannot be called by third-party applications.
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");
``` ```
...@@ -545,7 +545,7 @@ This is a system API and cannot be called by third-party applications. ...@@ -545,7 +545,7 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
```js ```js
var path = process.cwd(); let path = process.cwd();
``` ```
...@@ -589,7 +589,7 @@ Obtains the running time of this process. ...@@ -589,7 +589,7 @@ Obtains the running time of this process.
**Example** **Example**
```js ```js
var time = process.uptime(); let time = process.uptime();
``` ```
...@@ -617,6 +617,6 @@ Sends a signal to the specified process to terminate it. ...@@ -617,6 +617,6 @@ Sends a signal to the specified process to terminate it.
**Example** **Example**
```js ```js
var pres = process.pid let pres = process.pid
var result = process.kill(28, pres) let result = process.kill(28, pres)
``` ```
...@@ -47,7 +47,7 @@ A constructor used to create a URI instance. ...@@ -47,7 +47,7 @@ A constructor used to create a URI instance.
**Example** **Example**
```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
......
...@@ -26,16 +26,16 @@ Creates a **URLSearchParams** instance. ...@@ -26,16 +26,16 @@ Creates a **URLSearchParams** instance.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| init | string[][]&nbsp;\|&nbsp;Record&lt;string,&nbsp;string&gt;&nbsp;\|&nbsp;string&nbsp;\|&nbsp;URLSearchParams | No| Input parameter objects, which include the following:<br>- **string[][]**: two-dimensional string array<br>- **Record&lt;string,&nbsp;string&gt;**: list of objects<br>- **string**: string<br>- **URLSearchParams**: object| | init | string[][] \| Record&lt;string, string&gt; \| string \| URLSearchParams | No| Input parameter objects, which include the following:<br>- **string[][]**: two-dimensional string array<br>- **Record&lt;string, string&gt;**: list of objects<br>- **string**: string<br>- **URLSearchParams**: object|
**Example** **Example**
```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);
``` ```
...@@ -133,7 +133,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ...@@ -133,7 +133,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
**Example** **Example**
```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]);
} }
...@@ -197,9 +197,9 @@ Obtains the value of the first key-value pair based on the specified key. ...@@ -197,9 +197,9 @@ Obtains the value of the first key-value pair based on the specified key.
**Example** **Example**
```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
``` ```
...@@ -267,7 +267,7 @@ Sorts all key-value pairs contained in this object based on the Unicode code poi ...@@ -267,7 +267,7 @@ Sorts all key-value pairs contained in this object based on the Unicode code poi
**Example** **Example**
```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
``` ```
...@@ -290,7 +290,7 @@ Obtains an ES6 iterator that contains the keys of all the key-value pairs. ...@@ -290,7 +290,7 @@ Obtains an ES6 iterator that contains the keys of all the key-value pairs.
**Example** **Example**
```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);
} }
...@@ -314,7 +314,7 @@ Obtains an ES6 iterator that contains the values of all the key-value pairs. ...@@ -314,7 +314,7 @@ Obtains an ES6 iterator that contains the values of all the key-value pairs.
**Example** **Example**
```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);
} }
...@@ -409,11 +409,11 @@ Creates a URL. ...@@ -409,11 +409,11 @@ Creates a URL.
**Example** **Example**
```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
......
...@@ -24,19 +24,21 @@ Prints the input content in a formatted string. ...@@ -24,19 +24,21 @@ Prints the input content in a formatted string.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| format | string | Yes| Format of the string to print.| | format | string | Yes| Format of the string to print.|
| ...args | Object[] | No| Data to format.| | ...args | Object[] | No| Data to format.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String in the specified format.| | string | String in the specified format.|
**Example** **Example**
```js ```js
var res = util.printf("%s", "hello world!"); let res = util.printf("%s", "hello world!");
console.log(res); console.log(res);
``` ```
...@@ -50,19 +52,21 @@ Obtains detailed information about a system error code. ...@@ -50,19 +52,21 @@ Obtains detailed information about a system error code.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| errno | number | Yes| Error code generated.| | errno | number | Yes| Error code generated.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Detailed information about the error code.| | string | Detailed information about the error code.|
**Example** **Example**
```js ```js
var errnum = 10; // 10 is a system error code. let errnum = 10; // 10 is a system error code.
var result = util.getErrorString(errnum); let result = util.getErrorString(errnum);
console.log("result = " + result); console.log("result = " + result);
``` ```
...@@ -82,6 +86,7 @@ Calls back an asynchronous function. In the callback, the first parameter indica ...@@ -82,6 +86,7 @@ Calls back an asynchronous function. In the callback, the first parameter indica
| original | Function | Yes| Asynchronous function.| | original | Function | Yes| Asynchronous function.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Function | Callback, in which the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved) and the second parameter indicates the resolved value.| | Function | Callback, in which the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved) and the second parameter indicates the resolved value.|
...@@ -91,8 +96,8 @@ Calls back an asynchronous function. In the callback, the first parameter indica ...@@ -91,8 +96,8 @@ Calls back an asynchronous function. In the callback, the first parameter indica
async function promiseFn() { async function promiseFn() {
return Promise.reject('value'); return Promise.reject('value');
} }
var err = "type err"; let err = "type err";
var cb = util.callbackWrapper(promiseFn); let cb = util.callbackWrapper(promiseFn);
cb((err, ret) => { cb((err, ret) => {
console.log(err); console.log(err);
console.log(ret); console.log(ret);
...@@ -105,7 +110,6 @@ Calls back an asynchronous function. In the callback, the first parameter indica ...@@ -105,7 +110,6 @@ Calls back an asynchronous function. In the callback, the first parameter indica
promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
> **NOTE** > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use **[util.promisify9+](#utilpromisify9)** instead. > This API is deprecated since API version 9. You are advised to use **[util.promisify9+](#utilpromisify9)** instead.
Processes an asynchronous function and returns a promise version. Processes an asynchronous function and returns a promise version.
...@@ -119,9 +123,10 @@ Processes an asynchronous function and returns a promise version. ...@@ -119,9 +123,10 @@ Processes an asynchronous function and returns a promise version.
| original | Function | Yes| Asynchronous function.| | original | Function | Yes| Asynchronous function.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise version.| | Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
## util.promisify<sup>9+</sup> ## util.promisify<sup>9+</sup>
...@@ -132,11 +137,13 @@ Processes an asynchronous function and returns a promise. ...@@ -132,11 +137,13 @@ Processes an asynchronous function and returns a promise.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.| | original | Function | Yes| Asynchronous function.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.| | Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
...@@ -156,6 +163,90 @@ Processes an asynchronous function and returns a promise. ...@@ -156,6 +163,90 @@ Processes an asynchronous function and returns a promise.
}) })
``` ```
## util.randomUUID<sup>9+</sup>
randomUUID(entropyCache?: boolean): string
Uses a secure random number generator to generate a random universally unique identifier (UUID) of RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | A string representing the UUID generated.|
**Example**
```js
let uuid = util.randomUUID(true);
console.log("RFC 4122 Version 4 UUID:" + uuid);
// Output:
// RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
```
## util.randomBinaryUUID<sup>9+</sup>
randomBinaryUUID(entropyCache?: boolean): Uint8Array
Uses a secure random number generator to generate a random binary UUID of RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.|
**Return value**
| Type| Description|
| -------- | -------- |
| Uint8Array | A Uint8Array value representing the UUID generated.|
**Example**
```js
let uuid = util.randomBinaryUUID(true);
console.log(JSON.stringify(uuid));
// Output:
// 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150
```
## util.parseUUID<sup>9+</sup>
parseUUID(uuid: string): Uint8Array
Parses a UUID from a string, as described in RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uuid | string | Yes| A string representing the UUID.|
**Return value**
| Type| Description|
| -------- | -------- |
| Uint8Array | A Uint8Array value representing the UUID parsed. If the parsing fails, **SyntaxError** is thrown.|
**Example**
```js
let uuid = util.parseUUID("84bdf796-66cc-4655-9b89-d6218d100f9c");
console.log(JSON.stringify(uuid));
// Output:
// 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156
```
## TextDecoder ## TextDecoder
### Attributes ### Attributes
...@@ -178,6 +269,7 @@ A constructor used to create a **TextDecoder** object. ...@@ -178,6 +269,7 @@ A constructor used to create a **TextDecoder** object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.| | encoding | string | No| Encoding format.|
...@@ -192,7 +284,7 @@ A constructor used to create a **TextDecoder** object. ...@@ -192,7 +284,7 @@ A constructor used to create a **TextDecoder** object.
**Example** **Example**
```js ```js
var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
``` ```
...@@ -205,6 +297,7 @@ Decodes the input content. ...@@ -205,6 +297,7 @@ Decodes the input content.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| input | Uint8Array | Yes| Uint8Array to decode.| | input | Uint8Array | Yes| Uint8Array to decode.|
...@@ -217,14 +310,15 @@ Decodes the input content. ...@@ -217,14 +310,15 @@ Decodes the input content.
| stream | boolean | No| Whether to allow data blocks in subsequent **decode()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.| | stream | boolean | No| Whether to allow data blocks in subsequent **decode()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Data decoded.| | string | Data decoded.|
**Example** **Example**
```js ```js
var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
var result = new Uint8Array(6); let result = new Uint8Array(6);
result[0] = 0xEF; result[0] = 0xEF;
result[1] = 0xBB; result[1] = 0xBB;
result[2] = 0xBF; result[2] = 0xBF;
...@@ -232,7 +326,50 @@ Decodes the input content. ...@@ -232,7 +326,50 @@ Decodes the input content.
result[4] = 0x62; result[4] = 0x62;
result[5] = 0x63; result[5] = 0x63;
console.log("input num:"); console.log("input num:");
var retStr = textDecoder.decode( result , {stream: false}); let retStr = textDecoder.decode( result , {stream: false});
console.log("retStr = " + retStr);
```
### decodeWithStream<sup>9+</sup>
decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string
Decodes the input content.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| input | Uint8Array | Yes| Uint8Array to decode.|
| options | Object | No| Options related to decoding.|
**Table 2** options
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| stream | boolean | No| Whether to allow data blocks in subsequent **decodeWithStream()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Data decoded.|
**Example**
```js
let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
let result = new Uint8Array(6);
result[0] = 0xEF;
result[1] = 0xBB;
result[2] = 0xBF;
result[3] = 0x61;
result[4] = 0x62;
result[5] = 0x63;
console.log("input num:");
let retStr = textDecoder.decodeWithStream( result , {stream: false});
console.log("retStr = " + retStr); console.log("retStr = " + retStr);
``` ```
...@@ -258,7 +395,7 @@ A constructor used to create a **TextEncoder** object. ...@@ -258,7 +395,7 @@ A constructor used to create a **TextEncoder** object.
**Example** **Example**
```js ```js
var textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
``` ```
...@@ -271,20 +408,22 @@ Encodes the input content. ...@@ -271,20 +408,22 @@ Encodes the input content.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| input | string | Yes| String to encode.| | input | string | Yes| String to encode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Uint8Array | Encoded text.| | Uint8Array | Encoded text.|
**Example** **Example**
```js ```js
var textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
var buffer = new ArrayBuffer(20); let buffer = new ArrayBuffer(20);
var result = new Uint8Array(buffer); let result = new Uint8Array(buffer);
result = textEncoder.encode("\uD800¥¥"); result = textEncoder.encode("\uD800¥¥");
``` ```
...@@ -298,22 +437,24 @@ Stores the UTF-8 encoded text. ...@@ -298,22 +437,24 @@ Stores the UTF-8 encoded text.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| input | string | Yes| String to encode.| | input | string | Yes| String to encode.|
| dest | Uint8Array | Yes| **Uint8Array** instance used to store the UTF-8 encoded text.| | dest | Uint8Array | Yes| **Uint8Array** instance used to store the UTF-8 encoded text.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Uint8Array | Encoded text.| | Uint8Array | Encoded text.|
**Example** **Example**
```js ```js
var that = new util.TextEncoder() let that = new util.TextEncoder()
var buffer = new ArrayBuffer(4) let buffer = new ArrayBuffer(4)
var dest = new Uint8Array(buffer) let dest = new Uint8Array(buffer)
var result = new Object() let result = new Object()
result = that.encodeInto('abcd', dest) result = that.encodeInto('abcd', dest)
``` ```
...@@ -329,6 +470,7 @@ A constructor used to create a **RationalNumber** object. ...@@ -329,6 +470,7 @@ A constructor used to create a **RationalNumber** object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| numerator | number | Yes| Numerator, which is an integer.| | numerator | number | Yes| Numerator, which is an integer.|
...@@ -336,7 +478,7 @@ A constructor used to create a **RationalNumber** object. ...@@ -336,7 +478,7 @@ A constructor used to create a **RationalNumber** object.
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
``` ```
...@@ -349,19 +491,21 @@ Creates a **RationalNumber** object based on the given string. ...@@ -349,19 +491,21 @@ Creates a **RationalNumber** object based on the given string.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| rationalString | string | Yes| String used to create the **RationalNumber** object.| | rationalString | string | Yes| String used to create the **RationalNumber** object.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| object | **RationalNumber** object created.| | object | **RationalNumber** object created.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var rational = util.RationalNumber.createRationalFromString("3/4"); let rational = util.RationalNumber.createRationalFromString("3/4");
``` ```
...@@ -374,20 +518,22 @@ Compares this **RationalNumber** object with a given object. ...@@ -374,20 +518,22 @@ Compares this **RationalNumber** object with a given object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.| | another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.| | number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var rational = util.RationalNumber.createRationalFromString("3/4"); let rational = util.RationalNumber.createRationalFromString("3/4");
var result = rationalNumber.compareTo(rational); let result = rationalNumber.compareTo(rational);
``` ```
...@@ -400,14 +546,15 @@ Obtains the value of this **RationalNumber** object as an integer or a floating- ...@@ -400,14 +546,15 @@ Obtains the value of this **RationalNumber** object as an integer or a floating-
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | An integer or a floating-point number.| | number | An integer or a floating-point number.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = rationalNumber.valueOf(); let result = rationalNumber.valueOf();
``` ```
...@@ -420,20 +567,22 @@ Checks whether this **RationalNumber** object equals the given object. ...@@ -420,20 +567,22 @@ Checks whether this **RationalNumber** object equals the given object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| object | Object | Yes| Object used to compare with this **RationalNumber** object.| | object | Object | Yes| Object used to compare with this **RationalNumber** object.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the two objects are equal; returns **false** otherwise.| | boolean | Returns **true** if the two objects are equal; returns **false** otherwise.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var rational = util.RationalNumber.createRationalFromString("3/4"); let rational = util.RationalNumber.createRationalFromString("3/4");
var result = rationalNumber.equals(rational); let result = rationalNumber.equals(rational);
``` ```
...@@ -446,20 +595,22 @@ Obtains the greatest common divisor of two specified integers. ...@@ -446,20 +595,22 @@ Obtains the greatest common divisor of two specified integers.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| number1 | number | Yes| The first integer used to get the greatest common divisor.| | number1 | number | Yes| The first integer used to get the greatest common divisor.|
| number2 | number | Yes| The second integer used to get the greatest common divisor.| | number2 | number | Yes| The second integer used to get the greatest common divisor.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Greatest common divisor obtained.| | number | Greatest common divisor obtained.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = util.RationalNumber.getCommonDivisor(4,6); let result = util.RationalNumber.getCommonDivisor(4,6);
``` ```
...@@ -479,8 +630,8 @@ Obtains the numerator of this **RationalNumber** object. ...@@ -479,8 +630,8 @@ Obtains the numerator of this **RationalNumber** object.
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = rationalNumber.getNumerator(); let result = rationalNumber.getNumerator();
``` ```
...@@ -493,14 +644,15 @@ Obtains the denominator of this **RationalNumber** object. ...@@ -493,14 +644,15 @@ Obtains the denominator of this **RationalNumber** object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Denominator of this **RationalNumber** object.| | number | Denominator of this **RationalNumber** object.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = rationalNumber.getDenominator(); let result = rationalNumber.getDenominator();
``` ```
...@@ -513,14 +665,15 @@ Checks whether this **RationalNumber** object is **0**. ...@@ -513,14 +665,15 @@ Checks whether this **RationalNumber** object is **0**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.| | boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = rationalNumber.isZero(); let result = rationalNumber.isZero();
``` ```
...@@ -533,14 +686,15 @@ Checks whether this **RationalNumber** object is a Not a Number (NaN). ...@@ -533,14 +686,15 @@ Checks whether this **RationalNumber** object is a Not a Number (NaN).
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.| | boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = rationalNumber.isNaN(); let result = rationalNumber.isNaN();
``` ```
...@@ -553,14 +707,15 @@ Checks whether this **RationalNumber** object represents a finite value. ...@@ -553,14 +707,15 @@ Checks whether this **RationalNumber** object represents a finite value.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.| | boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = rationalNumber.isFinite(); let result = rationalNumber.isFinite();
``` ```
...@@ -573,14 +728,15 @@ Obtains the string representation of this **RationalNumber** object. ...@@ -573,14 +728,15 @@ Obtains the string representation of this **RationalNumber** object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Returns **NaN** if the numerator and denominator of this object are both **0**; returns a string in Numerator/Denominator format otherwise, for example, **3/5**.| | string | Returns **NaN** if the numerator and denominator of this object are both **0**; returns a string in Numerator/Denominator format otherwise, for example, **3/5**.|
**Example** **Example**
```js ```js
var rationalNumber = new util.RationalNumber(1,2); let rationalNumber = new util.RationalNumber(1,2);
var result = rationalNumber.toString(); let result = rationalNumber.toString();
``` ```
## LruBuffer<sup>8+</sup> ## LruBuffer<sup>8+</sup>
...@@ -595,10 +751,10 @@ Obtains the string representation of this **RationalNumber** object. ...@@ -595,10 +751,10 @@ Obtains the string representation of this **RationalNumber** object.
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
pro.put(1,8); pro.put(1,8);
var result = pro.length; let result = pro.length;
``` ```
...@@ -611,13 +767,14 @@ A constructor used to create an **LruBuffer** instance. The default capacity of ...@@ -611,13 +767,14 @@ A constructor used to create an **LruBuffer** instance. The default capacity of
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| capacity | number | No| Capacity of the **LruBuffer** to create.| | capacity | number | No| Capacity of the **LruBuffer** to create.|
**Example** **Example**
```js ```js
var lrubuffer= new util.LruBuffer(); let lrubuffer= new util.LruBuffer();
``` ```
...@@ -630,14 +787,15 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to ...@@ -630,14 +787,15 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| newCapacity | number | Yes| New capacity of the **LruBuffer**.| | newCapacity | number | Yes| New capacity of the **LruBuffer**.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
var result = pro.updateCapacity(100); let result = pro.updateCapacity(100);
``` ```
...@@ -650,17 +808,18 @@ Obtains the string representation of this **LruBuffer** object. ...@@ -650,17 +808,18 @@ Obtains the string representation of this **LruBuffer** object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String representation of this **LruBuffer** object.| | string | String representation of this **LruBuffer** object.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
pro.get(2); pro.get(2);
pro.remove(20); pro.remove(20);
var result = pro.toString(); let result = pro.toString();
``` ```
...@@ -673,14 +832,15 @@ Obtains the capacity of this buffer. ...@@ -673,14 +832,15 @@ Obtains the capacity of this buffer.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Capacity of this buffer.| | number | Capacity of this buffer.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
var result = pro.getCapacity(); let result = pro.getCapacity();
``` ```
...@@ -694,9 +854,9 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c ...@@ -694,9 +854,9 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.length; let result = pro.length;
pro.clear(); pro.clear();
``` ```
...@@ -710,15 +870,16 @@ Obtains the number of return values for **createDefault()**. ...@@ -710,15 +870,16 @@ Obtains the number of return values for **createDefault()**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Number of return values for **createDefault()**.| | number | Number of return values for **createDefault()**.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(1,8); pro.put(1,8);
var result = pro.getCreateCount(); let result = pro.getCreateCount();
``` ```
...@@ -731,16 +892,17 @@ Obtains the number of times that the queried values are mismatched. ...@@ -731,16 +892,17 @@ Obtains the number of times that the queried values are mismatched.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Number of times that the queried values are mismatched.| | number | Number of times that the queried values are mismatched.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
pro.get(2); pro.get(2);
var result = pro.getMissCount(); let result = pro.getMissCount();
``` ```
...@@ -753,17 +915,18 @@ Obtains the number of removals from this buffer. ...@@ -753,17 +915,18 @@ Obtains the number of removals from this buffer.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Number of removals from the buffer.| | number | Number of removals from the buffer.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
pro.updateCapacity(2); pro.updateCapacity(2);
pro.put(50,22); pro.put(50,22);
var result = pro.getRemovalCount(); let result = pro.getRemovalCount();
``` ```
...@@ -776,16 +939,17 @@ Obtains the number of times that the queried values are matched. ...@@ -776,16 +939,17 @@ Obtains the number of times that the queried values are matched.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Number of times that the queried values are matched.| | number | Number of times that the queried values are matched.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
pro.get(2); pro.get(2);
var result = pro.getMatchCount(); let result = pro.getMatchCount();
``` ```
...@@ -798,15 +962,16 @@ Obtains the number of additions to this buffer. ...@@ -798,15 +962,16 @@ Obtains the number of additions to this buffer.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Number of additions to the buffer.| | number | Number of additions to the buffer.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.getPutCount(); let result = pro.getPutCount();
``` ```
...@@ -819,15 +984,16 @@ Checks whether this buffer is empty. ...@@ -819,15 +984,16 @@ Checks whether this buffer is empty.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the buffer does not contain any value.| | boolean | Returns **true** if the buffer does not contain any value.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.isEmpty(); let result = pro.isEmpty();
``` ```
...@@ -840,20 +1006,22 @@ Obtains the value of the specified key. ...@@ -840,20 +1006,22 @@ Obtains the value of the specified key.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | K | Yes| Key based on which the value is queried.| | key | K | Yes| Key based on which the value is queried.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.| | V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.get(2); let result = pro.get(2);
``` ```
...@@ -866,23 +1034,24 @@ Adds a key-value pair to this buffer. ...@@ -866,23 +1034,24 @@ Adds a key-value pair to this buffer.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | K | Yes| Key of the key-value pair to add.| | key | K | Yes| Key of the key-value pair to add.|
| value | V | Yes| Value of the key-value pair to add.| | value | V | Yes| Value of the key-value pair to add.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. | | V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. |
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
var result = pro.put(2,10); let result = pro.put(2,10);
``` ```
### values<sup>8+</sup> ### values<sup>8+</sup>
values(): V[] values(): V[]
...@@ -892,17 +1061,18 @@ Obtains all values in this buffer, listed from the most to the least recently ac ...@@ -892,17 +1061,18 @@ Obtains all values in this buffer, listed from the most to the least recently ac
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| V [] | All values in the buffer, listed from the most to the least recently accessed.| | V [] | All values in the buffer, listed from the most to the least recently accessed.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
pro.put(2,"anhu"); pro.put(2,"anhu");
pro.put("afaf","grfb"); pro.put("afaf","grfb");
var result = pro.values(); let result = pro.values();
``` ```
...@@ -915,15 +1085,16 @@ Obtains all keys in this buffer, listed from the most to the least recently acce ...@@ -915,15 +1085,16 @@ Obtains all keys in this buffer, listed from the most to the least recently acce
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| K [] | All keys in the buffer, listed from the most to the least recently accessed.| | K [] | All keys in the buffer, listed from the most to the least recently accessed.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.keys(); let result = pro.keys();
``` ```
...@@ -936,20 +1107,22 @@ Removes the specified key and its value from this buffer. ...@@ -936,20 +1107,22 @@ Removes the specified key and its value from this buffer.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | K | Yes| Key to remove.| | key | K | Yes| Key to remove.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| V \| undefind | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.| | V \| undefind | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.remove(20); let result = pro.remove(20);
``` ```
...@@ -962,6 +1135,7 @@ Performs subsequent operations after a value is removed. ...@@ -962,6 +1135,7 @@ Performs subsequent operations after a value is removed.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.| | isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
...@@ -971,8 +1145,8 @@ Performs subsequent operations after a value is removed. ...@@ -971,8 +1145,8 @@ Performs subsequent operations after a value is removed.
**Example** **Example**
```js ```js
var arr = []; let arr = [];
class ChildLruBuffer extends util.LruBuffer class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
{ {
constructor() constructor()
{ {
...@@ -986,7 +1160,7 @@ Performs subsequent operations after a value is removed. ...@@ -986,7 +1160,7 @@ Performs subsequent operations after a value is removed.
} }
} }
} }
var lru = new ChildLruBuffer(); let lru = new ChildLruBuffer();
lru.afterRemoval(false,10,30,null); lru.afterRemoval(false,10,30,null);
``` ```
...@@ -1000,20 +1174,22 @@ Checks whether this buffer contains the specified key. ...@@ -1000,20 +1174,22 @@ Checks whether this buffer contains the specified key.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | K | Yes| Key to check.| | key | K | Yes| Key to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.| | boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.contains(20); let result = pro.contains(20);
``` ```
...@@ -1026,19 +1202,21 @@ Creates a value if the value of the specified key is not available. ...@@ -1026,19 +1202,21 @@ Creates a value if the value of the specified key is not available.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | K | Yes| Key of which the value is missing.| | key | K | Yes| Key of which the value is missing.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| V | Value of the key.| | V | Value of the key.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
var result = pro.createDefault(50); let result = pro.createDefault(50);
``` ```
...@@ -1051,15 +1229,16 @@ Obtains a new iterator object that contains all key-value pairs in this object. ...@@ -1051,15 +1229,16 @@ Obtains a new iterator object that contains all key-value pairs in this object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [K, V] | Iterable array.| | [K, V] | Iterable array.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro.entries(); let result = pro.entries();
``` ```
...@@ -1072,15 +1251,16 @@ Obtains a two-dimensional array in key-value pairs. ...@@ -1072,15 +1251,16 @@ Obtains a two-dimensional array in key-value pairs.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [K, V] | Two-dimensional array in key-value pairs.| | [K, V] | Two-dimensional array in key-value pairs.|
**Example** **Example**
```js ```js
var pro = new util.LruBuffer(); let pro = new util.LruBuffer();
pro.put(2,10); pro.put(2,10);
var result = pro[Symbol.iterator](); let result = pro[Symbol.iterator]();
``` ```
...@@ -1133,6 +1313,7 @@ A constructor used to create a **Scope** object with the specified upper and low ...@@ -1133,6 +1313,7 @@ A constructor used to create a **Scope** object with the specified upper and low
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.| | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
...@@ -1140,9 +1321,9 @@ A constructor used to create a **Scope** object with the specified upper and low ...@@ -1140,9 +1321,9 @@ A constructor used to create a **Scope** object with the specified upper and low
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
``` ```
...@@ -1155,16 +1336,17 @@ Obtains a string representation that contains this **Scope**. ...@@ -1155,16 +1336,17 @@ Obtains a string representation that contains this **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String representation containing the **Scope**.| | string | String representation containing the **Scope**.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var result = range.toString(); let result = range.toString();
``` ```
...@@ -1177,23 +1359,25 @@ Obtains the intersection of this **Scope** and the given **Scope**. ...@@ -1177,23 +1359,25 @@ Obtains the intersection of this **Scope** and the given **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| range | [Scope](#scope8) | Yes| **Scope** specified.| | range | [Scope](#scope8) | Yes| **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.| | [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var tempMiDF = new Temperature(35); let tempMiDF = new Temperature(35);
var tempMidS = new Temperature(39); let tempMidS = new Temperature(39);
var rangeFir = new util.Scope(tempMiDF, tempMidS); let rangeFir = new util.Scope(tempMiDF, tempMidS);
range.intersect(rangeFir ); range.intersect(rangeFir );
``` ```
...@@ -1207,24 +1391,26 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. ...@@ -1207,24 +1391,26 @@ Obtains the intersection of this **Scope** and the given lower and upper limits.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.| | upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scope8) | Intersection of this **Scope** and the given lower and upper limits.| | [Scope](#scope8) | Intersection of this **Scope** and the given lower and upper limits.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var tempMiDF = new Temperature(35); let tempMiDF = new Temperature(35);
var tempMidS = new Temperature(39); let tempMidS = new Temperature(39);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var result = range.intersect(tempMiDF, tempMidS); let result = range.intersect(tempMiDF, tempMidS);
``` ```
...@@ -1244,10 +1430,10 @@ Obtains the upper limit of this **Scope**. ...@@ -1244,10 +1430,10 @@ Obtains the upper limit of this **Scope**.
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var result = range.getUpper(); let result = range.getUpper();
``` ```
...@@ -1260,16 +1446,17 @@ Obtains the lower limit of this **Scope**. ...@@ -1260,16 +1446,17 @@ Obtains the lower limit of this **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.| | [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var result = range.getLower(); let result = range.getLower();
``` ```
...@@ -1282,12 +1469,14 @@ Obtains the union set of this **Scope** and the given lower and upper limits. ...@@ -1282,12 +1469,14 @@ Obtains the union set of this **Scope** and the given lower and upper limits.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.| | upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scope8) | Union set of this **Scope** and the given lower and upper limits.| | [Scope](#scope8) | Union set of this **Scope** and the given lower and upper limits.|
...@@ -1295,12 +1484,12 @@ Obtains the union set of this **Scope** and the given lower and upper limits. ...@@ -1295,12 +1484,12 @@ Obtains the union set of this **Scope** and the given lower and upper limits.
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var tempMiDF = new Temperature(35); let tempMiDF = new Temperature(35);
var tempMidS = new Temperature(39); let tempMidS = new Temperature(39);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var result = range.expand(tempMiDF, tempMidS); let result = range.expand(tempMiDF, tempMidS);
``` ```
...@@ -1313,24 +1502,26 @@ Obtains the union set of this **Scope** and the given **Scope**. ...@@ -1313,24 +1502,26 @@ Obtains the union set of this **Scope** and the given **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| range | [Scope](#scope8) | Yes| **Scope** specified.| | range | [Scope](#scope8) | Yes| **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scope8) | Union set of this **Scope** and the given **Scope**.| | [Scope](#scope8) | Union set of this **Scope** and the given **Scope**.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var tempMiDF = new Temperature(35); let tempMiDF = new Temperature(35);
var tempMidS = new Temperature(39); let tempMidS = new Temperature(39);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var rangeFir = new util.Scope(tempMiDF, tempMidS); let rangeFir = new util.Scope(tempMiDF, tempMidS);
var result = range.expand(rangeFir); let result = range.expand(rangeFir);
``` ```
...@@ -1343,22 +1534,24 @@ Obtains the union set of this **Scope** and the given value. ...@@ -1343,22 +1534,24 @@ Obtains the union set of this **Scope** and the given value.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.| | value | [ScopeType](#scopetype8) | Yes| Value specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scope8) | Union set of this **Scope** and the given value.| | [Scope](#scope8) | Union set of this **Scope** and the given value.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var tempMiDF = new Temperature(35); let tempMiDF = new Temperature(35);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var result = range.expand(tempMiDF); let result = range.expand(tempMiDF);
``` ```
...@@ -1371,21 +1564,23 @@ Checks whether a value is within this **Scope**. ...@@ -1371,21 +1564,23 @@ Checks whether a value is within this **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.| | value | [ScopeType](#scopetype8) | Yes| Value specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.| | boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var tempMiDF = new Temperature(35); let tempMiDF = new Temperature(35);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
range.contains(tempMiDF); range.contains(tempMiDF);
``` ```
...@@ -1399,24 +1594,26 @@ Checks whether a range is within this **Scope**. ...@@ -1399,24 +1594,26 @@ Checks whether a range is within this **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| range | [Scope](#scope8) | Yes| **Scope** specified.| | range | [Scope](#scope8) | Yes| **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.| | boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var tempLess = new Temperature(20); let tempLess = new Temperature(20);
var tempMore = new Temperature(45); let tempMore = new Temperature(45);
var rangeSec = new util.Scope(tempLess, tempMore); let rangeSec = new util.Scope(tempLess, tempMore);
var result = range.contains(rangeSec); let result = range.contains(rangeSec);
``` ```
...@@ -1429,22 +1626,24 @@ Limits a value to this **Scope**. ...@@ -1429,22 +1626,24 @@ Limits a value to this **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.| | value | [ScopeType](#scopetype8) | Yes| Value specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.| | [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.|
**Example** **Example**
```js ```js
var tempLower = new Temperature(30); let tempLower = new Temperature(30);
var tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
var tempMiDF = new Temperature(35); let tempMiDF = new Temperature(35);
var range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
var result = range.clamp(tempMiDF); let result = range.clamp(tempMiDF);
``` ```
...@@ -1461,7 +1660,7 @@ A constructor used to create a **Base64** object. ...@@ -1461,7 +1660,7 @@ A constructor used to create a **Base64** object.
**Example** **Example**
```js ```js
var base64 = new util.Base64(); let base64 = new util.Base64();
``` ```
...@@ -1474,20 +1673,22 @@ Encodes the input content. ...@@ -1474,20 +1673,22 @@ Encodes the input content.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.| | src | Uint8Array | Yes| Uint8Array to encode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Uint8Array | Uint8Array encoded.| | Uint8Array | Uint8Array encoded.|
**Example** **Example**
```js ```js
var that = new util.Base64(); let that = new util.Base64();
var array = new Uint8Array([115,49,51]); let array = new Uint8Array([115,49,51]);
var result = that.encodeSync(array); let result = that.encodeSync(array);
``` ```
...@@ -1500,20 +1701,22 @@ Encodes the input content. ...@@ -1500,20 +1701,22 @@ Encodes the input content.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.| | src | Uint8Array | Yes| Uint8Array to encode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String encoded from the Uint8Array.| | string | String encoded from the Uint8Array.|
**Example** **Example**
```js ```js
var that = new util.Base64(); let that = new util.Base64();
var array = new Uint8Array([115,49,51]); let array = new Uint8Array([115,49,51]);
var result = that.encodeToStringSync(array); let result = that.encodeToStringSync(array);
``` ```
...@@ -1526,20 +1729,22 @@ Decodes the input content. ...@@ -1526,20 +1729,22 @@ Decodes the input content.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array \| string | Yes| Uint8Array or string to decode.| | src | Uint8Array \| string | Yes| Uint8Array or string to decode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Uint8Array | Uint8Array decoded.| | Uint8Array | Uint8Array decoded.|
**Example** **Example**
```js ```js
var that = new util.Base64(); let that = new util.Base64();
var buff = 'czEz'; let buff = 'czEz';
var result = that.decodeSync(buff); let result = that.decodeSync(buff);
``` ```
...@@ -1552,20 +1757,22 @@ Encodes the input content asynchronously. ...@@ -1552,20 +1757,22 @@ Encodes the input content asynchronously.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.| | src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.| | Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
**Example** **Example**
```js ```js
var that = new util.Base64(); let that = new util.Base64();
var array = new Uint8Array([115,49,51]); let array = new Uint8Array([115,49,51]);
var rarray = new Uint8Array([99,122,69,122]); let rarray = new Uint8Array([99,122,69,122]);
that.encode(array).then(val=>{ that.encode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) { for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString()) console.log(val[i].toString())
...@@ -1583,19 +1790,21 @@ Encodes the input content asynchronously. ...@@ -1583,19 +1790,21 @@ Encodes the input content asynchronously.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.| | src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.| | Promise&lt;string&gt; | String obtained after asynchronous encoding.|
**Example** **Example**
```js ```js
var that = new util.Base64(); let that = new util.Base64();
var array = new Uint8Array([115,49,51]); let array = new Uint8Array([115,49,51]);
that.encodeToString(array).then(val=>{ that.encodeToString(array).then(val=>{
console.log(val) console.log(val)
}) })
...@@ -1611,20 +1820,22 @@ Decodes the input content asynchronously. ...@@ -1611,20 +1820,22 @@ Decodes the input content asynchronously.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.| | src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.| | Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
**Example** **Example**
```js ```js
var that = new util.Base64(); let that = new util.Base64();
var array = new Uint8Array([99,122,69,122]); let array = new Uint8Array([99,122,69,122]);
var rarray = new Uint8Array([115,49,51]); let rarray = new Uint8Array([115,49,51]);
that.decode(array).then(val=>{ that.decode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) { for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString()) console.log(val[i].toString())
...@@ -1646,7 +1857,7 @@ A constructor used to create a **Types** object. ...@@ -1646,7 +1857,7 @@ A constructor used to create a **Types** object.
**Example** **Example**
```js ```js
var type = new util.types(); let type = new util.types();
``` ```
...@@ -1659,19 +1870,21 @@ Checks whether the input value is of the **ArrayBuffer** type. ...@@ -1659,19 +1870,21 @@ Checks whether the input value is of the **ArrayBuffer** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isAnyArrayBuffer(new ArrayBuffer(0)); let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
``` ```
...@@ -1686,19 +1899,21 @@ Checks whether the input value is of the **ArrayBufferView** type. ...@@ -1686,19 +1899,21 @@ Checks whether the input value is of the **ArrayBufferView** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isArrayBufferView(new Int8Array([])); let result = that.isArrayBufferView(new Int8Array([]));
``` ```
...@@ -1711,22 +1926,24 @@ Checks whether the input value is of the **arguments** type. ...@@ -1711,22 +1926,24 @@ Checks whether the input value is of the **arguments** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
function foo() { function foo() {
var result = that.isArgumentsObject(arguments); var result = that.isArgumentsObject(arguments);
} }
var f = foo(); let f = foo();
``` ```
...@@ -1739,19 +1956,21 @@ Checks whether the input value is of the **ArrayBuffer** type. ...@@ -1739,19 +1956,21 @@ Checks whether the input value is of the **ArrayBuffer** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isArrayBuffer(new ArrayBuffer(0)); let result = that.isArrayBuffer(new ArrayBuffer(0));
``` ```
...@@ -1764,19 +1983,21 @@ Checks whether the input value is an asynchronous function. ...@@ -1764,19 +1983,21 @@ Checks whether the input value is an asynchronous function.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.| | boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isAsyncFunction(async function foo() {}); let result = that.isAsyncFunction(async function foo() {});
``` ```
...@@ -1789,19 +2010,21 @@ Checks whether the input value is of the **Boolean** type. ...@@ -1789,19 +2010,21 @@ Checks whether the input value is of the **Boolean** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isBooleanObject(new Boolean(true)); let result = that.isBooleanObject(new Boolean(true));
``` ```
...@@ -1814,19 +2037,21 @@ Checks whether the input value is of the **Boolean**, **Number**, **String**, or ...@@ -1814,19 +2037,21 @@ Checks whether the input value is of the **Boolean**, **Number**, **String**, or
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isBoxedPrimitive(new Boolean(false)); let result = that.isBoxedPrimitive(new Boolean(false));
``` ```
...@@ -1839,20 +2064,22 @@ Checks whether the input value is of the **DataView** type. ...@@ -1839,20 +2064,22 @@ Checks whether the input value is of the **DataView** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
const ab = new ArrayBuffer(20); const ab = new ArrayBuffer(20);
var result = that.isDataView(new DataView(ab)); let result = that.isDataView(new DataView(ab));
``` ```
...@@ -1865,19 +2092,21 @@ Checks whether the input value is of the **Date** type. ...@@ -1865,19 +2092,21 @@ Checks whether the input value is of the **Date** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isDate(new Date()); let result = that.isDate(new Date());
``` ```
...@@ -1890,19 +2119,21 @@ Checks whether the input value is of the **native external** type. ...@@ -1890,19 +2119,21 @@ Checks whether the input value is of the **native external** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isExternal(true); let result = that.isExternal(true);
``` ```
...@@ -1915,19 +2146,21 @@ Checks whether the input value is of the **Float32Array** type. ...@@ -1915,19 +2146,21 @@ Checks whether the input value is of the **Float32Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isFloat32Array(new Float32Array()); let result = that.isFloat32Array(new Float32Array());
``` ```
...@@ -1940,19 +2173,21 @@ Checks whether the input value is of the **Float64Array** type. ...@@ -1940,19 +2173,21 @@ Checks whether the input value is of the **Float64Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isFloat64Array(new Float64Array()); let result = that.isFloat64Array(new Float64Array());
``` ```
...@@ -1965,19 +2200,21 @@ Checks whether the input value is a generator function. ...@@ -1965,19 +2200,21 @@ Checks whether the input value is a generator function.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.| | boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isGeneratorFunction(function* foo() {}); let result = that.isGeneratorFunction(function* foo() {});
``` ```
...@@ -1990,21 +2227,23 @@ Checks whether the input value is a generator object. ...@@ -1990,21 +2227,23 @@ Checks whether the input value is a generator object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.| | boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
function* foo() {} function* foo() {}
const generator = foo(); const generator = foo();
var result = that.isGeneratorObject(generator); let result = that.isGeneratorObject(generator);
``` ```
...@@ -2017,19 +2256,21 @@ Checks whether the input value is of the **Int8Array** type. ...@@ -2017,19 +2256,21 @@ Checks whether the input value is of the **Int8Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isInt8Array(new Int8Array([])); let result = that.isInt8Array(new Int8Array([]));
``` ```
...@@ -2042,19 +2283,21 @@ Checks whether the input value is of the **Int16Array** type. ...@@ -2042,19 +2283,21 @@ Checks whether the input value is of the **Int16Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isInt16Array(new Int16Array([])); let result = that.isInt16Array(new Int16Array([]));
``` ```
...@@ -2067,19 +2310,21 @@ Checks whether the input value is of the **Int32Array** type. ...@@ -2067,19 +2310,21 @@ Checks whether the input value is of the **Int32Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isInt32Array(new Int32Array([])); let result = that.isInt32Array(new Int32Array([]));
``` ```
...@@ -2092,19 +2337,21 @@ Checks whether the input value is of the **Map** type. ...@@ -2092,19 +2337,21 @@ Checks whether the input value is of the **Map** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isMap(new Map()); let result = that.isMap(new Map());
``` ```
...@@ -2117,20 +2364,22 @@ Checks whether the input value is of the **MapIterator** type. ...@@ -2117,20 +2364,22 @@ Checks whether the input value is of the **MapIterator** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
const map = new Map(); const map = new Map();
var result = that.isMapIterator(map.keys()); let result = that.isMapIterator(map.keys());
``` ```
...@@ -2143,19 +2392,21 @@ Checks whether the input value is of the **Error** type. ...@@ -2143,19 +2392,21 @@ Checks whether the input value is of the **Error** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isNativeError(new TypeError()); let result = that.isNativeError(new TypeError());
``` ```
...@@ -2168,19 +2419,21 @@ Checks whether the input value is a number object. ...@@ -2168,19 +2419,21 @@ Checks whether the input value is a number object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.| | boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isNumberObject(new Number(0)); let result = that.isNumberObject(new Number(0));
``` ```
...@@ -2193,19 +2446,21 @@ Checks whether the input value is a promise. ...@@ -2193,19 +2446,21 @@ Checks whether the input value is a promise.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a promise; returns **false** otherwise.| | boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isPromise(Promise.resolve(1)); let result = that.isPromise(Promise.resolve(1));
``` ```
...@@ -2218,21 +2473,23 @@ Checks whether the input value is a proxy. ...@@ -2218,21 +2473,23 @@ Checks whether the input value is a proxy.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.| | boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
const target = {}; const target = {};
const proxy = new Proxy(target, {}); const proxy = new Proxy(target, {});
var result = that.isProxy(proxy); let result = that.isProxy(proxy);
``` ```
...@@ -2245,19 +2502,21 @@ Checks whether the input value is of the **RegExp** type. ...@@ -2245,19 +2502,21 @@ Checks whether the input value is of the **RegExp** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isRegExp(new RegExp('abc')); let result = that.isRegExp(new RegExp('abc'));
``` ```
...@@ -2270,19 +2529,21 @@ Checks whether the input value is of the **Set** type. ...@@ -2270,19 +2529,21 @@ Checks whether the input value is of the **Set** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isSet(new Set()); let result = that.isSet(new Set());
``` ```
...@@ -2295,20 +2556,22 @@ Checks whether the input value is of the **SetIterator** type. ...@@ -2295,20 +2556,22 @@ Checks whether the input value is of the **SetIterator** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
const set = new Set(); const set = new Set();
var result = that.isSetIterator(set.keys()); let result = that.isSetIterator(set.keys());
``` ```
...@@ -2321,19 +2584,21 @@ Checks whether the input value is a string object. ...@@ -2321,19 +2584,21 @@ Checks whether the input value is a string object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.| | boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isStringObject(new String('foo')); let result = that.isStringObject(new String('foo'));
``` ```
...@@ -2346,20 +2611,22 @@ Checks whether the input value is a symbol object. ...@@ -2346,20 +2611,22 @@ Checks whether the input value is a symbol object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.| | boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
const symbols = Symbol('foo'); const symbols = Symbol('foo');
var result = that.isSymbolObject(Object(symbols)); let result = that.isSymbolObject(Object(symbols));
``` ```
...@@ -2374,19 +2641,21 @@ Checks whether the input value is of the **TypedArray** type. ...@@ -2374,19 +2641,21 @@ Checks whether the input value is of the **TypedArray** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isTypedArray(new Float64Array([])); let result = that.isTypedArray(new Float64Array([]));
``` ```
...@@ -2399,19 +2668,21 @@ Checks whether the input value is of the **Uint8Array** type. ...@@ -2399,19 +2668,21 @@ Checks whether the input value is of the **Uint8Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isUint8Array(new Uint8Array([])); let result = that.isUint8Array(new Uint8Array([]));
``` ```
...@@ -2424,19 +2695,21 @@ Checks whether the input value is of the **Uint8ClampedArray** type. ...@@ -2424,19 +2695,21 @@ Checks whether the input value is of the **Uint8ClampedArray** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isUint8ClampedArray(new Uint8ClampedArray([])); let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
``` ```
...@@ -2449,19 +2722,21 @@ Checks whether the input value is of the **Uint16Array** type. ...@@ -2449,19 +2722,21 @@ Checks whether the input value is of the **Uint16Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isUint16Array(new Uint16Array([])); let result = that.isUint16Array(new Uint16Array([]));
``` ```
...@@ -2474,19 +2749,21 @@ Checks whether the input value is of the **Uint32Array** type. ...@@ -2474,19 +2749,21 @@ Checks whether the input value is of the **Uint32Array** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isUint32Array(new Uint32Array([])); let result = that.isUint32Array(new Uint32Array([]));
``` ```
...@@ -2499,19 +2776,21 @@ Checks whether the input value is of the **WeakMap** type. ...@@ -2499,19 +2776,21 @@ Checks whether the input value is of the **WeakMap** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isWeakMap(new WeakMap()); let result = that.isWeakMap(new WeakMap());
``` ```
...@@ -2524,17 +2803,128 @@ Checks whether the input value is of the **WeakSet** type. ...@@ -2524,17 +2803,128 @@ Checks whether the input value is of the **WeakSet** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.| | boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
var that = new util.types(); let that = new util.types();
var result = that.isWeakSet(new WeakSet()); let result = that.isWeakSet(new WeakSet());
```
### isBigInt64Array<sup>8+</sup>
isBigInt64Array(value: Object): boolean
Checks whether the input value is of the **BigInt64Array** type.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.|
**Example**
```js
let that = new util.types();
let result = that.isBigInt64Array(new BigInt64Array([]));
```
### isBigUint64Array<sup>8+</sup>
isBigUint64Array(value: Object): boolean
Checks whether the input value is of the **BigUint64Array** type.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.|
**Example**
```js
let that = new util.types();
let result = that.isBigUint64Array(new BigUint64Array([]));
```
### isModuleNamespaceObject<sup>8+</sup>
isModuleNamespaceObject(value: Object): boolean
Checks whether the input value is a module namespace object.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.|
**Example**
```js
import url from '@ohos.url'
let that = new util.types();
let result = that.isModuleNamespaceObject(url);
```
### isSharedArrayBuffer<sup>8+</sup>
isSharedArrayBuffer(value: Object): boolean
Checks whether the input value is of the **SharedArrayBuffer** type.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.|
**Example**
```js
let that = new util.types();
let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
``` ```
...@@ -32,9 +32,9 @@ A constructor used to create an **XmlSerializer** instance. ...@@ -32,9 +32,9 @@ A constructor used to create an **XmlSerializer** instance.
**Example** **Example**
```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);
``` ```
...@@ -56,9 +56,9 @@ Sets an attribute. ...@@ -56,9 +56,9 @@ Sets an attribute.
**Example** **Example**
```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");
``` ```
...@@ -80,9 +80,9 @@ Adds an empty element. ...@@ -80,9 +80,9 @@ Adds an empty element.
**Example** **Example**
```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/>
``` ```
...@@ -98,9 +98,9 @@ Sets a declaration. ...@@ -98,9 +98,9 @@ Sets a declaration.
**Example** **Example**
```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"?>;
``` ```
...@@ -122,8 +122,8 @@ Writes the start tag based on the given element name. ...@@ -122,8 +122,8 @@ Writes the start tag based on the given element name.
**Example** **Example**
```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/>';
``` ```
...@@ -140,9 +140,9 @@ Writes the end tag of the element. ...@@ -140,9 +140,9 @@ Writes the end tag of the element.
**Example** **Example**
```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");
...@@ -169,8 +169,8 @@ Sets the namespace for an element tag. ...@@ -169,8 +169,8 @@ Sets the namespace for an element tag.
**Example** **Example**
```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");
...@@ -194,8 +194,8 @@ Sets the comment. ...@@ -194,8 +194,8 @@ Sets the comment.
**Example** **Example**
```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>';
...@@ -219,8 +219,8 @@ Sets CDATA attributes. ...@@ -219,8 +219,8 @@ Sets CDATA attributes.
**Example** **Example**
```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]]>';
``` ```
...@@ -242,8 +242,8 @@ Sets **Text**. ...@@ -242,8 +242,8 @@ Sets **Text**.
**Example** **Example**
```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");
...@@ -268,8 +268,8 @@ Sets **DocType**. ...@@ -268,8 +268,8 @@ Sets **DocType**.
**Example** **Example**
```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>';
``` ```
...@@ -295,20 +295,20 @@ Creates and returns an **XmlPullParser** object. The **XmlPullParser** object pa ...@@ -295,20 +295,20 @@ Creates and returns an **XmlPullParser** object. The **XmlPullParser** object pa
**Example** **Example**
```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*2); 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);// Set the ArrayBuffer mode. bufView[i] = strXml.charCodeAt(i);// Set the ArrayBuffer mode.
} }
var that = new xml.XmlPullParser(arrayBuffer); let that = new xml.XmlPullParser(arrayBuffer);
``` ```
...@@ -329,30 +329,30 @@ Parses XML information. ...@@ -329,30 +329,30 @@ Parses XML information.
**Example** **Example**
```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*2); 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);
// Output: // Output:
...@@ -387,7 +387,7 @@ Provides APIs to manage the parsed XML information. ...@@ -387,7 +387,7 @@ Provides APIs to manage the parsed XML information.
getColumnNumber(): number getColumnNumber(): number
Obtains the column line number, which starts from 1. Obtains the column line number, starting from 1.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册