diff --git a/en/application-dev/reference/apis/js-apis-util.md b/en/application-dev/reference/apis/js-apis-util.md index 226f7686f490b2d3fd28e8263d7226eb02091c09..8897b51f07b4e00feae752e792820e6b9b32370f 100755 --- a/en/application-dev/reference/apis/js-apis-util.md +++ b/en/application-dev/reference/apis/js-apis-util.md @@ -1,17 +1,15 @@ -# util +# @ohos.util +This module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types. > **NOTE** > > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -This module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types. - - ## Modules to Import -``` +```js import util from '@ohos.util'; ``` @@ -45,14 +43,14 @@ console.log(res); ## util.printf(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [util.format9+](#utilformat9) instead. - printf(format: string, ...args: Object[]): string Formats the specified values and inserts them into the string by replacing the wildcard in the string. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.format9+](#utilformat9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -60,7 +58,7 @@ Formats the specified values and inserts them into the string by replacing the w | 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. | +| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.| **Return value** @@ -69,6 +67,7 @@ Formats the specified values and inserts them into the string by replacing the w | string | String containing the formatted values.| **Example** + ```js let res = util.printf("%s", "hello world!"); console.log(res); @@ -96,22 +95,22 @@ Obtains detailed information about a system error code. **Example** - ```js +```js let errnum = 10; // 10 is a system error code. let result = util.errnoToString(errnum); console.log("result = " + result); - ``` +``` ## util.getErrorString(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [util.errnoToString9+](#utilerrnotostring9) instead. - getErrorString(errno: number): string Obtains detailed information about a system error code. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.errnoToString9+](#utilerrnotostring9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -127,6 +126,7 @@ Obtains detailed information about a system error code. | string | Detailed information about the error code.| **Example** + ```js let errnum = 10; // 10 is a system error code. let result = util.getErrorString(errnum); @@ -154,6 +154,7 @@ Calls back an asynchronous function. In the callback, the first parameter indica | Function | Callback, in which the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved) and the second parameter indicates the resolved value.| **Example** + ```js async function promiseFn() { return Promise.reject('value'); @@ -187,6 +188,7 @@ Processes an asynchronous function and returns a promise. | Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.| **Example** + ```js function aysnFun(str1, str2) { if (typeof str1 === 'object' && typeof str2 === 'object') { @@ -205,11 +207,11 @@ Processes an asynchronous function and returns a promise. promiseWrapper(original: (err: Object, value: Object) => void): Object +Processes an asynchronous function and returns a promise. + > **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. +> This API is unavailable. You are advised to use [util.promisify9+](#utilpromisify9) instead. **System capability**: SystemCapability.Utils.Lang @@ -246,6 +248,7 @@ Uses a secure random number generator to generate a random universally unique id | string | A string representing the UUID generated.| **Example** + ```js let uuid = util.randomUUID(true); console.log("RFC 4122 Version 4 UUID:" + uuid); @@ -274,6 +277,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41 | Uint8Array | A Uint8Array value representing the UUID generated.| **Example** + ```js let uuid = util.randomBinaryUUID(true); console.log(JSON.stringify(uuid)); @@ -302,6 +306,7 @@ Parses a UUID from a string, as described in RFC 4122 version 4. | Uint8Array | A Uint8Array value representing the UUID parsed. If the parsing fails, **SyntaxError** is thrown.| **Example** + ```js let uuid = util.parseUUID("84bdf796-66cc-4655-9b89-d6218d100f9c"); console.log(JSON.stringify(uuid)); @@ -335,6 +340,8 @@ create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean },): T Creates a **TextDecoder** object. It provides the same function as the deprecated argument constructor. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name | Type | Mandatory| Description | @@ -342,7 +349,7 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate | encoding | string | No | Encoding format. | | options | Object | No | Encoding-related options, which include **fatal** and **ignoreBOM**.| - **Table 1.1** options +**Table 1.1** options | Name | Type| Mandatory| Description | | --------- | -------- | ---- | ------------------ | @@ -351,21 +358,21 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate **Example** - ```js +```js let textDecoder = new util.TextDecoder() textDecoder.create('utf-8', { ignoreBOM : true }); - ``` +``` ### constructor(deprecated) -> **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 },) A constructor used to create a **TextDecoder** object. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -383,6 +390,7 @@ A constructor used to create a **TextDecoder** object. | ignoreBOM | boolean | No| Whether to ignore the BOM.| **Example** + ```js let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); ``` @@ -402,7 +410,7 @@ Decodes the input content. | input | Uint8Array | Yes| Uint8Array to decode.| | options | Object | No| Options related to decoding.| - **Table 2** options +**Table 2** options | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -415,6 +423,7 @@ Decodes the input content. | string | Data decoded.| **Example** + ```js let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); let result = new Uint8Array(6); @@ -445,7 +454,7 @@ Decodes the input content. | input | Uint8Array | Yes| Uint8Array to decode.| | options | Object | No| Options related to decoding.| - **Table 2** options +**Table 2** options | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | @@ -458,6 +467,7 @@ Decodes the input content. | string | Data decoded.| **Example** + ```js let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true}); let result = new Uint8Array(6); @@ -493,6 +503,7 @@ A constructor used to create a **TextEncoder** object. **System capability**: SystemCapability.Utils.Lang **Example** + ```js let textEncoder = new util.TextEncoder(); ``` @@ -509,7 +520,7 @@ Encodes the input content. | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ------------------ | -| input | string | Yes | String to encode.| +| input | string | No | String to encode.| **Return value** @@ -528,21 +539,21 @@ result = textEncoder.encodeInto("\uD800¥¥"); ### encode(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [encodeInto9+](#encodeinto9) instead. - encode(input?: string): Uint8Array Encodes the input content. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeInto9+](#encodeinto9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| input | string | Yes| String to encode.| +| input | string | No| String to encode.| **Return value** @@ -591,14 +602,14 @@ result = that.encodeInto('abcd', dest) ### encodeInto(deprecated) -> **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 } Stores the UTF-8 encoded text. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeIntoUint8Array9+](#encodeintouint8array9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -635,13 +646,13 @@ A constructor used to create a **RationalNumber** object. **Example** - ```js +```js let rationalNumber = new util.RationalNumber(); - ``` +``` ### parseRationalNumber9+ -parseRationalNumber(numerator: number,denominator: number) +parseRationalNumber(numerator: number,denominator: number): RationalNumber Parses a rational number. Previously, this processing is an internal action of the deprecated constructor. @@ -656,21 +667,20 @@ Parses a rational number. Previously, this processing is an internal action of t **Example** - ```js -let rationalNumber = new util.RationalNumber(); -rationalNumber.parseRationalNumber(1,2) - ``` +```js +let rationalNumber = util.RationalNumber.parseRationalNumber(1,2) +``` ### constructor(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. - constructor(numerator: number,denominator: number) A constructor used to create a **RationalNumber** object. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -682,9 +692,9 @@ A constructor used to create a **RationalNumber** object. **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - ``` +```js +let rationalNumber = new util.RationalNumber(1,2); +``` ### createRationalFromString8+ @@ -707,10 +717,11 @@ Creates a **RationalNumber** object based on the given string. | object | **RationalNumber** object created.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let rational = util.RationalNumber.createRationalFromString("3/4"); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let rational = util.RationalNumber.createRationalFromString("3/4"); +``` ### compare9+ @@ -740,16 +751,16 @@ let rational = util.RationalNumber.createRationalFromString("3/4"); let result = rationalNumber.compare(rational); ``` -### compareTo8+(deprecated) - -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [compare9+](#compare9) instead. +### compareTo(deprecated) compareTo​(another: RationalNumber): number​ Compares this **RationalNumber** object with a given object. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [compare9+](#compare9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -765,11 +776,12 @@ Compares this **RationalNumber** object with a given object. | number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let rational = util.RationalNumber.createRationalFromString("3/4"); - let result = rationalNumber.compareTo(rational); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let rational = util.RationalNumber.createRationalFromString("3/4"); +let result = rationalNumber.compareTo(rational); +``` ### valueOf8+ @@ -786,10 +798,11 @@ Obtains the value of this **RationalNumber** object as an integer or a floating- | number | An integer or a floating-point number.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = rationalNumber.valueOf(); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = rationalNumber.valueOf(); +``` ### equals8+ @@ -812,11 +825,12 @@ Checks whether this **RationalNumber** object equals the given object. | boolean | Returns **true** if the two objects are equal; returns **false** otherwise.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let rational = util.RationalNumber.createRationalFromString("3/4"); - let result = rationalNumber.equals(rational); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let rational = util.RationalNumber.createRationalFromString("3/4"); +let result = rationalNumber.equals(rational); +``` ### getCommonFactor9+ @@ -841,20 +855,21 @@ Obtains the greatest common divisor of two specified integers. **Example** - ```js +```js let rationalNumber = new util.RationalNumber(1,2); let result = util.RationalNumber.getCommonFactor(4,6); - ``` +``` ### getCommonDivisor(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [getCommonFactor9+](#getcommonfactor9) instead. static getCommonDivisor​(number1: number,number2: number): number Obtains the greatest common divisor of two specified integers. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCommonFactor9+](#getcommonfactor9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -871,10 +886,11 @@ Obtains the greatest common divisor of two specified integers. | number | Greatest common divisor obtained.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = util.RationalNumber.getCommonDivisor(4,6); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = util.RationalNumber.getCommonDivisor(4,6); +``` ### getNumerator8+ @@ -891,10 +907,11 @@ Obtains the numerator of this **RationalNumber** object. | number | Numerator of this **RationalNumber** object.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = rationalNumber.getNumerator(); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = rationalNumber.getNumerator(); +``` ### getDenominator8+ @@ -911,10 +928,11 @@ Obtains the denominator of this **RationalNumber** object. | number | Denominator of this **RationalNumber** object.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = rationalNumber.getDenominator(); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = rationalNumber.getDenominator(); +``` ### isZero8+ @@ -931,10 +949,11 @@ Checks whether this **RationalNumber** object is **0**. | boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = rationalNumber.isZero(); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = rationalNumber.isZero(); +``` ### isNaN8+ @@ -951,10 +970,11 @@ Checks whether this **RationalNumber** object is a Not a Number (NaN). | boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = rationalNumber.isNaN(); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = rationalNumber.isNaN(); +``` ### isFinite8+ @@ -971,10 +991,11 @@ Checks whether this **RationalNumber** object represents a finite value. | boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = rationalNumber.isFinite(); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = rationalNumber.isFinite(); +``` ### toString8+ @@ -991,10 +1012,11 @@ Obtains the string representation of this **RationalNumber** object. | string | Returns **NaN** if the numerator and denominator of this object are both **0**; returns a string in Numerator/Denominator format otherwise, for example, **3/5**.| **Example** - ```js - let rationalNumber = new util.RationalNumber(1,2); - let result = rationalNumber.toString(); - ``` + +```js +let rationalNumber = new util.RationalNumber(1,2); +let result = rationalNumber.toString(); +``` ## LRUCache9+ @@ -1005,22 +1027,22 @@ Obtains the string representation of this **RationalNumber** object. | 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 cache.| **Example** - ```js +```js let pro = new util.LRUCache(); pro.put(2,10); pro.put(1,8); let result = pro.length; - ``` +``` ### constructor9+ constructor(capacity?: number) -A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64. +A constructor used to create a **LruCache** instance. The default capacity of the cache is 64. **System capability**: SystemCapability.Utils.Lang @@ -1028,20 +1050,20 @@ A constructor used to create a **LruBuffer** instance. The default capacity of t | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ---------------------------- | -| capacity | number | No | Capacity of the **LruBuffer** to create.| +| capacity | number | No | Capacity of the **LruCache** to create.| **Example** - ```js +```js let lrubuffer= new util.LRUCache(); - ``` +``` ### updateCapacity9+ updateCapacity(newCapacity: number): void -Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown. +Changes the **LruCache** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown. **System capability**: SystemCapability.Utils.Lang @@ -1049,21 +1071,21 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to | Name | Type | Mandatory| Description | | ----------- | ------ | ---- | ---------------------------- | -| newCapacity | number | Yes | New capacity of the **LruBuffer**.| +| newCapacity | number | Yes | New capacity of the **LruCache**.| **Example** - ```js +```js let pro = new util.LRUCache(); let result = pro.updateCapacity(100); - ``` +``` ### toString9+ toString(): string -Obtains the string representation of this **LruBuffer** object. +Obtains the string representation of this **LruCache** object. **System capability**: SystemCapability.Utils.Lang @@ -1071,24 +1093,24 @@ Obtains the string representation of this **LruBuffer** object. | Type | Description | | ------ | -------------------------- | -| string | String representation of this **LruBuffer** object.| +| string | String representation of this **LruCache** object.| **Example** - ```js +```js let pro = new util.LRUCache(); pro.put(2,10); pro.get(2); pro.remove(20); let result = pro.toString(); - ``` +``` ### getCapacity9+ getCapacity(): number -Obtains the capacity of this buffer. +Obtains the capacity of this cache. **System capability**: SystemCapability.Utils.Lang @@ -1096,7 +1118,7 @@ Obtains the capacity of this buffer. | Type | Description | | ------ | ---------------------- | -| number | Capacity of this buffer.| +| number | Capacity of this cache.| **Example** @@ -1110,7 +1132,7 @@ let result = pro.getCapacity(); clear(): void -Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations. +Clears key-value pairs from this cache. The **afterRemoval()** method will be called to perform subsequent operations. **System capability**: SystemCapability.Utils.Lang @@ -1175,7 +1197,7 @@ let result = pro.getMissCount(); getRemovalCount(): number -Obtains the number of removals from this buffer. +Obtains the number of removals from this cache. **System capability**: SystemCapability.Utils.Lang @@ -1183,7 +1205,7 @@ Obtains the number of removals from this buffer. | Type | Description | | ------ | -------------------------- | -| number | Number of removals from the buffer.| +| number | Number of removals from the cache.| **Example** @@ -1224,7 +1246,7 @@ let result = pro.getMatchCount(); getPutCount(): number -Obtains the number of additions to this buffer. +Obtains the number of additions to this cache. **System capability**: SystemCapability.Utils.Lang @@ -1232,7 +1254,7 @@ Obtains the number of additions to this buffer. | Type | Description | | ------ | ---------------------------- | -| number | Number of additions to the buffer.| +| number | Number of additions to the cache.| **Example** @@ -1247,7 +1269,7 @@ let result = pro.getPutCount(); isEmpty(): boolean -Checks whether this buffer is empty. +Checks whether this cache is empty. **System capability**: SystemCapability.Utils.Lang @@ -1255,7 +1277,7 @@ Checks whether this buffer is empty. | Type | Description | | ------- | ---------------------------------------- | -| boolean | Returns **true** if the buffer does not contain any value.| +| boolean | Returns **true** if the cache does not contain any value.| **Example** @@ -1284,7 +1306,7 @@ Obtains the value of the specified key. | Type | Description | | ------------------------ | ------------------------------------------------------------ | -| V \| undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.| +| V \| undefined | Returns the value of the key if a match is found in the cache; returns **undefined** otherwise.| **Example** @@ -1299,7 +1321,7 @@ let result = pro.get(2); put(key: K,value: V): V -Adds a key-value pair to this buffer. +Adds a key-value pair to this cache. **System capability**: SystemCapability.Utils.Lang @@ -1327,7 +1349,7 @@ let result = pro.put(2,10); values(): V[] -Obtains all values in this buffer, listed from the most to the least recently accessed. +Obtains all values in this cache, listed from the most to the least recently accessed. **System capability**: SystemCapability.Utils.Lang @@ -1335,7 +1357,7 @@ Obtains all values in this buffer, listed from the most to the least recently ac | Type | Description | | --------- | ------------------------------------------------------------ | -| V [] | All values in the buffer, listed from the most to the least recently accessed.| +| V [] | All values in the cache, listed from the most to the least recently accessed.| **Example** @@ -1352,7 +1374,7 @@ let result = pro.values(); keys(): K[] -Obtains all keys in this buffer, listed from the most to the least recently accessed. +Obtains all keys in this cache, listed from the most to the least recently accessed. **System capability**: SystemCapability.Utils.Lang @@ -1360,7 +1382,7 @@ Obtains all keys in this buffer, listed from the most to the least recently acce | Type | Description | | --------- | ------------------------------------------------------------ | -| K [] | All keys in the buffer, listed from the most to the least recently accessed.| +| K [] | All keys in the cache, listed from the most to the least recently accessed.| **Example** @@ -1375,7 +1397,7 @@ let result = pro.keys(); remove(key: K): V | undefined -Removes the specified key and its value from this buffer. +Removes the specified key and its value from this cache. **System capability**: SystemCapability.Utils.Lang @@ -1389,7 +1411,7 @@ Removes the specified key and its value from this buffer. | 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 \| undefined | Returns an **Optional** object containing the removed key-value pair if the key exists in the cache; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.| **Example** @@ -1412,10 +1434,10 @@ Performs subsequent operations after a value is removed. | 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 | Yes | Whether the cache 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.| +| newValue | V | Yes | New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.| **Example** @@ -1442,30 +1464,31 @@ lru.afterRemoval(false,10,30,null); ### contains9+ -contains(key: K): boolean +contains(key: object): boolean -Checks whether this buffer contains the specified key. +Checks whether this cache contains the specified key. **System capability**: SystemCapability.Utils.Lang **Parameters** -| Name| Type| Mandatory| Description | -| ------ | ---- | ---- | ---------------- | -| key | K | Yes | Key to check.| +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ---------------- | +| key | object | Yes | Key to check.| **Return value** | Type | Description | | ------- | ------------------------------------------ | -| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.| +| boolean | Returns **true** if the cache contains the specified key; returns **false** otherwise.| **Example** ```js let pro = new util.LRUCache(); pro.put(2,10); -let result = pro.contains(20); +let obj = {1:"key"}; +let result = pro.contains(obj); ``` @@ -1545,7 +1568,7 @@ let result = pro[Symbol.iterator](); > **NOTE** > -> This API is deprecated since API version 9. You are advised to use [LRUCache9+](#lrucache9) instead. +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache9+](#lrucache9) instead. ### Attributes @@ -1556,6 +1579,7 @@ let result = pro[Symbol.iterator](); | length | number | Yes| No| Total number of values in this buffer.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1565,14 +1589,14 @@ let result = pro[Symbol.iterator](); ### constructor(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -1582,20 +1606,21 @@ A constructor used to create a **LruBuffer** instance. The default capacity of t | capacity | number | No| Capacity of the **LruBuffer** to create.| **Example** + ```js let lrubuffer= new util.LruBuffer(); ``` ### updateCapacity(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [updateCapacity9+](#updatecapacity9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -1605,6 +1630,7 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to | newCapacity | number | Yes| New capacity of the **LruBuffer**.| **Example** + ```js let pro = new util.LruBuffer(); let result = pro.updateCapacity(100); @@ -1612,14 +1638,14 @@ Changes the **LruBuffer** capacity. If the new capacity is less than or equal to ### toString(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString9+](#tostring9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1629,6 +1655,7 @@ Obtains the string representation of this **LruBuffer** object. | string | String representation of this **LruBuffer** object.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1639,14 +1666,14 @@ Obtains the string representation of this **LruBuffer** object. ### getCapacity(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCapacity9+](#getcapacity9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1663,17 +1690,18 @@ Obtains the capacity of this buffer. ### clear(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clear9+](#clear9) instead. + **System capability**: SystemCapability.Utils.Lang **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1683,14 +1711,14 @@ Clears key-value pairs from this buffer. The **afterRemoval()** method will be c ### getCreateCount(deprecated) -> **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()**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCreateCount9+](#getcreatecount9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1700,6 +1728,7 @@ Obtains the number of return values for **createDefault()**. | number | Number of return values for **createDefault()**.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(1,8); @@ -1708,14 +1737,14 @@ Obtains the number of return values for **createDefault()**. ### getMissCount(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMissCount9+](#getmisscount9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1725,6 +1754,7 @@ Obtains the number of times that the queried values are mismatched. | number | Number of times that the queried values are mismatched.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1734,14 +1764,14 @@ Obtains the number of times that the queried values are mismatched. ### getRemovalCount(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRemovalCount9+](#getremovalcount9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1751,6 +1781,7 @@ Obtains the number of removals from this buffer. | number | Number of removals from the buffer.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1761,14 +1792,14 @@ Obtains the number of removals from this buffer. ### getMatchCount(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMatchCount9+](#getmatchcount9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1778,6 +1809,7 @@ Obtains the number of times that the queried values are matched. | number | Number of times that the queried values are matched.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1787,14 +1819,14 @@ Obtains the number of times that the queried values are matched. ### getPutCount(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getPutCount9+](#getputcount9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1804,6 +1836,7 @@ Obtains the number of additions to this buffer. | number | Number of additions to the buffer.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1812,14 +1845,14 @@ Obtains the number of additions to this buffer. ### isEmpty(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isEmpty9+](#isempty9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1829,6 +1862,7 @@ Checks whether this buffer is empty. | boolean | Returns **true** if the buffer does not contain any value.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -1837,14 +1871,14 @@ Checks whether this buffer is empty. ### get(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [get9+](#get9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -1860,6 +1894,7 @@ Obtains the value of the specified key. | V \| 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); @@ -1868,14 +1903,14 @@ Obtains the value of the specified key. ### put(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [put9+](#put9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -1892,6 +1927,7 @@ Adds a key-value pair to this buffer. | 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); @@ -1899,14 +1935,14 @@ Adds a key-value pair to this buffer. ### values(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [values9+](#values9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1916,6 +1952,7 @@ Obtains all values in this buffer, listed from the most to the least recently ac | V [] | 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); @@ -1926,14 +1963,14 @@ Obtains all values in this buffer, listed from the most to the least recently ac ### keys(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [keys9+](#keys9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -1951,14 +1988,14 @@ Obtains all keys in this buffer, listed from the most to the least recently acce ### remove(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [remove9+](#remove9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -1982,26 +2019,27 @@ Removes the specified key and its value from this buffer. ### afterRemoval(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [afterRemoval9+](#afterremoval9) instead. + **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.| +| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.| | key | K | Yes| Key removed.| | 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 | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.| **Example** + ```js let arr = []; class ChildLruBuffer extends util.LruBuffer @@ -2024,14 +2062,15 @@ Performs subsequent operations after a value is removed. ### contains(deprecated) -> **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. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains9+](#contains9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2047,6 +2086,7 @@ Checks whether this buffer contains the specified key. | boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -2055,14 +2095,14 @@ Checks whether this buffer contains the specified key. ### createDefault(deprecated) -> **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. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createDefault9+](#createdefault9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2078,6 +2118,7 @@ Creates a value if the value of the specified key is not available. | V | Value of the key.| **Example** + ```js let pro = new util.LruBuffer(); let result = pro.createDefault(50); @@ -2085,14 +2126,14 @@ Creates a value if the value of the specified key is not available. ### entries(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [entries9+](#entries9) instead. - entries(): IterableIterator<[K,V]> Obtains a new iterator object that contains all key-value pairs in this object. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [entries9+](#entries9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -2102,6 +2143,7 @@ Obtains a new iterator object that contains all key-value pairs in this object. | [K, V] | Iterable array.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -2110,14 +2152,14 @@ Obtains a new iterator object that contains all key-value pairs in this object. ### [Symbol.iterator](deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [Symbol.iterator9+](#symboliterator9) instead. - [Symbol.iterator]\(): IterableIterator<[K, V]> Obtains a two-dimensional array in key-value pairs. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Symbol.iterator9+](#symboliterator9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -2127,6 +2169,7 @@ Obtains a two-dimensional array in key-value pairs. | [K, V] | Two-dimensional array in key-value pairs.| **Example** + ```js let pro = new util.LruBuffer(); pro.put(2,10); @@ -2138,6 +2181,7 @@ Obtains a two-dimensional array in key-value pairs. 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; @@ -2229,9 +2273,9 @@ Obtains the intersection of this **Scope** and the given **Scope**. **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ------------------------------ | ---- | ------------------ | -| range | [ScopeHelper9+](#scopehelper9) | Yes | **Scope** specified.| +| Name| Type | Mandatory| Description | +| ------ | ---------------------------- | ---- | ------------------ | +| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.| **Return value** @@ -2269,9 +2313,9 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. **Return value** -| Type | Description | -| ------------------------------ | ---------------------------------------- | -| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.| +| Type | Description | +| ---------------------------- | ---------------------------------------- | +| [ScopeHelper](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.| **Example** @@ -2350,9 +2394,9 @@ Obtains the union set of this **Scope** and the given lower and upper limits. **Return value** -| Type | Description | -| ------------------------------ | ------------------------------------ | -| [ScopeHelper9+](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.| +| Type | Description | +| ---------------------------- | ------------------------------------ | +| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.| **Example** @@ -2376,15 +2420,15 @@ Obtains the union set of this **Scope** and the given **Scope**. **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ------------------------------ | ---- | ------------------ | -| range | [ScopeHelper9+](#scopehelper9) | Yes | **Scope** specified.| +| Name| Type | Mandatory| Description | +| ------ | ---------------------------- | ---- | ------------------ | +| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.| **Return value** -| Type | Description | -| ------------------------------ | ---------------------------------- | -| [ScopeHelper9+](#scopehelper9) | Union set of this **Scope** and the given **Scope**.| +| Type | Description | +| ---------------------------- | ---------------------------------- | +| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given **Scope**.| **Example** @@ -2415,9 +2459,9 @@ Obtains the union set of this **Scope** and the given value. **Return value** -| Type | Description | -| ------------------------------ | -------------------------------- | -| [ScopeHelper9+](#scopehelper9) | Union set of this **Scope** and the given value.| +| Type | Description | +| ---------------------------- | -------------------------------- | +| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given value.| **Example** @@ -2471,9 +2515,9 @@ Checks whether a range is within this **Scope**. **Parameters** -| Name| Type | Mandatory| Description | -| ------ | ------------------------------ | ---- | ------------------ | -| range | [ScopeHelper9+](#scopehelper9) | Yes | **Scope** specified.| +| Name| Type | Mandatory| Description | +| ------ | ---------------------------- | ---- | ------------------ | +| range | [ScopeHelper](#scopehelper9) | Yes | **Scope** specified.| **Return value** @@ -2528,18 +2572,19 @@ let result = range.clamp(tempMiDF); > **NOTE** > -> This class is deprecated since API version 9. You are advised to use [ScopeHelper9+](#scopehelper9) instead. +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper9+](#scopehelper9) instead. ### constructor(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. - constructor(lowerObj: ScopeType, upperObj: ScopeType) A constructor used to create a **Scope** object with the specified upper and lower limits. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. + + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2558,14 +2603,14 @@ A constructor used to create a **Scope** object with the specified upper and low ### toString(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [toString9+](#tostring9) instead. - toString(): string Obtains a string representation that contains this **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString9+](#tostring9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -2575,6 +2620,7 @@ Obtains a string representation that contains this **Scope**. | string | String representation containing the **Scope**.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -2584,14 +2630,14 @@ Obtains a string representation that contains this **Scope**. ### intersect(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead. - intersect(range: Scope): Scope Obtains the intersection of this **Scope** and the given **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2620,14 +2666,14 @@ Obtains the intersection of this **Scope** and the given **Scope**. ### intersect(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead. - intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope Obtains the intersection of this **Scope** and the given lower and upper limits. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2644,6 +2690,7 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. | [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -2655,14 +2702,14 @@ Obtains the intersection of this **Scope** and the given lower and upper limits. ### getUpper(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [getUpper9+](#getupper9) instead. - getUpper(): ScopeType Obtains the upper limit of this **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getUpper9+](#getupper9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -2672,6 +2719,7 @@ Obtains the upper limit of this **Scope**. | [ScopeType](#scopetype8) | Upper limit of this **Scope**.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -2681,14 +2729,14 @@ Obtains the upper limit of this **Scope**. ### getLower(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [getLower9+](#getlower9) instead. - getLower(): ScopeType Obtains the lower limit of this **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLower9+](#getlower9) instead. + **System capability**: SystemCapability.Utils.Lang **Return value** @@ -2698,6 +2746,7 @@ Obtains the lower limit of this **Scope**. | [ScopeType](#scopetype8) | Lower limit of this **Scope**.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -2707,14 +2756,14 @@ Obtains the lower limit of this **Scope**. ### expand(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead. - expand(lowerObj: ScopeType,upperObj: ScopeType): Scope Obtains the union set of this **Scope** and the given lower and upper limits. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand9+](#expand9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2743,14 +2792,14 @@ Obtains the union set of this **Scope** and the given lower and upper limits. ### expand(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead. - expand(range: Scope): Scope Obtains the union set of this **Scope** and the given **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand9+](#expand9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2766,6 +2815,7 @@ Obtains the union set of this **Scope** and the given **Scope**. | [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -2778,14 +2828,14 @@ Obtains the union set of this **Scope** and the given **Scope**. ### expand(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead. - expand(value: ScopeType): Scope Obtains the union set of this **Scope** and the given value. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand9+](#expand9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2801,6 +2851,7 @@ Obtains the union set of this **Scope** and the given value. | [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -2811,14 +2862,14 @@ Obtains the union set of this **Scope** and the given value. ### contains(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead. - contains(value: ScopeType): boolean Checks whether a value is within this **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains9+](#contains9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2834,6 +2885,7 @@ Checks whether a value is within this **Scope**. | boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -2844,14 +2896,14 @@ Checks whether a value is within this **Scope**. ### contains(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead. - contains(range: Scope): boolean Checks whether a range is within this **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains9+](#contains9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2880,14 +2932,15 @@ Checks whether a range is within this **Scope**. ### clamp(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [clamp9+](#clamp9) instead. clamp(value: ScopeType): ScopeType Limits a value to this **Scope**. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clamp9+](#clamp9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -2903,6 +2956,7 @@ Limits a value to this **Scope**. | [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.| **Example** + ```js let tempLower = new Temperature(30); let tempUpper = new Temperature(40); @@ -3117,35 +3171,36 @@ that.decode(array).then(val=>{ > **NOTE** > -> This class is deprecated since API version 9. You are advised to use [Base64Helper9+](#base64helper9) instead. +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper9+](#base64helper9) instead. ### constructor(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. - constructor() A constructor used to create a **Base64** object. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead. + **System capability**: SystemCapability.Utils.Lang **Example** + ```js let base64 = new util.Base64(); ``` ### encodeSync(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [encodeSync9+](#encodesync9) instead. - encodeSync(src: Uint8Array): Uint8Array Encodes the input content. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeSync9+](#encodesync9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -3170,14 +3225,14 @@ Encodes the input content. ### encodeToStringSync(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [encodeToStringSync9+](#encodetostringsync9) instead. - encodeToStringSync(src: Uint8Array): string Encodes the input content. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToStringSync9+](#encodetostringsync9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -3193,6 +3248,7 @@ Encodes the input content. | string | String encoded from the Uint8Array.| **Example** + ```js let that = new util.Base64(); let array = new Uint8Array([115,49,51]); @@ -3201,14 +3257,14 @@ Encodes the input content. ### decodeSync(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [decodeSync9+](#decodesync9) instead. - decodeSync(src: Uint8Array | string): Uint8Array Decodes the input content. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decodeSync9+](#decodesync9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -3224,6 +3280,7 @@ Decodes the input content. | Uint8Array | Uint8Array decoded.| **Example** + ```js let that = new util.Base64(); let buff = 'czEz'; @@ -3232,14 +3289,14 @@ Decodes the input content. ### encode(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [encode9+](#encode9) instead. - encode(src: Uint8Array): Promise<Uint8Array> Encodes the input content asynchronously. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encode9+](#encode9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -3255,6 +3312,7 @@ Encodes the input content asynchronously. | Promise<Uint8Array> | Uint8Array obtained after asynchronous encoding.| **Example** + ```js let that = new util.Base64(); let array = new Uint8Array([115,49,51]); @@ -3268,14 +3326,14 @@ Encodes the input content asynchronously. ### encodeToString(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [encodeToString9+](#encodetostring9) instead. - encodeToString(src: Uint8Array): Promise<string> Encodes the input content asynchronously. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToString9+](#encodetostring9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -3291,6 +3349,7 @@ Encodes the input content asynchronously. | Promise<string> | String obtained after asynchronous encoding.| **Example** + ```js let that = new util.Base64(); let array = new Uint8Array([115,49,51]); @@ -3301,14 +3360,15 @@ Encodes the input content asynchronously. ### decode(deprecated) -> **NOTE** -> -> This API is deprecated since API version 9. You are advised to use [decode9+](#decode9) instead. decode(src: Uint8Array | string): Promise<Uint8Array> Decodes the input content asynchronously. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decode9+](#decode9) instead. + **System capability**: SystemCapability.Utils.Lang **Parameters** @@ -3324,6 +3384,7 @@ Decodes the input content asynchronously. | Promise<Uint8Array> | Uint8Array obtained after asynchronous decoding.| **Example** + ```js let that = new util.Base64(); let array = new Uint8Array([99,122,69,122]); @@ -3347,6 +3408,7 @@ A constructor used to create a **Types** object. **System capability**: SystemCapability.Utils.Lang **Example** + ```js let type = new util.types(); ``` @@ -3373,6 +3435,7 @@ Checks whether the input value is of the **ArrayBuffer** type. | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isAnyArrayBuffer(new ArrayBuffer(0)); @@ -3402,6 +3465,7 @@ Checks whether the input value is of the **ArrayBufferView** type. | boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isArrayBufferView(new Int8Array([])); @@ -3429,6 +3493,7 @@ Checks whether the input value is of the **arguments** type. | boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); function foo() { @@ -3459,6 +3524,7 @@ Checks whether the input value is of the **ArrayBuffer** type. | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isArrayBuffer(new ArrayBuffer(0)); @@ -3486,6 +3552,7 @@ Checks whether the input value is an asynchronous function. | boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isAsyncFunction(async function foo() {}); @@ -3513,6 +3580,7 @@ Checks whether the input value is of the **Boolean** type. | boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isBooleanObject(new Boolean(true)); @@ -3540,6 +3608,7 @@ Checks whether the input value is of the **Boolean**, **Number**, **String**, or | boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isBoxedPrimitive(new Boolean(false)); @@ -3567,6 +3636,7 @@ Checks whether the input value is of the **DataView** type. | boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); const ab = new ArrayBuffer(20); @@ -3595,6 +3665,7 @@ Checks whether the input value is of the **Date** type. | boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isDate(new Date()); @@ -3622,6 +3693,7 @@ Checks whether the input value is of the **native external** type. | boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isExternal(true); @@ -3649,6 +3721,7 @@ Checks whether the input value is of the **Float32Array** type. | boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isFloat32Array(new Float32Array()); @@ -3676,6 +3749,7 @@ Checks whether the input value is of the **Float64Array** type. | boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isFloat64Array(new Float64Array()); @@ -3703,6 +3777,7 @@ Checks whether the input value is a generator function. | boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isGeneratorFunction(function* foo() {}); @@ -3730,6 +3805,7 @@ Checks whether the input value is a generator object. | boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.| **Example** + ```js let that = new util.types(); function* foo() {} @@ -3759,6 +3835,7 @@ Checks whether the input value is of the **Int8Array** type. | boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isInt8Array(new Int8Array([])); @@ -3786,6 +3863,7 @@ Checks whether the input value is of the **Int16Array** type. | boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isInt16Array(new Int16Array([])); @@ -3813,6 +3891,7 @@ Checks whether the input value is of the **Int32Array** type. | boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isInt32Array(new Int32Array([])); @@ -3840,6 +3919,7 @@ Checks whether the input value is of the **Map** type. | boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isMap(new Map()); @@ -3856,6 +3936,7 @@ Checks whether the input value is of the **MapIterator** type. **Parameters** + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | Object | Yes| Object to check.| @@ -3867,6 +3948,7 @@ Checks whether the input value is of the **MapIterator** type. | boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); const map = new Map(); @@ -3895,6 +3977,7 @@ Checks whether the input value is of the **Error** type. | boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isNativeError(new TypeError()); @@ -3922,6 +4005,7 @@ Checks whether the input value is a number object. | boolean | Returns **true** if the input value is a number object; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isNumberObject(new Number(0)); @@ -3949,6 +4033,7 @@ Checks whether the input value is a promise. | boolean | Returns **true** if the input value is a promise; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isPromise(Promise.resolve(1)); @@ -3976,6 +4061,7 @@ Checks whether the input value is a proxy. | boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.| **Example** + ```js let that = new util.types(); const target = {}; @@ -4005,6 +4091,7 @@ Checks whether the input value is of the **RegExp** type. | boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isRegExp(new RegExp('abc')); @@ -4032,6 +4119,7 @@ Checks whether the input value is of the **Set** type. | boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isSet(new Set()); @@ -4059,6 +4147,7 @@ Checks whether the input value is of the **SetIterator** type. | boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); const set = new Set(); @@ -4087,6 +4176,7 @@ Checks whether the input value is a string object. | boolean | Returns **true** if the input value is a string object; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isStringObject(new String('foo')); @@ -4114,6 +4204,7 @@ Checks whether the input value is a symbol object. | boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.| **Example** + ```js let that = new util.types(); const symbols = Symbol('foo'); @@ -4144,6 +4235,7 @@ Checks whether the input value is of the **TypedArray** type. | boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isTypedArray(new Float64Array([])); @@ -4171,6 +4263,7 @@ Checks whether the input value is of the **Uint8Array** type. | boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isUint8Array(new Uint8Array([])); @@ -4198,6 +4291,7 @@ Checks whether the input value is of the **Uint8ClampedArray** type. | boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isUint8ClampedArray(new Uint8ClampedArray([])); @@ -4225,6 +4319,7 @@ Checks whether the input value is of the **Uint16Array** type. | boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isUint16Array(new Uint16Array([])); @@ -4252,6 +4347,7 @@ Checks whether the input value is of the **Uint32Array** type. | boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isUint32Array(new Uint32Array([])); @@ -4279,6 +4375,7 @@ Checks whether the input value is of the **WeakMap** type. | boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isWeakMap(new WeakMap()); @@ -4306,6 +4403,7 @@ Checks whether the input value is of the **WeakSet** type. | boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isWeakSet(new WeakSet()); @@ -4333,6 +4431,7 @@ Checks whether the input value is of the **BigInt64Array** type. | boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isBigInt64Array(new BigInt64Array([])); @@ -4360,6 +4459,7 @@ Checks whether the input value is of the **BigUint64Array** type. | boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isBigUint64Array(new BigUint64Array([])); @@ -4387,6 +4487,7 @@ Checks whether the input value is a module namespace object. | boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.| **Example** + ```js import url from '@ohos.url' let that = new util.types(); @@ -4415,6 +4516,7 @@ Checks whether the input value is of the **SharedArrayBuffer** type. | boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.| **Example** + ```js let that = new util.types(); let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));