提交 c4847dd0 编写于 作者: G Gloria

Update docs against 10952+11279+10936

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 4223d843
...@@ -15,8 +15,54 @@ import convertxml from '@ohos.convertxml'; ...@@ -15,8 +15,54 @@ import convertxml from '@ohos.convertxml';
## ConvertXML ## ConvertXML
### convertToJSObject<sup>9+</sup>
### convert convertToJSObject(xml: string, options?: ConvertOptions) : Object
Converts an XML text into a JavaScript object.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | --------------------------------- | ---- | --------------- |
| xml | string | Yes | XML text to convert.|
| options | [ConvertOptions](#convertoptions) | No | Options for conversion. |
**Return value**
| Type | Description |
| ------ | ---------------------------- |
| Object | JavaScript object.|
**Example**
```js
let xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let conv = new convertxml.convertToJSObject();
let options = {trim : false, declarationKey:"_declaration",
instructionKey : "_instruction", attributesKey : "_attributes",
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
nameKey : "_name", elementsKey : "_elements"}
let result = JSON.stringify(conv.convert(xml, options));
console.log(result);
// Output (non-compact)
// {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note","_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title","_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Play"}]}]}]}
```
### convert<sup>(deprecated)</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [convertToJSObject9+](#converttojsobject9) instead.
convert(xml: string, options?: ConvertOptions) : Object convert(xml: string, options?: ConvertOptions) : Object
...@@ -24,7 +70,6 @@ Converts an XML text into a JavaScript object. ...@@ -24,7 +70,6 @@ Converts an XML text into a JavaScript object.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
......
...@@ -4,7 +4,7 @@ The **EffectKit** module provides basic image processing capabilities, including ...@@ -4,7 +4,7 @@ The **EffectKit** module provides basic image processing capabilities, including
This module provides the following classes: This module provides the following classes:
- [Filter](#filter): a class that provides the effect chain, which is a linked list of image processing effects. - [Filter](#filter): a class that adds a specified effect to the image source.
- [Color](#color): a class used to store the color picked. - [Color](#color): a class used to store the color picked.
- [ColorPicker](#colorpicker): a smart color picker. - [ColorPicker](#colorpicker): a smart color picker.
...@@ -43,7 +43,6 @@ Creates a **Filter** instance based on the pixel map. ...@@ -43,7 +43,6 @@ Creates a **Filter** instance based on the pixel map.
import image from "@ohos.multimedia.image"; import image from "@ohos.multimedia.image";
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelMap) => { image.createPixelMap(color, opts).then((pixelMap) => {
let headFilter = effectKit.createEffect(pixelMap); let headFilter = effectKit.createEffect(pixelMap);
...@@ -76,7 +75,6 @@ Creates a **ColorPicker** instance based on the pixel map. This API uses a promi ...@@ -76,7 +75,6 @@ Creates a **ColorPicker** instance based on the pixel map. This API uses a promi
import image from "@ohos.multimedia.image"; import image from "@ohos.multimedia.image";
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelMap) => { image.createPixelMap(color, opts).then((pixelMap) => {
effectKit.createColorPicker(pixelMap).then(colorPicker => { effectKit.createColorPicker(pixelMap).then(colorPicker => {
...@@ -106,7 +104,6 @@ Creates a **ColorPicker** instance based on the pixel map. This API uses an asyn ...@@ -106,7 +104,6 @@ Creates a **ColorPicker** instance based on the pixel map. This API uses an asyn
import image from "@ohos.multimedia.image"; import image from "@ohos.multimedia.image";
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelMap) => { image.createPixelMap(color, opts).then((pixelMap) => {
effectKit.createColorPicker(pixelMap, (error, colorPicker) => { effectKit.createColorPicker(pixelMap, (error, colorPicker) => {
...@@ -181,6 +178,7 @@ Obtains the main color of the image and writes the result to a **[Color](#color) ...@@ -181,6 +178,7 @@ Obtains the main color of the image and writes the result to a **[Color](#color)
let color = colorPicker.getMainColorSync(); let color = colorPicker.getMainColorSync();
console.log('get main color =' + color); console.log('get main color =' + color);
``` ```
![en-us_image_Main_Color.png](figures/en-us_image_Main_Color.png)
## Filter ## Filter
...@@ -204,7 +202,7 @@ Adds the blur effect to the filter linked list, and returns the head node of the ...@@ -204,7 +202,7 @@ Adds the blur effect to the filter linked list, and returns the head node of the
| Type | Description | | Type | Description |
| :------------- | :---------------------------------------------- | | :------------- | :---------------------------------------------- |
| [Filter](#filter) | Head node of the filter linked list.| | [Filter](#filter) | Final image effect.|
**Example** **Example**
...@@ -221,6 +219,7 @@ image.createPixelMap(color, opts).then((pixelMap) => { ...@@ -221,6 +219,7 @@ image.createPixelMap(color, opts).then((pixelMap) => {
} }
}) })
``` ```
![en-us_image_Add_Blur.png](figures/en-us_image_Add_Blur.png)
### brightness ### brightness
...@@ -240,7 +239,7 @@ Adds the brightness effect to the filter linked list, and returns the head node ...@@ -240,7 +239,7 @@ Adds the brightness effect to the filter linked list, and returns the head node
| Type | Description | | Type | Description |
| :------------- | :---------------------------------------------- | | :------------- | :---------------------------------------------- |
| [Filter](#filter) | Head node of the filter linked list.| | [Filter](#filter) | Final image effect.|
**Example** **Example**
...@@ -257,6 +256,7 @@ image.createPixelMap(color, opts).then((pixelMap) => { ...@@ -257,6 +256,7 @@ image.createPixelMap(color, opts).then((pixelMap) => {
} }
}) })
``` ```
![en-us_image_Add_Brightness.png](figures/en-us_image_Add_Brightness.png)
### grayscale ### grayscale
...@@ -270,7 +270,7 @@ Adds the grayscale effect to the filter linked list, and returns the head node o ...@@ -270,7 +270,7 @@ Adds the grayscale effect to the filter linked list, and returns the head node o
| Type | Description | | Type | Description |
| :------------- | :---------------------------------------------- | | :------------- | :---------------------------------------------- |
| [Filter](#filter) | Head node of the filter linked list.| | [Filter](#filter) | Final image effect.|
**Example** **Example**
...@@ -286,10 +286,11 @@ image.createPixelMap(color, opts).then((pixelMap) => { ...@@ -286,10 +286,11 @@ image.createPixelMap(color, opts).then((pixelMap) => {
} }
}) })
``` ```
![en-us_image_Add_Grayscale.png](figures/en-us_image_Add_Grayscale.png)
### getPixelMap ### getPixelMap
getPixelMap(): image.PixelMap getPixelMap(): [image.PixelMap](js-apis-image.md#pixelmap7)
Obtains **image.PixelMap** of the source image to which the filter linked list is added. Obtains **image.PixelMap** of the source image to which the filter linked list is added.
......
...@@ -77,7 +77,10 @@ result.toString() ...@@ -77,7 +77,10 @@ result.toString()
``` ```
### equals ### equals<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [equalsTo<sup>9+</sup>](#equalsto9) instead.
equals(other: URI): boolean equals(other: URI): boolean
...@@ -104,6 +107,33 @@ const uriInstance = new uri.URI('http://username:password@host:8080/directory/fi ...@@ -104,6 +107,33 @@ const uriInstance = new uri.URI('http://username:password@host:8080/directory/fi
const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment'); const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment');
uriInstance.equals(uriInstance1); uriInstance.equals(uriInstance1);
``` ```
### equalsTo<sup>9+</sup>
equalsTo(other: URI): boolean
Checks whether this URI is the same as another URI object.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type.| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| other | [URI](#uri) | Yes| URI object to compare.|
**Return value**
| Type.| Description|
| -------- | -------- |
| boolean | Returns **true** if the two URIs are the same; returns **false** otherwise.|
**Example**
```js
const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment');
uriInstance.equalsTo(uriInstance1);
```
### checkIsAbsolute ### checkIsAbsolute
......
...@@ -4,21 +4,379 @@ ...@@ -4,21 +4,379 @@
> >
> 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.
## Modules to Import ## Modules to Import
``` ```
import Url from '@ohos.url' import Url from '@ohos.url'
``` ```
## URLParams<sup>9+</sup>
## URLSearchParams
### constructor<sup>9+</sup>
### constructor constructor(init?: string[][] | Record&lt;string, string&gt; | string | URLParams)
A constructor used to create a **URLParams** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| init | string[][] \| Record&lt;string, string&gt; \| string \| URLParams | No| Input parameter objects, which include the following:<br>- **string[][]**: two-dimensional string array<br>- **Record&lt;string, string&gt;**: list of objects<br>- **string**: string<br>- **URLParams**: object|
**Example**
```js
let objectParams = new Url.URLParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
let objectParams1 = 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 params = new Url.URLParams(urlObject.search);
```
### append<sup>9+</sup>
append(name: string, value: string): void
Appends a key-value pair into the query string.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key of the key-value pair to append.|
| value | string | Yes| Value of the key-value pair to append.|
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.append('fod', '3');
```
### delete<sup>9+</sup>
delete(name: string): void
Deletes key-value pairs of the specified key.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key of the key-value pairs to delete.|
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsobject = new Url.URLParams(urlObject.search.slice(1));
paramsobject.delete('fod');
```
### getAll<sup>9+</sup>
getAll(name: string): string[]
Obtains all the key-value pairs based on the specified key.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key specified to obtain all key-value pairs.|
**Return value**
| Type| Description|
| -------- | -------- |
| string[] | All key-value pairs matching the specified key.|
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(urlObject.search.slice(1));
params.append('fod', '3'); // Add a second value for the fod parameter.
console.log(params.getAll('fod').toString()) // Output ["1","3"].
```
### entries<sup>9+</sup>
entries(): IterableIterator<[string, string]>
Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;[string, string]&gt; | ES6 iterator.|
**Example**
```js
let searchParamsObject = new Url.URLParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]);
}
```
### forEach<sup>9+</sup>
forEach(callbackfn: (value: string, key: string, searchParams: this) => void, thisArg?: Object): void
Traverses the key-value pairs in the **URLSearchParams** instance by using a callback.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackfn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.|
| thisArg | Object | No| Value to use when the callback is invoked.|
**Table 1** callbackfn parameter description
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string | Yes| Value that is currently traversed.|
| key | string | Yes| Key that is currently traversed.|
| searchParams | Object | Yes| Instance that invokes the **forEach** method.|
**Example**
```js
const myURLObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.URLParams.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.searchParams === searchParams);
});
```
### get<sup>9+</sup>
get(name: string): string | null
Obtains the value of the first key-value pair based on the specified key.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key specified to obtain the value.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Returns the value of the first key-value pair if obtained.|
| null | Returns **null** if no value is obtained.|
**Example**
```js
let paramsObject = new Url.URLParams('name=Jonathan&age=18');
let name = paramsObject.get("name"); // is the string "Jonathan"
let age = parseInt(paramsObject.get("age"), 10); // is the number 18
```
### has<sup>9+</sup>
has(name: string): boolean
Checks whether a key has a value.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key specified to search for its value.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value exists; returns **false** otherwise.|
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.has('bard') === true;
```
### set<sup>9+</sup>
set(name: string, value: string): void
Sets the value for a key. If key-value pairs matching the specified key exist, the value of the first key-value pair will be set to the specified value and other key-value pairs will be deleted. Otherwise, the key-value pair will be appended to the query string.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Key of the value to set.|
| value | string | Yes| Value to set.|
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.set('baz', '3'); // Add a third parameter.
```
### sort<sup>9+</sup>
sort(): void
Sorts all key-value pairs contained in this object based on the Unicode code points of the keys and returns undefined. This method uses a stable sorting algorithm, that is, the relative order between key-value pairs with equal keys is retained.
**System capability**: SystemCapability.Utils.Lang
**Example**
```js
let searchParamsObject = new Url.URLParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object
searchParamsObject.sort(); // Sort the key/value pairs
console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4
```
### keys<sup>9+</sup>
keys(): IterableIterator&lt;string&gt;
Obtains an ES6 iterator that contains the keys of all the key-value pairs.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;string&gt; | ES6 iterator that contains the keys of all the key-value pairs.|
**Example**
```js
let searchParamsObject = new Url.URLParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var key of searchParamsObject .keys()) { // Output key-value pairs
console.log(key);
}
```
### values<sup>9+</sup>
values(): IterableIterator&lt;string&gt;
Obtains an ES6 iterator that contains the values of all the key-value pairs.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;string&gt; | ES6 iterator that contains the values of all the key-value pairs.|
**Example**
```js
let searchParams = new Url.URLParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var value of searchParams.values()) {
console.log(value);
}
```
### [Symbol.iterator]<sup>9+</sup>
[Symbol.iterator]\(): IterableIterator&lt;[string, string]&gt;
Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;[string, string]&gt; | ES6 iterator.|
**Example**
```js
const paramsObject = new Url.URLParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject) {
console.log(name, value);
}
```
### tostring<sup>9+</sup>
toString(): string
Obtains search parameters that are serialized as a string and, if necessary, percent-encodes the characters in the string.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| string | String of serialized search parameters, which is percent-encoded if necessary.|
**Example**
```js
let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(url.search.slice(1));
params.append('fod', '3');
console.log(params.toString());
```
## URLSearchParams<sup>(deprecated)</sup>
### constructor<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>](#constructor9+) instead.
constructor(init?: string[][] | Record&lt;string, string&gt; | string | URLSearchParams) constructor(init?: string[][] | Record&lt;string, string&gt; | string | URLSearchParams)
Creates a **URLSearchParams** instance. A constructor used to create a **URLSearchParams** instance.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -38,8 +396,11 @@ let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); ...@@ -38,8 +396,11 @@ let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2');
let params = new Url.URLSearchParams(urlObject.search); let params = new Url.URLSearchParams(urlObject.search);
``` ```
### append<sup>(deprecated)</sup>
### append > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.append<sup>9+</sup>](#append9) instead.
append(name: string, value: string): void append(name: string, value: string): void
...@@ -62,8 +423,11 @@ let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); ...@@ -62,8 +423,11 @@ let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', '3'); paramsObject.append('fod', '3');
``` ```
### delete<sup>(deprecated)</sup>
### delete > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.delete<sup>9+</sup>](#delete9) instead.
delete(name: string): void delete(name: string): void
...@@ -85,8 +449,11 @@ let paramsobject = new Url.URLSearchParams(urlObject.search.slice(1)); ...@@ -85,8 +449,11 @@ let paramsobject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsobject.delete('fod'); paramsobject.delete('fod');
``` ```
### getAll<sup>(deprecated)</sup>
### getAll > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.getAll<sup>9+</sup>](#getall9) instead.
getAll(name: string): string[] getAll(name: string): string[]
...@@ -115,8 +482,11 @@ params.append('fod', '3'); // Add a second value for the fod parameter. ...@@ -115,8 +482,11 @@ 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"].
``` ```
### entries<sup>(deprecated)</sup>
### entries > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.entries<sup>9+</sup>](#entries9) instead.
entries(): IterableIterator<[string, string]> entries(): IterableIterator<[string, string]>
...@@ -140,7 +510,10 @@ for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pair ...@@ -140,7 +510,10 @@ for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pair
``` ```
### forEach ### forEach<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.forEach<sup>9+</sup>](#foreach9) instead.
forEach(callbackfn: (value: string, key: string, searchParams: this) => void, thisArg?: Object): void forEach(callbackfn: (value: string, key: string, searchParams: this) => void, thisArg?: Object): void
...@@ -173,7 +546,10 @@ myURLObject.searchParams.forEach((value, name, searchParams) => { ...@@ -173,7 +546,10 @@ myURLObject.searchParams.forEach((value, name, searchParams) => {
``` ```
### get ### get<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.get<sup>9+</sup>](#get9) instead.
get(name: string): string | null get(name: string): string | null
...@@ -203,7 +579,10 @@ let age = parseInt(paramsObject.get("age"), 10); // is the number 18 ...@@ -203,7 +579,10 @@ let age = parseInt(paramsObject.get("age"), 10); // is the number 18
``` ```
### has ### has<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.has<sup>9+</sup>](#has9) instead.
has(name: string): boolean has(name: string): boolean
...@@ -232,7 +611,10 @@ paramsObject.has('bard') === true; ...@@ -232,7 +611,10 @@ paramsObject.has('bard') === true;
``` ```
### set ### set<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.set<sup>9+</sup>](#set9) instead.
set(name: string, value: string): void set(name: string, value: string): void
...@@ -256,7 +638,10 @@ paramsObject.set('baz', '3'); // Add a third parameter. ...@@ -256,7 +638,10 @@ paramsObject.set('baz', '3'); // Add a third parameter.
``` ```
### sort ### sort<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.sort<sup>9+</sup>](#sort9) instead.
sort(): void sort(): void
...@@ -273,7 +658,10 @@ console.log(searchParamsObject.toString()); // Display the sorted query string / ...@@ -273,7 +658,10 @@ console.log(searchParamsObject.toString()); // Display the sorted query string /
``` ```
### keys ### keys<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.keys<sup>9+</sup>](#keys9) instead.
keys(): IterableIterator&lt;string&gt; keys(): IterableIterator&lt;string&gt;
...@@ -297,7 +685,10 @@ for (var key of searchParamsObject .keys()) { // Output key-value pairs ...@@ -297,7 +685,10 @@ for (var key of searchParamsObject .keys()) { // Output key-value pairs
``` ```
### values ### values<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.values<sup>9+</sup>](#values9) instead.
values(): IterableIterator&lt;string&gt; values(): IterableIterator&lt;string&gt;
...@@ -321,7 +712,10 @@ for (var value of searchParams.values()) { ...@@ -321,7 +712,10 @@ for (var value of searchParams.values()) {
``` ```
### [Symbol.iterator] ### [Symbol.iterator]<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.[Symbol.iterator]<sup>9+</sup>](#symbol.iterator9) instead.
[Symbol.iterator]\(): IterableIterator&lt;[string, string]&gt; [Symbol.iterator]\(): IterableIterator&lt;[string, string]&gt;
...@@ -344,8 +738,10 @@ for (const [name, value] of paramsObject) { ...@@ -344,8 +738,10 @@ for (const [name, value] of paramsObject) {
} }
``` ```
### tostring<sup>(deprecated)</sup>
### tostring > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [URLParams<sup>9+</sup>.tostring<sup>9+</sup>](#tostring9) instead.
toString(): string toString(): string
...@@ -368,7 +764,6 @@ params.append('fod', '3'); ...@@ -368,7 +764,6 @@ params.append('fod', '3');
console.log(params.toString()); console.log(params.toString());
``` ```
## URL ## URL
### Attributes ### Attributes
...@@ -388,12 +783,13 @@ console.log(params.toString()); ...@@ -388,12 +783,13 @@ console.log(params.toString());
| 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 | 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.| | username | string | Yes| Yes| Username in a URL.|
### constructor ### constructor
constructor(url: string, base?: string | URL) constructor(url?: string, base?: string | URL)
Creates a URL. Creates a URL.
...@@ -423,6 +819,27 @@ new Url.URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ ...@@ -423,6 +819,27 @@ new Url.URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/
new Url.URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ new Url.URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/
``` ```
### parseURL<sup>9+</sup>
static parseURL(inputUrl : string, inputBase ?: string | URL)
Parses a URL.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| inputUrl | string | Yes| Input object.|
| inputBase | string \| URL | No| Input parameter, which can be any of the following:<br>- **string**: string<br>- **URL**: string or object|
**Example**
```js
let mm = 'http://username:password@host:8080';
Url.URL.parseURL(mm); // Output 'http://username:password@host:8080/';
```
### tostring ### tostring
...@@ -465,3 +882,4 @@ Converts the parsed URL into a JSON string. ...@@ -465,3 +882,4 @@ Converts the parsed URL into a JSON string.
const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON(); url.toJSON();
``` ```
<!--no_check-->
...@@ -15,11 +15,43 @@ This module provides common utility functions, such as **TextEncoder** and **Tex ...@@ -15,11 +15,43 @@ This module provides common utility functions, such as **TextEncoder** and **Tex
import util from '@ohos.util'; import util from '@ohos.util';
``` ```
## util.printf ## util.format<sup>9+</sup>
format(format: string, ...args: Object[]): string
Formats the specified values and inserts them into the string by replacing the wildcard in the string.
**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.format("%s", "hello world!");
console.log(res);
```
## util.printf<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [util.format9+](#utilformat9) instead.
printf(format: string, ...args: Object[]): string printf(format: string, ...args: Object[]): string
Prints the input content in a formatted string. Formats the specified values and inserts them into the string by replacing the wildcard in the string.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -27,14 +59,14 @@ Prints the input content in a formatted string. ...@@ -27,14 +59,14 @@ Prints the input content in a formatted string.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| format | string | Yes| Format of the string to print.| | format | string | Yes| String.|
| ...args | Object[] | No| Data to format.| | ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string. |
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String in the specified format.| | string | String containing the formatted values.|
**Example** **Example**
```js ```js
...@@ -42,8 +74,39 @@ Prints the input content in a formatted string. ...@@ -42,8 +74,39 @@ Prints the input content in a formatted string.
console.log(res); console.log(res);
``` ```
## util.errnoToString<sup>9+</sup>
errnoToString(errno: number): string
Obtains detailed information about a system error code.
**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.errnoToString(errnum);
console.log("result = " + result);
```
## util.getErrorString<sup>(deprecated)</sup>
## util.getErrorString > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [util.errnoToString9+](#utilerrnotostring9) instead.
getErrorString(errno: number): string getErrorString(errno: number): string
...@@ -70,12 +133,11 @@ Obtains detailed information about a system error code. ...@@ -70,12 +133,11 @@ Obtains detailed information about a system error code.
console.log("result = " + result); 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
Wraps an asynchronous function (or a function that returns a promise) into an error-first callback, which means that **(err, value) => ...** is used as the last parameter of the callback. In the callback, the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved), and the second parameter indicates the resolved value. Calls back an asynchronous function. In the callback, the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved), and the second parameter indicates the resolved value.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
...@@ -104,31 +166,6 @@ Wraps an asynchronous function (or a function that returns a promise) into an er ...@@ -104,31 +166,6 @@ Wraps an asynchronous function (or a function that returns a promise) into an er
}, err) }, err)
``` ```
## util.promiseWrapper<sup>(deprecated)</sup>
promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use **[util.promisify9+](#utilpromisify9)** instead.
Wraps a function that follows the error-first callback paradigm into a promise.
**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.promisify<sup>9+</sup> ## util.promisify<sup>9+</sup>
promisify(original: (err: Object, value: Object) =&gt; void): Function promisify(original: (err: Object, value: Object) =&gt; void): Function
...@@ -164,6 +201,30 @@ Processes an asynchronous function and returns a promise. ...@@ -164,6 +201,30 @@ Processes an asynchronous function and returns a promise.
}) })
``` ```
## util.promiseWrapper<sup>(deprecated)</sup>
promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use **[util.promisify9+](#utilpromisify9)** instead.
Processes an asynchronous function and returns a promise.
**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
...@@ -260,8 +321,46 @@ Parses a UUID from a string, as described in RFC 4122 version 4. ...@@ -260,8 +321,46 @@ Parses a UUID from a string, as described in RFC 4122 version 4.
| fatal | boolean | Yes| No| Whether to display fatal errors.| | fatal | boolean | Yes| No| Whether to display fatal errors.|
| ignoreBOM | boolean | Yes| No| Whether to ignore the byte order marker (BOM). The default value is **false**, which indicates that the result contains the BOM.| | ignoreBOM | boolean | Yes| No| Whether to ignore the byte order marker (BOM). The default value is **false**, which indicates that the result contains the BOM.|
### constructor<sup>9+</sup>
### constructor constructor()
A constructor used to create a **TextDecoder** object.
**System capability**: SystemCapability.Utils.Lang
### create<sup>9+</sup>
create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean },): TextDecoder;
Creates a **TextDecoder** object. It provides the same function as the deprecated argument constructor.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------ |
| encoding | string | No | Encoding format. |
| options | Object | No | Encoding-related options, which include **fatal** and **ignoreBOM**.|
**Table 1.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()
textDecoder.create('utf-8', { ignoreBOM : true });
```
### constructor<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },) constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
...@@ -288,7 +387,6 @@ A constructor used to create a **TextDecoder** object. ...@@ -288,7 +387,6 @@ A constructor used to create a **TextDecoder** object.
let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
``` ```
### decode ### decode
decode(input: Uint8Array, options?: { stream?: false }): string decode(input: Uint8Array, options?: { stream?: false }): string
...@@ -399,8 +497,40 @@ A constructor used to create a **TextEncoder** object. ...@@ -399,8 +497,40 @@ A constructor used to create a **TextEncoder** object.
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
``` ```
### encodeInto<sup>9+</sup>
encodeInto(input?: string): Uint8Array
Encodes the input content.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| input | string | Yes | 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.encodeInto("\uD800¥¥");
```
### encode<sup>(deprecated)</sup>
### encode > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeInto9+](#encodeinto9) instead.
encode(input?: string): Uint8Array encode(input?: string): Uint8Array
...@@ -428,8 +558,42 @@ Encodes the input content. ...@@ -428,8 +558,42 @@ Encodes the input content.
result = textEncoder.encode("\uD800¥¥"); result = textEncoder.encode("\uD800¥¥");
``` ```
### encodeIntoUint8Array<sup>9+</sup>
encodeIntoUint8Array(input: string, dest: Uint8Array, ): { read: number; written: number }
Stores the UTF-8 encoded text.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ------------------------------------------------------- |
| input | string | Yes | String to encode. |
| dest | Uint8Array | Yes | **Uint8Array** instance used to store the UTF-8 encoded text.|
**Return value**
| Type | Description |
| ---------- | ------------------ |
| Uint8Array | Encoded text.|
**Example**
```js
let that = new util.TextEncoder()
let buffer = new ArrayBuffer(4)
let dest = new Uint8Array(buffer)
let result = new Object()
result = that.encodeInto('abcd', dest)
```
### encodeInto<sup>(deprecated)</sup>
### encodeInto > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeIntoUint8Array9+](#encodeintouint8array9) instead.
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number } encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
...@@ -461,8 +625,47 @@ Stores the UTF-8 encoded text. ...@@ -461,8 +625,47 @@ Stores the UTF-8 encoded text.
## RationalNumber<sup>8+</sup> ## RationalNumber<sup>8+</sup>
### constructor<sup>9+</sup>
### constructor<sup>8+</sup> constructor()
A constructor used to create a **RationalNumber** object.
**System capability**: SystemCapability.Utils.Lang
**Example**
```js
let rationalNumber = new util.RationalNumber();
```
### parseRationalNumber<sup>9+</sup>
parseRationalNumber(numerator: number,denominator: number)
Parses a rational number. Previously, this processing is an internal action of the deprecated constructor.
**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();
rationalNumber.parseRationalNumber(1,2)
```
### constructor<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
constructor(numerator: number,denominator: number) constructor(numerator: number,denominator: number)
...@@ -478,11 +681,11 @@ A constructor used to create a **RationalNumber** object. ...@@ -478,11 +681,11 @@ A constructor used to create a **RationalNumber** object.
| denominator | number | Yes| Denominator, which is an integer.| | denominator | number | Yes| Denominator, which is an integer.|
**Example** **Example**
```js ```js
let rationalNumber = new util.RationalNumber(1,2); 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​
...@@ -509,8 +712,39 @@ Creates a **RationalNumber** object based on the given string. ...@@ -509,8 +712,39 @@ Creates a **RationalNumber** object based on the given string.
let rational = util.RationalNumber.createRationalFromString("3/4"); let rational = util.RationalNumber.createRationalFromString("3/4");
``` ```
### compare<sup>9+</sup>
compare​(another: RationalNumber): number​
Compares this **RationalNumber** object with a given object.
**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.compare(rational);
```
### compareTo<sup>8+</sup><sup>(deprecated)</sup>
### compareTo<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [compare9+](#compare9) instead.
compareTo​(another: RationalNumber): number​ compareTo​(another: RationalNumber): number​
...@@ -537,7 +771,6 @@ Compares this **RationalNumber** object with a given object. ...@@ -537,7 +771,6 @@ Compares this **RationalNumber** object with a given object.
let result = rationalNumber.compareTo(rational); let result = rationalNumber.compareTo(rational);
``` ```
### valueOf<sup>8+</sup> ### valueOf<sup>8+</sup>
valueOf(): number valueOf(): number
...@@ -558,7 +791,6 @@ Obtains the value of this **RationalNumber** object as an integer or a floating- ...@@ -558,7 +791,6 @@ Obtains the value of this **RationalNumber** object as an integer or a floating-
let result = rationalNumber.valueOf(); let result = rationalNumber.valueOf();
``` ```
### equals<sup>8+</sup> ### equals<sup>8+</sup>
equals​(obj: Object): boolean equals​(obj: Object): boolean
...@@ -586,8 +818,38 @@ Checks whether this **RationalNumber** object equals the given object. ...@@ -586,8 +818,38 @@ Checks whether this **RationalNumber** object equals the given object.
let result = rationalNumber.equals(rational); let result = rationalNumber.equals(rational);
``` ```
### getCommonFactor<sup>9+</sup>
getCommonFactor(number1: number,number2: number): number
Obtains the greatest common divisor of two specified integers.
**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.|
### getCommonDivisor<sup>8+</sup> **Example**
```js
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonFactor(4,6);
```
### getCommonDivisor<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getCommonFactor9+](#getcommonfactor9) instead.
static getCommonDivisor​(number1: number,number2: number): number static getCommonDivisor​(number1: number,number2: number): number
...@@ -614,7 +876,6 @@ Obtains the greatest common divisor of two specified integers. ...@@ -614,7 +876,6 @@ Obtains the greatest common divisor of two specified integers.
let result = util.RationalNumber.getCommonDivisor(4,6); let result = util.RationalNumber.getCommonDivisor(4,6);
``` ```
### getNumerator<sup>8+</sup> ### getNumerator<sup>8+</sup>
getNumerator​(): number getNumerator​(): number
...@@ -635,7 +896,6 @@ Obtains the numerator of this **RationalNumber** object. ...@@ -635,7 +896,6 @@ Obtains the numerator of this **RationalNumber** object.
let result = rationalNumber.getNumerator(); let result = rationalNumber.getNumerator();
``` ```
### getDenominator<sup>8+</sup> ### getDenominator<sup>8+</sup>
getDenominator​(): number getDenominator​(): number
...@@ -656,7 +916,6 @@ Obtains the denominator of this **RationalNumber** object. ...@@ -656,7 +916,6 @@ Obtains the denominator of this **RationalNumber** object.
let result = rationalNumber.getDenominator(); let result = rationalNumber.getDenominator();
``` ```
### isZero<sup>8+</sup> ### isZero<sup>8+</sup>
isZero​():boolean isZero​():boolean
...@@ -677,7 +936,6 @@ Checks whether this **RationalNumber** object is **0**. ...@@ -677,7 +936,6 @@ Checks whether this **RationalNumber** object is **0**.
let result = rationalNumber.isZero(); let result = rationalNumber.isZero();
``` ```
### isNaN<sup>8+</sup> ### isNaN<sup>8+</sup>
isNaN​(): boolean isNaN​(): boolean
...@@ -698,7 +956,6 @@ Checks whether this **RationalNumber** object is a Not a Number (NaN). ...@@ -698,7 +956,6 @@ Checks whether this **RationalNumber** object is a Not a Number (NaN).
let result = rationalNumber.isNaN(); let result = rationalNumber.isNaN();
``` ```
### isFinite<sup>8+</sup> ### isFinite<sup>8+</sup>
isFinite​():boolean isFinite​():boolean
...@@ -719,7 +976,6 @@ Checks whether this **RationalNumber** object represents a finite value. ...@@ -719,7 +976,6 @@ Checks whether this **RationalNumber** object represents a finite value.
let result = rationalNumber.isFinite(); let result = rationalNumber.isFinite();
``` ```
### toString<sup>8+</sup> ### toString<sup>8+</sup>
toString​(): string toString​(): string
...@@ -740,46 +996,48 @@ Obtains the string representation of this **RationalNumber** object. ...@@ -740,46 +996,48 @@ Obtains the string representation of this **RationalNumber** object.
let result = rationalNumber.toString(); let result = rationalNumber.toString();
``` ```
## LruBuffer<sup>8+</sup>
## LRUCache<sup>9+</sup>
### Attributes ### Attributes
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description| | Name | Type | Readable| Writable| Description |
| -------- | -------- | -------- | -------- | -------- | | ------ | ------ | ---- | ---- | ---------------------- |
| length | number | Yes| No| Total number of values in this buffer.| | length | number | Yes | No | Total number of values in this buffer. |
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
pro.put(1,8); pro.put(1,8);
let result = pro.length; let result = pro.length;
``` ```
### constructor<sup>9+</sup>
### constructor<sup>8+</sup>
constructor(capacity?: number) constructor(capacity?: number)
A constructor used to create an **LruBuffer** instance. The default capacity of the buffer is 64. A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ------ | ---- | ---------------------------- |
| capacity | number | No| Capacity of the **LruBuffer** to create.| | capacity | number | No | Capacity of the **LruBuffer** to create.|
**Example** **Example**
```js ```js
let lrubuffer= new util.LruBuffer(); let lrubuffer= new util.LRUCache();
``` ```
### updateCapacity<sup>8+</sup> ### updateCapacity<sup>9+</sup>
updateCapacity(newCapacity: number): void updateCapacity(newCapacity: number): void
...@@ -789,18 +1047,19 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to ...@@ -789,18 +1047,19 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | ----------- | ------ | ---- | ---------------------------- |
| newCapacity | number | Yes| New capacity of the **LruBuffer**.| | newCapacity | number | Yes | New capacity of the **LruBuffer**.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
let result = pro.updateCapacity(100); let result = pro.updateCapacity(100);
``` ```
### toString<sup>8+</sup> ### toString<sup>9+</sup>
toString(): string toString(): string
...@@ -810,21 +1069,22 @@ Obtains the string representation of this **LruBuffer** object. ...@@ -810,21 +1069,22 @@ Obtains the string representation of this **LruBuffer** object.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | -------------------------- |
| string | String representation of this **LruBuffer** object.| | string | String representation of this **LruBuffer** object.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
pro.get(2); pro.get(2);
pro.remove(20); pro.remove(20);
let result = pro.toString(); let result = pro.toString();
``` ```
### getCapacity<sup>8+</sup> ### getCapacity<sup>9+</sup>
getCapacity(): number getCapacity(): number
...@@ -834,18 +1094,19 @@ Obtains the capacity of this buffer. ...@@ -834,18 +1094,19 @@ Obtains the capacity of this buffer.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | ---------------------- |
| number | Capacity of this buffer.| | number | Capacity of this buffer.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
let result = pro.getCapacity(); let result = pro.getCapacity();
``` ```
### clear<sup>8+</sup> ### clear<sup>9+</sup>
clear(): void clear(): void
...@@ -854,15 +1115,16 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c ...@@ -854,15 +1115,16 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
let result = pro.length; let result = pro.length;
pro.clear(); pro.clear();
``` ```
### getCreateCount<sup>8+</sup> ### getCreateCount<sup>9+</sup>
getCreateCount(): number getCreateCount(): number
...@@ -872,19 +1134,20 @@ Obtains the number of return values for **createDefault()**. ...@@ -872,19 +1134,20 @@ Obtains the number of return values for **createDefault()**.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | --------------------------------- |
| number | Number of return values for **createDefault()**.| | number | Number of return values for **createDefault()**.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(1,8); pro.put(1,8);
let result = pro.getCreateCount(); let result = pro.getCreateCount();
``` ```
### getMissCount<sup>8+</sup> ### getMissCount<sup>9+</sup>
getMissCount(): number getMissCount(): number
...@@ -894,20 +1157,21 @@ Obtains the number of times that the queried values are mismatched. ...@@ -894,20 +1157,21 @@ Obtains the number of times that the queried values are mismatched.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | ------------------------ |
| number | Number of times that the queried values are mismatched.| | number | Number of times that the queried values are mismatched.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
pro.get(2); pro.get(2);
let result = pro.getMissCount(); let result = pro.getMissCount();
``` ```
### getRemovalCount<sup>8+</sup> ### getRemovalCount<sup>9+</sup>
getRemovalCount(): number getRemovalCount(): number
...@@ -917,21 +1181,22 @@ Obtains the number of removals from this buffer. ...@@ -917,21 +1181,22 @@ Obtains the number of removals from this buffer.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | -------------------------- |
| number | Number of removals from the buffer.| | number | Number of removals from the buffer.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
pro.updateCapacity(2); pro.updateCapacity(2);
pro.put(50,22); pro.put(50,22);
let result = pro.getRemovalCount(); let result = pro.getRemovalCount();
``` ```
### getMatchCount<sup>8+</sup> ### getMatchCount<sup>9+</sup>
getMatchCount(): number getMatchCount(): number
...@@ -941,20 +1206,21 @@ Obtains the number of times that the queried values are matched. ...@@ -941,20 +1206,21 @@ Obtains the number of times that the queried values are matched.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | -------------------------- |
| number | Number of times that the queried values are matched.| | number | Number of times that the queried values are matched.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
pro.get(2); pro.get(2);
let result = pro.getMatchCount(); let result = pro.getMatchCount();
``` ```
### getPutCount<sup>8+</sup> ### getPutCount<sup>9+</sup>
getPutCount(): number getPutCount(): number
...@@ -964,19 +1230,20 @@ Obtains the number of additions to this buffer. ...@@ -964,19 +1230,20 @@ Obtains the number of additions to this buffer.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------ | ---------------------------- |
| number | Number of additions to the buffer.| | number | Number of additions to the buffer.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
let result = pro.getPutCount(); let result = pro.getPutCount();
``` ```
### isEmpty<sup>8+</sup> ### isEmpty<sup>9+</sup>
isEmpty(): boolean isEmpty(): boolean
...@@ -986,19 +1253,20 @@ Checks whether this buffer is empty. ...@@ -986,19 +1253,20 @@ Checks whether this buffer is empty.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | ---------------------------------------- |
| boolean | Returns **true** if the buffer does not contain any value.| | boolean | Returns **true** if the buffer does not contain any value.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
let result = pro.isEmpty(); let result = pro.isEmpty();
``` ```
### get<sup>8+</sup> ### get<sup>9+</sup>
get(key: K): V | undefined get(key: K): V | undefined
...@@ -1008,25 +1276,26 @@ Obtains the value of the specified key. ...@@ -1008,25 +1276,26 @@ Obtains the value of the specified key.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ---- | ---- | ------------ |
| key | K | Yes| Key based on which the value is queried.| | key | K | Yes | Key based on which the value is queried.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------------ | ------------------------------------------------------------ |
| V \| undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** 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 pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
let result = pro.get(2); let result = pro.get(2);
``` ```
### put<sup>8+</sup> ### put<sup>9+</sup>
put(key: K,value: V): V put(key: K,value: V): V
...@@ -1036,24 +1305,25 @@ Adds a key-value pair to this buffer. ...@@ -1036,24 +1305,25 @@ Adds a key-value pair to this buffer.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ---- | ---- | -------------------------- |
| key | K | Yes| Key of the key-value pair to add.| | key | K | Yes | Key of the key-value pair to add. |
| value | V | Yes| Value of the key-value pair to add.| | value | V | Yes | Value of the key-value pair to add.|
**Return value** **Return value**
| Type| Description| | Type| Description |
| -------- | -------- | | ---- | ------------------------------------------------------------ |
| V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. | | V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. |
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
let result = pro.put(2,10); let result = pro.put(2,10);
``` ```
### values<sup>8+</sup> ### values<sup>9+</sup>
values(): V[] values(): V[]
...@@ -1063,21 +1333,22 @@ Obtains all values in this buffer, listed from the most to the least recently ac ...@@ -1063,21 +1333,22 @@ Obtains all values in this buffer, listed from the most to the least recently ac
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | --------- | ------------------------------------------------------------ |
| V [] | All values in the buffer, listed from the most to the least recently accessed.| | V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
pro.put(2,"anhu"); pro.put(2,"anhu");
pro.put("afaf","grfb"); pro.put("afaf","grfb");
let result = pro.values(); let result = pro.values();
``` ```
### keys<sup>8+</sup> ### keys<sup>9+</sup>
keys(): K[] keys(): K[]
...@@ -1087,19 +1358,20 @@ Obtains all keys in this buffer, listed from the most to the least recently acce ...@@ -1087,19 +1358,20 @@ Obtains all keys in this buffer, listed from the most to the least recently acce
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | --------- | ------------------------------------------------------------ |
| K [] | All keys in the buffer, listed from the most to the least recently accessed.| | K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
let result = pro.keys(); let result = pro.keys();
``` ```
### remove<sup>8+</sup> ### remove<sup>9+</sup>
remove(key: K): V | undefined remove(key: K): V | undefined
...@@ -1109,25 +1381,26 @@ Removes the specified key and its value from this buffer. ...@@ -1109,25 +1381,26 @@ Removes the specified key and its value from this buffer.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ---- | ---- | -------------- |
| key | K | Yes| Key to remove.| | key | K | Yes | Key to remove.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------------ | ------------------------------------------------------------ |
| V \| 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.| | 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 pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
let result = pro.remove(20); let result = pro.remove(20);
``` ```
### afterRemoval<sup>8+</sup> ### afterRemoval<sup>9+</sup>
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
...@@ -1137,18 +1410,19 @@ Performs subsequent operations after a value is removed. ...@@ -1137,18 +1410,19 @@ Performs subsequent operations after a value is removed.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ------- | ---- | ------------------------------------------------------------ |
| isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.| | isEvict | boolean | No | Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity. |
| key | K | Yes| Key removed.| | key | K | Yes | Key removed. |
| value | V | Yes| Value removed.| | value | V | Yes | Value removed. |
| newValue | V | No| 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.| | newValue | V | No | 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.|
**Example** **Example**
```js ```js
let arr = []; let arr = [];
class ChildLruBuffer<K, V> extends util.LruBuffer<K, V> class ChildLruBuffer<K, V> extends util.LRUCache<K, V>
{ {
constructor() constructor()
{ {
super(); super();
...@@ -1160,13 +1434,13 @@ Performs subsequent operations after a value is removed. ...@@ -1160,13 +1434,13 @@ Performs subsequent operations after a value is removed.
arr = [key, value, newValue]; arr = [key, value, newValue];
} }
} }
} }
let lru = new ChildLruBuffer(); let lru = new ChildLruBuffer();
lru.afterRemoval(false,10,30,null); lru.afterRemoval(false,10,30,null);
``` ```
### contains<sup>8+</sup> ### contains<sup>9+</sup>
contains(key: K): boolean contains(key: K): boolean
...@@ -1176,25 +1450,26 @@ Checks whether this buffer contains the specified key. ...@@ -1176,25 +1450,26 @@ Checks whether this buffer contains the specified key.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description |
| -------- | -------- | -------- | -------- | | ------ | ---- | ---- | ---------------- |
| key | K | Yes| Key to check.| | key | K | Yes | Key to check.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | ------------------------------------------ |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.| | boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LRUCache();
pro.put(2,10); pro.put(2,10);
let result = pro.contains(20); let result = pro.contains(20);
``` ```
### createDefault<sup>8+</sup> ### createDefault<sup>9+</sup>
createDefault(key: K): V createDefault(key: K): V
...@@ -1204,108 +1479,1062 @@ Creates a value if the value of the specified key is not available. ...@@ -1204,108 +1479,1062 @@ Creates a value if the value of the specified key is not available.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------- |
| key | K | Yes | Key of which the value is missing.|
**Return value**
| Type| Description |
| ---- | ------------------ |
| V | Value of the key.|
**Example**
```js
let pro = new util.LRUCache();
let result = pro.createDefault(50);
```
### entries<sup>9+</sup>
entries(): IterableIterator&lt;[K,V]&gt;
Obtains a new iterator object that contains all key-value pairs in this object.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type | Description |
| ----------- | -------------------- |
| [K,&nbsp;V] | Iterable array.|
**Example**
```js
let pro = new util.LRUCache();
pro.put(2,10);
let result = pro.entries();
```
### [Symbol.iterator]<sup>9+</sup>
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
Obtains a two-dimensional array in key-value pairs.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type | Description |
| ----------- | ------------------------------ |
| [K,&nbsp;V] | Two-dimensional array in key-value pairs.|
**Example**
```js
let pro = new util.LRUCache();
pro.put(2,10);
let result = pro[Symbol.iterator]();
```
## LruBuffer<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [LRUCache9+](#lrucache9) instead.
### Attributes
**System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Total number of values in this buffer.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
pro.put(1,8);
let result = pro.length;
```
### constructor<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
constructor(capacity?: number)
A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | K | Yes| Key of which the value is missing.| | capacity | number | No| Capacity of the **LruBuffer** to create.|
**Example**
```js
let lrubuffer= new util.LruBuffer();
```
### updateCapacity<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [updateCapacity9+](#updatecapacity9) instead.
updateCapacity(newCapacity: number): void
Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newCapacity | number | Yes| New capacity of the **LruBuffer**.|
**Example**
```js
let pro = new util.LruBuffer();
let result = pro.updateCapacity(100);
```
### toString<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [toString9+](#tostring9) instead.
toString(): string
Obtains the string representation of this **LruBuffer** object.
**System capability**: SystemCapability.Utils.Lang
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| V | Value of the key.| | string | String representation of this **LruBuffer** object.|
**Example** **Example**
```js ```js
let pro = new util.LruBuffer(); let pro = new util.LruBuffer();
let result = pro.createDefault(50); pro.put(2,10);
pro.get(2);
pro.remove(20);
let result = pro.toString();
```
### getCapacity<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getCapacity9+](#getcapacity9) instead.
getCapacity(): number
Obtains the capacity of this buffer.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| number | Capacity of this buffer.|
**Example**
```js
let pro = new util.LruBuffer();
let result = pro.getCapacity();
```
### clear<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [clear9+](#clear9) instead.
clear(): void
Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations.
**System capability**: SystemCapability.Utils.Lang
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.length;
pro.clear();
```
### getCreateCount<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getCreateCount9+](#getcreatecount9) instead.
getCreateCount(): number
Obtains the number of return values for **createDefault()**.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of return values for **createDefault()**.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(1,8);
let result = pro.getCreateCount();
```
### getMissCount<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getMissCount9+](#getmisscount9) instead.
getMissCount(): number
Obtains the number of times that the queried values are mismatched.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are mismatched.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
pro.get(2);
let result = pro.getMissCount();
```
### getRemovalCount<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getRemovalCount9+](#getremovalcount9) instead.
getRemovalCount(): number
Obtains the number of removals from this buffer.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of removals from the buffer.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
pro.updateCapacity(2);
pro.put(50,22);
let result = pro.getRemovalCount();
```
### getMatchCount<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getMatchCount9+](#getmatchcount9) instead.
getMatchCount(): number
Obtains the number of times that the queried values are matched.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are matched.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
pro.get(2);
let result = pro.getMatchCount();
```
### getPutCount<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getPutCount9+](#getputcount9) instead.
getPutCount(): number
Obtains the number of additions to this buffer.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of additions to the buffer.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.getPutCount();
```
### isEmpty<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [isEmpty9+](#isempty9) instead.
isEmpty(): boolean
Checks whether this buffer is empty.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer does not contain any value.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.isEmpty();
```
### get<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [get9+](#get9) instead.
get(key: K): V | undefined
Obtains the value of the specified key.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key based on which the value is queried.|
**Return value**
| Type| Description|
| -------- | -------- |
| V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.get(2);
```
### put<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [put9+](#put9) instead.
put(key: K,value: V): V
Adds a key-value pair to this buffer.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key of the key-value pair to add.|
| value | V | Yes| Value of the key-value pair to add.|
**Return value**
| 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. |
**Example**
```js
let pro = new util.LruBuffer();
let result = pro.put(2,10);
```
### values<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [values9+](#values9) instead.
values(): V[]
Obtains all values in this buffer, listed from the most to the least recently accessed.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
pro.put(2,"anhu");
pro.put("afaf","grfb");
let result = pro.values();
```
### keys<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [keys9+](#keys9) instead.
keys(): K[]
Obtains all keys in this buffer, listed from the most to the least recently accessed.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.keys();
```
### remove<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [remove9+](#remove9) instead.
remove(key: K): V | undefined
Removes the specified key and its value from this buffer.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to remove.|
**Return value**
| 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.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.remove(20);
```
### afterRemoval<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [afterRemoval9+](#afterremoval9) instead.
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
Performs subsequent operations after a value is removed.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.|
| newValue | V | No| 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.|
**Example**
```js
let arr = [];
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>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead.
contains(key: K): boolean
Checks whether this buffer contains the specified key.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.contains(20);
```
### createDefault<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [createDefault9+](#createdefault9) instead.
createDefault(key: K): V
Creates a value if the value of the specified key is not available.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key of which the value is missing.|
**Return value**
| Type| Description|
| -------- | -------- |
| V | Value of the key.|
**Example**
```js
let pro = new util.LruBuffer();
let result = pro.createDefault(50);
```
### entries<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [entries9+](#entries9) instead.
entries(): IterableIterator&lt;[K,V]&gt;
Obtains a new iterator object that contains all key-value pairs in this object.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| [K,&nbsp;V] | Iterable array.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
let result = pro.entries();
```
### [Symbol.iterator]<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [Symbol.iterator9+](#symboliterator9) instead.
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
Obtains a two-dimensional array in key-value pairs.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| [K,&nbsp;V] | Two-dimensional array in key-value pairs.|
**Example**
```js
let pro = new util.LruBuffer();
pro.put(2,10);
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>
### 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
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ---------------------- |
| lowerObj | [ScopeType](#scopetype8) | Yes | Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes | Upper limit of the **Scope** object.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
```
### toString<sup>9+</sup>
toString(): string
Obtains a string representation that contains this **Scope**.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type | Description |
| ------ | -------------------------------------- |
| string | String representation containing the **Scope**.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.toString();
```
### intersect<sup>9+</sup>
intersect(range: ScopeHelper): ScopeHelper
Obtains the intersection of this **Scope** and the given **Scope**.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ------------------ |
| range | [ScopeHelper9+](#scopehelper9) | Yes | **Scope** specified.|
**Return value**
| Type | Description |
| ------------------------------ | ------------------------------ |
| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given **Scope**.|
**Example**
```js
let tempLower = new Temperature(30);
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 );
```
### intersect<sup>9+</sup>
intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper
Obtains the intersection of this **Scope** and the given lower and upper limits.
**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 |
| ------------------------------ | ---------------------------------------- |
| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
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>
getUpper(): ScopeType
Obtains the upper limit of this **Scope**.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type | Description |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getUpper();
```
### getLower<sup>9+</sup>
getLower(): ScopeType
Obtains the lower limit of this **Scope**.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type | Description |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getLower();
```
### expand<sup>9+</sup>
expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper
Obtains the union set of this **Scope** and the given lower and upper limits.
**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 |
| ------------------------------ | ------------------------------------ |
| [ScopeHelper9+](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF, tempMidS);
```
### expand<sup>9+</sup>
expand(range: ScopeHelper): ScopeHelper
Obtains the union set of this **Scope** and the given **Scope**.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ------------------ |
| range | [ScopeHelper9+](#scopehelper9) | Yes | **Scope** specified.|
**Return value**
| Type | Description |
| ------------------------------ | ---------------------------------- |
| [ScopeHelper9+](#scopehelper9) | Union set of this **Scope** and the given **Scope**.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
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>
expand(value: ScopeType): ScopeHelper
Obtains the union set of this **Scope** and the given value.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------ | ---- | ---------------- |
| value | [ScopeType](#scopetype8) | Yes | Value specified.|
**Return value**
| Type | Description |
| ------------------------------ | -------------------------------- |
| [ScopeHelper9+](#scopehelper9) | Union set of this **Scope** and the given value.|
**Example**
```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF);
``` ```
### entries<sup>8+</sup> ### contains<sup>9+</sup>
entries(): IterableIterator&lt;[K,V]&gt; contains(value: ScopeType): boolean
Obtains a new iterator object that contains all key-value pairs in this object. Checks whether a value is within this **Scope**.
**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 |
| -------- | -------- | | ------- | --------------------------------------------------- |
| [K, V] | Iterable array.| | 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.entries(); let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
range.contains(tempMiDF);
``` ```
### [Symbol.iterator]<sup>8+</sup> ### contains<sup>9+</sup>
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt; contains(range: ScopeHelper): boolean
Obtains a two-dimensional array in key-value pairs. Checks whether a range is within this **Scope**.
**System capability**: SystemCapability.Utils.Lang **System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ------------------ |
| range | [ScopeHelper9+](#scopehelper9) | Yes | **Scope** specified.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | ----------------------------------------------------- |
| [K, V] | Two-dimensional array in key-value pairs.| | 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[Symbol.iterator](); 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);
``` ```
## Scope<sup>8+</sup> ### clamp<sup>9+</sup>
clamp(value: ScopeType): ScopeType
### ScopeType<sup>8+</sup> Limits a value to this **Scope**.
Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**. **System capability**: SystemCapability.Utils.Lang
The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable. **Parameters**
```js
interface ScopeComparable{
compareTo(other: ScopeComparable): boolean;
}
type ScopeType = ScopeComparable | number;
```
| Name| Type | Mandatory| Description |
| ------ | ------------------------ | ---- | -------------- |
| value | [ScopeType](#scopetype8) | Yes | Value specified.|
Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#scopetype8) object. **Return value**
| 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**.|
Example **Example**
```js
class Temperature{ ```js
constructor(value){ let tempLower = new Temperature(30);
// If TS is used for development, add the following code: let tempUpper = new Temperature(40);
// private readonly _temp: Temperature; let tempMiDF = new Temperature(35);
this._temp = value; let range = new util.ScopeHelper(tempLower, tempUpper);
} let result = range.clamp(tempMiDF);
compareTo(value){ ```
return this._temp >= value.getTemp();
}
getTemp(){
return this._temp;
}
toString(){
return this._temp.toString();
}
}
```
## Scope<sup>8+(deprecated)</sup>
### constructor<sup>8+</sup> > **NOTE**
>
> This class is deprecated since API version 9. You are advised to use [ScopeHelper9+](#scopehelper9) instead.
### constructor<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
constructor(lowerObj: ScopeType, upperObj: ScopeType) constructor(lowerObj: ScopeType, upperObj: ScopeType)
...@@ -1327,8 +2556,11 @@ A constructor used to create a **Scope** object with the specified upper and low ...@@ -1327,8 +2556,11 @@ A constructor used to create a **Scope** object with the specified upper and low
let range = new util.Scope(tempLower, tempUpper); let range = new util.Scope(tempLower, tempUpper);
``` ```
### toString<sup>8+(deprecated)</sup>
### toString<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [toString9+](#tostring9) instead.
toString(): string toString(): string
...@@ -1350,8 +2582,11 @@ Obtains a string representation that contains this **Scope**. ...@@ -1350,8 +2582,11 @@ Obtains a string representation that contains this **Scope**.
let result = range.toString(); let result = range.toString();
``` ```
### intersect<sup>8+(deprecated)</sup>
### intersect<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead.
intersect(range: Scope): Scope intersect(range: Scope): Scope
...@@ -1372,6 +2607,7 @@ Obtains the intersection of this **Scope** and the given **Scope**. ...@@ -1372,6 +2607,7 @@ Obtains the intersection of this **Scope** and the given **Scope**.
| [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.| | [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let tempLower = new Temperature(30);
let tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
...@@ -1382,8 +2618,11 @@ Obtains the intersection of this **Scope** and the given **Scope**. ...@@ -1382,8 +2618,11 @@ Obtains the intersection of this **Scope** and the given **Scope**.
range.intersect(rangeFir ); range.intersect(rangeFir );
``` ```
### intersect<sup>8+(deprecated)</sup>
### intersect<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead.
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
...@@ -1414,8 +2653,11 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. ...@@ -1414,8 +2653,11 @@ Obtains the intersection of this **Scope** and the given lower and upper limits.
let result = range.intersect(tempMiDF, tempMidS); let result = range.intersect(tempMiDF, tempMidS);
``` ```
### getUpper<sup>8+(deprecated)</sup>
### getUpper<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getUpper9+](#getupper9) instead.
getUpper(): ScopeType getUpper(): ScopeType
...@@ -1437,8 +2679,11 @@ Obtains the upper limit of this **Scope**. ...@@ -1437,8 +2679,11 @@ Obtains the upper limit of this **Scope**.
let result = range.getUpper(); let result = range.getUpper();
``` ```
### getLower<sup>8+(deprecated)</sup>
### getLower<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getLower9+](#getlower9) instead.
getLower(): ScopeType getLower(): ScopeType
...@@ -1460,8 +2705,11 @@ Obtains the lower limit of this **Scope**. ...@@ -1460,8 +2705,11 @@ Obtains the lower limit of this **Scope**.
let result = range.getLower(); let result = range.getLower();
``` ```
### expand<sup>8+(deprecated)</sup>
### expand<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead.
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
...@@ -1493,8 +2741,11 @@ Obtains the union set of this **Scope** and the given lower and upper limits. ...@@ -1493,8 +2741,11 @@ Obtains the union set of this **Scope** and the given lower and upper limits.
let result = range.expand(tempMiDF, tempMidS); let result = range.expand(tempMiDF, tempMidS);
``` ```
### expand<sup>8+(deprecated)</sup>
### expand<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead.
expand(range: Scope): Scope expand(range: Scope): Scope
...@@ -1525,8 +2776,11 @@ Obtains the union set of this **Scope** and the given **Scope**. ...@@ -1525,8 +2776,11 @@ Obtains the union set of this **Scope** and the given **Scope**.
let result = range.expand(rangeFir); let result = range.expand(rangeFir);
``` ```
### expand<sup>8+(deprecated)</sup>
### expand<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead.
expand(value: ScopeType): Scope expand(value: ScopeType): Scope
...@@ -1555,8 +2809,11 @@ Obtains the union set of this **Scope** and the given value. ...@@ -1555,8 +2809,11 @@ Obtains the union set of this **Scope** and the given value.
let result = range.expand(tempMiDF); let result = range.expand(tempMiDF);
``` ```
### contains<sup>8+(deprecated)</sup>
### contains<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead.
contains(value: ScopeType): boolean contains(value: ScopeType): boolean
...@@ -1585,8 +2842,11 @@ Checks whether a value is within this **Scope**. ...@@ -1585,8 +2842,11 @@ Checks whether a value is within this **Scope**.
range.contains(tempMiDF); range.contains(tempMiDF);
``` ```
### contains<sup>8+(deprecated)</sup>
### contains<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead.
contains(range: Scope): boolean contains(range: Scope): boolean
...@@ -1607,6 +2867,7 @@ Checks whether a range is within this **Scope**. ...@@ -1607,6 +2867,7 @@ Checks whether a range is within this **Scope**.
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.| | boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
**Example** **Example**
```js ```js
let tempLower = new Temperature(30); let tempLower = new Temperature(30);
let tempUpper = new Temperature(40); let tempUpper = new Temperature(40);
...@@ -1617,8 +2878,11 @@ Checks whether a range is within this **Scope**. ...@@ -1617,8 +2878,11 @@ Checks whether a range is within this **Scope**.
let result = range.contains(rangeSec); let result = range.contains(rangeSec);
``` ```
### clamp<sup>8+(deprecated)</sup>
### clamp<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [clamp9+](#clamp9) instead.
clamp(value: ScopeType): ScopeType clamp(value: ScopeType): ScopeType
...@@ -1647,11 +2911,219 @@ Limits a value to this **Scope**. ...@@ -1647,11 +2911,219 @@ Limits a value to this **Scope**.
let result = range.clamp(tempMiDF); let result = range.clamp(tempMiDF);
``` ```
## Base64Helper<sup>9+</sup>
## Base64<sup>8+</sup> ### constructor<sup>9+</sup>
constructor()
### constructor<sup>8+</sup> A constructor used to create a **Base64Helper** instance.
**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**
| Type | Description |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array encoded.|
**Example**
```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeSync(array);
```
### encodeToStringSync<sup>9+</sup>
encodeToStringSync(src: Uint8Array): string
Encodes the input content.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ------------------- |
| src | Uint8Array | Yes | Uint8Array to encode.|
**Return value**
| Type | Description |
| ------ | -------------------- |
| string | String encoded from the Uint8Array.|
**Example**
```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeToStringSync(array);
```
### decodeSync<sup>9+</sup>
decodeSync(src: Uint8Array | string): Uint8Array
Decodes the input content.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | ----------------------------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode.|
**Return value**
| Type | Description |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array decoded.|
**Example**
```js
let that = new util.Base64Helper();
let buff = 'czEz';
let result = that.decodeSync(buff);
```
### encode<sup>9+</sup>
encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
Encodes the input content asynchronously.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ----------------------- |
| src | Uint8Array | Yes | Uint8Array to encode asynchronously.|
**Return value**
| Type | Description |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
**Example**
```js
let that = new util.Base64Helper();
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>9+</sup>
encodeToString(src: Uint8Array): Promise&lt;string&gt;
Encodes the input content asynchronously.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------- | ---- | ----------------------- |
| src | Uint8Array | Yes | Uint8Array to encode asynchronously.|
**Return value**
| Type | Description |
| --------------------- | ------------------------ |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
**Example**
```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
that.encodeToString(array).then(val=>{
console.log(val)
})
```
### decode<sup>9+</sup>
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
Decodes the input content asynchronously.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------ | ---- | --------------------------------- |
| src | Uint8Array&nbsp;\|&nbsp;string | Yes | Uint8Array or string to decode asynchronously.|
**Return value**
| Type | Description |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
**Example**
```js
let that = new util.Base64Helper();
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())
}
})
```
## Base64<sup>8+(deprecated)</sup>
> **NOTE**
>
> This class is deprecated since API version 9. You are advised to use [Base64Helper9+](#base64helper9) instead.
### constructor<sup>8+(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
constructor() constructor()
...@@ -1664,8 +3136,11 @@ A constructor used to create a **Base64** object. ...@@ -1664,8 +3136,11 @@ A constructor used to create a **Base64** object.
let base64 = new util.Base64(); let base64 = new util.Base64();
``` ```
### encodeSync<sup>8+(deprecated)</sup>
### encodeSync<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeSync9+](#encodesync9) instead.
encodeSync(src: Uint8Array): Uint8Array encodeSync(src: Uint8Array): Uint8Array
...@@ -1686,14 +3161,18 @@ Encodes the input content. ...@@ -1686,14 +3161,18 @@ Encodes the input content.
| Uint8Array | Uint8Array encoded.| | Uint8Array | Uint8Array encoded.|
**Example** **Example**
```js ```js
let that = new util.Base64(); let that = new util.Base64();
let array = new Uint8Array([115,49,51]); let array = new Uint8Array([115,49,51]);
let result = that.encodeSync(array); let result = that.encodeSync(array);
``` ```
### encodeToStringSync<sup>8+(deprecated)</sup>
### encodeToStringSync<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeToStringSync9+](#encodetostringsync9) instead.
encodeToStringSync(src: Uint8Array): string encodeToStringSync(src: Uint8Array): string
...@@ -1720,8 +3199,11 @@ Encodes the input content. ...@@ -1720,8 +3199,11 @@ Encodes the input content.
let result = that.encodeToStringSync(array); let result = that.encodeToStringSync(array);
``` ```
### decodeSync<sup>8+(deprecated)</sup>
### decodeSync<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [decodeSync9+](#decodesync9) instead.
decodeSync(src: Uint8Array | string): Uint8Array decodeSync(src: Uint8Array | string): Uint8Array
...@@ -1733,7 +3215,7 @@ Decodes the input content. ...@@ -1733,7 +3215,7 @@ Decodes the input content.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array \| string | Yes| Uint8Array or string to decode.| | src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.|
**Return value** **Return value**
...@@ -1748,8 +3230,11 @@ Decodes the input content. ...@@ -1748,8 +3230,11 @@ Decodes the input content.
let result = that.decodeSync(buff); let result = that.decodeSync(buff);
``` ```
### encode<sup>8+(deprecated)</sup>
### encode<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encode9+](#encode9) instead.
encode(src: Uint8Array): Promise&lt;Uint8Array&gt; encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
...@@ -1781,8 +3266,11 @@ Encodes the input content asynchronously. ...@@ -1781,8 +3266,11 @@ Encodes the input content asynchronously.
}) })
``` ```
### encodeToString<sup>8+(deprecated)</sup>
### encodeToString<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeToString9+](#encodetostring9) instead.
encodeToString(src: Uint8Array): Promise&lt;string&gt; encodeToString(src: Uint8Array): Promise&lt;string&gt;
...@@ -1811,8 +3299,11 @@ Encodes the input content asynchronously. ...@@ -1811,8 +3299,11 @@ Encodes the input content asynchronously.
}) })
``` ```
### decode<sup>8+(deprecated)</sup>
### decode<sup>8+</sup> > **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [decode9+](#decode9) instead.
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt; decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
...@@ -1824,7 +3315,7 @@ Decodes the input content asynchronously. ...@@ -1824,7 +3315,7 @@ Decodes the input content asynchronously.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.| | src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.|
**Return value** **Return value**
...@@ -1844,7 +3335,6 @@ Decodes the input content asynchronously. ...@@ -1844,7 +3335,6 @@ Decodes the input content asynchronously.
}) })
``` ```
## types<sup>8+</sup> ## types<sup>8+</sup>
...@@ -2929,3 +4419,4 @@ Checks whether the input value is of the **SharedArrayBuffer** type. ...@@ -2929,3 +4419,4 @@ Checks whether the input value is of the **SharedArrayBuffer** type.
let that = new util.types(); let that = new util.types();
let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0)); let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
``` ```
<!--no_check-->
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册