“811a3174f16d802366b3925f174678568765b392”上不存在“...git@gitcode.net:s920243400/PaddleDetection.git”
提交 3f62f27f 编写于 作者: G Gloria

Update container APIs against multiple PRs

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 7ba8c722
# @ohos.util.ArrayList (Linear Container ArrayList) # @ohos.util.ArrayList (Linear Container ArrayList)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**ArrayList** is a linear data structure that is implemented based on arrays. **ArrayList** can dynamically adjust the capacity based on project requirements. It increases the capacity by 50% each time. **ArrayList** is a linear data structure that is implemented based on arrays. **ArrayList** can dynamically adjust the capacity based on project requirements. It increases the capacity by 50% each time.
...@@ -42,7 +41,7 @@ A constructor used to create an **ArrayList** instance. ...@@ -42,7 +41,7 @@ A constructor used to create an **ArrayList** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -77,7 +76,7 @@ Adds an element at the end of this container. ...@@ -77,7 +76,7 @@ Adds an element at the end of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -113,12 +112,12 @@ Inserts an element at the specified position in this container. ...@@ -113,12 +112,12 @@ Inserts an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The insert method cannot be bound. | | 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -151,7 +150,7 @@ Checks whether this container has the specified element. ...@@ -151,7 +150,7 @@ Checks whether this container has the specified element.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -188,7 +187,7 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -188,7 +187,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -230,7 +229,7 @@ Obtains the index of the last occurrence of the specified element in this contai ...@@ -230,7 +229,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -272,12 +271,12 @@ Removes an element with the specified position from this container. ...@@ -272,12 +271,12 @@ Removes an element with the specified position from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. | | 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -313,7 +312,7 @@ Removes the first occurrence of the specified element from this container. ...@@ -313,7 +312,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -347,12 +346,12 @@ Removes from this container all of the elements within a range, including the el ...@@ -347,12 +346,12 @@ Removes from this container all of the elements within a range, including the el
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The removeByRange method cannot be bound. | | 10200011 | The removeByRange method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of fromIndex or toIndex is out of range. |
**Example** **Example**
...@@ -391,7 +390,7 @@ callbackfn ...@@ -391,7 +390,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -426,7 +425,7 @@ Uses a callback to traverse the elements in this container and obtain their posi ...@@ -426,7 +425,7 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.| | callbackFn | function | Yes| Callback invoked for the replacement.|
| thisArg | Object | No| Value to use when the callback is invoked.| | thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn callbackfn
...@@ -439,7 +438,7 @@ callbackfn ...@@ -439,7 +438,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -481,7 +480,7 @@ comparator ...@@ -481,7 +480,7 @@ comparator
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -523,12 +522,12 @@ Obtains elements within a range in this container, including the element at the ...@@ -523,12 +522,12 @@ Obtains elements within a range in this container, including the element at the
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The subArrayList method cannot be bound. | | 10200011 | The subArrayList method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of fromIndex or toIndex is out of range. |
**Example** **Example**
...@@ -553,7 +552,7 @@ Clears this container and sets its length to **0**. ...@@ -553,7 +552,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -587,7 +586,7 @@ Clones this container and returns a copy. The modification to the copy does not ...@@ -587,7 +586,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -620,7 +619,7 @@ Obtains the capacity of this container. ...@@ -620,7 +619,7 @@ Obtains the capacity of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -653,7 +652,7 @@ Converts this container into an array. ...@@ -653,7 +652,7 @@ Converts this container into an array.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -686,7 +685,7 @@ Checks whether this container is empty (contains no element). ...@@ -686,7 +685,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -719,7 +718,7 @@ Increases the capacity of this container. ...@@ -719,7 +718,7 @@ Increases the capacity of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -747,7 +746,7 @@ Trims the capacity of this container to its current length. ...@@ -747,7 +746,7 @@ Trims the capacity of this container to its current length.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -780,7 +779,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -780,7 +779,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.Deque (Linear Container Deque) # @ohos.util.Deque (Linear Container Deque)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Double-ended queue (deque) is a sequence container implemented based on the queue data structure that follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). It allows insertion and removal of elements at both the ends. **Deque** can dynamically adjust the capacity based on project requirements. It doubles the capacity each time. **Deque** differs from **[Queue](js-apis-queue.md)** and **[Vector](js-apis-vector.md)** mainly in the following aspects: Double-ended queue (deque) is a sequence container implemented based on the queue data structure that follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). It allows insertion and removal of elements at both the ends. **Deque** can dynamically adjust the capacity based on project requirements. It doubles the capacity each time. **Deque** differs from **[Queue](js-apis-queue.md)** and **[Vector](js-apis-vector.md)** mainly in the following aspects:
...@@ -41,7 +40,7 @@ A constructor used to create a **Deque** instance. ...@@ -41,7 +40,7 @@ A constructor used to create a **Deque** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -69,7 +68,7 @@ Inserts an element at the front of this container. ...@@ -69,7 +68,7 @@ Inserts an element at the front of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -104,7 +103,7 @@ Inserts an element at the end of this container. ...@@ -104,7 +103,7 @@ Inserts an element at the end of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -145,7 +144,7 @@ Checks whether this container has the specified element. ...@@ -145,7 +144,7 @@ Checks whether this container has the specified element.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -172,11 +171,11 @@ Removes the first element of this container. ...@@ -172,11 +171,11 @@ Removes the first element of this container.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | First element removed.|
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -206,11 +205,11 @@ Removes the last element of this container. ...@@ -206,11 +205,11 @@ Removes the last element of this container.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| T | Element removed.| | T | Last element removed.|
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -254,7 +253,7 @@ callbackfn ...@@ -254,7 +253,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -289,7 +288,7 @@ Obtains the first element of this container. ...@@ -289,7 +288,7 @@ Obtains the first element of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -322,7 +321,7 @@ Obtains the last element of this container. ...@@ -322,7 +321,7 @@ Obtains the last element of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -355,7 +354,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -355,7 +354,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.HashMap (Nonlinear Container HashMap) # @ohos.util.HashMap (Nonlinear Container HashMap)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashMap** is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion, and removal. The elements in a **HashMap** instance are mappings of key-value pairs. Each key must be unique and have only one value. **HashMap** is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion, and removal. The elements in a **HashMap** instance are mappings of key-value pairs. Each key must be unique and have only one value.
...@@ -43,7 +42,7 @@ A constructor used to create a **HashMap** instance. ...@@ -43,7 +42,7 @@ A constructor used to create a **HashMap** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -72,7 +71,7 @@ Checks whether this container is empty (contains no element). ...@@ -72,7 +71,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -108,7 +107,7 @@ Checks whether this container contains the specified key. ...@@ -108,7 +107,7 @@ Checks whether this container contains the specified key.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -146,7 +145,7 @@ Checks whether this container contains the specified value. ...@@ -146,7 +145,7 @@ Checks whether this container contains the specified value.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -184,7 +183,7 @@ Obtains the value of the specified key in this container. ...@@ -184,7 +183,7 @@ Obtains the value of the specified key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -216,7 +215,7 @@ Adds all elements in a **HashMap** instance to this container. ...@@ -216,7 +215,7 @@ Adds all elements in a **HashMap** instance to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -256,7 +255,7 @@ Adds an element to this container. ...@@ -256,7 +255,7 @@ Adds an element to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -292,7 +291,7 @@ Removes an element with the specified key from this container. ...@@ -292,7 +291,7 @@ Removes an element with the specified key from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -318,7 +317,7 @@ Clears this container and sets its length to **0**. ...@@ -318,7 +317,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -350,7 +349,7 @@ Obtains an iterator that contains all the elements in this container. ...@@ -350,7 +349,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -387,7 +386,7 @@ Obtains an iterator that contains all the values in this container. ...@@ -387,7 +386,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -431,7 +430,7 @@ Replaces an element in this container. ...@@ -431,7 +430,7 @@ Replaces an element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -470,7 +469,7 @@ callbackfn ...@@ -470,7 +469,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -504,7 +503,7 @@ Obtains an iterator that contains all the elements in this container. ...@@ -504,7 +503,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -542,14 +541,13 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -542,14 +541,13 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. | | 10200011 | The Symbol.iterator method cannot be bound. |
**Example** **Example**
```ts ```ts
let hashMap = new HashMap(); let hashMap = new HashMap();
hashMap.set("squirrel", 123); hashMap.set("squirrel", 123);
......
# @ohos.util.HashSet (Nonlinear Container HashSet) # @ohos.util.HashSet (Nonlinear Container HashSet)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashSet** is implemented based on [HashMap](js-apis-hashmap.md). In **HashSet**, only the **value** object is processed. **HashSet** is implemented based on [HashMap](js-apis-hashmap.md). In **HashSet**, only the **value** object is processed.
...@@ -51,7 +50,7 @@ A constructor used to create a **HashSet** instance. ...@@ -51,7 +50,7 @@ A constructor used to create a **HashSet** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -80,7 +79,7 @@ Checks whether this container is empty (contains no element). ...@@ -80,7 +79,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -116,7 +115,7 @@ Checks whether this container contains the specified element. ...@@ -116,7 +115,7 @@ Checks whether this container contains the specified element.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -154,7 +153,7 @@ Adds an element to this container. ...@@ -154,7 +153,7 @@ Adds an element to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -190,7 +189,7 @@ Removes an element from this container. ...@@ -190,7 +189,7 @@ Removes an element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -216,7 +215,7 @@ Clears this container and sets its length to **0**. ...@@ -216,7 +215,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -248,7 +247,7 @@ Obtains an iterator that contains all the values in this container. ...@@ -248,7 +247,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -293,7 +292,7 @@ callbackfn ...@@ -293,7 +292,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -326,7 +325,7 @@ Obtains an iterator that contains all the elements in this container. ...@@ -326,7 +325,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -364,7 +363,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -364,7 +363,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.LightWeightMap (Nonlinear Container LightWeightMap) # @ohos.util.LightWeightMap (Nonlinear Container LightWeightMap)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightMap** stores key-value (KV) pairs. Each key must be unique and have only one value. **LightWeightMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
**LightWeightMap** is based on generics and uses a lightweight structure. Keys in the map are searched using hash values, which are stored in an array. **LightWeightMap** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion.
The keys in such a set are searched using hash values, which are stored in an array.
Compared with **[HashMap](js-apis-hashmap.md)**, which can also store KV pairs, **LightWeightMap** occupies less memory. Compared with **[HashMap](js-apis-hashmap.md)**, which can also store KV pairs, **LightWeightMap** occupies less memory.
...@@ -44,7 +45,7 @@ A constructor used to create a **LightWeightMap** instance. ...@@ -44,7 +45,7 @@ A constructor used to create a **LightWeightMap** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -73,7 +74,7 @@ Checks whether this container is empty (contains no element). ...@@ -73,7 +74,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -109,7 +110,7 @@ Checks whether this container contains all elements of the specified **LightWeig ...@@ -109,7 +110,7 @@ Checks whether this container contains all elements of the specified **LightWeig
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -149,7 +150,7 @@ Checks whether this container contains the specified key. ...@@ -149,7 +150,7 @@ Checks whether this container contains the specified key.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -159,10 +160,8 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er ...@@ -159,10 +160,8 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er
```ts ```ts
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.hasKey;
lightWeightMap.hasKey("squirrel");
lightWeightMap.set("squirrel", 123); lightWeightMap.set("squirrel", 123);
let result1 = lightWeightMap.hasKey("squirrel"); let result = lightWeightMap.hasKey("squirrel");
``` ```
...@@ -188,7 +187,7 @@ Checks whether this container contains the specified value. ...@@ -188,7 +187,7 @@ Checks whether this container contains the specified value.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -214,7 +213,7 @@ Increases the capacity of this container. ...@@ -214,7 +213,7 @@ Increases the capacity of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -256,7 +255,7 @@ Obtains the value of the specified key in this container. ...@@ -256,7 +255,7 @@ Obtains the value of the specified key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -294,7 +293,7 @@ Obtains the index of the first occurrence of an element with the specified key i ...@@ -294,7 +293,7 @@ Obtains the index of the first occurrence of an element with the specified key i
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -332,7 +331,7 @@ Obtains the index of the first occurrence of an element with the specified value ...@@ -332,7 +331,7 @@ Obtains the index of the first occurrence of an element with the specified value
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -370,12 +369,12 @@ Obtains the key of an element at the specified position in this container. ...@@ -370,12 +369,12 @@ Obtains the key of an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The getKeyAt method cannot be bound. | | 10200011 | The getKeyAt method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -403,7 +402,7 @@ Adds all elements in a **LightWeightMap** instance to this container. ...@@ -403,7 +402,7 @@ Adds all elements in a **LightWeightMap** instance to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -416,7 +415,7 @@ let lightWeightMap = new LightWeightMap(); ...@@ -416,7 +415,7 @@ let lightWeightMap = new LightWeightMap();
lightWeightMap.set("squirrel", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sparrow", 356); lightWeightMap.set("sparrow", 356);
let map = new LightWeightMap(); let map = new LightWeightMap();
lightWeightMap.setAll(map); map.setAll(lightWeightMap); // Add all elements in lightWeightMap to the map.
``` ```
...@@ -442,7 +441,7 @@ Adds an element to this container. ...@@ -442,7 +441,7 @@ Adds an element to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -478,7 +477,7 @@ Removes an element with the specified key from this container. ...@@ -478,7 +477,7 @@ Removes an element with the specified key from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -516,7 +515,7 @@ Removes an element at the specified position from this container. ...@@ -516,7 +515,7 @@ Removes an element at the specified position from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -555,12 +554,12 @@ Sets a value for an element at the specified position in this container. ...@@ -555,12 +554,12 @@ Sets a value for an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The setValueAt method cannot be bound. | | 10200011 | The setValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -594,12 +593,12 @@ Obtains the value of an element at the specified position in this container. ...@@ -594,12 +593,12 @@ Obtains the value of an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. | | 10200011 | The getValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -621,7 +620,7 @@ Clears this container and sets its length to **0**. ...@@ -621,7 +620,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -653,7 +652,7 @@ Obtains an iterator that contains all the keys in this container. ...@@ -653,7 +652,7 @@ Obtains an iterator that contains all the keys in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -690,7 +689,7 @@ Obtains an iterator that contains all the values in this container. ...@@ -690,7 +689,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -735,7 +734,7 @@ callbackfn ...@@ -735,7 +734,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -769,7 +768,7 @@ Obtains an iterator that contains all the elements in this container. ...@@ -769,7 +768,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -800,13 +799,13 @@ Concatenates the elements in this container into a string and returns the string ...@@ -800,13 +799,13 @@ Concatenates the elements in this container into a string and returns the string
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| String | String obtained.| | String | String obtained.|
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -818,7 +817,7 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er ...@@ -818,7 +817,7 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
lightWeightMap.set("squirrel", 123); lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sparrow", 356); lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.toString(); let result = lightWeightMap.toString();
``` ```
### [Symbol.iterator] ### [Symbol.iterator]
...@@ -837,7 +836,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -837,7 +836,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.LightWeightSet (Nonlinear Container LightWeightSet) # @ohos.util.LightWeightSet (Nonlinear Container LightWeightSet)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightSet** stores a set of values, each of which must be unique. **LightWeightSet** stores a set of values, each of which must be unique.
...@@ -44,7 +43,7 @@ A constructor used to create a **LightWeightSet** instance. ...@@ -44,7 +43,7 @@ A constructor used to create a **LightWeightSet** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -73,7 +72,7 @@ Checks whether this container is empty (contains no element). ...@@ -73,7 +72,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -108,7 +107,7 @@ Adds an element to this container. ...@@ -108,7 +107,7 @@ Adds an element to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -138,7 +137,7 @@ Adds all elements in a **LightWeightSet** instance to this container. ...@@ -138,7 +137,7 @@ Adds all elements in a **LightWeightSet** instance to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -178,7 +177,7 @@ Checks whether this container contains all elements of the specified **LightWeig ...@@ -178,7 +177,7 @@ Checks whether this container contains all elements of the specified **LightWeig
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -218,7 +217,7 @@ Checks whether this container has the specified key. ...@@ -218,7 +217,7 @@ Checks whether this container has the specified key.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -246,7 +245,7 @@ Checks whether this container contains objects of the same type as the specified ...@@ -246,7 +245,7 @@ Checks whether this container contains objects of the same type as the specified
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| obj | Object | Yes| Object to be used for comparison.| | obj | Object | Yes| **LightWeightSet** instance to be used for comparison.|
**Return value** **Return value**
...@@ -256,7 +255,7 @@ Checks whether this container contains objects of the same type as the specified ...@@ -256,7 +255,7 @@ Checks whether this container contains objects of the same type as the specified
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -289,12 +288,12 @@ Increases the capacity of this container. ...@@ -289,12 +288,12 @@ Increases the capacity of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The increaseCapacityTo method cannot be bound. | | 10200011 | The increaseCapacityTo method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of minimumCapacity is out of range. |
**Example** **Example**
...@@ -326,7 +325,7 @@ Obtains the position index of the element with the specified key in this contain ...@@ -326,7 +325,7 @@ Obtains the position index of the element with the specified key in this contain
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -364,7 +363,7 @@ Removes an element of the specified key from this container. ...@@ -364,7 +363,7 @@ Removes an element of the specified key from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -402,7 +401,7 @@ Removes the element at the specified position from this container. ...@@ -402,7 +401,7 @@ Removes the element at the specified position from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -440,7 +439,7 @@ Obtains the value of the element at the specified position in this container. ...@@ -440,7 +439,7 @@ Obtains the value of the element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -466,7 +465,7 @@ Clears this container and sets its length to **0**. ...@@ -466,7 +465,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -496,14 +495,6 @@ Obtains a string that contains all elements in this container. ...@@ -496,14 +495,6 @@ Obtains a string that contains all elements in this container.
| -------- | -------- | | -------- | -------- |
| String | String obtained.| | String | String obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The toString method cannot be bound. |
**Example** **Example**
```ts ```ts
...@@ -530,7 +521,7 @@ Obtains an array that contains all objects in this container. ...@@ -530,7 +521,7 @@ Obtains an array that contains all objects in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -562,7 +553,7 @@ Obtains an iterator that contains all the values in this container. ...@@ -562,7 +553,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -607,7 +598,7 @@ callbackfn ...@@ -607,7 +598,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -641,7 +632,7 @@ Obtains an iterator that contains all the elements in this container. ...@@ -641,7 +632,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -678,7 +669,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -678,7 +669,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.LinkedList (Linear Container LinkedList) # @ohos.util.LinkedList (Linear Container LinkedList)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LinkedList** is implemented based on the doubly linked list. Each node of the doubly linked list has references pointing to the previous element and the next element. When querying an element, the system traverses the list from the beginning or end. **LinkedList** offers efficient insertion and removal operations but supports low query efficiency. **LinkedList** allows null elements. **LinkedList** is implemented based on the doubly linked list. Each node of the doubly linked list has references pointing to the previous element and the next element. When querying an element, the system traverses the list from the beginning or end. **LinkedList** offers efficient insertion and removal operations but supports low query efficiency. **LinkedList** allows null elements.
Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList** is a doubly linked list that supports insertion and removal at both ends. Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList** is a doubly linked list that supports insertion and removal at both ends.
**LinkedList** is less efficient in data access than **[ArrayList](js-apis-arraylist.md)**. **LinkedList** is more efficient in data insertion than **[ArrayList](js-apis-arraylist.md)**, but less efficient in data access.
**Recommended use case**: Use **LinkedList** for frequent insertion and removal operations. **Recommended use case**: Use **LinkedList** for frequent insertion and removal operations.
...@@ -42,7 +41,7 @@ A constructor used to create a **LinkedList** instance. ...@@ -42,7 +41,7 @@ A constructor used to create a **LinkedList** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -78,7 +77,7 @@ Adds an element at the end of this container. ...@@ -78,7 +77,7 @@ Adds an element at the end of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -113,7 +112,7 @@ Adds an element at the top of this container. ...@@ -113,7 +112,7 @@ Adds an element at the top of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -149,12 +148,12 @@ Inserts an element at the specified position in this container. ...@@ -149,12 +148,12 @@ Inserts an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The insert method cannot be bound. | | 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -187,7 +186,7 @@ Checks whether this container has the specified element. ...@@ -187,7 +186,7 @@ Checks whether this container has the specified element.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -224,7 +223,7 @@ Obtains an element at the specified position in this container. ...@@ -224,7 +223,7 @@ Obtains an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -266,7 +265,7 @@ Obtains the index of the last occurrence of the specified element in this contai ...@@ -266,7 +265,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -308,7 +307,7 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -308,7 +307,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -350,12 +349,12 @@ Removes an element at the specified position from this container. ...@@ -350,12 +349,12 @@ Removes an element at the specified position from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. | | 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -385,7 +384,7 @@ Removes the first element from this container. ...@@ -385,7 +384,7 @@ Removes the first element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -420,7 +419,7 @@ Removes the last element from this container. ...@@ -420,7 +419,7 @@ Removes the last element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -461,7 +460,7 @@ Removes the first occurrence of the specified element from this container. ...@@ -461,7 +460,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -500,7 +499,7 @@ Removes the first occurrence of the specified element from this container. ...@@ -500,7 +499,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -540,7 +539,7 @@ Removes the last occurrence of the specified element from this container. ...@@ -540,7 +539,7 @@ Removes the last occurrence of the specified element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -574,7 +573,7 @@ Clones this container and returns a copy. The modification to the copy does not ...@@ -574,7 +573,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -617,7 +616,7 @@ callbackfn ...@@ -617,7 +616,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -646,7 +645,7 @@ Clears this container and sets its length to **0**. ...@@ -646,7 +645,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -686,12 +685,12 @@ Replaces an element at the specified position in this container with a given ele ...@@ -686,12 +685,12 @@ Replaces an element at the specified position in this container with a given ele
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The set method cannot be bound. | | 10200011 | The set method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -720,7 +719,7 @@ Converts this container into an array. ...@@ -720,7 +719,7 @@ Converts this container into an array.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -752,7 +751,7 @@ Obtains the first element in this container. ...@@ -752,7 +751,7 @@ Obtains the first element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -785,7 +784,7 @@ Obtains the last element in this container. ...@@ -785,7 +784,7 @@ Obtains the last element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -818,7 +817,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -818,7 +817,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.List (Linear Container List) # @ohos.util.List (Linear Container List)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**List** is implemented based on the singly linked list. Each node has a reference pointing to the next element. When querying an element, the system traverses the list from the beginning. **List** offers efficient insertion and removal operations but supports low query efficiency. **List** allows null elements. **List** is implemented based on the singly linked list. Each node has a reference pointing to the next element. When querying an element, the system traverses the list from the beginning. **List** offers efficient insertion and removal operations but supports low query efficiency. **List** allows null elements.
...@@ -26,7 +25,7 @@ import List from '@ohos.util.List'; ...@@ -26,7 +25,7 @@ import List from '@ohos.util.List';
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
| Name| Type | Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Number of elements in a list (called container later).| | length | number | Yes| No| Number of elements in a list (called container later).|
...@@ -41,7 +40,7 @@ A constructor used to create a **List** instance. ...@@ -41,7 +40,7 @@ A constructor used to create a **List** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -76,7 +75,7 @@ Adds an element at the end of this container. ...@@ -76,7 +75,7 @@ Adds an element at the end of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -112,12 +111,12 @@ Inserts an element at the specified position in this container. ...@@ -112,12 +111,12 @@ Inserts an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The insert method cannot be bound. | | 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -150,7 +149,7 @@ Checks whether this container has the specified element. ...@@ -150,7 +149,7 @@ Checks whether this container has the specified element.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -187,7 +186,7 @@ Obtains the element at the specified position in this container. ...@@ -187,7 +186,7 @@ Obtains the element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -229,7 +228,7 @@ Obtains the index of the last occurrence of the specified element in this contai ...@@ -229,7 +228,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -271,7 +270,7 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -271,7 +270,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -314,7 +313,7 @@ Compares whether a specified object is equal to this container. ...@@ -314,7 +313,7 @@ Compares whether a specified object is equal to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -359,12 +358,12 @@ Removes an element at the specified position from this container. ...@@ -359,12 +358,12 @@ Removes an element at the specified position from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. | | 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -400,7 +399,7 @@ Removes the first occurrence of the specified element from this container. ...@@ -400,7 +399,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -443,7 +442,7 @@ callbackfn ...@@ -443,7 +442,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -478,7 +477,7 @@ Uses a callback to traverse the elements in this container and obtain their posi ...@@ -478,7 +477,7 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Value Type | Mandatory| Description| | Name| Value Type | Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.| | callbackFn | function | Yes| Callback invoked for the replacement.|
| thisArg | Object | No| Value to use when the callback is invoked.| | thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn callbackfn
...@@ -491,7 +490,7 @@ callbackfn ...@@ -491,7 +490,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -533,7 +532,7 @@ comparator ...@@ -533,7 +532,7 @@ comparator
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -547,8 +546,8 @@ list.add(2); ...@@ -547,8 +546,8 @@ list.add(2);
list.add(4); list.add(4);
list.add(5); list.add(5);
list.add(4); list.add(4);
list.sort((a: number, b: number) => a - b); list.sort((a: number, b: number) => a - b); // The elements are sorted in ascending order.
list.sort((a: number, b: number) => b - a); list.sort((a: number, b: number) => b - a); // The elements are sorted in descending order.
``` ```
### getSubList ### getSubList
...@@ -574,12 +573,12 @@ Obtains elements within a range in this container, including the element at the ...@@ -574,12 +573,12 @@ Obtains elements within a range in this container, including the element at the
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The getSubList method cannot be bound. | | 10200011 | The getSubList method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of fromIndex or toIndex is out of range. |
**Example** **Example**
...@@ -604,7 +603,7 @@ Clears this container and sets its length to **0**. ...@@ -604,7 +603,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -644,12 +643,12 @@ Replaces an element at the specified position in this container with a given ele ...@@ -644,12 +643,12 @@ Replaces an element at the specified position in this container with a given ele
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The set method cannot be bound. | | 10200011 | The set method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -678,7 +677,7 @@ Converts this container into an array. ...@@ -678,7 +677,7 @@ Converts this container into an array.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -711,7 +710,7 @@ Checks whether this container is empty (contains no element). ...@@ -711,7 +710,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -744,7 +743,7 @@ Obtains the first element in this container. ...@@ -744,7 +743,7 @@ Obtains the first element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -777,7 +776,7 @@ Obtains the last element in this container. ...@@ -777,7 +776,7 @@ Obtains the last element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -810,7 +809,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -810,7 +809,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.PlainArray (Nonlinear Container PlainArray) # @ohos.util.PlainArray (Nonlinear Container PlainArray)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value. **PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value.
...@@ -21,6 +20,8 @@ This topic uses the following to identify the use of generics: ...@@ -21,6 +20,8 @@ This topic uses the following to identify the use of generics:
import PlainArray from '@ohos.util.PlainArray'; import PlainArray from '@ohos.util.PlainArray';
``` ```
## PlainArray ## PlainArray
### Attributes ### Attributes
...@@ -42,7 +43,7 @@ A constructor used to create a **PlainArray** instance. ...@@ -42,7 +43,7 @@ A constructor used to create a **PlainArray** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -71,7 +72,7 @@ Checks whether this container is empty. ...@@ -71,7 +72,7 @@ Checks whether this container is empty.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -107,7 +108,7 @@ Checks whether this container contains the specified key. ...@@ -107,7 +108,7 @@ Checks whether this container contains the specified key.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -145,7 +146,7 @@ Obtains the value of the specified key in this container. ...@@ -145,7 +146,7 @@ Obtains the value of the specified key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -183,7 +184,7 @@ Obtains the index of the first occurrence of an element with the specified key i ...@@ -183,7 +184,7 @@ Obtains the index of the first occurrence of an element with the specified key i
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -221,7 +222,7 @@ Obtains the index of the first occurrence of an element with the specified value ...@@ -221,7 +222,7 @@ Obtains the index of the first occurrence of an element with the specified value
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -259,7 +260,7 @@ Obtains the key of the element at the specified position in this container. ...@@ -259,7 +260,7 @@ Obtains the key of the element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -284,24 +285,24 @@ Obtains the value of an element at the specified position in this container. ...@@ -284,24 +285,24 @@ Obtains the value of an element at the specified position in this container.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description| | Name| Type | Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the target element.| | index | number | Yes| Position index of the target element.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| T | Returns the value of the element if obtained; returns **undefined** otherwise.| | T | Returns the value of the element if obtained; returns **undefined** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. | | 10200011 | The getValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -328,7 +329,7 @@ Clones this container and returns a copy. The modification to the copy does not ...@@ -328,7 +329,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -361,7 +362,7 @@ Adds an element to this container. ...@@ -361,7 +362,7 @@ Adds an element to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -397,7 +398,7 @@ Removes an element with the specified key from this container. ...@@ -397,7 +398,7 @@ Removes an element with the specified key from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -435,7 +436,7 @@ Removes an element at the specified position from this container. ...@@ -435,7 +436,7 @@ Removes an element at the specified position from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -474,12 +475,12 @@ Removes elements in a specified range from this container. ...@@ -474,12 +475,12 @@ Removes elements in a specified range from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The removeRangeFrom method cannot be bound. | | 10200011 | The removeRangeFrom method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -508,12 +509,12 @@ Sets a value for an element at the specified position in this container. ...@@ -508,12 +509,12 @@ Sets a value for an element at the specified position in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 10200011 | The setValueAt method cannot be bound. | | 10200011 | The setValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. | | 10200001 | The value of index is out of range. |
**Example** **Example**
...@@ -541,7 +542,7 @@ Obtains a string that contains all elements in this container. ...@@ -541,7 +542,7 @@ Obtains a string that contains all elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -567,7 +568,7 @@ Clears this container and sets its length to **0**. ...@@ -567,7 +568,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -607,7 +608,7 @@ callbackfn ...@@ -607,7 +608,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -641,7 +642,7 @@ Obtains an iterator object that contains key-value pairs, where the key is of th ...@@ -641,7 +642,7 @@ Obtains an iterator object that contains key-value pairs, where the key is of th
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.Queue (Linear Container Queue) # @ohos.util.Queue (Linear Container Queue)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Queue** follows the principle of First In First Out (FIFO). It supports insertion of elements at the end and removal from the front of the queue. **Queue** is implemented based on the queue data structure. **Queue** follows the principle of First In First Out (FIFO). It supports insertion of elements at the end and removal from the front of the queue. **Queue** is implemented based on the queue data structure.
...@@ -41,7 +40,7 @@ A constructor used to create a **Queue** instance. ...@@ -41,7 +40,7 @@ A constructor used to create a **Queue** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -76,7 +75,7 @@ Adds an element at the end of this container. ...@@ -76,7 +75,7 @@ Adds an element at the end of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -110,7 +109,7 @@ Removes the first element from this container. ...@@ -110,7 +109,7 @@ Removes the first element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -144,7 +143,7 @@ Obtains the first element of this container. ...@@ -144,7 +143,7 @@ Obtains the first element of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -187,7 +186,7 @@ callbackfn ...@@ -187,7 +186,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -222,7 +221,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -222,7 +221,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.Stack (Linear Container Stack) # @ohos.util.Stack (Linear Container Stack)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Stack** is implemented based on the array data structure. It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end. **Stack** is implemented based on the array data structure. It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end.
...@@ -40,7 +39,7 @@ A constructor used to create a **Stack** instance. ...@@ -40,7 +39,7 @@ A constructor used to create a **Stack** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -75,7 +74,7 @@ Adds an element at the top of this container. ...@@ -75,7 +74,7 @@ Adds an element at the top of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -109,7 +108,7 @@ Removes the top element from this container. ...@@ -109,7 +108,7 @@ Removes the top element from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -143,7 +142,7 @@ Obtains the top element of this container. ...@@ -143,7 +142,7 @@ Obtains the top element of this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -182,7 +181,7 @@ Obtains the index of the first occurrence of the specified element in this conta ...@@ -182,7 +181,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -225,7 +224,7 @@ callbackfn ...@@ -225,7 +224,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -260,7 +259,7 @@ Checks whether this container is empty (contains no elements). ...@@ -260,7 +259,7 @@ Checks whether this container is empty (contains no elements).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -293,7 +292,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -293,7 +292,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.TreeMap (Nonlinear Container TreeMap) # @ohos.util.TreeMap (Nonlinear Container TreeMap)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeMap** stores key-value (KV) pairs. Each key must be unique and have only one value. **TreeMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
...@@ -49,7 +48,7 @@ A constructor used to create a **TreeMap** instance. ...@@ -49,7 +48,7 @@ A constructor used to create a **TreeMap** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -78,7 +77,7 @@ Checks whether this container is empty (contains no element). ...@@ -78,7 +77,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -114,7 +113,7 @@ Checks whether this container has the specified key. ...@@ -114,7 +113,7 @@ Checks whether this container has the specified key.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -152,7 +151,7 @@ Checks whether this container has the specified value. ...@@ -152,7 +151,7 @@ Checks whether this container has the specified value.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -190,7 +189,7 @@ Obtains the value of the specified key in this container. ...@@ -190,7 +189,7 @@ Obtains the value of the specified key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -222,7 +221,7 @@ Obtains the first key in this container. ...@@ -222,7 +221,7 @@ Obtains the first key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -254,7 +253,7 @@ Obtains the last key in this container. ...@@ -254,7 +253,7 @@ Obtains the last key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -282,11 +281,11 @@ Adds all elements in a **TreeMap** instance to this container. ...@@ -282,11 +281,11 @@ Adds all elements in a **TreeMap** instance to this container.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| map | TreeMap<K, V> | Yes| **TreeMap** instance whose elements are to be added to the current container.| | map | TreeMap<K, V> | Yes| **TreeMap** object to be added to the container.|
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -299,7 +298,11 @@ let treeMap = new TreeMap(); ...@@ -299,7 +298,11 @@ let treeMap = new TreeMap();
treeMap.set("squirrel", 123); treeMap.set("squirrel", 123);
treeMap.set("sparrow", 356); treeMap.set("sparrow", 356);
let map = new TreeMap(); let map = new TreeMap();
treeMap.setAll(map); map.set("demo", 12);
map.setAll(treeMap); // Add all elements in the treeMap to the map.
map.forEach((value, key) => {
console.log("test" + value, key); // Print result: 12 demo, 356 sparrow, and 123 squirrel
})
``` ```
...@@ -326,7 +329,7 @@ Adds an element to this container. ...@@ -326,7 +329,7 @@ Adds an element to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -362,7 +365,7 @@ Removes the element with the specified key from this container. ...@@ -362,7 +365,7 @@ Removes the element with the specified key from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -400,7 +403,7 @@ Obtains the key that is placed in front of the input key in this container. ...@@ -400,7 +403,7 @@ Obtains the key that is placed in front of the input key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -439,7 +442,7 @@ Obtains the key that is placed next to the input key in this container. ...@@ -439,7 +442,7 @@ Obtains the key that is placed next to the input key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -478,7 +481,7 @@ Replaces an element in this container. ...@@ -478,7 +481,7 @@ Replaces an element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -503,7 +506,7 @@ Clears this container and sets its length to **0**. ...@@ -503,7 +506,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -535,7 +538,7 @@ Obtains an iterator that contains all the keys in this container. ...@@ -535,7 +538,7 @@ Obtains an iterator that contains all the keys in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -572,7 +575,7 @@ Obtains an iterator that contains all the values in this container. ...@@ -572,7 +575,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -617,7 +620,7 @@ callbackfn ...@@ -617,7 +620,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -651,7 +654,7 @@ Obtains an iterator that contains all the elements in this container. ...@@ -651,7 +654,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -688,7 +691,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -688,7 +691,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
# @ohos.util.TreeSet (Nonlinear Container TreeSet) # @ohos.util.TreeSet (Nonlinear Container TreeSet)
> **NOTE** > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeSet** is implemented based on **[TreeMap](js-apis-treemap.md)**. In **TreeSet**, only **value** objects are processed. **TreeSet** can be used to store values, each of which must be unique. **TreeSet** is implemented based on **[TreeMap](js-apis-treemap.md)**. In **TreeSet**, only **value** objects are processed. **TreeSet** can be used to store values, each of which must be unique.
...@@ -46,7 +45,7 @@ A constructor used to create a **TreeSet** instance. ...@@ -46,7 +45,7 @@ A constructor used to create a **TreeSet** instance.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -75,7 +74,7 @@ Checks whether this container is empty (contains no element). ...@@ -75,7 +74,7 @@ Checks whether this container is empty (contains no element).
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -111,7 +110,7 @@ Checks whether this container has the specified value. ...@@ -111,7 +110,7 @@ Checks whether this container has the specified value.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -143,7 +142,7 @@ Obtains the value of the first element in this container. ...@@ -143,7 +142,7 @@ Obtains the value of the first element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -175,7 +174,7 @@ Obtains the value of the last element in this container. ...@@ -175,7 +174,7 @@ Obtains the value of the last element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -213,7 +212,7 @@ Adds an element to this container. ...@@ -213,7 +212,7 @@ Adds an element to this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -249,7 +248,7 @@ Removes the element with the specified key from this container. ...@@ -249,7 +248,7 @@ Removes the element with the specified key from this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -287,7 +286,7 @@ Obtains the value that is placed in front of the input key in this container. ...@@ -287,7 +286,7 @@ Obtains the value that is placed in front of the input key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -326,7 +325,7 @@ Obtains the value that is placed next to the input key in this container. ...@@ -326,7 +325,7 @@ Obtains the value that is placed next to the input key in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -359,7 +358,7 @@ Removes the first element in this container. ...@@ -359,7 +358,7 @@ Removes the first element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -391,7 +390,7 @@ Removes the last element in this container. ...@@ -391,7 +390,7 @@ Removes the last element in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -417,7 +416,7 @@ Clears this container and sets its length to **0**. ...@@ -417,7 +416,7 @@ Clears this container and sets its length to **0**.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -449,7 +448,7 @@ Obtains an iterator that contains all the values in this container. ...@@ -449,7 +448,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -494,7 +493,7 @@ callbackfn ...@@ -494,7 +493,7 @@ callbackfn
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -528,7 +527,7 @@ Obtains an iterator that contains all the elements in this container. ...@@ -528,7 +527,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
...@@ -566,7 +565,7 @@ Obtains an iterator, each item of which is a JavaScript object. ...@@ -566,7 +565,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes** **Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md). For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
......
...@@ -29,6 +29,70 @@ import uri from '@ohos.uri' ...@@ -29,6 +29,70 @@ import uri from '@ohos.uri'
| authority | string | Yes| No| Authority part in the URI.| | authority | string | Yes| No| Authority part in the URI.|
| ssp | string | Yes| No| Scheme-specific part in the URI.| | ssp | string | Yes| No| Scheme-specific part in the URI.|
### Naming Rules
Naming format:
A standard URI consists of the following parts:
[scheme:]scheme-specific-part[#fragment]
- Scheme: scheme component, which is mandatory. Example values: **http**, **https**, **ftp**, **datashare**, and **dataability**.
- scheme-specific-part: specific part of the URI decoding scheme. The value consists of [//][authority][path][?query]. Set this parameter as required.
- authority: decoding authority component of the URI. The value consists of [userinfo@]host[:port]. Set this parameter as required.
- userinfo: user information. Set this parameter as required.
- host: host name of the server. This parameter is mandatory when authority exists.
- port: port number of the server. Set this parameter as required.
- path: path information. Set this parameter as required.
- query: query component. Set this parameter as required.
- fragment: fragment component. Set this parameter as required.
**Example URIs**
```js
const result1 = new uri.URI("ftp://ftp.aaa.bbb.ccc/dddd/eee.txt");
console.log(result1.host) // ftp.aaa.bbb.ccc
console.log(result1.fragment) // null
console.log(result1.path) // /dddd/eee.txt
console.log(result1.scheme) // ftp
console.log(result1.userInfo) // null
console.log(result1.port) // -1
console.log(result1.query) // null
const result2 = new uri.URI("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#fragment");
console.log(result2.host) // spinaltap.micro.umn.edu
console.log(result2.fragment) // fragment
console.log(result2.path) // /dddd/eee.txt
console.log(result2.scheme) // ftp
console.log(result2.userInfo) // null
console.log(result2.port) //-1
console.log(result2.query) // null
const result3 = new uri.URI("datashare:///com.samples.datasharetest.DataShare/DB00/TBL00");
console.log(result3.host) // null
console.log(result3.fragment) // null
console.log(result3.path) // /com.samples.datasharetest.DataShare/DB00/TBL00
console.log(result3.scheme) // datashare
console.log(result3.userInfo) // null
console.log(result3.port) // -1
console.log(result3.query) // null
const result4 = new uri.URI("https://username:password@host:8080/directory/file?foo=1&bar=2#fragment");
console.log(result4.host) // host
console.log(result4.fragment) // fragment
console.log(result4.path) // /directory/file
console.log(result4.scheme) // https
console.log(result4.userInfo) // username:password
console.log(result4.port) // 8080
console.log(result4.query) // foo=1&bar=2
const result5 = new uri.URI("dataability:///com.example.DataAbility");
console.log(result5.host) // null
console.log(result5.fragment) // null
console.log(result5.path) // /com.example.DataAbility:
console.log(result5.scheme) // dataability
console.log(result5.userInfo) // null
console.log(result5.port) // -1
console.log(result5.query) // null
```
### constructor ### constructor
...@@ -44,6 +108,14 @@ A constructor used to create a URI instance. ...@@ -44,6 +108,14 @@ A constructor used to create a URI instance.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes| Input object.| | uri | string | Yes| Input object.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200002 | Invalid uri string. |
**Example** **Example**
```js ```js
...@@ -79,14 +151,14 @@ result.toString() ...@@ -79,14 +151,14 @@ result.toString()
### equals<sup>(deprecated)</sup> ### equals<sup>(deprecated)</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [equalsTo<sup>9+</sup>](#equalsto9) instead.
equals(other: URI): boolean equals(other: URI): boolean
Checks whether this URI is the same as another URI object. Checks whether this URI is the same as another URI object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [equalsTo<sup>9+</sup>](#equalsto9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
...@@ -105,7 +177,7 @@ Checks whether this URI is the same as another URI object. ...@@ -105,7 +177,7 @@ Checks whether this URI is the same as another URI object.
```js ```js
const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment'); const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
uriInstance.equals(uriInstance1); uriInstance.equals(uriInstance1);
``` ```
### equalsTo<sup>9+</sup> ### equalsTo<sup>9+</sup>
...@@ -132,7 +204,7 @@ Checks whether this URI is the same as another URI object. ...@@ -132,7 +204,7 @@ Checks whether this URI is the same as another URI object.
```js ```js
const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment'); const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
uriInstance.equalsTo(uriInstance1); uriInstance.equalsTo(uriInstance1);
``` ```
...@@ -148,7 +220,7 @@ Checks whether this URI is an absolute URI (whether the scheme component is defi ...@@ -148,7 +220,7 @@ Checks whether this URI is an absolute URI (whether the scheme component is defi
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the URI is an absolute URI; returns **false** otherwise.| | boolean | If the URI is an absolute URI, **true** is returned. Otherwise, **false** is returned.|
**Example** **Example**
......
...@@ -11,7 +11,6 @@ import Url from '@ohos.url' ...@@ -11,7 +11,6 @@ import Url from '@ohos.url'
``` ```
## URLParams<sup>9+</sup> ## URLParams<sup>9+</sup>
### constructor<sup>9+</sup> ### constructor<sup>9+</sup>
constructor(init?: string[][] | Record&lt;string, string&gt; | string | URLSearchParams) constructor(init?: string[][] | Record&lt;string, string&gt; | string | URLSearchParams)
...@@ -32,7 +31,7 @@ A constructor used to create a **URLParams** instance. ...@@ -32,7 +31,7 @@ A constructor used to create a **URLParams** instance.
let objectParams = new Url.URLParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); let objectParams = new Url.URLParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
let objectParams1 = new Url.URLParams({"fod" : '1' , "bard" : '2'}); let objectParams1 = new Url.URLParams({"fod" : '1' , "bard" : '2'});
let objectParams2 = new Url.URLParams('?fod=1&bard=2'); let objectParams2 = new Url.URLParams('?fod=1&bard=2');
let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.mozilla.org/?fod=1&bard=2');
let params = new Url.URLParams(urlObject.search); let params = new Url.URLParams(urlObject.search);
``` ```
...@@ -55,7 +54,7 @@ Appends a key-value pair into the query string. ...@@ -55,7 +54,7 @@ Appends a key-value pair into the query string.
**Example** **Example**
```js ```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.append('fod', '3'); paramsObject.append('fod', '3');
``` ```
...@@ -78,9 +77,9 @@ Deletes key-value pairs of the specified key. ...@@ -78,9 +77,9 @@ Deletes key-value pairs of the specified key.
**Example** **Example**
```js ```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsobject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsobject.delete('fod'); paramsObject.delete('fod');
``` ```
...@@ -88,7 +87,7 @@ paramsobject.delete('fod'); ...@@ -88,7 +87,7 @@ paramsobject.delete('fod');
getAll(name: string): string[] getAll(name: string): string[]
Obtains all the key-value pairs based on the specified key. Obtains all the key-value pairs based on the specified name.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -102,12 +101,12 @@ Obtains all the key-value pairs based on the specified key. ...@@ -102,12 +101,12 @@ Obtains all the key-value pairs based on the specified key.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string[] | All key-value pairs matching the specified key.| | string[] | Key-value pairs obtained.|
**Example** **Example**
```js ```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(urlObject.search.slice(1)); let params = new Url.URLParams(urlObject.search.slice(1));
params.append('fod', '3'); // Add a second value for the fod parameter. params.append('fod', '3'); // Add a second value for the fod parameter.
console.log(params.getAll('fod').toString()) // Output ["1","3"]. console.log(params.getAll('fod').toString()) // Output ["1","3"].
...@@ -132,7 +131,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ...@@ -132,7 +131,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
```js ```js
let searchParamsObject = new Url.URLParams("keyName1=valueName1&keyName2=valueName2"); let searchParamsObject = new Url.URLParams("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]);
} }
``` ```
...@@ -164,9 +163,9 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal ...@@ -164,9 +163,9 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal
**Example** **Example**
```js ```js
const myURLObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); const myURLObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.searchParams.forEach((value, name, searchParams) => { myURLObject.params.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.searchParams === searchParams); console.log(name, value, myURLObject.params === searchParams);
}); });
``` ```
...@@ -224,7 +223,7 @@ Checks whether a key has a value. ...@@ -224,7 +223,7 @@ Checks whether a key has a value.
**Example** **Example**
```js ```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.has('bard') === true; paramsObject.has('bard') === true;
``` ```
...@@ -248,7 +247,7 @@ Sets the value for a key. If key-value pairs matching the specified key exist, t ...@@ -248,7 +247,7 @@ Sets the value for a key. If key-value pairs matching the specified key exist, t
**Example** **Example**
```js ```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.set('baz', '3'); // Add a third parameter. paramsObject.set('baz', '3'); // Add a third parameter.
``` ```
...@@ -360,7 +359,7 @@ Obtains search parameters that are serialized as a string and, if necessary, per ...@@ -360,7 +359,7 @@ Obtains search parameters that are serialized as a string and, if necessary, per
**Example** **Example**
```js ```js
let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let url = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(url.search.slice(1)); let params = new Url.URLParams(url.search.slice(1));
params.append('fod', '3'); params.append('fod', '3');
console.log(params.toString()); console.log(params.toString());
...@@ -384,20 +383,20 @@ console.log(params.toString()); ...@@ -384,20 +383,20 @@ console.log(params.toString());
| port | string | Yes| Yes| Port in a URL.| | port | string | Yes| Yes| Port in a URL.|
| protocol | string | Yes| Yes| Protocol in a URL.| | protocol | string | Yes| Yes| Protocol in a URL.|
| search | string | Yes| Yes| Serialized query string in a URL.| | search | string | Yes| Yes| Serialized query string in a URL.|
| searchParams | URLSearchParams | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.| | searchParams<sup>(deprecated)</sup> | [URLSearchParams](#urlsearchparamsdeprecated) | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.<br>- **NOTE**: This attribute is supported since API version 7 and is deprecated since API version 9. You are advised to use params<sup>9+</sup> instead.|
| URLParams | URLParams | Yes| No| **URLParams** object allowing access to the query parameters in a URL.| | params<sup>9+</sup> | [URLParams](#urlparams9) | Yes| No| **URLParams** object allowing access to the query parameters in a URL.|
| username | string | Yes| Yes| Username in a URL.| | username | string | Yes| Yes| Username in a URL.|
### constructor<sup>(deprecated)</sup> ### constructor<sup>(deprecated)</sup>
constructor(url: string, base?: string | URL)
Creates a URL.
> **NOTE** > **NOTE**
> >
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [parseURL<sup>9+</sup>](#parseurl9) instead. > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [parseURL<sup>9+</sup>](#parseurl9) instead.
constructor(url: string, base?: string | URL)
Creates a URL.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
...@@ -410,13 +409,13 @@ Creates a URL. ...@@ -410,13 +409,13 @@ Creates a URL.
**Example** **Example**
```js ```js
let mm = 'http://username:password@host:8080'; let mm = 'https://username:password@host:8080';
let a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/';
let b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; let b = new Url.URL(mm); // Output 'https://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 'https://username:password@host:8080/path/path1';
let c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; let c = new Url.URL('/path/path1', b); // Output 'https://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 'https://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 'https://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
new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL
new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL
...@@ -424,6 +423,14 @@ new Url.URL('https://www.example.com', ); // Output https://www.example.com/ ...@@ -424,6 +423,14 @@ new Url.URL('https://www.example.com', ); // Output https://www.example.com/
new Url.URL('https://www.example.com', b); // Output https://www.example.com/ new Url.URL('https://www.example.com', b); // Output https://www.example.com/
``` ```
### constructor<sup>9+</sup>
constructor()
A no-argument constructor used to create a URL. It returns a **URL** object after **parseURL** is called. It is not used independently.
**System capability**: SystemCapability.Utils.Lang
### parseURL<sup>9+</sup> ### parseURL<sup>9+</sup>
static parseURL(url : string, base?: string | URL): URL static parseURL(url : string, base?: string | URL): URL
...@@ -447,11 +454,13 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ...@@ -447,11 +454,13 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
| -------- | -------- | | -------- | -------- |
| 10200002 | Invalid url string. | | 10200002 | Invalid url string. |
**Example** **Example**
```js ```js
let mm = 'http://username:password@host:8080'; let mm = 'https://username:password@host:8080';
Url.URL.parseURL(mm); // Output 'http://username:password@host:8080/'; let url = Url.URL.parseURL(mm);
url.toString(); // Output 'https://username:password@host:8080/';
``` ```
### tostring ### tostring
...@@ -471,11 +480,10 @@ Converts the parsed URL into a string. ...@@ -471,11 +480,10 @@ Converts the parsed URL into a string.
**Example** **Example**
```js ```js
const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString(); url.toString();
``` ```
### toJSON ### toJSON
toJSON(): string toJSON(): string
...@@ -492,7 +500,7 @@ Converts the parsed URL into a JSON string. ...@@ -492,7 +500,7 @@ Converts the parsed URL into a JSON string.
**Example** **Example**
```js ```js
const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON(); url.toJSON();
``` ```
...@@ -634,7 +642,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ...@@ -634,7 +642,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
```js ```js
let 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]);
} }
``` ```
...@@ -657,7 +665,7 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal ...@@ -657,7 +665,7 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.| | callbackFn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.|
| thisArg | Object | No| Value to use when **callbackFn** is invoked.| | thisArg | Object | No| Value of **this** to use when **callbackFn** is invoked.|
**Table 1** callbackFn parameter description **Table 1** callbackFn parameter description
...@@ -902,126 +910,4 @@ let params = new Url.URLSearchParams(url.search.slice(1)); ...@@ -902,126 +910,4 @@ let params = new Url.URLSearchParams(url.search.slice(1));
params.append('fod', '3'); params.append('fod', '3');
console.log(params.toString()); console.log(params.toString());
``` ```
## URL
### Attributes
**System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| hash | string | Yes| Yes| String that contains a harsh mark (#) followed by the fragment identifier of a URL.|
| host | string | Yes| Yes| Host information in a URL.|
| hostname | string | Yes| Yes| Hostname (without the port) in a URL.|
| href | string | Yes| Yes| String that contains the whole URL.|
| origin | string | Yes| No| Read-only string that contains the Unicode serialization of the origin of the represented URL.|
| password | string | Yes| Yes| Password in a URL.|
| pathname | string | Yes| Yes| Path in a URL.|
| port | string | Yes| Yes| Port in a URL.|
| protocol | string | Yes| Yes| Protocol in a URL.|
| search | string | Yes| Yes| Serialized query string in a URL.|
| searchParams | URLSearchParams | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.|
| URLParams | URLParams | Yes| No| **URLParams** object allowing access to the query parameters in a URL.|
| username | string | Yes| Yes| Username in a URL.|
### constructor<sup>(deprecated)</sup>
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [parseURL<sup>9+</sup>](#parseurl9) instead.
constructor(url: string, base?: string | URL)
Creates a URL.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| url | string | Yes| Input object.|
| base | string \| URL | No| Input parameter, which can be any of the following:<br>- **string**: string<br>- **URL**: string or object|
**Example**
```js
let mm = 'https://username:password@host:8080';
let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/';
let b = new Url.URL(mm); // Output 'https://username:password@host:8080/';
new Url.URL('path/path1', b); // Output 'https://username:password@host:8080/path/path1';
let c = new Url.URL('/path/path1', b); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', c); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', a); // Output 'https://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', ''); // Raises a TypeError exception as '' is not a valid URL
new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL
new Url.URL('https://www.example.com', ); // Output https://www.example.com/
new Url.URL('https://www.example.com', b); // Output https://www.example.com/
```
### parseURL<sup>9+</sup>
static parseURL(url : string, base?: string | URL): URL
Parses a URL.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| url | string | Yes| Input object.|
| base | string \| URL | No| Input parameter, which can be any of the following:<br>- **string**: string<br>- **URL**: string or object|
**Example**
```js
let mm = 'https://username:password@host:8080';
Url.URL.parseURL(mm); // Output 'https://username:password@host:8080/';
```
### tostring
toString(): string
Converts the parsed URL into a string.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| string | Website address in a serialized string.|
**Example**
```js
const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString();
```
### toJSON
toJSON(): string
Converts the parsed URL into a JSON string.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| string | Website address in a serialized string.|
**Example**
```js
const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON();
```
<!--no_check--> <!--no_check-->
# @ohos.util (Utilities) # @ohos.util (util)
The **util** module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types. The **util** module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types.
...@@ -41,38 +41,6 @@ let res = util.format("%s", "hello world!"); ...@@ -41,38 +41,6 @@ let res = util.format("%s", "hello world!");
console.log(res); console.log(res);
``` ```
## util.printf<sup>(deprecated)</sup>
printf(format: string, ...args: Object[]): string
Formats the specified values and inserts them into the string by replacing the wildcard in the string.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.format<sup>9+</sup>](#utilformat9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| format | string | Yes| String.|
| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | String containing the formatted values.|
**Example**
```js
let res = util.printf("%s", "hello world!");
console.log(res);
```
## util.errnoToString<sup>9+</sup> ## util.errnoToString<sup>9+</sup>
errnoToString(errno: number): string errnoToString(errno: number): string
...@@ -96,43 +64,11 @@ Obtains detailed information about a system error code. ...@@ -96,43 +64,11 @@ Obtains detailed information about a system error code.
**Example** **Example**
```js ```js
let errnum = 10; // 10 is a system error code. let errnum = -1; // -1 is a system error code.
let result = util.errnoToString(errnum); let result = util.errnoToString(errnum);
console.log("result = " + result); console.log("result = " + result);
``` ```
## util.getErrorString<sup>(deprecated)</sup>
getErrorString(errno: number): string
Obtains detailed information about a system error code.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.errnoToString<sup>9+</sup>](#utilerrnotostring9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errno | number | Yes| Error code generated.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Detailed information about the error code.|
**Example**
```js
let errnum = 10; // 10 is a system error code.
let result = util.getErrorString(errnum);
console.log("result = " + result);
```
## util.callbackWrapper ## util.callbackWrapper
callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void
...@@ -203,30 +139,6 @@ Processes an asynchronous function and returns a promise. ...@@ -203,30 +139,6 @@ Processes an asynchronous function and returns a promise.
}) })
``` ```
## util.promiseWrapper<sup>(deprecated)</sup>
promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
Processes an asynchronous function and returns a promise.
> **NOTE**
>
> This API is unavailable. You are advised to use [util.promisify<sup>9+</sup>](#utilpromisify9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|
**Return value**
| Type| Description|
| -------- | -------- |
| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
## util.randomUUID<sup>9+</sup> ## util.randomUUID<sup>9+</sup>
randomUUID(entropyCache?: boolean): string randomUUID(entropyCache?: boolean): string
...@@ -314,6 +226,96 @@ Parses a UUID from a string, as described in RFC 4122 version 4. ...@@ -314,6 +226,96 @@ Parses a UUID from a string, as described in RFC 4122 version 4.
// 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156 // 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156
``` ```
## util.printf<sup>(deprecated)</sup>
printf(format: string, ...args: Object[]): string
Formats the specified values and inserts them into the string by replacing the wildcard in the string.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.format<sup>9+</sup>](#utilformat9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| format | string | Yes| String.|
| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | String containing the formatted values.|
**Example**
```js
let res = util.printf("%s", "hello world!");
console.log(res);
```
## util.getErrorString<sup>(deprecated)</sup>
getErrorString(errno: number): string
Obtains detailed information about a system error code.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.errnoToString<sup>9+</sup>](#utilerrnotostring9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errno | number | Yes| Error code generated.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Detailed information about the error code.|
**Example**
```js
let errnum = -1; // -1 is a system error code.
let result = util.getErrorString(errnum);
console.log("result = " + result);
```
## util.promiseWrapper<sup>(deprecated)</sup>
promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
Processes an asynchronous function and returns a promise.
> **NOTE**
>
> This API is unavailable. You are advised to use [util.promisify<sup>9+</sup>](#utilpromisify9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|
**Return value**
| Type| Description|
| -------- | -------- |
| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
## TextDecoder ## TextDecoder
### Attributes ### Attributes
...@@ -336,7 +338,7 @@ A constructor used to create a **TextDecoder** object. ...@@ -336,7 +338,7 @@ A constructor used to create a **TextDecoder** object.
### create<sup>9+</sup> ### create<sup>9+</sup>
create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean },): TextDecoder; create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoder;
Creates a **TextDecoder** object. It provides the same function as the deprecated argument constructor. Creates a **TextDecoder** object. It provides the same function as the deprecated argument constructor.
...@@ -363,41 +365,9 @@ let textDecoder = new util.TextDecoder() ...@@ -363,41 +365,9 @@ let textDecoder = new util.TextDecoder()
textDecoder.create('utf-8', { ignoreBOM : true }); textDecoder.create('utf-8', { ignoreBOM : true });
``` ```
### constructor<sup>(deprecated)</sup> ### decodeWithStream<sup>9+</sup>
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
A constructor used to create a **TextDecoder** object.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.|
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
**Table 1** options
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fatal | boolean | No| Whether to display fatal errors.|
| ignoreBOM | boolean | No| Whether to ignore the BOM.|
**Example**
```js
let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
```
### decode
decode(input: Uint8Array, options?: { stream?: false }): string decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string
Decodes the input content. Decodes the input content.
...@@ -414,7 +384,7 @@ Decodes the input content. ...@@ -414,7 +384,7 @@ Decodes the input content.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| 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 **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** **Return value**
...@@ -434,17 +404,52 @@ Decodes the input content. ...@@ -434,17 +404,52 @@ Decodes the input content.
result[4] = 0x62; result[4] = 0x62;
result[5] = 0x63; result[5] = 0x63;
console.log("input num:"); console.log("input num:");
let retStr = textDecoder.decode( result , {stream: false}); let retStr = textDecoder.decodeWithStream( result , {stream: false});
console.log("retStr = " + retStr); console.log("retStr = " + retStr);
``` ```
### constructor<sup>(deprecated)</sup>
### decodeWithStream<sup>9+</sup> constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean })
decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string A constructor used to create a **TextDecoder** object.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [create<sup>9+</sup>](#create9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.|
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
**Table 1** options
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fatal | boolean | No| Whether to display fatal errors.|
| ignoreBOM | boolean | No| Whether to ignore the BOM.|
**Example**
```js
let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
```
### decode<sup>(deprecated)</sup>
decode(input: Uint8Array, options?: { stream?: false }): string
Decodes the input content. Decodes the input content.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [decodeWithStream<sup>9+</sup>](#decodewithstream9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
...@@ -458,7 +463,7 @@ Decodes the input content. ...@@ -458,7 +463,7 @@ Decodes the input content.
| Name| Type| Mandatory| Description| | 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**.| | 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**
...@@ -478,11 +483,10 @@ Decodes the input content. ...@@ -478,11 +483,10 @@ Decodes the input content.
result[4] = 0x62; result[4] = 0x62;
result[5] = 0x63; result[5] = 0x63;
console.log("input num:"); console.log("input num:");
let retStr = textDecoder.decodeWithStream( result , {stream: false}); let retStr = textDecoder.decode( result , {stream: false});
console.log("retStr = " + retStr); console.log("retStr = " + retStr);
``` ```
## TextEncoder ## TextEncoder
### Attributes ### Attributes
...@@ -493,7 +497,6 @@ Decodes the input content. ...@@ -493,7 +497,6 @@ Decodes the input content.
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.| | encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
### constructor ### constructor
constructor() constructor()
...@@ -508,65 +511,53 @@ A constructor used to create a **TextEncoder** object. ...@@ -508,65 +511,53 @@ A constructor used to create a **TextEncoder** object.
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
``` ```
### encodeInto<sup>9+</sup> ### constructor<sup>9+</sup>
encodeInto(input?: string): Uint8Array constructor(encoding?: string)
Encodes the input content. A constructor used to create a **TextEncoder** object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ------------------ | | ----- | ---- | ---- | ---- |
| input | string | No | String to encode.| | encoding | string | No| Encoding format.|
**Return value**
| Type | Description |
| ---------- | ------------------ |
| Uint8Array | Encoded text.|
**Example** **Example**
```js ```js
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder("utf-8");
let buffer = new ArrayBuffer(20);
let result = new Uint8Array(buffer);
result = textEncoder.encodeInto("\uD800¥¥");
``` ```
### encode<sup>(deprecated)</sup> ### encodeInto<sup>9+</sup>
encode(input?: string): Uint8Array encodeInto(input?: string): Uint8Array
Encodes the input content. Encodes the input content.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeInto<sup>9+</sup>](#encodeinto9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ------ | ---- | ------------------ |
| input | string | No| String to encode.| | input | string | No | String to encode.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------- | ------------------ |
| Uint8Array | Encoded text.| | Uint8Array | Encoded text.|
**Example** **Example**
```js ```js
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let buffer = new ArrayBuffer(20); let buffer = new ArrayBuffer(20);
let result = new Uint8Array(buffer); let result = new Uint8Array(buffer);
result = textEncoder.encode("\uD800¥¥"); result = textEncoder.encodeInto("\uD800¥¥");
``` ```
### encodeIntoUint8Array<sup>9+</sup> ### encodeIntoUint8Array<sup>9+</sup>
...@@ -597,7 +588,7 @@ let that = new util.TextEncoder() ...@@ -597,7 +588,7 @@ let that = new util.TextEncoder()
let buffer = new ArrayBuffer(4) let buffer = new ArrayBuffer(4)
let dest = new Uint8Array(buffer) let dest = new Uint8Array(buffer)
let result = new Object() let result = new Object()
result = that.encodeInto('abcd', dest) result = that.encodeIntoUint8Array('abcd', dest)
``` ```
### encodeInto<sup>(deprecated)</sup> ### encodeInto<sup>(deprecated)</sup>
...@@ -634,6 +625,38 @@ Stores the UTF-8 encoded text. ...@@ -634,6 +625,38 @@ Stores the UTF-8 encoded text.
result = that.encodeInto('abcd', dest) result = that.encodeInto('abcd', dest)
``` ```
### encode<sup>(deprecated)</sup>
encode(input?: string): Uint8Array
Encodes the input content.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeInto<sup>9+</sup>](#encodeinto9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| input | string | No| String to encode.|
**Return value**
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
**Example**
```js
let textEncoder = new util.TextEncoder();
let buffer = new ArrayBuffer(20);
let result = new Uint8Array(buffer);
result = textEncoder.encode("\uD800¥¥");
```
## RationalNumber<sup>8+</sup> ## RationalNumber<sup>8+</sup>
### constructor<sup>9+</sup> ### constructor<sup>9+</sup>
...@@ -671,31 +694,6 @@ Parses a rational number. Previously, this processing is an internal action of t ...@@ -671,31 +694,6 @@ Parses a rational number. Previously, this processing is an internal action of t
let rationalNumber = util.RationalNumber.parseRationalNumber(1,2) let rationalNumber = util.RationalNumber.parseRationalNumber(1,2)
``` ```
### constructor<sup>(deprecated)</sup>
constructor(numerator: number,denominator: number)
A constructor used to create a **RationalNumber** object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| numerator | number | Yes| Numerator, which is an integer.|
| denominator | number | Yes| Denominator, which is an integer.|
**Example**
```js
let rationalNumber = new util.RationalNumber(1,2);
```
### createRationalFromString<sup>8+</sup> ### createRationalFromString<sup>8+</sup>
static createRationalFromString​(rationalString: string): RationalNumber​ static createRationalFromString​(rationalString: string): RationalNumber​
...@@ -751,38 +749,6 @@ let rational = util.RationalNumber.createRationalFromString("3/4"); ...@@ -751,38 +749,6 @@ let rational = util.RationalNumber.createRationalFromString("3/4");
let result = rationalNumber.compare(rational); let result = rationalNumber.compare(rational);
``` ```
### compareTo<sup>(deprecated)</sup>
compareTo​(another: RationalNumber): number​
Compares this **RationalNumber** object with a given object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [compare<sup>9+</sup>](#compare9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
**Return value**
| 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.|
**Example**
```js
let rationalNumber = new util.RationalNumber(1,2);
let rational = util.RationalNumber.createRationalFromString("3/4");
let result = rationalNumber.compareTo(rational);
```
### valueOf<sup>8+</sup> ### valueOf<sup>8+</sup>
valueOf(): number valueOf(): number
...@@ -860,38 +826,6 @@ let rationalNumber = new util.RationalNumber(1,2); ...@@ -860,38 +826,6 @@ let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonFactor(4,6); let result = util.RationalNumber.getCommonFactor(4,6);
``` ```
### getCommonDivisor<sup>(deprecated)</sup>
static getCommonDivisor​(number1: number,number2: number): number
Obtains the greatest common divisor of two specified integers.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCommonFactor<sup>9+</sup>](#getcommonfactor9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Greatest common divisor obtained.|
**Example**
```js
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonDivisor(4,6);
```
### getNumerator<sup>8+</sup> ### getNumerator<sup>8+</sup>
getNumerator​(): number getNumerator​(): number
...@@ -1018,6 +952,94 @@ let rationalNumber = new util.RationalNumber(1,2); ...@@ -1018,6 +952,94 @@ let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.toString(); let result = rationalNumber.toString();
``` ```
### constructor<sup>(deprecated)</sup>
constructor(numerator: number,denominator: number)
A constructor used to create a **RationalNumber** object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| numerator | number | Yes| Numerator, which is an integer.|
| denominator | number | Yes| Denominator, which is an integer.|
**Example**
```js
let rationalNumber = new util.RationalNumber(1,2);
```
### compareTo<sup>(deprecated)</sup>
compareTo​(another: RationalNumber): number​
Compares this **RationalNumber** object with a given object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [compare<sup>9+</sup>](#compare9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
**Return value**
| 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.|
**Example**
```js
let rationalNumber = new util.RationalNumber(1,2);
let rational = util.RationalNumber.createRationalFromString("3/4");
let result = rationalNumber.compareTo(rational);
```
### getCommonDivisor<sup>(deprecated)</sup>
static getCommonDivisor​(number1: number,number2: number): number
Obtains the greatest common divisor of two specified integers.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCommonFactor<sup>9+</sup>](#getcommonfactor9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Greatest common divisor obtained.|
**Example**
```js
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonDivisor(4,6);
```
## LRUCache<sup>9+</sup> ## LRUCache<sup>9+</sup>
...@@ -1464,7 +1486,7 @@ lru.afterRemoval(false,10,30,null); ...@@ -1464,7 +1486,7 @@ lru.afterRemoval(false,10,30,null);
### contains<sup>9+</sup> ### contains<sup>9+</sup>
contains(key: object): boolean contains(key: K): boolean
Checks whether this cache contains the specified key. Checks whether this cache contains the specified key.
...@@ -1474,7 +1496,7 @@ Checks whether this cache contains the specified key. ...@@ -1474,7 +1496,7 @@ Checks whether this cache contains the specified key.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------- | | ------ | ------ | ---- | ---------------- |
| key | object | Yes | Key to check.| | key | K | Yes | Key to check.|
**Return value** **Return value**
...@@ -1564,1026 +1586,1014 @@ pro.put(2,10); ...@@ -1564,1026 +1586,1014 @@ pro.put(2,10);
let result = pro[Symbol.iterator](); let result = pro[Symbol.iterator]();
``` ```
## LruBuffer<sup>(deprecated)</sup> ## ScopeComparable<sup>8+</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache<sup>9+</sup>](#lrucache9) instead.
### Attributes The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description| ### compareTo<sup>8+</sup>
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Total number of values in this buffer.|
**Example** compareTo(other: ScopeComparable): boolean;
```js Compares two values and returns a Boolean value.
let pro = new util.LruBuffer();
pro.put(2,10);
pro.put(1,8);
let result = pro.length;
```
### constructor<sup>(deprecated)</sup> **System capability**: SystemCapability.Utils.Lang
constructor(capacity?: number) **Parameters**
A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64. | Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------- |
| other | [ScopeComparable](#scopecomparable8) | Yes | The other value to be compared with the current value.|
> **NOTE** **Return value**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
**System capability**: SystemCapability.Utils.Lang | Type| Description |
| ---- | ------------------ |
| boolean | If the current value is greater than or equal to the input value, **true** is returned. Otherwise, **false** is returned.|
**Parameters** **Example**
| Name| Type| Mandatory| Description| Create a class to implement the **compareTo** method. The **Temperature** class is used as an example in the following sample code.
| -------- | -------- | -------- | -------- |
| capacity | number | No| Capacity of the **LruBuffer** to create.|
**Example** ```js
class Temperature{
constructor(value){
// If TS is used for development, add the following code:
// private readonly _temp: Temperature;
this._temp = value;
}
compareTo(value){
return this._temp >= value.getTemp();
}
getTemp(){
return this._temp;
}
toString(){
return this._temp.toString();
}
}
```
```js ## ScopeType<sup>8+</sup>
let lrubuffer= new util.LruBuffer();
```
### updateCapacity<sup>(deprecated)</sup> Defines the type of values in a **Scope** object.
updateCapacity(newCapacity: number): void **System capability**: SystemCapability.Utils.Lang
Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown. | Type| Description|
| -------- | -------- |
| number | The value type is a number.|
| [ScopeComparable](#scopecomparable8) | The value type is ScopeComparable.|
> **NOTE** ## ScopeHelper<sup>9+</sup>
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [updateCapacity<sup>9+</sup>](#updatecapacity9) instead. ### constructor<sup>9+</sup>
constructor(lowerObj: ScopeType, upperObj: ScopeType)
A constructor used to create a **ScopeHelper** object with the specified upper and lower limits.
**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**.| | lowerObj | [ScopeType](#scopetype8) | Yes | Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes | Upper limit of the **Scope** object.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
let result = pro.updateCapacity(100); let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
``` ```
### toString<sup>(deprecated)</sup>
toString(): string ### toString<sup>9+</sup>
Obtains the string representation of this **LruBuffer** object. toString(): string
> **NOTE** Obtains a string representation that contains this **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead.
**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 containing the **Scope**.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
pro.get(2); let range = new util.ScopeHelper(tempLower, tempUpper);
pro.remove(20); let result = range.toString();
let result = pro.toString();
``` ```
### getCapacity<sup>(deprecated)</sup>
getCapacity(): number ### intersect<sup>9+</sup>
Obtains the capacity of this buffer. intersect(range: ScopeHelper): ScopeHelper
> **NOTE** Obtains the intersection of this **Scope** and the given **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCapacity<sup>9+</sup>](#getcapacity9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------------------------- | ---- | ------------------ |
| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------------------ | ------------------------------ |
| number | Capacity of this buffer.| | [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given **Scope**.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
let result = pro.getCapacity(); let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
range.intersect(rangeFir);
``` ```
### clear<sup>(deprecated)</sup>
clear(): void ### intersect<sup>9+</sup>
Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations. intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper
> **NOTE** Obtains the intersection of this **Scope** and the given lower and upper limits.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clear<sup>9+</sup>](#clear9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ---------------- |
| lowerObj | [ScopeType](#scopetype8) | Yes | Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes | Upper limit.|
**Return value**
| Type | Description |
| ---------------------------- | ---------------------------------------- |
| [ScopeHelper](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
let result = pro.length; let tempMiDF = new Temperature(35);
pro.clear(); let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.intersect(tempMiDF, tempMidS);
``` ```
### getCreateCount<sup>(deprecated)</sup>
getCreateCount(): number ### getUpper<sup>9+</sup>
Obtains the number of return values for **createDefault()**. getUpper(): ScopeType
> **NOTE** Obtains the upper limit of this **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
**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()**.| | [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(1,8); let tempUpper = new Temperature(40);
let result = pro.getCreateCount(); let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getUpper();
``` ```
### getMissCount<sup>(deprecated)</sup>
getMissCount(): number ### getLower<sup>9+</sup>
Obtains the number of times that the queried values are mismatched. getLower(): ScopeType
> **NOTE** Obtains the lower limit of this **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMissCount<sup>9+</sup>](#getmisscount9) instead.
**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.| | [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
pro.get(2); let range = new util.ScopeHelper(tempLower, tempUpper);
let result = pro.getMissCount(); let result = range.getLower();
``` ```
### getRemovalCount<sup>(deprecated)</sup>
getRemovalCount(): number ### expand<sup>9+</sup>
Obtains the number of removals from this buffer. expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper
> **NOTE** Obtains the union set of this **Scope** and the given lower and upper limits.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ---------------- |
| lowerObj | [ScopeType](#scopetype8) | Yes | Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes | Upper limit.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------------- | ------------------------------------ |
| number | Number of removals from the buffer.| | [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
pro.updateCapacity(2); let tempMiDF = new Temperature(35);
pro.put(50,22); let tempMidS = new Temperature(39);
let result = pro.getRemovalCount(); let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF, tempMidS);
``` ```
### getMatchCount<sup>(deprecated)</sup>
getMatchCount(): number ### expand<sup>9+</sup>
Obtains the number of times that the queried values are matched. expand(range: ScopeHelper): ScopeHelper
> **NOTE** Obtains the union set of this **Scope** and the given **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------------------------- | ---- | ------------------ |
| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------------- | ---------------------------------- |
| number | Number of times that the queried values are matched.| | [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given **Scope**.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
pro.get(2); let tempMiDF = new Temperature(35);
let result = pro.getMatchCount(); let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
let result = range.expand(rangeFir);
``` ```
### getPutCount<sup>(deprecated)</sup>
getPutCount(): number ### expand<sup>9+</sup>
Obtains the number of additions to this buffer. expand(value: ScopeType): ScopeHelper
> **NOTE** Obtains the union set of this **Scope** and the given value.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getPutCount<sup>9+</sup>](#getputcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------ | ---- | ---------------- |
| value | [ScopeType](#scopetype8) | Yes | Value specified.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------------- | -------------------------------- |
| number | Number of additions to the buffer.| | [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given value.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
let result = pro.getPutCount(); let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF);
``` ```
### isEmpty<sup>(deprecated)</sup>
isEmpty(): boolean ### contains<sup>9+</sup>
Checks whether this buffer is empty. contains(value: ScopeType): boolean
> **NOTE** Checks whether a value is within this **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isEmpty<sup>9+</sup>](#isempty9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------ | ---- | ---------------- |
| value | [ScopeType](#scopetype8) | Yes | Value specified.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | --------------------------------------------------- |
| boolean | Returns **true** if the buffer does not contain any value.| | boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
let result = pro.isEmpty(); let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
range.contains(tempMiDF);
``` ```
### get<sup>(deprecated)</sup>
get(key: K): V | undefined ### contains<sup>9+</sup>
Obtains the value of the specified key. contains(range: ScopeHelper): boolean
> **NOTE** Checks whether a range is within this **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [get<sup>9+</sup>](#get9) instead.
**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.| | range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | ----------------------------------------------------- |
| V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.| | boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
pro.put(2,10); let tempUpper = new Temperature(40);
let result = pro.get(2); let range = new util.ScopeHelper(tempLower, tempUpper);
let tempLess = new Temperature(20);
let tempMore = new Temperature(45);
let rangeSec = new util.ScopeHelper(tempLess, tempMore);
let result = range.contains(rangeSec);
``` ```
### put<sup>(deprecated)</sup>
put(key: K,value: V): V ### clamp<sup>9+</sup>
Adds a key-value pair to this buffer. clamp(value: ScopeType): ScopeType
> **NOTE** Limits a value to this **Scope**.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [put<sup>9+</sup>](#put9) instead.
**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.| | value | [ScopeType](#scopetype8) | Yes | Value specified.|
| 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. | | [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
let pro = new util.LruBuffer(); let tempLower = new Temperature(30);
let result = pro.put(2,10); let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.clamp(tempMiDF);
``` ```
### values<sup>(deprecated)</sup> ## Base64Helper<sup>9+</sup>
values(): V[] ### constructor<sup>9+</sup>
Obtains all values in this buffer, listed from the most to the least recently accessed. constructor()
> **NOTE** A constructor used to create a **Base64Helper** instance.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [values<sup>9+</sup>](#values9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Example**
```js
let base64 = new util.Base64Helper();
```
### encodeSync<sup>9+</sup>
encodeSync(src: Uint8Array): Uint8Array
Encodes the input content.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ------------------- |
| src | Uint8Array | Yes | Uint8Array to encode.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------- | ----------------------------- |
| V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.| | Uint8Array | Uint8Array encoded.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let that = new util.Base64Helper();
pro.put(2,10); let array = new Uint8Array([115,49,51]);
pro.put(2,"anhu"); let result = that.encodeSync(array);
pro.put("afaf","grfb");
let result = pro.values();
``` ```
### keys<sup>(deprecated)</sup>
keys(): K[] ### encodeToStringSync<sup>9+</sup>
Obtains all keys in this buffer, listed from the most to the least recently accessed. encodeToStringSync(src: Uint8Array): string
> **NOTE** Encodes the input content.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [keys<sup>9+</sup>](#keys9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ------------------- |
| src | Uint8Array | Yes | Uint8Array to encode.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | -------------------- |
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.| | string | String encoded from the Uint8Array.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let that = new util.Base64Helper();
pro.put(2,10); let array = new Uint8Array([115,49,51]);
let result = pro.keys(); let result = that.encodeToStringSync(array);
``` ```
### remove<sup>(deprecated)</sup>
remove(key: K): V | undefined ### decodeSync<sup>9+</sup>
Removes the specified key and its value from this buffer. decodeSync(src: Uint8Array | string): Uint8Array
> **NOTE** Decodes the input content.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [remove<sup>9+</sup>](#remove9) instead.
**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.| | src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------- | ----------------------------- |
| V&nbsp;\|&nbsp;undefined | 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.| | Uint8Array | Uint8Array decoded.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let that = new util.Base64Helper();
pro.put(2,10); let buff = 'czEz';
let result = pro.remove(20); let result = that.decodeSync(buff);
``` ```
### afterRemoval<sup>(deprecated)</sup>
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void ### encode<sup>9+</sup>
Performs subsequent operations after a value is removed. encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
> **NOTE** Encodes the input content asynchronously.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [afterRemoval<sup>9+</sup>](#afterremoval9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ---------- | ---- | ----------------------- |
| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.| | src | Uint8Array | Yes | Uint8Array to encode asynchronously.|
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.| **Return value**
| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
| Type | Description |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
**Example** **Example**
```js ```js
let arr = []; let that = new util.Base64Helper();
class ChildLruBuffer<K, V> extends util.LruBuffer<K, V> let array = new Uint8Array([115,49,51]);
{ let rarray = new Uint8Array([99,122,69,122]);
constructor() that.encode(array).then(val=>{
{ for (var i = 0; i < rarray.length; i++) {
super(); console.log(val[i].toString())
}
afterRemoval(isEvict, key, value, newValue)
{
if (isEvict === false)
{
arr = [key, value, newValue];
}
}
} }
let lru = new ChildLruBuffer(); })
lru.afterRemoval(false,10,30,null);
``` ```
### contains<sup>(deprecated)</sup>
contains(key: K): boolean
Checks whether this buffer contains the specified key. ### encodeToString<sup>9+</sup>
encodeToString(src: Uint8Array): Promise&lt;string&gt;
> **NOTE** Encodes the input content asynchronously.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead.
**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.| | src | Uint8Array | Yes | Uint8Array to encode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | --------------------- | ------------------------ |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.| | Promise&lt;string&gt; | String obtained after asynchronous encoding.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let that = new util.Base64Helper();
pro.put(2,10); let array = new Uint8Array([115,49,51]);
let result = pro.contains(20); that.encodeToString(array).then(val=>{
console.log(val)
})
``` ```
### createDefault<sup>(deprecated)</sup>
createDefault(key: K): V ### decode<sup>9+</sup>
Creates a value if the value of the specified key is not available. decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
> **NOTE** Decodes the input content asynchronously.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createDefault<sup>9+</sup>](#createdefault9) instead.
**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.| | src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------------- | --------------------------------- |
| V | Value of the key.| | Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let that = new util.Base64Helper();
let result = pro.createDefault(50); let array = new Uint8Array([99,122,69,122]);
let rarray = new Uint8Array([115,49,51]);
that.decode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
})
``` ```
### entries<sup>(deprecated)</sup> ## types<sup>8+</sup>
entries(): IterableIterator&lt;[K,V]&gt; ### constructor<sup>8+</sup>
Obtains a new iterator object that contains all key-value pairs in this object. constructor()
> **NOTE** A constructor used to create a **Types** object.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [entries<sup>9+</sup>](#entries9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| [K,&nbsp;V] | Iterable array.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let type = new util.types();
pro.put(2,10);
let result = pro.entries();
``` ```
### [Symbol.iterator]<sup>(deprecated)</sup>
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt; ### isAnyArrayBuffer<sup>8+</sup>
Obtains a two-dimensional array in key-value pairs. isAnyArrayBuffer(value: Object): boolean
> **NOTE** Checks whether the input value is of the **ArrayBuffer** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [K,&nbsp;V] | Two-dimensional array in key-value pairs.| | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let that = new util.types();
pro.put(2,10); let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
let result = pro[Symbol.iterator]();
``` ```
### ScopeType<sup>8+</sup>
Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**.
The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
```js
interface ScopeComparable{
compareTo(other: ScopeComparable): boolean;
}
type ScopeType = ScopeComparable | number;
```
Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#scopetype8) object.
Example
```js
class Temperature{
constructor(value){
// If TS is used for development, add the following code:
// private readonly _temp: Temperature;
this._temp = value;
}
compareTo(value){
return this._temp >= value.getTemp();
}
getTemp(){
return this._temp;
}
toString(){
return this._temp.toString();
}
}
```
## ScopeHelper<sup>9+</sup> ### isArrayBufferView<sup>8+</sup>
### constructor<sup>9+</sup> isArrayBufferView(value: Object): boolean
constructor(lowerObj: ScopeType, upperObj: ScopeType) Checks whether the input value is of the **ArrayBufferView** type.
A constructor used to create a **ScopeHelper** object with the specified upper and lower limits. **ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
**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.| | value | Object | Yes| Object to check.|
| upperObj | [ScopeType](#scopetype8) | Yes | Upper limit of the **Scope** object.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isArrayBufferView(new Int8Array([]));
let range = new util.ScopeHelper(tempLower, tempUpper);
``` ```
### toString<sup>9+</sup> ### isArgumentsObject<sup>8+</sup>
toString(): string isArgumentsObject(value: Object): boolean
Obtains a string representation that contains this **Scope**. Checks whether the input value is of the **arguments** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ------ | -------------------------------------- | | -------- | -------- |
| string | String representation containing the **Scope**.| | boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); function foo() {
let range = new util.ScopeHelper(tempLower, tempUpper); var result = that.isArgumentsObject(arguments);
let result = range.toString(); }
let f = foo();
``` ```
### intersect<sup>9+</sup> ### isArrayBuffer<sup>8+</sup>
intersect(range: ScopeHelper): ScopeHelper isArrayBuffer(value: Object): boolean
Obtains the intersection of this **Scope** and the given **Scope**. 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|
| ------ | ---------------------------- | ---- | ------------------ | | -------- | -------- | -------- | -------- |
| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ------------------------------ | ------------------------------ | | -------- | -------- |
| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given **Scope**.| | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isArrayBuffer(new ArrayBuffer(0));
let range = new util.ScopeHelper(tempLower, tempUpper);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
range.intersect(rangeFir );
``` ```
### intersect<sup>9+</sup> ### isAsyncFunction<sup>8+</sup>
intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper isAsyncFunction(value: Object): boolean
Obtains the intersection of this **Scope** and the given lower and upper limits. 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|
| -------- | ------------------------ | ---- | ---------------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes | Lower limit.| | value | Object | Yes| Object to check.|
| upperObj | [ScopeType](#scopetype8) | Yes | Upper limit.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ---------------------------- | ---------------------------------------- | | -------- | -------- |
| [ScopeHelper](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.| | boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isAsyncFunction(async function foo() {});
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.intersect(tempMiDF, tempMidS);
``` ```
### getUpper<sup>9+</sup> ### isBooleanObject<sup>8+</sup>
getUpper(): ScopeType isBooleanObject(value: Object): boolean
Obtains the upper limit of this **Scope**. Checks whether the input value is of the **Boolean** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ------------------------ | ---------------------- | | -------- | -------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.| | boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isBooleanObject(new Boolean(true));
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getUpper();
``` ```
### getLower<sup>9+</sup> ### isBoxedPrimitive<sup>8+</sup>
getLower(): ScopeType isBoxedPrimitive(value: Object): boolean
Obtains the lower limit of this **Scope**. Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ------------------------ | ---------------------- | | -------- | -------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.| | boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isBoxedPrimitive(new Boolean(false));
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getLower();
``` ```
### expand<sup>9+</sup> ### isDataView<sup>8+</sup>
expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper isDataView(value: Object): boolean
Obtains the union set of this **Scope** and the given lower and upper limits. 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|
| -------- | ------------------------ | ---- | ---------------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes | Lower limit.| | value | Object | Yes| Object to check.|
| upperObj | [ScopeType](#scopetype8) | Yes | Upper limit.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ---------------------------- | ------------------------------------ | | -------- | -------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.| | boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); const ab = new ArrayBuffer(20);
let tempMiDF = new Temperature(35); let result = that.isDataView(new DataView(ab));
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF, tempMidS);
``` ```
### expand<sup>9+</sup> ### isDate<sup>8+</sup>
expand(range: ScopeHelper): ScopeHelper isDate(value: Object): boolean
Obtains the union set of this **Scope** and the given **Scope**. 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|
| ------ | ---------------------------- | ---- | ------------------ | | -------- | -------- | -------- | -------- |
| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ---------------------------- | ---------------------------------- | | -------- | -------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given **Scope**.| | boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isDate(new Date());
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
let result = range.expand(rangeFir);
``` ```
### expand<sup>9+</sup> ### isExternal<sup>8+</sup>
expand(value: ScopeType): ScopeHelper isExternal(value: Object): boolean
Obtains the union set of this **Scope** and the given value. 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 | [ScopeType](#scopetype8) | Yes | Value specified.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ---------------------------- | -------------------------------- | | -------- | -------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given value.| | boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isExternal(true);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF);
``` ```
### contains<sup>9+</sup> ### isFloat32Array<sup>8+</sup>
contains(value: ScopeType): boolean isFloat32Array(value: Object): boolean
Checks whether a value is within this **Scope**. 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 | [ScopeType](#scopetype8) | Yes | Value specified.| | value | Object | Yes| Object to check.|
**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 input value is of the **Float32Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isFloat32Array(new Float32Array());
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
range.contains(tempMiDF);
``` ```
### contains<sup>9+</sup> ### isFloat64Array<sup>8+</sup>
contains(range: ScopeHelper): boolean isFloat64Array(value: Object): boolean
Checks whether a range is within this **Scope**. 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|
| ------ | ---------------------------- | ---- | ------------------ | | -------- | -------- | -------- | -------- |
| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.| | value | Object | Yes| Object to check.|
**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 input value is of the **Float64Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isFloat64Array(new Float64Array());
let range = new util.ScopeHelper(tempLower, tempUpper);
let tempLess = new Temperature(20);
let tempMore = new Temperature(45);
let rangeSec = new util.ScopeHelper(tempLess, tempMore);
let result = range.contains(rangeSec);
``` ```
### clamp<sup>9+</sup> ### isGeneratorFunction<sup>8+</sup>
clamp(value: ScopeType): ScopeType isGeneratorFunction(value: Object): boolean
Limits a value to this **Scope**. 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 | [ScopeType](#scopetype8) | Yes | Value specified.| | value | Object | Yes| Object to check.|
**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**.| | boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isGeneratorFunction(function* foo() {});
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.clamp(tempMiDF);
``` ```
## Scope<sup>(deprecated)</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper<sup>9+</sup>](#scopehelper9) instead.
### constructor<sup>(deprecated)</sup>
constructor(lowerObj: ScopeType, upperObj: ScopeType)
A constructor used to create a **Scope** object with the specified upper and lower limits. ### isGeneratorObject<sup>8+</sup>
> **NOTE** isGeneratorObject(value: Object): boolean
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
Checks whether the input value is a generator object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2591,52 +2601,57 @@ A constructor used to create a **Scope** object with the specified upper and low ...@@ -2591,52 +2601,57 @@ A constructor used to create a **Scope** object with the specified upper and low
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.| | value | Object | Yes| Object to check.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); function* foo() {}
let range = new util.Scope(tempLower, tempUpper); const generator = foo();
let result = that.isGeneratorObject(generator);
``` ```
### toString<sup>(deprecated)</sup>
toString(): string ### isInt8Array<sup>8+</sup>
Obtains a string representation that contains this **Scope**. isInt8Array(value: Object): boolean
> **NOTE** Checks whether the input value is of the **Int8Array** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String representation containing the **Scope**.| | boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isInt8Array(new Int8Array([]));
let range = new util.Scope(tempLower, tempUpper);
let result = range.toString();
``` ```
### intersect<sup>(deprecated)</sup>
intersect(range: Scope): Scope ### isInt16Array<sup>8+</sup>
Obtains the intersection of this **Scope** and the given **Scope**. isInt16Array(value: Object): boolean
> **NOTE** Checks whether the input value is of the **Int16Array** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2644,35 +2659,27 @@ Obtains the intersection of this **Scope** and the given **Scope**. ...@@ -2644,35 +2659,27 @@ Obtains the intersection of this **Scope** and the given **Scope**.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given **Scope**.| | boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isInt16Array(new Int16Array([]));
let range = new util.Scope(tempLower, tempUpper);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let rangeFir = new util.Scope(tempMiDF, tempMidS);
range.intersect(rangeFir );
``` ```
### intersect<sup>(deprecated)</sup>
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope ### isInt32Array<sup>8+</sup>
Obtains the intersection of this **Scope** and the given lower and upper limits. isInt32Array(value: Object): boolean
> **NOTE** Checks whether the input value is of the **Int32Array** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2680,89 +2687,85 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. ...@@ -2680,89 +2687,85 @@ Obtains the intersection of this **Scope** and the given lower and upper limits.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| | value | Object | Yes| Object to check.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.| | boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isInt32Array(new Int32Array([]));
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.Scope(tempLower, tempUpper);
let result = range.intersect(tempMiDF, tempMidS);
``` ```
### getUpper<sup>(deprecated)</sup>
getUpper(): ScopeType ### isMap<sup>8+</sup>
Obtains the upper limit of this **Scope**. isMap(value: Object): boolean
> **NOTE** Checks whether the input value is of the **Map** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getUpper<sup>9+</sup>](#getupper9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.| | boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isMap(new Map());
let range = new util.Scope(tempLower, tempUpper);
let result = range.getUpper();
``` ```
### getLower<sup>(deprecated)</sup>
getLower(): ScopeType ### isMapIterator<sup>8+</sup>
Obtains the lower limit of this **Scope**. isMapIterator(value: Object): boolean
> **NOTE** Checks whether the input value is of the **MapIterator** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLower<sup>9+</sup>](#getlower9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.| | boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); const map = new Map();
let range = new util.Scope(tempLower, tempUpper); let result = that.isMapIterator(map.keys());
let result = range.getLower();
``` ```
### expand<sup>(deprecated)</sup>
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope ### isNativeError<sup>8+</sup>
Obtains the union set of this **Scope** and the given lower and upper limits. isNativeError(value: Object): boolean
> **NOTE** Checks whether the input value is of the **Error** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2770,35 +2773,27 @@ Obtains the union set of this **Scope** and the given lower and upper limits. ...@@ -2770,35 +2773,27 @@ Obtains the union set of this **Scope** and the given lower and upper limits.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| | value | Object | Yes| Object to check.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given lower and upper limits.| | boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isNativeError(new TypeError());
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.Scope(tempLower, tempUpper);
let result = range.expand(tempMiDF, tempMidS);
``` ```
### expand<sup>(deprecated)</sup>
expand(range: Scope): Scope ### isNumberObject<sup>8+</sup>
Obtains the union set of this **Scope** and the given **Scope**. isNumberObject(value: Object): boolean
> **NOTE** Checks whether the input value is a number object.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2806,35 +2801,27 @@ Obtains the union set of this **Scope** and the given **Scope**. ...@@ -2806,35 +2801,27 @@ Obtains the union set of this **Scope** and the given **Scope**.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.| | boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isNumberObject(new Number(0));
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.Scope(tempLower, tempUpper);
let rangeFir = new util.Scope(tempMiDF, tempMidS);
let result = range.expand(rangeFir);
``` ```
### expand<sup>(deprecated)</sup>
expand(value: ScopeType): Scope ### isPromise<sup>8+</sup>
Obtains the union set of this **Scope** and the given value. isPromise(value: Object): boolean
> **NOTE** Checks whether the input value is a promise.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2842,33 +2829,27 @@ Obtains the union set of this **Scope** and the given value. ...@@ -2842,33 +2829,27 @@ Obtains the union set of this **Scope** and the given value.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.| | boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isPromise(Promise.resolve(1));
let tempMiDF = new Temperature(35);
let range = new util.Scope(tempLower, tempUpper);
let result = range.expand(tempMiDF);
``` ```
### contains<sup>(deprecated)</sup>
contains(value: ScopeType): boolean ### isProxy<sup>8+</sup>
Checks whether a value is within this **Scope**. isProxy(value: Object): boolean
> **NOTE** Checks whether the input value is a proxy.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2876,33 +2857,29 @@ Checks whether a value is within this **Scope**. ...@@ -2876,33 +2857,29 @@ Checks whether a value is within this **Scope**.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.| | value | Object | Yes| Object to check.|
**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 input value is a proxy; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); const target = {};
let tempMiDF = new Temperature(35); const proxy = new Proxy(target, {});
let range = new util.Scope(tempLower, tempUpper); let result = that.isProxy(proxy);
range.contains(tempMiDF);
``` ```
### contains<sup>(deprecated)</sup>
contains(range: Scope): boolean
Checks whether a range is within this **Scope**. ### isRegExp<sup>8+</sup>
> **NOTE** isRegExp(value: Object): boolean
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead. Checks whether the input value is of the **RegExp** type.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2910,36 +2887,27 @@ Checks whether a range is within this **Scope**. ...@@ -2910,36 +2887,27 @@ Checks whether a range is within this **Scope**.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.| | value | Object | Yes| Object to check.|
**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 input value is of the **RegExp** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isRegExp(new RegExp('abc'));
let range = new util.Scope(tempLower, tempUpper);
let tempLess = new Temperature(20);
let tempMore = new Temperature(45);
let rangeSec = new util.Scope(tempLess, tempMore);
let result = range.contains(rangeSec);
``` ```
### clamp<sup>(deprecated)</sup>
clamp(value: ScopeType): ScopeType ### isSet<sup>8+</sup>
Limits a value to this **Scope**. isSet(value: Object): boolean
> **NOTE** Checks whether the input value is of the **Set** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clamp<sup>9+</sup>](#clamp9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -2947,259 +2915,255 @@ Limits a value to this **Scope**. ...@@ -2947,259 +2915,255 @@ Limits a value to this **Scope**.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.| | value | Object | Yes| Object to check.|
**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**.| | boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let that = new util.types();
let tempUpper = new Temperature(40); let result = that.isSet(new Set());
let tempMiDF = new Temperature(35);
let range = new util.Scope(tempLower, tempUpper);
let result = range.clamp(tempMiDF);
``` ```
## Base64Helper<sup>9+</sup>
### constructor<sup>9+</sup> ### isSetIterator<sup>8+</sup>
constructor() isSetIterator(value: Object): boolean
A constructor used to create a **Base64Helper** instance. Checks whether the input value is of the **SetIterator** type.
**System capability**: SystemCapability.Utils.Lang **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 **SetIterator** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let base64 = new util.Base64Helper(); let that = new util.types();
const set = new Set();
let result = that.isSetIterator(set.keys());
``` ```
### encodeSync<sup>9+</sup>
encodeSync(src: Uint8Array): Uint8Array ### isStringObject<sup>8+</sup>
Encodes the input content. isStringObject(value: Object): boolean
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|
| ------ | ---------- | ---- | ------------------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes | Uint8Array to encode.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ---------- | ----------------------------- | | -------- | -------- |
| Uint8Array | Uint8Array encoded.| | boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64Helper(); let that = new util.types();
let array = new Uint8Array([115,49,51]); let result = that.isStringObject(new String('foo'));
let result = that.encodeSync(array);
``` ```
### encodeToStringSync<sup>9+</sup> ### isSymbolObjec<sup>8+</sup>
encodeToStringSync(src: Uint8Array): string isSymbolObject(value: Object): boolean
Encodes the input content. 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|
| ------ | ---------- | ---- | ------------------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes | Uint8Array to encode.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ------ | -------------------- | | -------- | -------- |
| string | String encoded from the Uint8Array.| | boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64Helper(); let that = new util.types();
let array = new Uint8Array([115,49,51]); const symbols = Symbol('foo');
let result = that.encodeToStringSync(array); let result = that.isSymbolObject(Object(symbols));
``` ```
### decodeSync<sup>9+</sup> ### isTypedArray<sup>8+</sup>
decodeSync(src: Uint8Array | string): Uint8Array isTypedArray(value: Object): boolean
Decodes the input content. Checks whether the input value is of the **TypedArray** type.
**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| ------ | ------------------------------ | ---- | ----------------------------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ---------- | ----------------------------- | | -------- | -------- |
| Uint8Array | Uint8Array decoded.| | boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64Helper(); let that = new util.types();
let buff = 'czEz'; let result = that.isTypedArray(new Float64Array([]));
let result = that.decodeSync(buff);
``` ```
### encode<sup>9+</sup> ### isUint8Array<sup>8+</sup>
encode(src: Uint8Array): Promise&lt;Uint8Array&gt; isUint8Array(value: Object): boolean
Encodes the input content asynchronously. 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|
| ------ | ---------- | ---- | ----------------------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes | Uint8Array to encode asynchronously.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ------------------------- | --------------------------------- | | -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.| | boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64Helper(); let that = new util.types();
let array = new Uint8Array([115,49,51]); let result = that.isUint8Array(new Uint8Array([]));
let rarray = new Uint8Array([99,122,69,122]);
that.encode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
})
``` ```
### encodeToString<sup>9+</sup> ### isUint8ClampedArray<sup>8+</sup>
encodeToString(src: Uint8Array): Promise&lt;string&gt; isUint8ClampedArray(value: Object): boolean
Encodes the input content asynchronously. 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|
| ------ | ---------- | ---- | ----------------------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes | Uint8Array to encode asynchronously.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| --------------------- | ------------------------ | | -------- | -------- |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.| | boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64Helper(); let that = new util.types();
let array = new Uint8Array([115,49,51]); let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
that.encodeToString(array).then(val=>{
console.log(val)
})
``` ```
### decode<sup>9+</sup> ### isUint16Array<sup>8+</sup>
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt; isUint16Array(value: Object): boolean
Decodes the input content asynchronously. 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|
| ------ | ------------------------------ | ---- | --------------------------------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode asynchronously.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type | Description | | Type| Description|
| ------------------------- | --------------------------------- | | -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.| | boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64Helper(); let that = new util.types();
let array = new Uint8Array([99,122,69,122]); let result = that.isUint16Array(new Uint16Array([]));
let rarray = new Uint8Array([115,49,51]);
that.decode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
})
``` ```
## Base64<sup>(deprecated)</sup> ### isUint32Array<sup>8+</sup>
> **NOTE** isUint32Array(value: Object): boolean
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper<sup>9+</sup>](#base64helper9) instead.
### constructor<sup>(deprecated)</sup> Checks whether the input value is of the **Uint32Array** type.
constructor() **System capability**: SystemCapability.Utils.Lang
A constructor used to create a **Base64** object. **Parameters**
> **NOTE** | Name| Type| Mandatory| Description|
> | -------- | -------- | -------- | -------- |
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead. | value | Object | Yes| Object to check.|
**System capability**: SystemCapability.Utils.Lang **Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let base64 = new util.Base64(); let that = new util.types();
let result = that.isUint32Array(new Uint32Array([]));
``` ```
### encodeSync<sup>(deprecated)</sup>
encodeSync(src: Uint8Array): Uint8Array ### isWeakMap<sup>8+</sup>
Encodes the input content. isWeakMap(value: Object): boolean
> **NOTE** Checks whether the input value is of the **WeakMap** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeSync<sup>9+</sup>](#encodesync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3207,31 +3171,27 @@ Encodes the input content. ...@@ -3207,31 +3171,27 @@ Encodes the input content.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Uint8Array | Uint8Array encoded.| | boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64(); let that = new util.types();
let array = new Uint8Array([115,49,51]); let result = that.isWeakMap(new WeakMap());
let result = that.encodeSync(array);
``` ```
### encodeToStringSync<sup>(deprecated)</sup>
encodeToStringSync(src: Uint8Array): string ### isWeakSet<sup>8+</sup>
Encodes the input content. isWeakSet(value: Object): boolean
> **NOTE** Checks whether the input value is of the **WeakSet** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3239,31 +3199,27 @@ Encodes the input content. ...@@ -3239,31 +3199,27 @@ Encodes the input content.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String encoded from the Uint8Array.| | boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64(); let that = new util.types();
let array = new Uint8Array([115,49,51]); let result = that.isWeakSet(new WeakSet());
let result = that.encodeToStringSync(array);
``` ```
### decodeSync<sup>(deprecated)</sup>
decodeSync(src: Uint8Array | string): Uint8Array ### isBigInt64Array<sup>8+</sup>
Decodes the input content. isBigInt64Array(value: Object): boolean
> **NOTE** Checks whether the input value is of the **BigInt64Array** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decodeSync<sup>9+</sup>](#decodesync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3271,31 +3227,27 @@ Decodes the input content. ...@@ -3271,31 +3227,27 @@ Decodes the input content.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Uint8Array | Uint8Array decoded.| | boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64(); let that = new util.types();
let buff = 'czEz'; let result = that.isBigInt64Array(new BigInt64Array([]));
let result = that.decodeSync(buff);
``` ```
### encode<sup>(deprecated)</sup>
encode(src: Uint8Array): Promise&lt;Uint8Array&gt; ### isBigUint64Array<sup>8+</sup>
Encodes the input content asynchronously. isBigUint64Array(value: Object): boolean
> **NOTE** Checks whether the input value is of the **BigUint64Array** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encode<sup>9+</sup>](#encode9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3303,36 +3255,27 @@ Encodes the input content asynchronously. ...@@ -3303,36 +3255,27 @@ Encodes the input content asynchronously.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.| | boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64(); let that = new util.types();
let array = new Uint8Array([115,49,51]); let result = that.isBigUint64Array(new BigUint64Array([]));
let rarray = new Uint8Array([99,122,69,122]);
that.encode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
})
``` ```
### encodeToString<sup>(deprecated)</sup>
encodeToString(src: Uint8Array): Promise&lt;string&gt; ### isModuleNamespaceObject<sup>8+</sup>
Encodes the input content asynchronously. isModuleNamespaceObject(value: Object): boolean
> **NOTE** Checks whether the input value is a module namespace object.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToString<sup>9+</sup>](#encodetostring9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3340,34 +3283,28 @@ Encodes the input content asynchronously. ...@@ -3340,34 +3283,28 @@ Encodes the input content asynchronously.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.| | boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64(); import url from '@ohos.url'
let array = new Uint8Array([115,49,51]); let that = new util.types();
that.encodeToString(array).then(val=>{ let result = that.isModuleNamespaceObject(url);
console.log(val)
})
``` ```
### decode<sup>(deprecated)</sup>
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt; ### isSharedArrayBuffer<sup>8+</sup>
Decodes the input content asynchronously. isSharedArrayBuffer(value: Object): boolean
> **NOTE** Checks whether the input value is of the **SharedArrayBuffer** type.
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decode<sup>9+</sup>](#decode9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3375,50 +3312,53 @@ Decodes the input content asynchronously. ...@@ -3375,50 +3312,53 @@ Decodes the input content asynchronously.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.| | value | Object | Yes| Object to check.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.| | boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.Base64(); let that = new util.types();
let array = new Uint8Array([99,122,69,122]); let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
let rarray = new Uint8Array([115,49,51]);
that.decode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
})
``` ```
## types<sup>8+</sup> ## LruBuffer<sup>(deprecated)</sup>
### constructor<sup>8+</sup>
constructor() > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache<sup>9+</sup>](#lrucache9) instead.
A constructor used to create a **Types** object. ### Attributes
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Total number of values in this buffer.|
**Example** **Example**
```js ```js
let type = new util.types(); let pro = new util.LruBuffer();
pro.put(2,10);
pro.put(1,8);
let result = pro.length;
``` ```
### constructor<sup>(deprecated)</sup>
### isAnyArrayBuffer<sup>8+</sup> constructor(capacity?: number)
isAnyArrayBuffer(value: Object): boolean A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
Checks whether the input value is of the **ArrayBuffer** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3426,29 +3366,23 @@ Checks whether the input value is of the **ArrayBuffer** type. ...@@ -3426,29 +3366,23 @@ Checks whether the input value is of the **ArrayBuffer** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | capacity | number | No| Capacity of the **LruBuffer** to create.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let lrubuffer= new util.LruBuffer();
let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
``` ```
### updateCapacity<sup>(deprecated)</sup>
### isArrayBufferView<sup>8+</sup> updateCapacity(newCapacity: number): void
isArrayBufferView(value: Object): boolean
Checks whether the input value is of the **ArrayBufferView** type. Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [updateCapacity<sup>9+</sup>](#updatecapacity9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3456,255 +3390,257 @@ Checks whether the input value is of the **ArrayBufferView** type. ...@@ -3456,255 +3390,257 @@ Checks whether the input value is of the **ArrayBufferView** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | newCapacity | number | Yes| New capacity of the **LruBuffer**.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isArrayBufferView(new Int8Array([])); let result = pro.updateCapacity(100);
``` ```
### toString<sup>(deprecated)</sup>
### isArgumentsObject<sup>8+</sup> toString(): string
isArgumentsObject(value: Object): boolean Obtains the string representation of this **LruBuffer** object.
Checks whether the input value is of the **arguments** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | string | String representation of this **LruBuffer** object.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
function foo() { pro.put(2,10);
var result = that.isArgumentsObject(arguments); pro.get(2);
} pro.remove(20);
let f = foo(); let result = pro.toString();
``` ```
### getCapacity<sup>(deprecated)</sup>
### isArrayBuffer<sup>8+</sup> getCapacity(): number
isArrayBuffer(value: Object): boolean Obtains the capacity of this buffer.
Checks whether the input value is of the **ArrayBuffer** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCapacity<sup>9+</sup>](#getcapacity9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | number | Capacity of this buffer.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isArrayBuffer(new ArrayBuffer(0)); let result = pro.getCapacity();
``` ```
### clear<sup>(deprecated)</sup>
### isAsyncFunction<sup>8+</sup> clear(): void
isAsyncFunction(value: Object): boolean Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations.
Checks whether the input value is an asynchronous function. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clear<sup>9+</sup>](#clear9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Example**
| Name| Type| Mandatory| Description| ```js
| -------- | -------- | -------- | -------- | let pro = new util.LruBuffer();
| value | Object | Yes| Object to check.| pro.put(2,10);
let result = pro.length;
pro.clear();
```
### getCreateCount<sup>(deprecated)</sup>
getCreateCount(): number
Obtains the number of return values for **createDefault()**.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
**System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.| | number | Number of return values for **createDefault()**.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isAsyncFunction(async function foo() {}); pro.put(1,8);
let result = pro.getCreateCount();
``` ```
### getMissCount<sup>(deprecated)</sup>
### isBooleanObject<sup>8+</sup> getMissCount(): number
isBooleanObject(value: Object): boolean Obtains the number of times that the queried values are mismatched.
Checks whether the input value is of the **Boolean** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMissCount<sup>9+</sup>](#getmisscount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | number | Number of times that the queried values are mismatched.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isBooleanObject(new Boolean(true)); pro.put(2,10);
pro.get(2);
let result = pro.getMissCount();
``` ```
### getRemovalCount<sup>(deprecated)</sup>
### isBoxedPrimitive<sup>8+</sup> getRemovalCount(): number
isBoxedPrimitive(value: Object): boolean Obtains the number of removals from this buffer.
Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | number | Number of removals from the buffer.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isBoxedPrimitive(new Boolean(false)); pro.put(2,10);
pro.updateCapacity(2);
pro.put(50,22);
let result = pro.getRemovalCount();
``` ```
### getMatchCount<sup>(deprecated)</sup>
### isDataView<sup>8+</sup> getMatchCount(): number
isDataView(value: Object): boolean Obtains the number of times that the queried values are matched.
Checks whether the input value is of the **DataView** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | number | Number of times that the queried values are matched.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
const ab = new ArrayBuffer(20); pro.put(2,10);
let result = that.isDataView(new DataView(ab)); pro.get(2);
let result = pro.getMatchCount();
``` ```
### getPutCount<sup>(deprecated)</sup>
### isDate<sup>8+</sup> getPutCount(): number
isDate(value: Object): boolean Obtains the number of additions to this buffer.
Checks whether the input value is of the **Date** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getPutCount<sup>9+</sup>](#getputcount9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | number | Number of additions to the buffer.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isDate(new Date()); pro.put(2,10);
let result = pro.getPutCount();
``` ```
### isEmpty<sup>(deprecated)</sup>
### isExternal<sup>8+</sup> isEmpty(): boolean
isExternal(value: Object): boolean Checks whether this buffer is empty.
Checks whether the input value is of the **native external** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isEmpty<sup>9+</sup>](#isempty9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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 buffer does not contain any value.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isExternal(true); pro.put(2,10);
let result = pro.isEmpty();
``` ```
### get<sup>(deprecated)</sup>
### isFloat32Array<sup>8+</sup> get(key: K): V | undefined
isFloat32Array(value: Object): boolean Obtains the value of the specified key.
Checks whether the input value is of the **Float32Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [get<sup>9+</sup>](#get9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3712,27 +3648,31 @@ Checks whether the input value is of the **Float32Array** type. ...@@ -3712,27 +3648,31 @@ Checks whether the input value is of the **Float32Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | key | K | Yes| Key based on which the value is queried.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.| | V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isFloat32Array(new Float32Array()); pro.put(2,10);
let result = pro.get(2);
``` ```
### put<sup>(deprecated)</sup>
### isFloat64Array<sup>8+</sup> put(key: K,value: V): V
isFloat64Array(value: Object): boolean Adds a key-value pair to this buffer.
Checks whether the input value is of the **Float64Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [put<sup>9+</sup>](#put9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3740,85 +3680,84 @@ Checks whether the input value is of the **Float64Array** type. ...@@ -3740,85 +3680,84 @@ Checks whether the input value is of the **Float64Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | key | K | Yes| Key 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|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.| | 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
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isFloat64Array(new Float64Array()); let result = pro.put(2,10);
``` ```
### values<sup>(deprecated)</sup>
### isGeneratorFunction<sup>8+</sup> values(): V[]
isGeneratorFunction(value: Object): boolean Obtains all values in this buffer, listed from the most to the least recently accessed.
Checks whether the input value is a generator function. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [values<sup>9+</sup>](#values9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isGeneratorFunction(function* foo() {}); pro.put(2,10);
pro.put(2,"anhu");
pro.put("afaf","grfb");
let result = pro.values();
``` ```
### keys<sup>(deprecated)</sup>
### isGeneratorObject<sup>8+</sup> keys(): K[]
isGeneratorObject(value: Object): boolean Obtains all keys in this buffer, listed from the most to the least recently accessed.
Checks whether the input value is a generator object. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [keys<sup>9+</sup>](#keys9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
function* foo() {} pro.put(2,10);
const generator = foo(); let result = pro.keys();
let result = that.isGeneratorObject(generator);
``` ```
### remove<sup>(deprecated)</sup>
### isInt8Array<sup>8+</sup> remove(key: K): V | undefined
isInt8Array(value: Object): boolean Removes the specified key and its value from this buffer.
Checks whether the input value is of the **Int8Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [remove<sup>9+</sup>](#remove9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3826,27 +3765,30 @@ Checks whether the input value is of the **Int8Array** type. ...@@ -3826,27 +3765,30 @@ Checks whether the input value is of the **Int8Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | key | K | Yes| Key to remove.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.| | V&nbsp;\|&nbsp;undefined | 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
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isInt8Array(new Int8Array([])); pro.put(2,10);
let result = pro.remove(20);
``` ```
### afterRemoval<sup>(deprecated)</sup>
### isInt16Array<sup>8+</sup> afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
isInt16Array(value: Object): boolean Performs subsequent operations after a value is removed.
Checks whether the input value is of the **Int16Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [afterRemoval<sup>9+</sup>](#afterremoval9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3854,27 +3796,43 @@ Checks whether the input value is of the **Int16Array** type. ...@@ -3854,27 +3796,43 @@ Checks whether the input value is of the **Int16Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
| key | K | Yes| Key removed.|
**Return value** | value | V | Yes| Value removed.|
| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let arr = [];
let result = that.isInt16Array(new Int16Array([])); class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
{
constructor()
{
super();
}
afterRemoval(isEvict, key, value, newValue)
{
if (isEvict === false)
{
arr = [key, value, newValue];
}
}
}
let lru = new ChildLruBuffer();
lru.afterRemoval(false,10,30,null);
``` ```
### contains<sup>(deprecated)</sup>
### isInt32Array<sup>8+</sup> contains(key: K): boolean
isInt32Array(value: Object): boolean Checks whether this buffer contains the specified key.
Checks whether the input value is of the **Int32Array** type.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3882,27 +3840,31 @@ Checks whether the input value is of the **Int32Array** type. ...@@ -3882,27 +3840,31 @@ Checks whether the input value is of the **Int32Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | key | K | Yes| Key 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 buffer contains the specified key; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isInt32Array(new Int32Array([])); pro.put(2,10);
let result = pro.contains(20);
``` ```
### createDefault<sup>(deprecated)</sup>
### isMap<sup>8+</sup> createDefault(key: K): V
isMap(value: Object): boolean Creates a value if the value of the specified key is not available.
Checks whether the input value is of the **Map** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createDefault<sup>9+</sup>](#createdefault9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3910,85 +3872,89 @@ Checks whether the input value is of the **Map** type. ...@@ -3910,85 +3872,89 @@ Checks whether the input value is of the **Map** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | key | K | Yes| Key of which the value is missing.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.| | V | Value of the key.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isMap(new Map()); let result = pro.createDefault(50);
``` ```
### entries<sup>(deprecated)</sup>
### isMapIterator<sup>8+</sup> entries(): IterableIterator&lt;[K,V]&gt;
isMapIterator(value: Object): boolean Obtains a new iterator object that contains all key-value pairs in this object.
Checks whether the input value is of the **MapIterator** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [entries<sup>9+</sup>](#entries9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | [K,&nbsp;V] | Iterable array.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
const map = new Map(); pro.put(2,10);
let result = that.isMapIterator(map.keys()); let result = pro.entries();
``` ```
### [Symbol.iterator]<sup>(deprecated)</sup>
### isNativeError<sup>8+</sup> [Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
isNativeError(value: Object): boolean Obtains a two-dimensional array in key-value pairs.
Checks whether the input value is of the **Error** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | [K,&nbsp;V] | Two-dimensional array in key-value pairs.|
**Example** **Example**
```js ```js
let that = new util.types(); let pro = new util.LruBuffer();
let result = that.isNativeError(new TypeError()); pro.put(2,10);
let result = pro[Symbol.iterator]();
``` ```
## Scope<sup>(deprecated)</sup>
### isNumberObject<sup>8+</sup> > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper<sup>9+</sup>](#scopehelper9) instead.
isNumberObject(value: Object): boolean ### constructor<sup>(deprecated)</sup>
constructor(lowerObj: ScopeType, upperObj: ScopeType)
A constructor used to create a **Scope** object with the specified upper and lower limits.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
Checks whether the input value is a number object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -3996,55 +3962,52 @@ Checks whether the input value is a number object. ...@@ -3996,55 +3962,52 @@ Checks whether the input value is a number object.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isNumberObject(new Number(0)); let tempUpper = new Temperature(40);
let range = new util.Scope(tempLower, tempUpper);
``` ```
### toString<sup>(deprecated)</sup>
### isPromise<sup>8+</sup> toString(): string
isPromise(value: Object): boolean Obtains a string representation that contains this **Scope**.
Checks whether the input value is a promise. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | string | String representation containing the **Scope**.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isPromise(Promise.resolve(1)); let tempUpper = new Temperature(40);
let range = new util.Scope(tempLower, tempUpper);
let result = range.toString();
``` ```
### intersect<sup>(deprecated)</sup>
### isProxy<sup>8+</sup> intersect(range: Scope): Scope
isProxy(value: Object): boolean Obtains the intersection of this **Scope** and the given **Scope**.
Checks whether the input value is a proxy. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4052,29 +4015,35 @@ Checks whether the input value is a proxy. ...@@ -4052,29 +4015,35 @@ Checks whether the input value is a proxy.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.| | [Scope](#scopedeprecated) | Intersection of this **Scope** and the given **Scope**.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
const target = {}; let tempUpper = new Temperature(40);
const proxy = new Proxy(target, {}); let range = new util.Scope(tempLower, tempUpper);
let result = that.isProxy(proxy); let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let rangeFir = new util.Scope(tempMiDF, tempMidS);
range.intersect(rangeFir );
``` ```
### intersect<sup>(deprecated)</sup>
### isRegExp<sup>8+</sup> intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
isRegExp(value: Object): boolean Obtains the intersection of this **Scope** and the given lower and upper limits.
Checks whether the input value is of the **RegExp** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4082,84 +4051,89 @@ Checks whether the input value is of the **RegExp** type. ...@@ -4082,84 +4051,89 @@ Checks whether the input value is of the **RegExp** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.| | [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isRegExp(new RegExp('abc')); let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.Scope(tempLower, tempUpper);
let result = range.intersect(tempMiDF, tempMidS);
``` ```
### getUpper<sup>(deprecated)</sup>
### isSet<sup>8+</sup> getUpper(): ScopeType
isSet(value: Object): boolean Obtains the upper limit of this **Scope**.
Checks whether the input value is of the **Set** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getUpper<sup>9+</sup>](#getupper9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isSet(new Set()); let tempUpper = new Temperature(40);
let range = new util.Scope(tempLower, tempUpper);
let result = range.getUpper();
``` ```
### getLower<sup>(deprecated)</sup>
### isSetIterator<sup>8+</sup> getLower(): ScopeType
isSetIterator(value: Object): boolean Obtains the lower limit of this **Scope**.
Checks whether the input value is of the **SetIterator** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLower<sup>9+</sup>](#getlower9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.| | [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
const set = new Set(); let tempUpper = new Temperature(40);
let result = that.isSetIterator(set.keys()); let range = new util.Scope(tempLower, tempUpper);
let result = range.getLower();
``` ```
### expand<sup>(deprecated)</sup>
### isStringObject<sup>8+</sup> expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
isStringObject(value: Object): boolean Obtains the union set of this **Scope** and the given lower and upper limits.
Checks whether the input value is a string object. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4167,27 +4141,35 @@ Checks whether the input value is a string object. ...@@ -4167,27 +4141,35 @@ Checks whether the input value is a string object.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.| | [Scope](#scopedeprecated) | Union set of this **Scope** and the given lower and upper limits.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isStringObject(new String('foo')); let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.Scope(tempLower, tempUpper);
let result = range.expand(tempMiDF, tempMidS);
``` ```
### expand<sup>(deprecated)</sup>
### isSymbolObjec<sup>8+</sup> expand(range: Scope): Scope
isSymbolObject(value: Object): boolean Obtains the union set of this **Scope** and the given **Scope**.
Checks whether the input value is a symbol object. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4195,30 +4177,35 @@ Checks whether the input value is a symbol object. ...@@ -4195,30 +4177,35 @@ Checks whether the input value is a symbol object.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.| | [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
const symbols = Symbol('foo'); let tempUpper = new Temperature(40);
let result = that.isSymbolObject(Object(symbols)); let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.Scope(tempLower, tempUpper);
let rangeFir = new util.Scope(tempMiDF, tempMidS);
let result = range.expand(rangeFir);
``` ```
### expand<sup>(deprecated)</sup>
### isTypedArray<sup>8+</sup> expand(value: ScopeType): Scope
isTypedArray(value: Object): boolean
Checks whether the input value is of the **TypedArray** type. Obtains the union set of this **Scope** and the given value.
**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4226,27 +4213,33 @@ Checks whether the input value is of the **TypedArray** type. ...@@ -4226,27 +4213,33 @@ Checks whether the input value is of the **TypedArray** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | [ScopeType](#scopetype8) | Yes| Value specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.| | [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isTypedArray(new Float64Array([])); let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.Scope(tempLower, tempUpper);
let result = range.expand(tempMiDF);
``` ```
### contains<sup>(deprecated)</sup>
### isUint8Array<sup>8+</sup> contains(value: ScopeType): boolean
isUint8Array(value: Object): boolean Checks whether a value is within this **Scope**.
Checks whether the input value is of the **Uint8Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4254,27 +4247,33 @@ Checks whether the input value is of the **Uint8Array** type. ...@@ -4254,27 +4247,33 @@ Checks whether the input value is of the **Uint8Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | [ScopeType](#scopetype8) | Yes| Value specified.|
**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 value is within this **Scope**; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isUint8Array(new Uint8Array([])); let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.Scope(tempLower, tempUpper);
range.contains(tempMiDF);
``` ```
### contains<sup>(deprecated)</sup>
### isUint8ClampedArray<sup>8+</sup> contains(range: Scope): boolean
isUint8ClampedArray(value: Object): boolean Checks whether a range is within this **Scope**.
Checks whether the input value is of the **Uint8ClampedArray** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4282,27 +4281,36 @@ Checks whether the input value is of the **Uint8ClampedArray** type. ...@@ -4282,27 +4281,36 @@ Checks whether the input value is of the **Uint8ClampedArray** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
**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 range is within this **Scope**; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isUint8ClampedArray(new Uint8ClampedArray([])); let tempUpper = new Temperature(40);
let range = new util.Scope(tempLower, tempUpper);
let tempLess = new Temperature(20);
let tempMore = new Temperature(45);
let rangeSec = new util.Scope(tempLess, tempMore);
let result = range.contains(rangeSec);
``` ```
### clamp<sup>(deprecated)</sup>
### isUint16Array<sup>8+</sup>
isUint16Array(value: Object): boolean clamp(value: ScopeType): ScopeType
Checks whether the input value is of the **Uint16Array** type. Limits a value to this **Scope**.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clamp<sup>9+</sup>](#clamp9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4310,55 +4318,58 @@ Checks whether the input value is of the **Uint16Array** type. ...@@ -4310,55 +4318,58 @@ Checks whether the input value is of the **Uint16Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | value | [ScopeType](#scopetype8) | Yes| Value specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.| | [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
let that = new util.types(); let tempLower = new Temperature(30);
let result = that.isUint16Array(new Uint16Array([])); let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.Scope(tempLower, tempUpper);
let result = range.clamp(tempMiDF);
``` ```
### isUint32Array<sup>8+</sup> ## Base64<sup>(deprecated)</sup>
isUint32Array(value: Object): boolean
Checks whether the input value is of the **Uint32Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper<sup>9+</sup>](#base64helper9) instead.
**System capability**: SystemCapability.Utils.Lang ### constructor<sup>(deprecated)</sup>
**Parameters** constructor()
| Name| Type| Mandatory| Description| A constructor used to create a **Base64** object.
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
**Return value** > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
| Type| Description| **System capability**: SystemCapability.Utils.Lang
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
**Example** **Example**
```js ```js
let that = new util.types(); let base64 = new util.Base64();
let result = that.isUint32Array(new Uint32Array([]));
``` ```
### encodeSync<sup>(deprecated)</sup>
### isWeakMap<sup>8+</sup> encodeSync(src: Uint8Array): Uint8Array
isWeakMap(value: Object): boolean Encodes the input content.
Checks whether the input value is of the **WeakMap** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeSync<sup>9+</sup>](#encodesync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4366,27 +4377,31 @@ Checks whether the input value is of the **WeakMap** type. ...@@ -4366,27 +4377,31 @@ Checks whether the input value is of the **WeakMap** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | src | Uint8Array | Yes| Uint8Array to encode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.| | Uint8Array | Uint8Array encoded.|
**Example** **Example**
```js ```js
let that = new util.types(); let that = new util.Base64();
let result = that.isWeakMap(new WeakMap()); let array = new Uint8Array([115,49,51]);
let result = that.encodeSync(array);
``` ```
### encodeToStringSync<sup>(deprecated)</sup>
### isWeakSet<sup>8+</sup> encodeToStringSync(src: Uint8Array): string
isWeakSet(value: Object): boolean Encodes the input content.
Checks whether the input value is of the **WeakSet** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4394,27 +4409,31 @@ Checks whether the input value is of the **WeakSet** type. ...@@ -4394,27 +4409,31 @@ Checks whether the input value is of the **WeakSet** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | src | Uint8Array | Yes| Uint8Array to encode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.| | string | String encoded from the Uint8Array.|
**Example** **Example**
```js ```js
let that = new util.types(); let that = new util.Base64();
let result = that.isWeakSet(new WeakSet()); let array = new Uint8Array([115,49,51]);
let result = that.encodeToStringSync(array);
``` ```
### decodeSync<sup>(deprecated)</sup>
### isBigInt64Array<sup>8+</sup> decodeSync(src: Uint8Array | string): Uint8Array
isBigInt64Array(value: Object): boolean Decodes the input content.
Checks whether the input value is of the **BigInt64Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decodeSync<sup>9+</sup>](#decodesync9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4422,27 +4441,31 @@ Checks whether the input value is of the **BigInt64Array** type. ...@@ -4422,27 +4441,31 @@ Checks whether the input value is of the **BigInt64Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.| | Uint8Array | Uint8Array decoded.|
**Example** **Example**
```js ```js
let that = new util.types(); let that = new util.Base64();
let result = that.isBigInt64Array(new BigInt64Array([])); let buff = 'czEz';
let result = that.decodeSync(buff);
``` ```
### encode<sup>(deprecated)</sup>
### isBigUint64Array<sup>8+</sup> encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
isBigUint64Array(value: Object): boolean Encodes the input content asynchronously.
Checks whether the input value is of the **BigUint64Array** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encode<sup>9+</sup>](#encode9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4450,27 +4473,36 @@ Checks whether the input value is of the **BigUint64Array** type. ...@@ -4450,27 +4473,36 @@ Checks whether the input value is of the **BigUint64Array** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.| | Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
**Example** **Example**
```js ```js
let that = new util.types(); let that = new util.Base64();
let result = that.isBigUint64Array(new BigUint64Array([])); let array = new Uint8Array([115,49,51]);
let rarray = new Uint8Array([99,122,69,122]);
that.encode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
})
``` ```
### encodeToString<sup>(deprecated)</sup>
### isModuleNamespaceObject<sup>8+</sup> encodeToString(src: Uint8Array): Promise&lt;string&gt;
isModuleNamespaceObject(value: Object): boolean Encodes the input content asynchronously.
Checks whether the input value is a module namespace object. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToString<sup>9+</sup>](#encodetostring9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4478,28 +4510,34 @@ Checks whether the input value is a module namespace object. ...@@ -4478,28 +4510,34 @@ Checks whether the input value is a module namespace object.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.| | Promise&lt;string&gt; | String obtained after asynchronous encoding.|
**Example** **Example**
```js ```js
import url from '@ohos.url' let that = new util.Base64();
let that = new util.types(); let array = new Uint8Array([115,49,51]);
let result = that.isModuleNamespaceObject(url); that.encodeToString(array).then(val=>{
console.log(val)
})
``` ```
### decode<sup>(deprecated)</sup>
### isSharedArrayBuffer<sup>8+</sup> decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
isSharedArrayBuffer(value: Object): boolean Decodes the input content asynchronously.
Checks whether the input value is of the **SharedArrayBuffer** type. > **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decode<sup>9+</sup>](#decode9) instead.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -4507,18 +4545,25 @@ Checks whether the input value is of the **SharedArrayBuffer** type. ...@@ -4507,18 +4545,25 @@ Checks whether the input value is of the **SharedArrayBuffer** type.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.| | src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.| | Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
**Example** **Example**
```js ```js
let that = new util.types(); let that = new util.Base64();
let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0)); let array = new Uint8Array([99,122,69,122]);
let rarray = new Uint8Array([115,49,51]);
that.decode(array).then(val=>{
for (var i = 0; i < rarray.length; i++) {
console.log(val[i].toString())
}
})
``` ```
<!--no_check--> <!--no_check-->
# @ohos.worker # @ohos.worker (Worker Startup)
The worker thread is an independent thread running in parallel with the main thread. The thread that creates the worker thread is referred to as the host thread. The URL file passed in during worker creation is executed in the worker thread. The worker thread can process time-consuming operations, but cannot directly operate the UI. The worker thread is an independent thread running in parallel with the main thread. The thread that creates the worker thread is referred to as the host thread. The URL file passed in during worker creation is executed in the worker thread. The worker thread can process time-consuming operations, but cannot directly operate the UI.
With the **Worker** module, you can provide a multithreading environment for an application, so that the application can perform a time-consuming operation in a background thread. This greatly prevents a computing-intensive or high-latency task from blocking the running of the main thread. A **Worker** instance will not be proactively destroyed once it is created. It consumes resources to keep running. Therefore, you should call the API to terminate it in a timely manner. With the **Worker** module, you can provide a multithreading environment for an application, so that the application can perform a time-consuming operation in a background thread. This greatly prevents a computing-intensive or high-latency task from blocking the running of the main thread. A **Worker** instance will not be proactively destroyed once it is created. It consumes resources to keep running. Therefore, you should call the API to terminate it in a timely manner.
The **Context** object of the worker thread is different from that of the main thread. The worker thread does not support UI operations.
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -40,13 +42,13 @@ Provides options that can be set for the **Worker** instance to create. ...@@ -40,13 +42,13 @@ Provides options that can be set for the **Worker** instance to create.
## ThreadWorker<sup>9+</sup> ## ThreadWorker<sup>9+</sup>
Before using the following APIs, you must create a **Worker** instance. The **Worker** class inherits from [WorkerEventTarget](#workereventtarget9). Before using the following APIs, you must create a **ThreadWorker** instance. The **ThreadWorker** class inherits from [WorkerEventTarget](#workereventtarget9).
### constructor<sup>9+</sup> ### constructor<sup>9+</sup>
constructor(scriptURL: string, options?: WorkerOptions) constructor(scriptURL: string, options?: WorkerOptions)
A constructor used to create a **Worker** instance. A constructor used to create a **ThreadWorker** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -60,8 +62,19 @@ A constructor used to create a **Worker** instance. ...@@ -60,8 +62,19 @@ A constructor used to create a **Worker** instance.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | --------------------------------------------------------- | | ------------ | ------------------------------------------------------------ |
| Worker | Returns the **Worker** instance created; returns **undefined** if the **Worker** instance fails to be created.| | ThreadWorker | Returns the **ThreadWorker** instance created; returns **undefined** if the **ThreadWorker** instance fails to be created.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200003 | Worker initialization failure. |
| 10200007 | The worker file patch is invalid path. |
**Example** **Example**
...@@ -94,7 +107,7 @@ In the FA model: ...@@ -94,7 +107,7 @@ In the FA model:
"buildOption": { "buildOption": {
"sourceOption": { "sourceOption": {
"workers": [ "workers": [
"./src/main/ets/MainAbility/workers/worker.ts" "./src/main/ets/entryability/workers/worker.ts"
] ]
} }
} }
...@@ -138,6 +151,40 @@ In the stage model: ...@@ -138,6 +151,40 @@ In the stage model:
} }
``` ```
### postMessage<sup>9+</sup>
postMessage(message: Object, transfer: ArrayBuffer[]): void;
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
| message | Object | Yes | Message to be sent to the worker thread. |
| transfer | ArrayBuffer[] | Yes | An **ArrayBuffer** object can be transferred. The value **null** should not be passed in the array.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200006 | Serializing an uncaught exception failed. |
**Example**
```js
const workerInstance = new worker.ThreadWorker("workers/worker.js");
workerInstance.postMessage("hello world");
var buffer = new ArrayBuffer(8);
workerInstance.postMessage(buffer, [buffer]);
```
### postMessage<sup>9+</sup> ### postMessage<sup>9+</sup>
...@@ -154,6 +201,15 @@ Sends a message to the worker thread. The data type of the message must be seque ...@@ -154,6 +201,15 @@ Sends a message to the worker thread. The data type of the message must be seque
| message | Object | Yes | Message to be sent to the worker thread. | | message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.| | options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200006 | Serializing an uncaught exception failed. |
**Example** **Example**
```js ```js
...@@ -165,7 +221,6 @@ var buffer = new ArrayBuffer(8); ...@@ -165,7 +221,6 @@ var buffer = new ArrayBuffer(8);
workerInstance.postMessage(buffer, [buffer]); workerInstance.postMessage(buffer, [buffer]);
``` ```
### on<sup>9+</sup> ### on<sup>9+</sup>
on(type: string, listener: WorkerEventListener): void on(type: string, listener: WorkerEventListener): void
...@@ -181,6 +236,15 @@ Adds an event listener for the worker thread. This API provides the same functio ...@@ -181,6 +236,15 @@ Adds an event listener for the worker thread. This API provides the same functio
| type | string | Yes | Type of the event to listen for. | | type | string | Yes | Type of the event to listen for. |
| listener | [WorkerEventListener](#workereventlistener9) | Yes| Callback to invoke when an event of the specified type occurs. Callback to invoke when an event of the specified type occurs.| | listener | [WorkerEventListener](#workereventlistener9) | Yes| Callback to invoke when an event of the specified type occurs. Callback to invoke when an event of the specified type occurs.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -206,6 +270,15 @@ Adds an event listener for the worker thread and removes the event listener afte ...@@ -206,6 +270,15 @@ Adds an event listener for the worker thread and removes the event listener afte
| type | string | Yes | Type of the event to listen for. | | type | string | Yes | Type of the event to listen for. |
| listener | [WorkerEventListener](#workereventlistener9) | Yes| Callback to invoke when an event of the specified type occurs. Callback to invoke when an event of the specified type occurs.| | listener | [WorkerEventListener](#workereventlistener9) | Yes| Callback to invoke when an event of the specified type occurs. Callback to invoke when an event of the specified type occurs.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -231,6 +304,15 @@ Removes an event listener for the worker thread. This API provides the same func ...@@ -231,6 +304,15 @@ Removes an event listener for the worker thread. This API provides the same func
| type | string | Yes | Type of the event for which the event listener is to be removed. | | type | string | Yes | Type of the event for which the event listener is to be removed. |
| listener | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. Callback of the event listener to remove.| | listener | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. Callback of the event listener to remove.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -248,6 +330,14 @@ Terminates the worker thread to stop it from receiving messages. ...@@ -248,6 +330,14 @@ Terminates the worker thread to stop it from receiving messages.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example** **Example**
```js ```js
...@@ -270,6 +360,15 @@ Defines the event handler to be called when the worker thread exits. The handler ...@@ -270,6 +360,15 @@ Defines the event handler to be called when the worker thread exits. The handler
| ------ | ------ | ---- | ------------------ | | ------ | ------ | ---- | ------------------ |
| code | number | Yes | Code indicating the worker thread exit state.| | code | number | Yes | Code indicating the worker thread exit state.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -301,6 +400,15 @@ Defines the event handler to be called when an exception occurs during worker ex ...@@ -301,6 +400,15 @@ Defines the event handler to be called when an exception occurs during worker ex
| ------ | ------------------------- | ---- | ---------- | | ------ | ------------------------- | ---- | ---------- |
| err | [ErrorEvent](#errorevent) | Yes | Error data.| | err | [ErrorEvent](#errorevent) | Yes | Error data.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -325,6 +433,15 @@ Defines the event handler to be called when the host thread receives a message s ...@@ -325,6 +433,15 @@ Defines the event handler to be called when the host thread receives a message s
| ------ | -------------------------------- | ---- | ---------------------- | | ------ | -------------------------------- | ---- | ---------------------- |
| event | [MessageEvents](#messageevents9) | Yes | Message received.| | event | [MessageEvents](#messageevents9) | Yes | Message received.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -351,6 +468,15 @@ Defines the event handler to be called when the worker thread receives a message ...@@ -351,6 +468,15 @@ Defines the event handler to be called when the worker thread receives a message
| ------ | -------------------------------- | ---- | ---------- | | ------ | -------------------------------- | ---- | ---------- |
| event | [MessageEvents](#messageevents9) | Yes | Error data.| | event | [MessageEvents](#messageevents9) | Yes | Error data.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -360,6 +486,169 @@ workerInstance.onmessageerror= function(e) { ...@@ -360,6 +486,169 @@ workerInstance.onmessageerror= function(e) {
} }
``` ```
### addEventListener<sup>9+</sup>
addEventListener(type: string, listener: WorkerEventListener): void
Adds an event listener for the worker thread. This API provides the same functionality as [on<sup>9+</sup>](#on9).
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ---------------- |
| type | string | Yes | Type of the event to listen for.|
| listener | [WorkerEventListener](#workereventlistener9) | Yes | Callback to invoke when an event of the specified type occurs. |
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example**
```js
const workerInstance = new worker.ThreadWorker("workers/worker.js");
workerInstance.addEventListener("alert", (e)=>{
console.log("alert listener callback");
})
```
### removeEventListener<sup>9+</sup>
removeEventListener(type: string, callback?: WorkerEventListener): void
Removes an event listener for the worker thread. This API provides the same functionality as [off<sup>9+</sup>](#off9).
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ---------------------------- |
| type | string | Yes | Type of the event for which the event listener is to be removed. |
| callback | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. Callback of the event listener to remove.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example**
```js
const workerInstance = new worker.ThreadWorker("workers/worker.js");
workerInstance.addEventListener("alert", (e)=>{
console.log("alert listener callback");
})
workerInstance.removeEventListener("alert");
```
### dispatchEvent<sup>9+</sup>
dispatchEvent(event: Event): boolean
Dispatches the event defined for the worker thread.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | --------------- | ---- | ---------------- |
| event | [Event](#event) | Yes | Event to dispatch.|
**Return value**
| Type | Description |
| ------- | ------------------------------- |
| boolean | Returns **true** if the event is dispatched successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example**
```js
const workerInstance = new worker.ThreadWorker("workers/worker.js");
// Usage 1:
workerInstance.on("alert_on", (e)=>{
console.log("alert listener callback");
})
workerInstance.once("alert_once", (e)=>{
console.log("alert listener callback");
})
workerInstance.addEventListener("alert_add", (e)=>{
console.log("alert listener callback");
})
// The event listener created by once is removed after being executed once.
workerInstance.dispatchEvent({type:"alert_once", timeStamp:0});// timeStamp is not supported yet.
// The event listener created by on will not be proactively deleted.
workerInstance.dispatchEvent({type:"alert_on", timeStamp:0});
workerInstance.dispatchEvent({type:"alert_on", timeStamp:0});
// The event listener created by addEventListener will be always valid and will not be proactively deleted.
workerInstance.dispatchEvent({type:"alert_add", timeStamp:0});
workerInstance.dispatchEvent({type:"alert_add", timeStamp:0});
// Usage 2:
// The event type can be customized, and the special types "message", "messageerror", and "error" exist.
// When type = "message", the event handler defined by onmessage will also be executed.
// When type = "messageerror", the event handler defined by onmessageerror will also be executed.
// When type = "error", the event handler defined by onerror will also be executed.
// removeEventListener or off can be used to remove an event listener that is created by addEventListener, on, or once.
workerInstance.addEventListener("message", (e)=>{
console.log("message listener callback");
})
workerInstance.onmessage = function(e) {
console.log("onmessage : message listener callback");
}
// When dispatchEvent is called to distribute the "message" event, the callback passed in addEventListener and onmessage will be invoked.
workerInstance.dispatchEvent({type:"message", timeStamp:0});
```
### removeAllListener<sup>9+</sup>
removeAllListener(): void
Removes all event listeners for the worker thread.
**System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example**
```js
const workerInstance = new worker.ThreadWorker("workers/worker.js");
workerInstance.addEventListener("alert", (e)=>{
console.log("alert listener callback");
})
workerInstance.removeAllListener();
```
## WorkerEventTarget<sup>9+</sup> ## WorkerEventTarget<sup>9+</sup>
...@@ -378,6 +667,15 @@ Adds an event listener for the worker thread. This API provides the same functio ...@@ -378,6 +667,15 @@ Adds an event listener for the worker thread. This API provides the same functio
| type | string | Yes | Type of the event to listen for.| | type | string | Yes | Type of the event to listen for.|
| listener | [WorkerEventListener](#workereventlistener9) | Yes | Callback to invoke when an event of the specified type occurs. | | listener | [WorkerEventListener](#workereventlistener9) | Yes | Callback to invoke when an event of the specified type occurs. |
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -401,7 +699,15 @@ Removes an event listener for the worker thread. This API provides the same func ...@@ -401,7 +699,15 @@ Removes an event listener for the worker thread. This API provides the same func
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ---------------------------- | | -------- | -------------------------------------------- | ---- | ---------------------------- |
| type | string | Yes | Type of the event for which the event listener is to be removed. | | type | string | Yes | Type of the event for which the event listener is to be removed. |
| callback | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. Callback of the event listener to remove.| | callback | [WorkerEventListener](#workereventlistener9) | No| Callback to invoke when an event of the specified type occurs. |
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example** **Example**
...@@ -434,6 +740,14 @@ Dispatches the event defined for the worker thread. ...@@ -434,6 +740,14 @@ Dispatches the event defined for the worker thread.
| ------- | ------------------------------- | | ------- | ------------------------------- |
| boolean | Returns **true** if the event is dispatched successfully; returns **false** otherwise.| | boolean | Returns **true** if the event is dispatched successfully; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example** **Example**
```js ```js
...@@ -450,11 +764,11 @@ workerInstance.addEventListener("alert_add", (e)=>{ ...@@ -450,11 +764,11 @@ workerInstance.addEventListener("alert_add", (e)=>{
}) })
// The event listener created by once is removed after being executed once. // The event listener created by once is removed after being executed once.
workerInstance.dispatchEvent({type:"alert_once", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_once", timeStamp:0});// timeStamp is not supported yet.
// The event listener created by on will be always valid and will not be proactively deleted. // The event listener created by on will not be proactively deleted.
workerInstance.dispatchEvent({type:"alert_on", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_on", timeStamp:0});
workerInstance.dispatchEvent({type:"alert_on", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_on", timeStamp:0});
// The event listener created by addEventListener will be always valid and will not be proactively deleted. // The event listener created by addEventListener will not be proactively deleted.
workerInstance.dispatchEvent({type:"alert_add", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_add", timeStamp:0});
workerInstance.dispatchEvent({type:"alert_add", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_add", timeStamp:0});
...@@ -484,6 +798,14 @@ Removes all event listeners for the worker thread. ...@@ -484,6 +798,14 @@ Removes all event listeners for the worker thread.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example** **Example**
```js ```js
...@@ -499,6 +821,53 @@ workerInstance.removeAllListener(); ...@@ -499,6 +821,53 @@ workerInstance.removeAllListener();
Implements communication between the worker thread and the host thread. The **postMessage** API is used to send messages to the host thread, and the **close** API is used to terminate the worker thread. The **ThreadWorkerGlobalScope** class inherits from [GlobalScope<sup>9+</sup>](#globalscope9). Implements communication between the worker thread and the host thread. The **postMessage** API is used to send messages to the host thread, and the **close** API is used to terminate the worker thread. The **ThreadWorkerGlobalScope** class inherits from [GlobalScope<sup>9+</sup>](#globalscope9).
### postMessage<sup>9+</sup>
postMessage(messageObject: Object, transfer: ArrayBuffer[]): void;
Sends a message to the host thread from the worker thread.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------------------------------------------- |
| message | Object | Yes | Message to be sent to the worker thread. |
| transfer | ArrayBuffer[] | Yes | An **ArrayBuffer** object can be transferred. The value **null** should not be passed in the array.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200006 | Serializing an uncaught exception failed. |
**Example**
```js
// main.js
import worker from '@ohos.worker';
const workerInstance = new worker.ThreadWorker("workers/worker.js");
workerInstance.postMessage("hello world");
workerInstance.onmessage = function(e) {
// let data = e.data;
console.log("receive data from worker.js");
}
```
```js
// worker.js
import worker from '@ohos.worker';
const workerPort = worker.workerPort;
workerPort.onmessage = function(e){
// let data = e.data;
var buffer = new ArrayBuffer(8);
workerPort.postMessage(buffer, [buffer]);
}
```
### postMessage<sup>9+</sup> ### postMessage<sup>9+</sup>
...@@ -515,6 +884,15 @@ Sends a message to the host thread from the worker thread. ...@@ -515,6 +884,15 @@ Sends a message to the host thread from the worker thread.
| message | Object | Yes | Message to be sent to the worker thread. | | message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.| | options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200006 | Serializing an uncaught exception failed. |
**Example** **Example**
```js ```js
...@@ -531,10 +909,10 @@ workerInstance.onmessage = function(e) { ...@@ -531,10 +909,10 @@ workerInstance.onmessage = function(e) {
```js ```js
// worker.js // worker.js
import worker from '@ohos.worker'; import worker from '@ohos.worker';
const parentPort = worker.workerPort; const workerPort = worker.workerPort;
parentPort.onmessage = function(e){ workerPort.onmessage = function(e){
// let data = e.data; // let data = e.data;
parentPort.postMessage("receive data from main.js"); workerPort.postMessage("receive data from main.js");
} }
``` ```
...@@ -547,6 +925,14 @@ Terminates the worker thread to stop it from receiving messages. ...@@ -547,6 +925,14 @@ Terminates the worker thread to stop it from receiving messages.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | ------------------------------- |
| 10200004 | Worker instance is not running. |
**Example** **Example**
```js ```js
...@@ -558,16 +944,16 @@ const workerInstance = new worker.ThreadWorker("workers/worker.js"); ...@@ -558,16 +944,16 @@ const workerInstance = new worker.ThreadWorker("workers/worker.js");
```js ```js
// worker.js // worker.js
import worker from '@ohos.worker'; import worker from '@ohos.worker';
const parentPort = worker.workerPort; const workerPort = worker.workerPort;
parentPort.onmessage = function(e) { workerPort.onmessage = function(e) {
parentPort.close() workerPort.close()
} }
``` ```
### onmessage<sup>9+</sup> ### onmessage<sup>9+</sup>
onmessage?: (this: ThreadWorkerGlobalScope, event: MessageEvents) =&gt; void onmessage?: (this: ThreadWorkerGlobalScope, ev: MessageEvents) =&gt; void
Defines the event handler to be called when the worker thread receives a message sent by the host thread through **postMessage**. The event handler is executed in the worker thread. Defines the event handler to be called when the worker thread receives a message sent by the host thread through **postMessage**. The event handler is executed in the worker thread.
...@@ -578,7 +964,16 @@ Defines the event handler to be called when the worker thread receives a message ...@@ -578,7 +964,16 @@ Defines the event handler to be called when the worker thread receives a message
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ---------------------------------------------------- | ---- | ------------------------ | | ------ | ---------------------------------------------------- | ---- | ------------------------ |
| this | [ThreadWorkerGlobalScope](#threadworkerglobalscope9) | Yes | Caller. | | this | [ThreadWorkerGlobalScope](#threadworkerglobalscope9) | Yes | Caller. |
| event | [MessageEvents](#messageevents9) | Yes | Message received.| | ev | [MessageEvents](#messageevents9) | Yes | Message received.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
...@@ -592,8 +987,8 @@ workerInstance.postMessage("hello world"); ...@@ -592,8 +987,8 @@ workerInstance.postMessage("hello world");
```js ```js
// worker.js // worker.js
import worker from '@ohos.worker'; import worker from '@ohos.worker';
const parentPort = worker.workerPort; const workerPort = worker.workerPort;
parentPort.onmessage = function(e) { workerPort.onmessage = function(e) {
console.log("receive main.js message"); console.log("receive main.js message");
} }
``` ```
...@@ -601,7 +996,7 @@ parentPort.onmessage = function(e) { ...@@ -601,7 +996,7 @@ parentPort.onmessage = function(e) {
### onmessageerror<sup>9+</sup> ### onmessageerror<sup>9+</sup>
onmessageerror?: (this: ThreadWorkerGlobalScope, event: MessageEvents) =&gt; void onmessageerror?: (this: ThreadWorkerGlobalScope, ev: MessageEvents) =&gt; void
Defines the event handler to be called when the worker thread receives a message that cannot be deserialized. The event handler is executed in the worker thread. Defines the event handler to be called when the worker thread receives a message that cannot be deserialized. The event handler is executed in the worker thread.
...@@ -612,7 +1007,16 @@ Defines the event handler to be called when the worker thread receives a message ...@@ -612,7 +1007,16 @@ Defines the event handler to be called when the worker thread receives a message
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | -------------------------------- | ---- | ---------- | | ------ | -------------------------------- | ---- | ---------- |
| this | [ThreadWorkerGlobalScope](#threadworkerglobalscope9) | Yes | Caller. | | this | [ThreadWorkerGlobalScope](#threadworkerglobalscope9) | Yes | Caller. |
| event | [MessageEvents](#messageevents9) | Yes | Error data.| | ev | [MessageEvents](#messageevents9) | Yes | Error data.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
...@@ -652,6 +1056,15 @@ Implements event listening. ...@@ -652,6 +1056,15 @@ Implements event listening.
| ------------------------------------- | ------------------------------- | | ------------------------------------- | ------------------------------- |
| void&nbsp;\|&nbsp;Promise&lt;void&gt; | Returns no value or returns a **Promise**.| | void&nbsp;\|&nbsp;Promise&lt;void&gt; | Returns no value or returns a **Promise**.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 10200004 | Worker instance is not running. |
| 10200005 | The invoked API is not supported in workers. |
**Example** **Example**
```js ```js
...@@ -701,8 +1114,8 @@ const workerInstance = new worker.ThreadWorker("workers/worker.js") ...@@ -701,8 +1114,8 @@ const workerInstance = new worker.ThreadWorker("workers/worker.js")
```js ```js
// worker.js // worker.js
import worker from '@ohos.worker'; import worker from '@ohos.worker';
const parentPort = worker.workerPort const workerPort = worker.workerPort
parentPort.onerror = function(e){ workerPort.onerror = function(e){
console.log("worker.js onerror") console.log("worker.js onerror")
} }
``` ```
...@@ -779,7 +1192,7 @@ In the FA model: ...@@ -779,7 +1192,7 @@ In the FA model:
"buildOption": { "buildOption": {
"sourceOption": { "sourceOption": {
"workers": [ "workers": [
"./src/main/ets/MainAbility/workers/worker.ts" "./src/main/ets/entryability/workers/worker.ts"
] ]
} }
} }
...@@ -816,9 +1229,10 @@ In the stage model: ...@@ -816,9 +1229,10 @@ In the stage model:
} }
} }
``` ```
### postMessage<sup>(deprecated)</sup> ### postMessage<sup>(deprecated)</sup>
postMessage(message: Object, options?: PostMessageOptions): void postMessage(message: Object, transfer: ArrayBuffer[]): void;
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information). Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
...@@ -830,9 +1244,9 @@ Sends a message to the worker thread. The data type of the message must be seque ...@@ -830,9 +1244,9 @@ Sends a message to the worker thread. The data type of the message must be seque
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------- | ---- | ----------------------------------------------- |
| message | Object | Yes | Message to be sent to the worker thread. | | message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.| | transfer | ArrayBuffer[] | Yes | **ArrayBuffer** instances that can be transferred.|
**Example** **Example**
...@@ -845,6 +1259,32 @@ var buffer = new ArrayBuffer(8); ...@@ -845,6 +1259,32 @@ var buffer = new ArrayBuffer(8);
workerInstance.postMessage(buffer, [buffer]); workerInstance.postMessage(buffer, [buffer]);
``` ```
### postMessage<sup>(deprecated)</sup>
postMessage(message: Object, options?: PostMessageOptions): void
Sends a message to the worker thread. The data type of the message must be sequenceable. For details about the sequenceable data types, see [More Information](#more-information).
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorker.postMessage<sup>9+</sup>](#postmessage9-1) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| message | Object | Yes | Message to be sent to the worker thread. |
| options | [PostMessageOptions](#postmessageoptions) | No | **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.|
**Example**
```js
const workerInstance = new worker.Worker("workers/worker.js");
workerInstance.postMessage("hello world");
```
### on<sup>(deprecated)</sup> ### on<sup>(deprecated)</sup>
...@@ -1024,7 +1464,7 @@ Defines the event handler to be called when the host thread receives a message s ...@@ -1024,7 +1464,7 @@ Defines the event handler to be called when the host thread receives a message s
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ---------------------- | | ------ | ------------------------------ | ---- | ---------------------- |
| event | [MessageEvent](#messageeventt) | Yes | Message received.| | event | [MessageEvent](#messageevent)| Yes | Message received.|
**Example** **Example**
...@@ -1053,7 +1493,7 @@ Defines the event handler to be called when the worker thread receives a message ...@@ -1053,7 +1493,7 @@ Defines the event handler to be called when the worker thread receives a message
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ---------- | | ------ | ------------------------------ | ---- | ---------- |
| event | [MessageEvent](#messageeventt) | Yes | Error data.| | event | [MessageEvent](#messageevent)| Yes | Error data.|
**Example** **Example**
...@@ -1166,7 +1606,7 @@ workerInstance.addEventListener("alert_add", (e)=>{ ...@@ -1166,7 +1606,7 @@ workerInstance.addEventListener("alert_add", (e)=>{
}) })
// The event listener created by once is removed after being executed once. // The event listener created by once is removed after being executed once.
workerInstance.dispatchEvent({type:"alert_once", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_once", timeStamp:0});// timeStamp is not supported yet.
// The event listener created by on will not be proactively deleted. // The event listener created by on will not be proactively deleted.
workerInstance.dispatchEvent({type:"alert_on", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_on", timeStamp:0});
workerInstance.dispatchEvent({type:"alert_on", timeStamp:0}); workerInstance.dispatchEvent({type:"alert_on", timeStamp:0});
...@@ -1219,6 +1659,44 @@ Implements communication between the worker thread and the host thread. The **po ...@@ -1219,6 +1659,44 @@ Implements communication between the worker thread and the host thread. The **po
> **NOTE**<br> > **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorkerGlobalScope<sup>9+</sup>](#threadworkerglobalscope9) instead. > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [ThreadWorkerGlobalScope<sup>9+</sup>](#threadworkerglobalscope9) instead.
### postMessage<sup>9+</sup>
postMessage(messageObject: Object, transfer: ArrayBuffer[]): void;
Sends a message to the host thread from the worker thread.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ----------------------------------------------------- |
| message | Object | Yes | Message to be sent to the worker thread. |
| transfer | ArrayBuffer[] | Yes | An **ArrayBuffer** object can be transferred. The value **null** should not be passed in the array.|
**Example**
```js
// main.js
import worker from '@ohos.worker';
const workerInstance = new worker.Worker("workers/worker.js");
workerInstance.postMessage("hello world");
workerInstance.onmessage = function(e) {
// let data = e.data;
console.log("receive data from worker.js");
}
```
```js
// worker.js
import worker from '@ohos.worker';
const parentPort = worker.parentPort;
parentPort.onmessage = function(e){
// let data = e.data;
let buffer = new ArrayBuffer(5)
parentPort.postMessage(buffer, [buffer]);
}
```
### postMessage<sup>(deprecated)</sup> ### postMessage<sup>(deprecated)</sup>
postMessage(messageObject: Object, options?: PostMessageOptions): void postMessage(messageObject: Object, options?: PostMessageOptions): void
...@@ -1259,7 +1737,6 @@ parentPort.onmessage = function(e){ ...@@ -1259,7 +1737,6 @@ parentPort.onmessage = function(e){
} }
``` ```
### close<sup>(deprecated)</sup> ### close<sup>(deprecated)</sup>
close(): void close(): void
...@@ -1290,7 +1767,7 @@ parentPort.onmessage = function(e) { ...@@ -1290,7 +1767,7 @@ parentPort.onmessage = function(e) {
### onmessage<sup>(deprecated)</sup> ### onmessage<sup>(deprecated)</sup>
onmessage?: (this: DedicatedWorkerGlobalScope, event: MessageEvent) =&gt; void onmessage?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) =&gt; void
Defines the event handler to be called when the worker thread receives a message sent by the host thread through **postMessage**. The event handler is executed in the worker thread. Defines the event handler to be called when the worker thread receives a message sent by the host thread through **postMessage**. The event handler is executed in the worker thread.
...@@ -1304,7 +1781,7 @@ Defines the event handler to be called when the worker thread receives a message ...@@ -1304,7 +1781,7 @@ Defines the event handler to be called when the worker thread receives a message
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------------------------------------ | ---- | ------------------------ | | ------ | ------------------------------------------------------------ | ---- | ------------------------ |
| this | [DedicatedWorkerGlobalScope](#dedicatedworkerglobalscopedeprecated) | Yes | Caller. | | this | [DedicatedWorkerGlobalScope](#dedicatedworkerglobalscopedeprecated) | Yes | Caller. |
| event | [MessageEvent](#messageeventt) | Yes | Message received.| | ev | [MessageEvent](#messageevent) | Yes | Message received.|
**Example** **Example**
...@@ -1326,7 +1803,7 @@ parentPort.onmessage = function(e) { ...@@ -1326,7 +1803,7 @@ parentPort.onmessage = function(e) {
### onmessageerror<sup>(deprecated)</sup> ### onmessageerror<sup>(deprecated)</sup>
onmessageerror?: (this: DedicatedWorkerGlobalScope, event: MessageEvent) =&gt; void onmessageerror?: (this: DedicatedWorkerGlobalScope, ev: MessageEvent) =&gt; void
Defines the event handler to be called when the worker thread receives a message that cannot be deserialized. The event handler is executed in the worker thread. Defines the event handler to be called when the worker thread receives a message that cannot be deserialized. The event handler is executed in the worker thread.
...@@ -1340,7 +1817,7 @@ Defines the event handler to be called when the worker thread receives a message ...@@ -1340,7 +1817,7 @@ Defines the event handler to be called when the worker thread receives a message
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ---------- | | ------ | ------------------------------ | ---- | ---------- |
| this | [DedicatedWorkerGlobalScope](#dedicatedworkerglobalscopedeprecated) | Yes | Caller.| | this | [DedicatedWorkerGlobalScope](#dedicatedworkerglobalscopedeprecated) | Yes | Caller.|
| event | [MessageEvent](#messageeventt) | Yes | Error data.| | ev | [MessageEvent](#messageevent)| Yes | Error data.|
**Example** **Example**
...@@ -1377,9 +1854,9 @@ Defines the event. ...@@ -1377,9 +1854,9 @@ Defines the event.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| --------- | ------ | ---- | ---- | ---------------------------------- | | --------- | ------ | ---- | ---- | -------------------------------------------- |
| type | string | Yes | No | Type of the event. | | type | string | Yes | No | Type of the event. |
| timeStamp | number | Yes | No | Timestamp (accurate to millisecond) when the event is created.| | timeStamp | number | Yes | No | Timestamp (accurate to millisecond) when the event is created. This parameter is not supported yet.|
## EventListener<sup>(deprecated)</sup> ## EventListener<sup>(deprecated)</sup>
...@@ -1525,14 +2002,14 @@ workerInstance.onmessage = function(d) { ...@@ -1525,14 +2002,14 @@ workerInstance.onmessage = function(d) {
```js ```js
// worker.js // worker.js
import worker from '@ohos.worker'; import worker from '@ohos.worker';
const parentPort = worker.workerPort; const workerPort = worker.workerPort;
class MyModel { class MyModel {
name = "undefined" name = "undefined"
Init() { Init() {
this.name = "MyModel" this.name = "MyModel"
} }
} }
parentPort.onmessage = function(d) { workerPort.onmessage = function(d) {
console.log("worker.js onmessage"); console.log("worker.js onmessage");
let data = d.data; let data = d.data;
let func1 = function() { let func1 = function() {
...@@ -1546,14 +2023,14 @@ parentPort.onmessage = function(d) { ...@@ -1546,14 +2023,14 @@ parentPort.onmessage = function(d) {
} }
} }
let obj2 = new MyModel(); let obj2 = new MyModel();
// parentPort.postMessage(func1); A serialization error occurs when passing func1. // workerPort.postMessage(func1); A serialization error occurs when passing func1.
// parentPort.postMessage(obj1); A serialization error occurs when passing obj1. // workerPort.postMessage(obj1); A serialization error occurs when passing obj1.
parentPort.postMessage(obj2); // No serialization error occurs when passing obj2. workerPort.postMessage(obj2); // No serialization error occurs when passing obj2.
} }
parentPort.onmessageerror = function(e) { workerPort.onmessageerror = function(e) {
console.log("worker.js onmessageerror"); console.log("worker.js onmessageerror");
} }
parentPort.onerror = function(e) { workerPort.onerror = function(e) {
console.log("worker.js onerror"); console.log("worker.js onerror");
} }
``` ```
...@@ -1571,6 +2048,7 @@ Each actor concurrently processes tasks of the main thread. For each actor, ther ...@@ -1571,6 +2048,7 @@ Each actor concurrently processes tasks of the main thread. For each actor, ther
- Since API version 9, if a **Worker** instance in a non-running state (such as destroyed or being destroyed) calls an API, a business error is thrown. - Since API version 9, if a **Worker** instance in a non-running state (such as destroyed or being destroyed) calls an API, a business error is thrown.
- Creating and terminating worker threads consume performance. Therefore, you are advised to manage available workers and reuse them. - Creating and terminating worker threads consume performance. Therefore, you are advised to manage available workers and reuse them.
- Do not use both **new worker.Worker** and **new worker.ThreadWorker** to create a **Worker** project. Otherwise, **Worker** functions abnormally. Since API version 9, you are advised to use [new worker.ThreadWorker](#constructor9). In API version 8 and earlier versions, you are advised to use [new worker.Worker](#constructordeprecated). - Do not use both **new worker.Worker** and **new worker.ThreadWorker** to create a **Worker** project. Otherwise, **Worker** functions abnormally. Since API version 9, you are advised to use [new worker.ThreadWorker](#constructor9). In API version 8 and earlier versions, you are advised to use [new worker.Worker](#constructordeprecated).
- When creating a **Worker** project, do not import any UI construction method (such as .ets file) to the worker thread file (for example, **worker.ts** used in this document). Otherwise, the worker module becomes invalid. To check whether any UI construction method has been imported, decompress the generated HAP file, find **worker.js** in the directory where the worker thread is created, and search for the keyword **View** globally. If the keyword exists, a UI construction method has been packaged in **worker.js**. If this is your case, change the directory level of **src** in the statement **import "xxx" from src** in the worker thread file.
## Sample Code ## Sample Code
> **NOTE**<br> > **NOTE**<br>
...@@ -1611,23 +2089,23 @@ workerInstance.onexit = function() { ...@@ -1611,23 +2089,23 @@ workerInstance.onexit = function() {
import worker from '@ohos.worker'; import worker from '@ohos.worker';
// Create an object in the worker thread for communicating with the main thread. // Create an object in the worker thread for communicating with the main thread.
const parentPort = worker.workerPort const workerPort = worker.workerPort
// In versions earlier than API version 9, use the following to create an object in the worker thread for communicating with the main thread. // In versions earlier than API version 9, use the following to create an object in the worker thread for communicating with the main thread.
// const parentPort = worker.parentPort // const parentPort = worker.parentPort
// The worker thread receives information from the main thread. // The worker thread receives information from the main thread.
parentPort.onmessage = function(e) { workerPort.onmessage = function(e) {
// data carries the information sent by the main thread. // data carries the information sent by the main thread.
let data = e.data; let data = e.data;
console.log("worker.ts onmessage"); console.log("worker.ts onmessage");
// The worker thread sends information to the main thread. // The worker thread sends information to the main thread.
parentPort.postMessage("123") workerPort.postMessage("123")
} }
// Trigger a callback when an error occurs in the worker thread. // Trigger a callback when an error occurs in the worker thread.
parentPort.onerror= function(e) { workerPort.onerror= function(e) {
console.log("worker.ts onerror"); console.log("worker.ts onerror");
} }
``` ```
...@@ -1636,7 +2114,7 @@ Configuration of the **build-profile.json5** file: ...@@ -1636,7 +2114,7 @@ Configuration of the **build-profile.json5** file:
"buildOption": { "buildOption": {
"sourceOption": { "sourceOption": {
"workers": [ "workers": [
"./src/main/ets/MainAbility/workers/worker.ts" "./src/main/ets/entryability/workers/worker.ts"
] ]
} }
} }
...@@ -1673,20 +2151,20 @@ workerInstance.onexit = function() { ...@@ -1673,20 +2151,20 @@ workerInstance.onexit = function() {
import worker from '@ohos.worker'; import worker from '@ohos.worker';
// Create an object in the worker thread for communicating with the main thread. // Create an object in the worker thread for communicating with the main thread.
const parentPort = worker.workerPort const workerPort = worker.workerPort
// The worker thread receives information from the main thread. // The worker thread receives information from the main thread.
parentPort.onmessage = function(e) { workerPort.onmessage = function(e) {
// data carries the information sent by the main thread. // data carries the information sent by the main thread.
let data = e.data; let data = e.data;
console.log("worker.ts onmessage"); console.log("worker.ts onmessage");
// The worker thread sends information to the main thread. // The worker thread sends information to the main thread.
parentPort.postMessage("123") workerPort.postMessage("123")
} }
// Trigger a callback when an error occurs in the worker thread. // Trigger a callback when an error occurs in the worker thread.
parentPort.onerror= function(e) { workerPort.onerror= function(e) {
console.log("worker.ts onerror"); console.log("worker.ts onerror");
} }
``` ```
......
...@@ -32,9 +32,16 @@ A constructor used to create an **XmlSerializer** instance. ...@@ -32,9 +32,16 @@ A constructor used to create an **XmlSerializer** instance.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); let arrayBuffer = new ArrayBuffer(2048);
let bufView = new DataView(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer,"utf-8");
let thatSer = new xml.XmlSerializer(bufView); thatSer.setDeclaration();
let result = '<?xml version="1.0" encoding="utf-8"?>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) //<?xml version="1.0" encoding="utf-8"?>
``` ```
...@@ -56,12 +63,19 @@ Sets an attribute. ...@@ -56,12 +63,19 @@ Sets an attribute.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let bufView = new DataView(arrayBuffer); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note"); thatSer.startElement("note");
thatSer.setAttributes("importance", "high"); thatSer.setAttributes("importance1", "high1");
thatSer.endElement(); thatSer.endElement();
let result = '<note importance1="high1"/>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) //<note importance1="high1"/>
``` ```
...@@ -82,10 +96,17 @@ Adds an empty element. ...@@ -82,10 +96,17 @@ Adds an empty element.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let bufView = new DataView(arrayBuffer); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.addEmptyElement("b"); // => <b/> thatSer.addEmptyElement("d");
let result = '<d/>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) //<d/>
``` ```
...@@ -100,10 +121,20 @@ Sets a declaration. ...@@ -100,10 +121,20 @@ Sets a declaration.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let bufView = new DataView(arrayBuffer); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>; thatSer.setDeclaration();
thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("note");
thatSer.endElement();
let result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) //<?xml version="1.0" encoding="utf-8"?>
``` ```
...@@ -124,13 +155,22 @@ Writes the start tag based on the given element name. ...@@ -124,13 +155,22 @@ Writes the start tag based on the given element name.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("notel"); thatSer.setDeclaration();
thatSer.endElement();// => '<notel/>'; thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("note");
thatSer.endElement();
let result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(JSON.stringify(view1)) //<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>
``` ```
### endElement ### endElement
endElement(): void endElement(): void
...@@ -142,14 +182,20 @@ Writes the end tag of the element. ...@@ -142,14 +182,20 @@ Writes the end tag of the element.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let bufView = new DataView(arrayBuffer); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(bufView); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setNamespace("h", "https://www.w3.org/TR/html4/"); thatSer.setDeclaration();
thatSer.startElement("table"); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.setAttributes("importance", "high"); thatSer.startElement("note");
thatSer.setText("Happy"); thatSer.endElement();
thatSer.endElement(); // => <h:table importance="high" xmlns:h="https://www.w3.org/TR/html4/">Happy</h:table> let result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(JSON.stringify(view1)) //<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>
``` ```
...@@ -171,12 +217,20 @@ Sets the namespace for an element tag. ...@@ -171,12 +217,20 @@ Sets the namespace for an element tag.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDeclaration(); thatSer.setDeclaration();
thatSer.setNamespace("h", "https://www.w3.org/TR/html4/"); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/");
thatSer.startElement("note"); thatSer.startElement("note");
thatSer.endElement();// = >'<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="https://www.w3.org/TR/html4/"/>'; thatSer.endElement();
let result = '<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(JSON.stringify(view1)) //<?xml version="1.0" encoding="utf-8"?>\r\n<h:note xmlns:h="http://www.w3.org/TR/html4/"/>
``` ```
### setComment ### setComment
...@@ -196,11 +250,17 @@ Sets the comment. ...@@ -196,11 +250,17 @@ Sets the comment.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.startElement("note"); thatSer.setComment("Hello, World!");
thatSer.setComment("Hi!"); let result = '<!--Hello, World!-->';
thatSer.endElement(); // => '<note>\r\n <!--Hi!-->\r\n</note>'; let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) //<!--Hello, World!-->'
``` ```
...@@ -221,9 +281,17 @@ Sets CDATA attributes. ...@@ -221,9 +281,17 @@ Sets CDATA attributes.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1028); const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setCDATA('root SYSTEM') // => '<![CDATA[root SYSTEM]]>'; thatSer.setCDATA('root SYSTEM')
let result = '<![CDATA[root SYSTEM]]>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) //'<![CDATA[root SYSTEM]]>''
``` ```
...@@ -244,12 +312,20 @@ Sets **Text**. ...@@ -244,12 +312,20 @@ Sets **Text**.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX);
let 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");
thatSer.endElement(); // => '<note importance="high">Happy1</note>'; thatSer.endElement();
let result = '<note importance="high">Happy1</note>';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) // '<note importance="high">Happy1</note>'
``` ```
...@@ -270,9 +346,17 @@ Sets **DocType**. ...@@ -270,9 +346,17 @@ Sets **DocType**.
**Example** **Example**
```js ```js
let arrayBuffer = new ArrayBuffer(1024); const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
thatSer.setDocType('root SYSTEM'); // => '<!DOCTYPE root SYSTEM>'; thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"');
let result = '<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">';
let view = new Uint8Array(arrayBuffer);
let view1 = "";
for (let i = 0; i < result.length; ++i) {
view1 = view1 + String.fromCodePoint(view[i]);
}
console.log(view1) //'<!DOCTYPE root SYSTEM "http://www.test.org/test.dtd">'
``` ```
...@@ -299,18 +383,39 @@ Creates and returns an **XmlPullParser** object. The **XmlPullParser** object pa ...@@ -299,18 +383,39 @@ Creates and returns an **XmlPullParser** object. The **XmlPullParser** object pa
```js ```js
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
'<!DOCTYPE note [\n<!ENTITY foo "baa">]>' +
'<note importance="high" logged="true">' + '<note importance="high" logged="true">' +
' <![CDATA[\r\nfuncrion matchwo(a,6)\r\n{\r\nreturn 1;\r\n}\r\n]]>' +
' <!--Hello, World!-->' +
' <company>John &amp; Hans</company>' +
' <title>Happy</title>' + ' <title>Happy</title>' +
' <todo>Work</todo>' + ' <title>Happy</title>' +
' <todo>Play</todo>' + ' <lens>Work</lens>' +
' <lens>Play</lens>' +
' <?go there?>' +
' <a><b/></a>' +
' <h:table xmlns:h="http://www.w3.org/TR/html4/">' +
' <h:tr>' +
' <h:td>Apples</h:td>' +
' <h:td>Bananas</h:td>' +
' </h:tr>' +
' </h:table>' +
'</note>'; '</note>';
let arrayBuffer = new ArrayBuffer(strXml.length); let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer); let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length; let strLen = strXml.length;
for (var i = 0; i < strLen; ++i) { for (let i = 0; i < strLen; ++i) {
bufView[i] = strXml.charCodeAt(i);// Set the ArrayBuffer mode. bufView[i] = strXml.charCodeAt(i);
} }
let that = new xml.XmlPullParser(arrayBuffer); let that = new xml.XmlPullParser(arrayBuffer, 'UTF-8');
let str1 = '';
function func1(name, value){
str1 += name+':'+value;
return true;
}
let options = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func1}
that.parse(options);
console.log(str1) //'note:company:title:title:lens:lens:a:b:h:table:h:tr:h:td:h:td:'
``` ```
...@@ -341,7 +446,7 @@ let strXml = ...@@ -341,7 +446,7 @@ let strXml =
let arrayBuffer = new ArrayBuffer(strXml.length); let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer); let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length; let strLen = strXml.length;
for (var tmp = 0; tmp < strLen; ++tmp) { for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp); bufView[tmp] = strXml.charCodeAt(tmp);
} }
let that = new xml.XmlPullParser(arrayBuffer); let that = new xml.XmlPullParser(arrayBuffer);
...@@ -399,6 +504,38 @@ Obtains the column line number, starting from 1. ...@@ -399,6 +504,38 @@ Obtains the column line number, starting from 1.
| ------ | -------------- | | ------ | -------------- |
| number | Column number obtained.| | number | Column number obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getColumnNumber();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:1key:2 value:77key:10 value:81key:2 value:88key:4 value:93key:3 value:101key:10 value:105key:2 value:111key:4 value:115key:3 value:122key:10 value:126key:2 value:132key:4 value:136key:3 value:143key:3 value:150key:1 value:299
```
### getDepth ### getDepth
...@@ -414,6 +551,41 @@ Obtains the depth of this element. ...@@ -414,6 +551,41 @@ Obtains the depth of this element.
| ------ | -------------------- | | ------ | -------------------- |
| number | Depth obtained.| | number | Depth obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getDepth();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:0key:2 value:1key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:3 value:1key:1 value:0
// Note:
// key indicates the event type, and value indicates the parsing depth. You can learn the specific parsed event based on EVENTTYPE. In this example, key: value means:
// 0(START_DOCUMENT):0 (START_DOCUMENT is being parsed, and the depth is 0), 2(START_TAG):1 (START_TAG is being parsed, and the depth is 1), 10(WHITESPACE):1 (WHITESPACE is being parsed, and the depth is 1), 2(START_TAG):2 (START_TAG is being parsed, and the depth is 2), ...
```
### getLineNumber ### getLineNumber
...@@ -429,6 +601,38 @@ Obtains the current line number, starting from 1. ...@@ -429,6 +601,38 @@ Obtains the current line number, starting from 1.
| ------ | -------------- | | ------ | -------------- |
| number | Line number obtained.| | number | Line number obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getLineNumber();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:1key:2 value:1key:10 value:1key:2 value:1key:4 value:1key:3 value:1key:10 value:1key:2 value:1key:4 value:1key:3 value:1key:10 value:1key:2 value:1key:4 value:1key:3 value:1key:3 value:1key:1 value:1
```
### getName ### getName
...@@ -444,7 +648,38 @@ Obtains the name of this element. ...@@ -444,7 +648,38 @@ Obtains the name of this element.
| ------ | ------------------ | | ------ | ------------------ |
| string | Element name obtained.| | string | Element name obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getName();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:key:2 value:notekey:10 value:key:2 value:titlekey:4 value:key:3 value:titlekey:10 value:key:2 value:todokey:4 value:key:3 value:todokey:10 value:key:2 value:todokey:4 value:key:3 value:todokey:3 value:notekey:1 value:
```
### getNamespace ### getNamespace
getNamespace(): string getNamespace(): string
...@@ -459,7 +694,38 @@ Obtains the namespace of this element. ...@@ -459,7 +694,38 @@ Obtains the namespace of this element.
| ------ | ------------------------ | | ------ | ------------------------ |
| string | Namespace obtained.| | string | Namespace obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getNamespace();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:key:2 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:3 value:key:1 value:
```
### getPrefix ### getPrefix
getPrefix(): string getPrefix(): string
...@@ -474,6 +740,38 @@ Obtains the prefix of this element. ...@@ -474,6 +740,38 @@ Obtains the prefix of this element.
| ------ | ------------------ | | ------ | ------------------ |
| string | Element prefix obtained.| | string | Element prefix obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getPrefix();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:key:2 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:3 value:key:1 value:
```
### getText ### getText
...@@ -489,7 +787,38 @@ Obtains the text of the current event. ...@@ -489,7 +787,38 @@ Obtains the text of the current event.
| ------ | ------------------------ | | ------ | ------------------------ |
| string | Text content obtained.| | string | Text content obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getText();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:key:2 value:key:10 value: key:2 value:key:4 value:Happykey:3 value:key:10 value: key:2 value:key:4 value:Workkey:3 value:key:10 value: key:2 value:key:4 value:Playkey:3 value:key:3 value:key:1 value:
```
### isEmptyElementTag ### isEmptyElementTag
isEmptyElementTag(): boolean isEmptyElementTag(): boolean
...@@ -504,7 +833,38 @@ Checks whether the current element is empty. ...@@ -504,7 +833,38 @@ Checks whether the current element is empty.
| ------- | ---------------------------- | | ------- | ---------------------------- |
| boolean | Returns **true** if the element is empty; returns **false** otherwise.| | boolean | Returns **true** if the element is empty; returns **false** otherwise.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.isEmptyElementTag();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:falsekey:2 value:falsekey:10 value:falsekey:2 value:falsekey:4 value:falsekey:3 value:falsekey:10 value:falsekey:2 value:falsekey:4 value:falsekey:3 value:falsekey:10 value:falsekey:2 value:falsekey:4 value:falsekey:3 value:falsekey:3 value:falsekey:1 value:false
```
### isWhitespace ### isWhitespace
isWhitespace(): boolean isWhitespace(): boolean
...@@ -519,7 +879,38 @@ Checks whether the current text event contains only whitespace characters. ...@@ -519,7 +879,38 @@ Checks whether the current text event contains only whitespace characters.
| ------- | -------------------------------------- | | ------- | -------------------------------------- |
| boolean | Returns **true** if the text event contains only whitespace characters; returns **false** otherwise.| | boolean | Returns **true** if the text event contains only whitespace characters; returns **false** otherwise.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.isWhitespace();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:truekey:2 value:falsekey:10 value:truekey:2 value:truekey:4 value:falsekey:3 value:truekey:10 value:truekey:2 value:truekey:4 value:falsekey:3 value:truekey:10 value:truekey:2 value:truekey:4 value:falsekey:3 value:truekey:3 value:truekey:1 value:true
```
### getAttributeCount ### getAttributeCount
getAttributeCount(): number getAttributeCount(): number
...@@ -533,6 +924,38 @@ Obtains the number of attributes for the current start tag. ...@@ -533,6 +924,38 @@ Obtains the number of attributes for the current start tag.
| ------ | ---------------------- | | ------ | ---------------------- |
| number | Number of attributes obtained.| | number | Number of attributes obtained.|
**Example**
```js
let strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let arrayBuffer = new ArrayBuffer(strXml.length);
let bufView = new Uint8Array(arrayBuffer);
let strLen = strXml.length;
for (let tmp = 0; tmp < strLen; ++tmp) {
bufView[tmp] = strXml.charCodeAt(tmp);
}
let that = new xml.XmlPullParser(arrayBuffer);
let arrTag = {};
let str = "";
let i = 0;
function func(key, value){
arrTag[i] = 'key:'+key+' value:'+ value.getAttributeCount();
str += arrTag[i];
i++;
return true; // Determines whether to continuely parse, which is used to continue or terminate parsing.
}
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options);
console.log(str);
// Output:
// key:0 value:0key:2 value:2key:10 value:0key:2 value:0key:4 value:0key:3 value:0key:10 value:0key:2 value:0key:4 value:0key:3 value:0key:10 value:0key:2 value:0key:4 value:0key:3 value:0key:3 value:0key:1 value:0
```
## EventType ## EventType
......
# @ohos.zlib # @ohos.zlib (Zip)
The **zlib** module provides APIs for file compression and decompression. The **Zip** module provides APIs for file compression and decompression.
> **NOTE** > **NOTE**
> >
...@@ -25,7 +25,7 @@ Zips a file. This API uses a promise to return the result. ...@@ -25,7 +25,7 @@ Zips a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ | | ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to zip. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).| | inFile | string | Yes | Path of the folder or file to zip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the zipped file. The file name extension is .zip. | | outFile | string | Yes | Path of the zipped file. The file name extension is .zip. |
| options | [Options](#options) | Yes | Optional parameters for the zip operation. | | options | [Options](#options) | Yes | Optional parameters for the zip operation. |
...@@ -39,6 +39,7 @@ Zips a file. This API uses a promise to return the result. ...@@ -39,6 +39,7 @@ Zips a file. This API uses a promise to return the result.
```typescript ```typescript
// Zip a file. // Zip a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib'; import zlib from '@ohos.zlib';
let inFile = '/xxx/filename.xxx'; let inFile = '/xxx/filename.xxx';
let outFile = '/xxx/xxx.zip'; let outFile = '/xxx/xxx.zip';
...@@ -59,6 +60,7 @@ zlib.zipFile(inFile, outFile, options).then((data) => { ...@@ -59,6 +60,7 @@ zlib.zipFile(inFile, outFile, options).then((data) => {
```typescript ```typescript
// Zip a folder. // Zip a folder.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib'; import zlib from '@ohos.zlib';
let inFile = '/xxx/xxx'; let inFile = '/xxx/xxx';
let outFile = '/xxx/xxx.zip'; let outFile = '/xxx/xxx.zip';
...@@ -89,7 +91,7 @@ Unzips a file. This API uses a promise to return the result. ...@@ -89,7 +91,7 @@ Unzips a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ | | ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to unzip. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).| | inFile | string | Yes | Path of the file to unzip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the unzipped file. | | outFile | string | Yes | Path of the unzipped file. |
| options | [Options](#options) | Yes | Optional parameters for the unzip operation. | | options | [Options](#options) | Yes | Optional parameters for the unzip operation. |
...@@ -103,6 +105,7 @@ Unzips a file. This API uses a promise to return the result. ...@@ -103,6 +105,7 @@ Unzips a file. This API uses a promise to return the result.
```typescript ```typescript
// Unzip a file. // Unzip a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib'; import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip'; let inFile = '/xx/xxx.zip';
let outFile = '/xxx'; let outFile = '/xxx';
...@@ -131,7 +134,7 @@ Compresses a file. This API uses an asynchronous callback to return the result. ...@@ -131,7 +134,7 @@ Compresses a file. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ | | ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to compress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).| | inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the compressed file. | | outFile | string | Yes | Path of the compressed file. |
| options | [Options](#options) | Yes | Compression parameters. | | options | [Options](#options) | Yes | Compression parameters. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. | | AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
...@@ -141,14 +144,14 @@ Compresses a file. This API uses an asynchronous callback to return the result. ...@@ -141,14 +144,14 @@ Compresses a file. This API uses an asynchronous callback to return the result.
For details about the error codes, see [zlib Error Codes](../errorcodes/errorcode-zlib.md). For details about the error codes, see [zlib Error Codes](../errorcodes/errorcode-zlib.md).
| ID| Error Message | | ID| Error Message |
| -------- | --------------------------------------| | -------- | --------------------------------------|
| 900001 | The Input source file is invalid. | | 900001 | The input source file is invalid. |
| 900002 | The Input destination file is invalid. | | 900002 | The input destination file is invalid. |
**Example** **Example**
```typescript ```typescript
// Compress a file. // Compress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context. // The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib'; import zlib from '@ohos.zlib';
let inFile = '/xxx/filename.xxx'; let inFile = '/xxx/filename.xxx';
let outFile = '/xxx/xxx.zip'; let outFile = '/xxx/xxx.zip';
...@@ -179,7 +182,7 @@ Compresses a file. This API uses a promise to return the result. ...@@ -179,7 +182,7 @@ Compresses a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ | | ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to compress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).| | inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the compressed file. | | outFile | string | Yes | Path of the compressed file. |
| options | [Options](#options) | Yes | Compression parameters. | | options | [Options](#options) | Yes | Compression parameters. |
...@@ -189,12 +192,12 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod ...@@ -189,12 +192,12 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------------------- | | -------- | ------------------------------------- |
| 900001 | The Input source file is invalid. | | 900001 | The input source file is invalid. |
| 900002 | The Input destination file is invalid. | | 900002 | The input destination file is invalid. |
```typescript ```typescript
// Compress a file. // Compress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context. // The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib'; import zlib from '@ohos.zlib';
let inFile = '/xxx/filename.xxx'; let inFile = '/xxx/filename.xxx';
let outFile = '/xxx/xxx.zip'; let outFile = '/xxx/xxx.zip';
...@@ -229,7 +232,7 @@ Decompresses a file. This API uses an asynchronous callback to return the result ...@@ -229,7 +232,7 @@ Decompresses a file. This API uses an asynchronous callback to return the result
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ | | ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to decompress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).| | inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. | | outFile | string | Yes | Path of the decompressed file. |
| options | [Options](#options) | Yes | Decompression parameters. | | options | [Options](#options) | Yes | Decompression parameters. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. | | AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
...@@ -240,14 +243,14 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod ...@@ -240,14 +243,14 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
| ID| Error Message | ID| Error Message
| -------- | --------------------------------------| | -------- | --------------------------------------|
| 900001 | The Input source file is invalid. | | 900001 | The input source file is invalid. |
| 900002 | The Input destination file is invalid. | | 900002 | The input destination file is invalid. |
**Example** **Example**
```typescript ```typescript
// Decompress a file. // Decompress a file.
// The path used in the code must be the application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context. // The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib'; import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip'; let inFile = '/xx/xxx.zip';
let outFile = '/xxx'; let outFile = '/xxx';
...@@ -270,7 +273,7 @@ try { ...@@ -270,7 +273,7 @@ try {
decompressFile(inFile: string, outFile: string, options: Options): Promise\<void>; decompressFile(inFile: string, outFile: string, options: Options): Promise\<void>;
Decompress a file. This API uses a promise to return the result. Decompresses a file. This API uses a promise to return the result.
**System capability**: SystemCapability.BundleManager.Zlib **System capability**: SystemCapability.BundleManager.Zlib
...@@ -278,7 +281,7 @@ Decompress a file. This API uses a promise to return the result. ...@@ -278,7 +281,7 @@ Decompress a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ | | ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to decompress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).| | inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. | | outFile | string | Yes | Path of the decompressed file. |
| options | [Options](#options) | Yes | Decompression parameters. | | options | [Options](#options) | Yes | Decompression parameters. |
...@@ -288,12 +291,12 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod ...@@ -288,12 +291,12 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
| ID| Error Message | | ID| Error Message |
| ------ | ------------------------------------- | | ------ | ------------------------------------- |
| 900001 | The Input source file is invalid. | | 900001 | The input source file is invalid. |
| 900002 | The Input destination file is invalid. | | 900002 | The input destination file is invalid. |
```typescript ```typescript
// Decompress a file. // Decompress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context. // The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib'; import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip'; let inFile = '/xx/xxx.zip';
let outFile = '/xxx'; let outFile = '/xxx';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册