js-apis-util.md 111.8 KB
Newer Older
1
# @ohos.util (util)
Z
zengyawen 已提交
2

S
shawn_he 已提交
3
The **util** module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types.
Z
zengyawen 已提交
4

W
wusongqing 已提交
5 6
> **NOTE**
>
W
wusongqing 已提交
7
> 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.
Z
zengyawen 已提交
8

W
wusongqing 已提交
9 10

## Modules to Import
Z
zengyawen 已提交
11

12
```js
Z
zengyawen 已提交
13 14 15
import util from '@ohos.util';
```

G
Gloria 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28
## 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.|
G
Gloria 已提交
29
| ...args | Object[] | No  | Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
G
Gloria 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

**Return value**

| Type  | Description                        |
| ------ | ---------------------------- |
| string | String containing the formatted values.|

**Example**

  ```js
let res = util.format("%s", "hello world!");
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**

66
```js
67
let errnum = -1; // -1 is a system error code.
G
Gloria 已提交
68 69
let result = util.errnoToString(errnum);
console.log("result = " + result);
70
```
G
Gloria 已提交
71

G
Gloria 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85
**Some error code and message examples**

| Error Code| Message                             |
| ------ | -------------------------------- |
| -1     | operation not permitted          |
| -2     | no such file or directory        |
| -3     | no such process                  |
| -4     | interrupted system call          |
| -5     | i/o error                        |
| -11    | resource temporarily unavailable |
| -12    | not enough memory                |
| -13    | permission denied                |
| -100   | network is down                  |

W
wusongqing 已提交
86 87 88 89
## util.callbackWrapper

callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void

G
Gloria 已提交
90
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.
Z
zengyawen 已提交
91

W
wusongqing 已提交
92 93 94 95
**System capability**: SystemCapability.Utils.Lang

**Parameters**

W
wusongqing 已提交
96 97 98
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|
Z
zengyawen 已提交
99

W
wusongqing 已提交
100
**Return value**
101

W
wusongqing 已提交
102 103 104
| Type| Description|
| -------- | -------- |
| Function | Callback, in which the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved) and the second parameter indicates the resolved value.|
Z
zengyawen 已提交
105

W
wusongqing 已提交
106
**Example**
107

108
  ```js
G
Gloria 已提交
109 110 111 112
async function fn() {
   return 'hello world';
}
let cb = util.callbackWrapper(fn);
G
Gloria 已提交
113
cb(1, (err, ret) => {
G
Gloria 已提交
114 115 116
   if (err) throw err;
   console.log(ret);
});
W
wusongqing 已提交
117 118
  ```

S
shikai-123 已提交
119
## util.promisify<sup>9+</sup>
S
shikai-123 已提交
120

S
shikai-123 已提交
121
promisify(original: (err: Object, value: Object) =&gt; void): Function
S
shikai-123 已提交
122

W
wusongqing 已提交
123
Processes an asynchronous function and returns a promise.
S
shikai-123 已提交
124 125 126 127

**System capability**: SystemCapability.Utils.Lang

**Parameters**
128

S
shikai-123 已提交
129 130 131 132 133
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|

**Return value**
134

S
shikai-123 已提交
135 136
| Type| Description|
| -------- | -------- |
W
wusongqing 已提交
137
| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
S
shikai-123 已提交
138

W
wusongqing 已提交
139
**Example**
140

141
  ```js
G
Gloria 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
function fun(num, callback) {
   if (typeof num === 'number') {
      callback(null, num + 3);
   } else {
      callback("type err");
   }
}

const addCall = util.promisify(fun);
(async () => {
   try {
      let res = await addCall(2);
      console.log(res);
   } catch (err) {
      console.log(err);
   }
})();
W
wusongqing 已提交
159 160
  ```

G
Gloria 已提交
161
## util.generateRandomUUID<sup>9+</sup>
162

G
Gloria 已提交
163
generateRandomUUID(entropyCache?: boolean): string
164

G
Gloria 已提交
165
Uses a secure random number generator to generate a random universally unique identifier (UUID) of the string type in RFC 4122 version 4.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.|

**Return value**

| Type| Description|
| -------- | -------- |
| string | A string representing the UUID generated.|

**Example**
182

183
  ```js
G
Gloria 已提交
184
  let uuid = util.generateRandomUUID(true);
185 186 187 188 189
  console.log("RFC 4122 Version 4 UUID:" + uuid);
  // Output:
  // RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
  ```

G
Gloria 已提交
190
## util.generateRandomBinaryUUID<sup>9+</sup>
191

G
Gloria 已提交
192
generateRandomBinaryUUID(entropyCache?: boolean): Uint8Array
193

G
Gloria 已提交
194
Uses a secure random number generator to generate a random UUID of the Uint8Array type in RFC 4122 version 4.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.|

**Return value**

| Type| Description|
| -------- | -------- |
| Uint8Array | A Uint8Array value representing the UUID generated.|

**Example**
211

212
  ```js
G
Gloria 已提交
213
  let uuid = util.generateRandomBinaryUUID(true);
214 215 216 217 218 219 220 221 222
  console.log(JSON.stringify(uuid));
  // Output:
  // 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150
  ```

## util.parseUUID<sup>9+</sup>

parseUUID(uuid: string): Uint8Array

G
Gloria 已提交
223
Converts the UUID of the string type generated by **generateRandomUUID** to the UUID of the **Uint8Array** type generated by **generateRandomBinaryUUID**, as described in RFC 4122 version 4.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| uuid | string | Yes| A string representing the UUID.|

**Return value**

| Type| Description|
| -------- | -------- |
| Uint8Array | A Uint8Array value representing the UUID parsed. If the parsing fails, **SyntaxError** is thrown.|

**Example**
240

241 242 243 244 245 246 247
  ```js
  let uuid = util.parseUUID("84bdf796-66cc-4655-9b89-d6218d100f9c");
  console.log(JSON.stringify(uuid));
  // Output:
  // 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156
  ```

248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
## util.printf<sup>(deprecated)</sup>

printf(format: string,  ...args: Object[]): string

Formats the specified values and inserts them into the string by replacing the wildcard in the string.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.format<sup>9+</sup>](#utilformat9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| format | string | Yes| String.|
G
Gloria 已提交
265
| ...args | Object[] | No| Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

**Return value**

| Type| Description|
| -------- | -------- |
| string | String containing the formatted values.|

**Example**

  ```js
  let res = util.printf("%s", "hello world!");
  console.log(res);
  ```


## util.getErrorString<sup>(deprecated)</sup>

getErrorString(errno: number): string

Obtains detailed information about a system error code.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.errnoToString<sup>9+</sup>](#utilerrnotostring9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errno | number | Yes| Error code generated.|

**Return value**

| Type| Description|
| -------- | -------- |
| string | Detailed information about the error code.|

**Example**

  ```js
  let errnum = -1; // -1 is a system error code.
  let result = util.getErrorString(errnum);
  console.log("result = " + result);
  ```

## util.promiseWrapper<sup>(deprecated)</sup>

promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object

Processes an asynchronous function and returns a promise.

> **NOTE**
>
> This API is unavailable. You are advised to use [util.promisify<sup>9+</sup>](#utilpromisify9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|

**Return value**

| Type| Description|
| -------- | -------- |
| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|


W
wusongqing 已提交
338 339 340 341
## TextDecoder

### Attributes

W
wusongqing 已提交
342 343
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
344 345 346 347 348
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format.<br>- Supported formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u, macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, x-mac-cyrilli, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, euc-kr, utf-16be, utf-16le|
| 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.|
W
wusongqing 已提交
349

G
Gloria 已提交
350
### constructor<sup>9+</sup>
W
wusongqing 已提交
351

G
Gloria 已提交
352 353 354 355 356 357 358 359
constructor()

A constructor used to create a **TextDecoder** object.

**System capability**: SystemCapability.Utils.Lang

### create<sup>9+</sup>

360
create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoder;
G
Gloria 已提交
361 362 363

Creates a **TextDecoder** object. It provides the same function as the deprecated argument constructor.

364 365
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
366 367 368 369 370 371 372
**Parameters**

| Name  | Type  | Mandatory| Description                                            |
| -------- | ------ | ---- | ------------------------------------------------ |
| encoding | string | No  | Encoding format.                                      |
| options  | Object | No  | Encoding-related options, which include **fatal** and **ignoreBOM**.|

373
**Table 1.1** options
G
Gloria 已提交
374 375 376 377 378 379 380 381

| Name     | Type| Mandatory| Description              |
| --------- | -------- | ---- | ------------------ |
| fatal     | boolean  | No  | Whether to display fatal errors.|
| ignoreBOM | boolean  | No  | Whether to ignore the BOM. |

**Example**

382
```js
G
Gloria 已提交
383 384
let result = util.TextDecoder.create('utf-8', { ignoreBOM : true })
let retStr = result.encoding
385
```
G
Gloria 已提交
386

387
### decodeWithStream<sup>9+</sup>
W
wusongqing 已提交
388

389
decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string
Z
zengyawen 已提交
390

Z
zengyawen 已提交
391
Decodes the input content.
Z
zengyawen 已提交
392

W
wusongqing 已提交
393 394 395
**System capability**: SystemCapability.Utils.Lang

**Parameters**
396

W
wusongqing 已提交
397 398
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
399
| input | Uint8Array | Yes| Uint8Array to decode.|
W
wusongqing 已提交
400
| options | Object | No| Options related to decoding.|
W
wusongqing 已提交
401

402
**Table 2** options
W
wusongqing 已提交
403

W
wusongqing 已提交
404 405
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
406
| stream | boolean | No| Whether to allow data blocks in subsequent **decodeWithStream()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
Z
zengyawen 已提交
407

W
wusongqing 已提交
408
**Return value**
409

W
wusongqing 已提交
410 411 412
| Type| Description|
| -------- | -------- |
| string | Data decoded.|
Z
zengyawen 已提交
413

W
wusongqing 已提交
414
**Example**
415

416
  ```js
417 418
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  let result = new Uint8Array(6);
W
wusongqing 已提交
419 420 421 422 423 424 425
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
426
  let retStr = textDecoder.decodeWithStream( result , {stream: false});
427 428 429
  console.log("retStr = " + retStr);
  ```

430
### constructor<sup>(deprecated)</sup>
431

432
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean })
433

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
A constructor used to create a **TextDecoder** object.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [create<sup>9+</sup>](#create9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.|
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|

  **Table 1** options

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fatal | boolean | No| Whether to display fatal errors.|
| ignoreBOM | boolean | No| Whether to ignore the BOM.|

**Example**

  ```js
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  ```

### decode<sup>(deprecated)</sup>

decode(input: Uint8Array, options?: { stream?: false }): string
465 466 467

Decodes the input content.

468 469 470 471
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [decodeWithStream<sup>9+</sup>](#decodewithstream9) instead.

472 473 474 475 476 477 478 479 480
**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| input | Uint8Array | Yes| Uint8Array to decode.|
| options | Object | No| Options related to decoding.|

481
**Table 2** options
482 483 484

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
485
| stream | boolean | No| Whether to allow data blocks in subsequent **decode()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
486 487 488 489 490 491 492 493

**Return value**

| Type| Description|
| -------- | -------- |
| string | Data decoded.|

**Example**
494

495 496 497 498 499 500 501 502 503 504
  ```js
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  let result = new Uint8Array(6);
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
505
  let retStr = textDecoder.decode( result , {stream: false});
W
wusongqing 已提交
506 507
  console.log("retStr = " + retStr);
  ```
Z
zengyawen 已提交
508

W
wusongqing 已提交
509
## TextEncoder
Z
zengyawen 已提交
510

W
wusongqing 已提交
511
### Attributes
Z
zengyawen 已提交
512

W
wusongqing 已提交
513 514
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
515 516 517
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
Z
zengyawen 已提交
518

G
Gloria 已提交
519

W
wusongqing 已提交
520
### constructor
Z
zengyawen 已提交
521

W
wusongqing 已提交
522
constructor()
Z
zengyawen 已提交
523

W
wusongqing 已提交
524
A constructor used to create a **TextEncoder** object.
Z
zengyawen 已提交
525

W
wusongqing 已提交
526 527 528
**System capability**: SystemCapability.Utils.Lang

**Example**
529

530
  ```js
531
  let textEncoder = new util.TextEncoder();
W
wusongqing 已提交
532 533
  ```

534
### constructor<sup>9+</sup>
G
Gloria 已提交
535

536
constructor(encoding?: string)
G
Gloria 已提交
537

538
A constructor used to create a **TextEncoder** object.
G
Gloria 已提交
539 540 541 542 543

**System capability**: SystemCapability.Utils.Lang

**Parameters**

544 545 546
| Name| Type| Mandatory| Description|
| ----- | ---- | ---- | ---- |
| encoding | string | No| Encoding format.|
G
Gloria 已提交
547 548 549 550

**Example**

  ```js
551
  let textEncoder = new util.TextEncoder("utf-8");
G
Gloria 已提交
552 553
  ```

554
### encodeInto<sup>9+</sup>
W
wusongqing 已提交
555

556
encodeInto(input?: string): Uint8Array
Z
zengyawen 已提交
557

Z
zengyawen 已提交
558
Encodes the input content.
Z
zengyawen 已提交
559

W
wusongqing 已提交
560 561 562
**System capability**: SystemCapability.Utils.Lang

**Parameters**
563

564 565 566
| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| input  | string | No  | String to encode.|
W
wusongqing 已提交
567

W
wusongqing 已提交
568
**Return value**
569

570 571
| Type      | Description              |
| ---------- | ------------------ |
W
wusongqing 已提交
572
| Uint8Array | Encoded text.|
W
wusongqing 已提交
573

W
wusongqing 已提交
574
**Example**
575

576
  ```js
577 578 579 580
let textEncoder = new util.TextEncoder();
let buffer = new ArrayBuffer(20);
let result = new Uint8Array(buffer);
result = textEncoder.encodeInto("\uD800¥¥");
W
wusongqing 已提交
581 582
  ```

G
Gloria 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
### 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()
611
result = that.encodeIntoUint8Array('abcd', dest)
G
Gloria 已提交
612 613 614
  ```

### encodeInto<sup>(deprecated)</sup>
W
wusongqing 已提交
615

X
xdmal 已提交
616
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
Z
zengyawen 已提交
617 618 619

Stores the UTF-8 encoded text.

620 621 622 623
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeIntoUint8Array<sup>9+</sup>](#encodeintouint8array9) instead.

W
wusongqing 已提交
624 625 626
**System capability**: SystemCapability.Utils.Lang

**Parameters**
627

W
wusongqing 已提交
628 629 630 631
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| input | string | Yes| String to encode.|
| dest | Uint8Array | Yes| **Uint8Array** instance used to store the UTF-8 encoded text.|
Z
zengyawen 已提交
632

W
wusongqing 已提交
633
**Return value**
634

W
wusongqing 已提交
635 636 637
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
Z
zengyawen 已提交
638

W
wusongqing 已提交
639
**Example**
640
  ```js
641 642 643 644
  let that = new util.TextEncoder()
  let buffer = new ArrayBuffer(4)
  let dest = new Uint8Array(buffer)
  let result = new Object()
S
shikai-123 已提交
645
  result = that.encodeInto('abcd', dest)
W
wusongqing 已提交
646
  ```
Z
zengyawen 已提交
647

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
### encode<sup>(deprecated)</sup>

encode(input?: string): Uint8Array

Encodes the input content.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeInto<sup>9+</sup>](#encodeinto9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| input | string | No| String to encode.|

**Return value**

| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|

**Example**
  ```js
  let textEncoder = new util.TextEncoder();
  let buffer = new ArrayBuffer(20);
  let result = new Uint8Array(buffer);
  result = textEncoder.encode("\uD800¥¥");
  ```

W
wusongqing 已提交
680
## RationalNumber<sup>8+</sup>
Z
zengyawen 已提交
681

G
Gloria 已提交
682
### constructor<sup>9+</sup>
Z
zengyawen 已提交
683

G
Gloria 已提交
684 685 686 687 688 689 690 691
constructor()

A constructor used to create a **RationalNumber** object.

**System capability**: SystemCapability.Utils.Lang

**Example**

692
```js
G
Gloria 已提交
693
let rationalNumber = new util.RationalNumber();
694
```
G
Gloria 已提交
695 696 697

### parseRationalNumber<sup>9+</sup>

698
parseRationalNumber(numerator: number,denominator: number): RationalNumber
G
Gloria 已提交
699 700 701 702 703 704 705 706 707 708 709 710 711 712

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**

713 714 715
```js
let rationalNumber = util.RationalNumber.parseRationalNumber(1,2)
```
G
Gloria 已提交
716

W
wusongqing 已提交
717
### createRationalFromString<sup>8+</sup>
Z
zengyawen 已提交
718

X
xdmal 已提交
719
static createRationalFromString​(rationalString: string): RationalNumber​
Z
zengyawen 已提交
720

W
wusongqing 已提交
721
Creates a **RationalNumber** object based on the given string.
Z
zengyawen 已提交
722

W
wusongqing 已提交
723 724 725
**System capability**: SystemCapability.Utils.Lang

**Parameters**
726

W
wusongqing 已提交
727 728 729
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rationalString | string | Yes| String used to create the **RationalNumber** object.|
Z
zengyawen 已提交
730

W
wusongqing 已提交
731
**Return value**
732

W
wusongqing 已提交
733 734 735
| Type| Description|
| -------- | -------- |
| object | **RationalNumber** object created.|
Z
zengyawen 已提交
736

W
wusongqing 已提交
737
**Example**
738 739 740 741 742

```js
let rationalNumber = new util.RationalNumber(1,2);
let rational = util.RationalNumber.createRationalFromString("3/4");
```
Z
zengyawen 已提交
743

G
Gloria 已提交
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
### 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);
  ```

W
wusongqing 已提交
772
### valueOf<sup>8+</sup>
Z
zengyawen 已提交
773

X
xdmal 已提交
774
valueOf(): number
Z
zengyawen 已提交
775

W
wusongqing 已提交
776
Obtains the value of this **RationalNumber** object as an integer or a floating-point number.
Z
zengyawen 已提交
777

W
wusongqing 已提交
778 779 780
**System capability**: SystemCapability.Utils.Lang

**Return value**
781

W
wusongqing 已提交
782 783 784
| Type| Description|
| -------- | -------- |
| number | An integer or a floating-point number.|
Z
zengyawen 已提交
785

W
wusongqing 已提交
786
**Example**
787 788 789 790 791

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.valueOf();
```
Z
zengyawen 已提交
792

W
wusongqing 已提交
793
### equals<sup>8+</sup>
Z
zengyawen 已提交
794

X
xdmal 已提交
795
equals​(obj: Object): boolean
Z
zengyawen 已提交
796

W
wusongqing 已提交
797
Checks whether this **RationalNumber** object equals the given object.
Z
zengyawen 已提交
798

W
wusongqing 已提交
799 800 801
**System capability**: SystemCapability.Utils.Lang

**Parameters**
802

W
wusongqing 已提交
803 804 805
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | Object | Yes| Object used to compare with this **RationalNumber** object.|
Z
zengyawen 已提交
806

W
wusongqing 已提交
807
**Return value**
808

W
wusongqing 已提交
809 810 811
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the two objects are equal; returns **false** otherwise.|
Z
zengyawen 已提交
812

W
wusongqing 已提交
813
**Example**
814 815 816 817 818 819

```js
let rationalNumber = new util.RationalNumber(1,2);
let rational = util.RationalNumber.createRationalFromString("3/4");
let result = rationalNumber.equals(rational);
```
Z
zengyawen 已提交
820

G
Gloria 已提交
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
### 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.|
Z
zengyawen 已提交
841

G
Gloria 已提交
842 843
**Example**

844
```js
G
Gloria 已提交
845 846
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonFactor(4,6);
847
```
G
Gloria 已提交
848

W
wusongqing 已提交
849
### getNumerator<sup>8+</sup>
Z
zengyawen 已提交
850

X
xdmal 已提交
851
getNumerator​(): number
Z
zengyawen 已提交
852

W
wusongqing 已提交
853
Obtains the numerator of this **RationalNumber** object.
Z
zengyawen 已提交
854

W
wusongqing 已提交
855 856 857 858
**System capability**: SystemCapability.Utils.Lang

**Return value**

W
wusongqing 已提交
859 860 861
| Type| Description|
| -------- | -------- |
| number | Numerator of this **RationalNumber** object.|
Z
zengyawen 已提交
862

W
wusongqing 已提交
863
**Example**
864 865 866 867 868

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.getNumerator();
```
Z
zengyawen 已提交
869

W
wusongqing 已提交
870
### getDenominator<sup>8+</sup>
Z
zengyawen 已提交
871

X
xdmal 已提交
872
getDenominator​(): number
Z
zengyawen 已提交
873

W
wusongqing 已提交
874
Obtains the denominator of this **RationalNumber** object.
Z
zengyawen 已提交
875

W
wusongqing 已提交
876 877 878
**System capability**: SystemCapability.Utils.Lang

**Return value**
879

W
wusongqing 已提交
880 881 882
| Type| Description|
| -------- | -------- |
| number | Denominator of this **RationalNumber** object.|
Z
zengyawen 已提交
883

W
wusongqing 已提交
884
**Example**
885 886 887 888 889

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.getDenominator();
```
Z
zengyawen 已提交
890

W
wusongqing 已提交
891
### isZero<sup>8+</sup>
Z
zengyawen 已提交
892

W
wusongqing 已提交
893
isZero​():boolean
Z
zengyawen 已提交
894

W
wusongqing 已提交
895
Checks whether this **RationalNumber** object is **0**.
Z
zengyawen 已提交
896

W
wusongqing 已提交
897 898 899
**System capability**: SystemCapability.Utils.Lang

**Return value**
900

W
wusongqing 已提交
901 902 903
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
Z
zengyawen 已提交
904

W
wusongqing 已提交
905
**Example**
906 907 908 909 910

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.isZero();
```
Z
zengyawen 已提交
911

W
wusongqing 已提交
912
### isNaN<sup>8+</sup>
Z
zengyawen 已提交
913

X
xdmal 已提交
914
isNaN​(): boolean
Z
zengyawen 已提交
915

W
wusongqing 已提交
916
Checks whether this **RationalNumber** object is a Not a Number (NaN).
Z
zengyawen 已提交
917

W
wusongqing 已提交
918 919 920
**System capability**: SystemCapability.Utils.Lang

**Return value**
921

W
wusongqing 已提交
922 923 924
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.|
Z
zengyawen 已提交
925

W
wusongqing 已提交
926
**Example**
927 928 929 930 931

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.isNaN();
```
Z
zengyawen 已提交
932

W
wusongqing 已提交
933
### isFinite<sup>8+</sup>
Z
zengyawen 已提交
934

W
wusongqing 已提交
935
isFinite​():boolean
Z
zengyawen 已提交
936

W
wusongqing 已提交
937
Checks whether this **RationalNumber** object represents a finite value.
Z
zengyawen 已提交
938

W
wusongqing 已提交
939 940 941
**System capability**: SystemCapability.Utils.Lang

**Return value**
942

W
wusongqing 已提交
943 944 945
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.|
Z
zengyawen 已提交
946

W
wusongqing 已提交
947
**Example**
948 949 950 951 952

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.isFinite();
```
Z
zengyawen 已提交
953

W
wusongqing 已提交
954
### toString<sup>8+</sup>
Z
zengyawen 已提交
955

X
xdmal 已提交
956
toString​(): string
Z
zengyawen 已提交
957

W
wusongqing 已提交
958
Obtains the string representation of this **RationalNumber** object.
Z
zengyawen 已提交
959

W
wusongqing 已提交
960 961 962
**System capability**: SystemCapability.Utils.Lang

**Return value**
963

W
wusongqing 已提交
964 965 966
| Type| Description|
| -------- | -------- |
| string | Returns **NaN** if the numerator and denominator of this object are both **0**; returns a string in Numerator/Denominator format otherwise, for example, **3/5**.|
Z
zengyawen 已提交
967

W
wusongqing 已提交
968
**Example**
969 970 971 972 973

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = rationalNumber.toString();
```
Z
zengyawen 已提交
974

975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
### constructor<sup>(deprecated)</sup>

constructor(numerator: number,denominator: number)

A constructor used to create a **RationalNumber** object.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| numerator | number | Yes| Numerator, which is an integer.|
| denominator | number | Yes| Denominator, which is an integer.|

**Example**

```js
let rationalNumber = new util.RationalNumber(1,2);
```

### compareTo<sup>(deprecated)</sup>

compareTo​(another: RationalNumber): number​

Compares this **RationalNumber** object with a given object.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [compare<sup>9+</sup>](#compare9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|

**Return value**

| Type| Description|
| -------- | -------- |
| number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.|

**Example**

```js
let rationalNumber = new util.RationalNumber(1,2);
let rational = util.RationalNumber.createRationalFromString("3/4");
let result = rationalNumber.compareTo(rational);
```

### getCommonDivisor<sup>(deprecated)</sup>

static getCommonDivisor​(number1: number,number2: number): number

Obtains the greatest common divisor of two specified integers.

> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCommonFactor<sup>9+</sup>](#getcommonfactor9) instead.

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| number1 | number | Yes| The first integer used to get the greatest common divisor.|
| number2 | number | Yes| The second integer used to get the greatest common divisor.|

**Return value**

| Type| Description|
| -------- | -------- |
| number | Greatest common divisor obtained.|

**Example**

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonDivisor(4,6);
```
G
Gloria 已提交
1063 1064

## LRUCache<sup>9+</sup>
Z
zengyawen 已提交
1065

W
wusongqing 已提交
1066
### Attributes
Z
zengyawen 已提交
1067

W
wusongqing 已提交
1068 1069
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
1070 1071
| Name  | Type  | Readable| Writable| Description                  |
| ------ | ------ | ---- | ---- | ---------------------- |
1072
| length | number | Yes  | No  | Total number of values in this cache.|
Z
zengyawen 已提交
1073

W
wusongqing 已提交
1074
**Example**
G
Gloria 已提交
1075

1076
```js
G
Gloria 已提交
1077 1078 1079 1080
let pro = new util.LRUCache();
pro.put(2,10);
pro.put(1,8);
let result = pro.length;
1081
```
Z
zengyawen 已提交
1082

G
Gloria 已提交
1083
### constructor<sup>9+</sup>
Z
zengyawen 已提交
1084

X
xdmal 已提交
1085
constructor(capacity?: number)
Z
zengyawen 已提交
1086

1087
A constructor used to create a **LruCache** instance. The default capacity of the cache is 64.
Z
zengyawen 已提交
1088

W
wusongqing 已提交
1089 1090 1091
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1092

G
Gloria 已提交
1093 1094
| Name  | Type  | Mandatory| Description                        |
| -------- | ------ | ---- | ---------------------------- |
1095
| capacity | number | No  | Capacity of the **LruCache** to create.|
Z
zengyawen 已提交
1096

W
wusongqing 已提交
1097
**Example**
G
Gloria 已提交
1098

1099
```js
G
Gloria 已提交
1100
let lrubuffer= new util.LRUCache();
1101
```
Z
zengyawen 已提交
1102 1103


G
Gloria 已提交
1104
### updateCapacity<sup>9+</sup>
Z
zengyawen 已提交
1105

X
xdmal 已提交
1106
updateCapacity(newCapacity: number): void
Z
zengyawen 已提交
1107

1108
Changes the **LruCache** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
Z
zengyawen 已提交
1109

W
wusongqing 已提交
1110 1111 1112
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1113

G
Gloria 已提交
1114 1115
| Name     | Type  | Mandatory| Description                        |
| ----------- | ------ | ---- | ---------------------------- |
1116
| newCapacity | number | Yes  | New capacity of the **LruCache**.|
Z
zengyawen 已提交
1117

W
wusongqing 已提交
1118
**Example**
G
Gloria 已提交
1119

1120
```js
G
Gloria 已提交
1121 1122
let pro = new util.LRUCache();
let result = pro.updateCapacity(100);
1123
```
Z
zengyawen 已提交
1124 1125


G
Gloria 已提交
1126
### toString<sup>9+</sup>
Z
zengyawen 已提交
1127

X
xdmal 已提交
1128
toString(): string
Z
zengyawen 已提交
1129

1130
Obtains the string representation of this **LruCache** object.
Z
zengyawen 已提交
1131

W
wusongqing 已提交
1132 1133 1134
**System capability**: SystemCapability.Utils.Lang

**Return value**
1135

G
Gloria 已提交
1136 1137
| Type  | Description                      |
| ------ | -------------------------- |
1138
| string | String representation of this **LruCache** object.|
W
wusongqing 已提交
1139

W
wusongqing 已提交
1140
**Example**
G
Gloria 已提交
1141

1142
```js
G
Gloria 已提交
1143 1144 1145 1146 1147
let pro = new util.LRUCache();
pro.put(2,10);
pro.get(2);
pro.remove(20);
let result = pro.toString();
1148
```
G
Gloria 已提交
1149 1150 1151 1152 1153 1154


### getCapacity<sup>9+</sup>

getCapacity(): number

1155
Obtains the capacity of this cache.
G
Gloria 已提交
1156 1157 1158 1159 1160 1161 1162

**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type  | Description                  |
| ------ | ---------------------- |
1163
| number | Capacity of this cache.|
G
Gloria 已提交
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176

**Example**

  ```js
let pro = new util.LRUCache();
let result = pro.getCapacity();
  ```


### clear<sup>9+</sup>

clear(): void

1177
Clears key-value pairs from this cache. The **afterRemoval()** method will be called to perform subsequent operations.
G
Gloria 已提交
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241

**System capability**: SystemCapability.Utils.Lang

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
let result = pro.length;
pro.clear();
  ```


### getCreateCount<sup>9+</sup>

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.LRUCache();
pro.put(1,8);
let result = pro.getCreateCount();
  ```


### getMissCount<sup>9+</sup>

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.LRUCache();
pro.put(2,10);
pro.get(2);
let result = pro.getMissCount();
  ```


### getRemovalCount<sup>9+</sup>

getRemovalCount(): number

1242
Obtains the number of removals from this cache.
G
Gloria 已提交
1243 1244 1245 1246 1247 1248 1249

**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type  | Description                      |
| ------ | -------------------------- |
1250
| number | Number of removals from the cache.|
G
Gloria 已提交
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
pro.updateCapacity(2);
pro.put(50,22);
let result = pro.getRemovalCount();
  ```


### getMatchCount<sup>9+</sup>

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.LRUCache();
pro.put(2,10);
pro.get(2);
let result = pro.getMatchCount();
  ```


### getPutCount<sup>9+</sup>

getPutCount(): number

1291
Obtains the number of additions to this cache.
G
Gloria 已提交
1292 1293 1294 1295 1296 1297 1298

**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type  | Description                        |
| ------ | ---------------------------- |
1299
| number | Number of additions to the cache.|
G
Gloria 已提交
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
let result = pro.getPutCount();
  ```


### isEmpty<sup>9+</sup>

isEmpty(): boolean

1314
Checks whether this cache is empty.
G
Gloria 已提交
1315 1316 1317 1318 1319 1320 1321

**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type   | Description                                    |
| ------- | ---------------------------------------- |
1322
| boolean | Returns **true** if the cache does not contain any value.|
G
Gloria 已提交
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
let result = pro.isEmpty();
  ```


### get<sup>9+</sup>

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                                                        |
| ------------------------ | ------------------------------------------------------------ |
1351
| V \| undefined | Returns the value of the key if a match is found in the cache; returns **undefined** otherwise.|
G
Gloria 已提交
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
let result  = pro.get(2);
  ```


### put<sup>9+</sup>

put(key: K,value: V): V

1366
Adds a key-value pair to this cache.
G
Gloria 已提交
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393

**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.LRUCache();
let result = pro.put(2,10);
  ```

### values<sup>9+</sup>

values(): V[]

1394
Obtains all values in this cache, listed from the most to the least recently accessed.
G
Gloria 已提交
1395 1396 1397 1398 1399 1400 1401

**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
1402
| V&nbsp;[] | All values in the cache, listed from the most to the least recently accessed.|
G
Gloria 已提交
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
pro.put(2,"anhu");
pro.put("afaf","grfb");
let result = pro.values();
  ```


### keys<sup>9+</sup>

keys(): K[]

1419
Obtains all keys in this cache, listed from the most to the least recently accessed.
G
Gloria 已提交
1420 1421 1422 1423 1424 1425 1426

**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
1427
| K&nbsp;[] | All keys in the cache, listed from the most to the least recently accessed.|
G
Gloria 已提交
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
let result = pro.keys();
  ```


### remove<sup>9+</sup>

remove(key: K): V | undefined

1442
Removes the specified key and its value from this cache.
G
Gloria 已提交
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description          |
| ------ | ---- | ---- | -------------- |
| key    | K    | Yes  | Key to remove.|

**Return value**

| Type                    | Description                                                        |
| ------------------------ | ------------------------------------------------------------ |
1456
| V&nbsp;\|&nbsp;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.|
G
Gloria 已提交
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
let result = pro.remove(20);
  ```


### afterRemoval<sup>9+</sup>

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                                                        |
| -------- | ------- | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
1479
| isEvict  | boolean | Yes  | Whether the cache capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity.   |
G
Gloria 已提交
1480 1481
| key      | K       | Yes  | Key removed.                                              |
| value    | V       | Yes  | Value removed.                                              |
1482
| 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.|
G
Gloria 已提交
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508

**Example**

  ```js
let arr = [];
class ChildLruBuffer<K, V> extends util.LRUCache<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>9+</sup>

1509
contains(key: K): boolean
G
Gloria 已提交
1510

1511
Checks whether this cache contains the specified key.
G
Gloria 已提交
1512 1513 1514 1515 1516

**System capability**: SystemCapability.Utils.Lang

**Parameters**

1517 1518
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
1519
| key    | K | Yes  | Key to check.|
G
Gloria 已提交
1520 1521 1522 1523 1524

**Return value**

| Type   | Description                                      |
| ------- | ------------------------------------------ |
1525
| boolean | Returns **true** if the cache contains the specified key; returns **false** otherwise.|
G
Gloria 已提交
1526 1527 1528 1529 1530 1531

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
1532 1533
let obj = {1:"key"};
let result = pro.contains(obj);
G
Gloria 已提交
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
  ```


### createDefault<sup>9+</sup>

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.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]();
  ```

1609
## ScopeComparable<sup>8+</sup>
G
Gloria 已提交
1610

1611
The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
G
Gloria 已提交
1612 1613 1614

**System capability**: SystemCapability.Utils.Lang

1615
### compareTo<sup>8+</sup>
G
Gloria 已提交
1616

1617
compareTo(other: ScopeComparable): boolean;
1618

1619
Compares two values and returns a Boolean value.
G
Gloria 已提交
1620

1621
**System capability**: SystemCapability.Utils.Lang
G
Gloria 已提交
1622

1623
**Parameters**
G
Gloria 已提交
1624

1625 1626 1627
| Name| Type| Mandatory| Description          |
| ------ | ---- | ---- | -------------- |
| other  | [ScopeComparable](#scopecomparable8) | Yes | The other value to be compared with the current value.|
G
Gloria 已提交
1628

1629
**Return value**
1630

1631 1632 1633
| Type| Description              |
| ---- | ------------------ |
| boolean | If the current value is greater than or equal to the input value, **true** is returned. Otherwise, **false** is returned.|
G
Gloria 已提交
1634

1635
**Example**
G
Gloria 已提交
1636

1637
Create a class to implement the **compareTo** method. The **Temperature** class is used as an example in the following sample code.
G
Gloria 已提交
1638

1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
```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();
    }
}
```
1657

1658
## ScopeType<sup>8+</sup>
G
Gloria 已提交
1659

1660
Defines the type of values in a **Scope** object.
G
Gloria 已提交
1661

1662
**System capability**: SystemCapability.Utils.Lang
G
Gloria 已提交
1663

1664 1665 1666 1667
| Type| Description|
| -------- | -------- |
| number | The value type is a number.|
| [ScopeComparable](#scopecomparable8) | The value type is ScopeComparable.|
G
Gloria 已提交
1668

1669 1670 1671 1672 1673 1674 1675
## 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.
1676

G
Gloria 已提交
1677 1678 1679 1680
**System capability**: SystemCapability.Utils.Lang

**Parameters**

1681 1682 1683 1684
| Name  | Type                    | Mandatory| Description                  |
| -------- | ------------------------ | ---- | ---------------------- |
| lowerObj | [ScopeType](#scopetype8) | Yes  | Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes  | Upper limit of the **Scope** object.|
G
Gloria 已提交
1685 1686

**Example**
1687

G
Gloria 已提交
1688
  ```js
1689 1690 1691
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
G
Gloria 已提交
1692 1693 1694
  ```


1695
### toString<sup>9+</sup>
G
Gloria 已提交
1696

1697
toString(): string
G
Gloria 已提交
1698

1699
Obtains a string representation that contains this **Scope**.
1700

G
Gloria 已提交
1701 1702 1703 1704
**System capability**: SystemCapability.Utils.Lang

**Return value**

1705 1706 1707
| Type  | Description                                  |
| ------ | -------------------------------------- |
| string | String representation containing the **Scope**.|
G
Gloria 已提交
1708 1709

**Example**
1710

G
Gloria 已提交
1711
  ```js
1712 1713 1714 1715
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.toString();
W
wusongqing 已提交
1716 1717 1718
  ```


1719
### intersect<sup>9+</sup>
W
wusongqing 已提交
1720

1721
intersect(range: ScopeHelper): ScopeHelper
W
wusongqing 已提交
1722

1723
Obtains the intersection of this **Scope** and the given **Scope**.
1724

W
wusongqing 已提交
1725 1726
**System capability**: SystemCapability.Utils.Lang

1727 1728 1729 1730 1731 1732
**Parameters**

| Name| Type                        | Mandatory| Description              |
| ------ | ---------------------------- | ---- | ------------------ |
| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|

W
wusongqing 已提交
1733
**Return value**
1734

1735 1736 1737
| Type                          | Description                          |
| ------------------------------ | ------------------------------ |
| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
1738

W
wusongqing 已提交
1739
**Example**
1740

1741
  ```js
1742 1743 1744 1745 1746 1747 1748
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);
W
wusongqing 已提交
1749
  ```
Z
zengyawen 已提交
1750 1751


1752
### intersect<sup>9+</sup>
Z
zengyawen 已提交
1753

1754
intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper
Z
zengyawen 已提交
1755

1756
Obtains the intersection of this **Scope** and the given lower and upper limits.
1757

W
wusongqing 已提交
1758 1759
**System capability**: SystemCapability.Utils.Lang

1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772
**Parameters**

| Name  | Type                    | Mandatory| Description            |
| -------- | ------------------------ | ---- | ---------------- |
| lowerObj | [ScopeType](#scopetype8) | Yes  | Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes  | Upper limit.|

**Return value**

| Type                        | Description                                    |
| ---------------------------- | ---------------------------------------- |
| [ScopeHelper](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.|

W
wusongqing 已提交
1773
**Example**
1774

1775
  ```js
1776 1777 1778 1779 1780 1781
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);
W
wusongqing 已提交
1782
  ```
Z
zengyawen 已提交
1783 1784


1785
### getUpper<sup>9+</sup>
W
wusongqing 已提交
1786

1787
getUpper(): ScopeType
W
wusongqing 已提交
1788

1789
Obtains the upper limit of this **Scope**.
1790

W
wusongqing 已提交
1791 1792 1793
**System capability**: SystemCapability.Utils.Lang

**Return value**
1794

1795 1796 1797
| Type                    | Description                  |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
W
wusongqing 已提交
1798

W
wusongqing 已提交
1799
**Example**
1800

1801
  ```js
1802 1803 1804 1805
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getUpper();
W
wusongqing 已提交
1806 1807 1808
  ```


1809
### getLower<sup>9+</sup>
W
wusongqing 已提交
1810

1811
getLower(): ScopeType
W
wusongqing 已提交
1812

1813
Obtains the lower limit of this **Scope**.
1814

W
wusongqing 已提交
1815 1816 1817
**System capability**: SystemCapability.Utils.Lang

**Return value**
1818

1819 1820 1821
| Type                    | Description                  |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
W
wusongqing 已提交
1822

W
wusongqing 已提交
1823
**Example**
1824

1825
  ```js
1826 1827 1828 1829
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getLower();
W
wusongqing 已提交
1830 1831 1832
  ```


1833
### expand<sup>9+</sup>
W
wusongqing 已提交
1834

1835
expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper
W
wusongqing 已提交
1836

1837
Obtains the union set of this **Scope** and the given lower and upper limits.
1838

W
wusongqing 已提交
1839 1840
**System capability**: SystemCapability.Utils.Lang

1841 1842 1843 1844 1845 1846 1847
**Parameters**

| Name  | Type                    | Mandatory| Description            |
| -------- | ------------------------ | ---- | ---------------- |
| lowerObj | [ScopeType](#scopetype8) | Yes  | Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes  | Upper limit.|

W
wusongqing 已提交
1848
**Return value**
1849

1850 1851 1852
| Type                        | Description                                |
| ---------------------------- | ------------------------------------ |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
1853

W
wusongqing 已提交
1854
**Example**
1855

1856
  ```js
1857 1858 1859 1860 1861 1862
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);
W
wusongqing 已提交
1863 1864 1865
  ```


1866
### expand<sup>9+</sup>
W
wusongqing 已提交
1867

1868
expand(range: ScopeHelper): ScopeHelper
W
wusongqing 已提交
1869

1870
Obtains the union set of this **Scope** and the given **Scope**.
1871

W
wusongqing 已提交
1872 1873
**System capability**: SystemCapability.Utils.Lang

1874 1875 1876 1877 1878 1879
**Parameters**

| Name| Type                        | Mandatory| Description              |
| ------ | ---------------------------- | ---- | ------------------ |
| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|

W
wusongqing 已提交
1880
**Return value**
1881

1882 1883 1884
| Type                        | Description                              |
| ---------------------------- | ---------------------------------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
1885

W
wusongqing 已提交
1886
**Example**
1887

1888
  ```js
1889 1890 1891 1892 1893 1894 1895
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);
W
wusongqing 已提交
1896 1897 1898
  ```


1899
### expand<sup>9+</sup>
W
wusongqing 已提交
1900

1901
expand(value: ScopeType): ScopeHelper
W
wusongqing 已提交
1902

1903
Obtains the union set of this **Scope** and the given value.
1904

W
wusongqing 已提交
1905 1906
**System capability**: SystemCapability.Utils.Lang

1907 1908 1909 1910 1911 1912
**Parameters**

| Name| Type                    | Mandatory| Description            |
| ------ | ------------------------ | ---- | ---------------- |
| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|

W
wusongqing 已提交
1913
**Return value**
1914

1915 1916 1917
| Type                        | Description                            |
| ---------------------------- | -------------------------------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given value.|
W
wusongqing 已提交
1918

W
wusongqing 已提交
1919
**Example**
1920

1921
  ```js
1922 1923 1924 1925 1926
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);
W
wusongqing 已提交
1927 1928 1929
  ```


1930
### contains<sup>9+</sup>
W
wusongqing 已提交
1931

1932
contains(value: ScopeType): boolean
W
wusongqing 已提交
1933

1934
Checks whether a value is within this **Scope**.
1935

W
wusongqing 已提交
1936 1937
**System capability**: SystemCapability.Utils.Lang

1938 1939 1940 1941 1942 1943
**Parameters**

| Name| Type                    | Mandatory| Description            |
| ------ | ------------------------ | ---- | ---------------- |
| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|

W
wusongqing 已提交
1944
**Return value**
1945

1946 1947 1948
| Type   | Description                                               |
| ------- | --------------------------------------------------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
1949

W
wusongqing 已提交
1950
**Example**
1951

1952
  ```js
1953 1954 1955 1956 1957
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
range.contains(tempMiDF);
W
wusongqing 已提交
1958 1959 1960
  ```


1961
### contains<sup>9+</sup>
Z
zengyawen 已提交
1962

1963
contains(range: ScopeHelper): boolean
Z
zengyawen 已提交
1964

1965
Checks whether a range is within this **Scope**.
1966

W
wusongqing 已提交
1967 1968 1969
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1970

1971 1972 1973
| Name| Type                        | Mandatory| Description              |
| ------ | ---------------------------- | ---- | ------------------ |
| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
W
wusongqing 已提交
1974

W
wusongqing 已提交
1975
**Return value**
1976

1977 1978 1979
| Type   | Description                                                 |
| ------- | ----------------------------------------------------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
1980

W
wusongqing 已提交
1981
**Example**
1982

1983
  ```js
1984 1985 1986 1987 1988 1989 1990
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
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);
W
wusongqing 已提交
1991 1992 1993
  ```


1994
### clamp<sup>9+</sup>
Z
zengyawen 已提交
1995

1996
clamp(value: ScopeType): ScopeType
Z
zengyawen 已提交
1997

1998
Limits a value to this **Scope**.
1999

W
wusongqing 已提交
2000 2001 2002
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2003

2004 2005 2006
| Name| Type                    | Mandatory| Description          |
| ------ | ------------------------ | ---- | -------------- |
| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|
Z
zengyawen 已提交
2007

W
wusongqing 已提交
2008
**Return value**
2009

2010 2011 2012
| 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**.|
Z
zengyawen 已提交
2013

W
wusongqing 已提交
2014
**Example**
2015

2016
  ```js
2017 2018 2019 2020 2021
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.clamp(tempMiDF);
W
wusongqing 已提交
2022
  ```
Z
zengyawen 已提交
2023

2024
## Base64Helper<sup>9+</sup>
G
Gloria 已提交
2025

2026
### constructor<sup>9+</sup>
W
wusongqing 已提交
2027

2028
constructor()
Z
zengyawen 已提交
2029

2030
A constructor used to create a **Base64Helper** instance.
2031

W
wusongqing 已提交
2032 2033
**System capability**: SystemCapability.Utils.Lang

2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053
**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.|

W
wusongqing 已提交
2054
**Return value**
2055

2056 2057 2058
| Type      | Description                         |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array encoded.|
Z
zengyawen 已提交
2059

W
wusongqing 已提交
2060
**Example**
2061

2062
  ```js
2063 2064 2065
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeSync(array);
W
wusongqing 已提交
2066
  ```
Z
zengyawen 已提交
2067 2068


2069
### encodeToStringSync<sup>9+</sup>
Z
zengyawen 已提交
2070

2071
encodeToStringSync(src: Uint8Array): string
Z
zengyawen 已提交
2072

2073
Encodes the input content.
2074

W
wusongqing 已提交
2075 2076
**System capability**: SystemCapability.Utils.Lang

2077 2078 2079 2080 2081 2082
**Parameters**

| Name| Type      | Mandatory| Description               |
| ------ | ---------- | ---- | ------------------- |
| src    | Uint8Array | Yes  | Uint8Array to encode.|

W
wusongqing 已提交
2083
**Return value**
2084

2085 2086 2087
| Type  | Description                |
| ------ | -------------------- |
| string | String encoded from the Uint8Array.|
W
wusongqing 已提交
2088

W
wusongqing 已提交
2089
**Example**
2090 2091 2092 2093 2094

  ```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeToStringSync(array);
W
wusongqing 已提交
2095 2096 2097
  ```


2098
### decodeSync<sup>9+</sup>
W
wusongqing 已提交
2099

2100
decodeSync(src: Uint8Array | string): Uint8Array
W
wusongqing 已提交
2101

2102
Decodes the input content.
2103

W
wusongqing 已提交
2104 2105 2106
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2107

2108 2109 2110
| Name| Type                          | Mandatory| Description                         |
| ------ | ------------------------------ | ---- | ----------------------------- |
| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode.|
W
wusongqing 已提交
2111

W
wusongqing 已提交
2112
**Return value**
2113

2114 2115 2116
| Type      | Description                         |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array decoded.|
W
wusongqing 已提交
2117

W
wusongqing 已提交
2118
**Example**
2119

2120
  ```js
2121 2122 2123
let that = new util.Base64Helper();
let buff = 'czEz';
let result = that.decodeSync(buff);
W
wusongqing 已提交
2124 2125 2126
  ```


2127
### encode<sup>9+</sup>
W
wusongqing 已提交
2128

2129
encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
W
wusongqing 已提交
2130

2131
Encodes the input content asynchronously.
2132

W
wusongqing 已提交
2133 2134 2135
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2136

2137 2138 2139 2140 2141 2142 2143 2144 2145
| Name| Type      | Mandatory| Description                   |
| ------ | ---------- | ---- | ----------------------- |
| src    | Uint8Array | Yes  | Uint8Array to encode asynchronously.|

**Return value**

| Type                     | Description                             |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
W
wusongqing 已提交
2146

W
wusongqing 已提交
2147
**Example**
2148

2149
  ```js
2150 2151 2152 2153 2154 2155 2156 2157
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())
    }
})
W
wusongqing 已提交
2158 2159 2160
  ```


2161
### encodeToString<sup>9+</sup>
Z
zengyawen 已提交
2162

2163
encodeToString(src: Uint8Array): Promise&lt;string&gt;
2164

2165
Encodes the input content asynchronously.
2166

W
wusongqing 已提交
2167 2168 2169
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2170

2171 2172 2173
| Name| Type      | Mandatory| Description                   |
| ------ | ---------- | ---- | ----------------------- |
| src    | Uint8Array | Yes  | Uint8Array to encode asynchronously.|
Z
zengyawen 已提交
2174

W
wusongqing 已提交
2175
**Return value**
2176

2177 2178 2179
| Type                 | Description                    |
| --------------------- | ------------------------ |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
Z
zengyawen 已提交
2180

W
wusongqing 已提交
2181
**Example**
2182

2183
  ```js
2184 2185 2186 2187 2188
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
that.encodeToString(array).then(val=>{    
    console.log(val)
})
W
wusongqing 已提交
2189
  ```
Z
zengyawen 已提交
2190 2191


2192
### decode<sup>9+</sup>
Z
zengyawen 已提交
2193

2194
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
2195

2196
Decodes the input content asynchronously.
2197

W
wusongqing 已提交
2198 2199 2200
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2201

2202 2203 2204
| Name| Type                          | Mandatory| Description                             |
| ------ | ------------------------------ | ---- | --------------------------------- |
| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode asynchronously.|
Z
zengyawen 已提交
2205

W
wusongqing 已提交
2206
**Return value**
2207

2208 2209 2210
| Type                     | Description                             |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
Z
zengyawen 已提交
2211

W
wusongqing 已提交
2212
**Example**
2213

2214
  ```js
2215 2216 2217 2218 2219 2220 2221 2222
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())
    }
})
G
Gloria 已提交
2223 2224
  ```

2225
## types<sup>8+</sup>
G
Gloria 已提交
2226

2227
### constructor<sup>8+</sup>
G
Gloria 已提交
2228

2229
constructor()
G
Gloria 已提交
2230

2231
A constructor used to create a **Types** object.
2232

G
Gloria 已提交
2233 2234 2235
**System capability**: SystemCapability.Utils.Lang

**Example**
2236

G
Gloria 已提交
2237
  ```js
2238
  let type = new util.types();
G
Gloria 已提交
2239 2240 2241
  ```


2242
### isAnyArrayBuffer<sup>8+</sup>
G
Gloria 已提交
2243

2244
isAnyArrayBuffer(value: Object): boolean
G
Gloria 已提交
2245

2246
Checks whether the input value is of the **ArrayBuffer** type.
2247

G
Gloria 已提交
2248 2249
**System capability**: SystemCapability.Utils.Lang

2250 2251 2252 2253 2254 2255
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

G
Gloria 已提交
2256 2257 2258 2259
**Return value**

| Type| Description|
| -------- | -------- |
2260
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
G
Gloria 已提交
2261 2262

**Example**
2263

G
Gloria 已提交
2264
  ```js
2265 2266
  let that = new util.types();
  let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
G
Gloria 已提交
2267 2268 2269
  ```


2270
### isArrayBufferView<sup>8+</sup>
G
Gloria 已提交
2271

2272
isArrayBufferView(value: Object): boolean
G
Gloria 已提交
2273

2274
Checks whether the input value is of the **ArrayBufferView** type.
G
Gloria 已提交
2275

2276
**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
G
Gloria 已提交
2277 2278 2279 2280 2281

**System capability**: SystemCapability.Utils.Lang

**Parameters**

2282 2283 2284 2285 2286 2287 2288 2289 2290
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
G
Gloria 已提交
2291 2292 2293 2294

**Example**

  ```js
2295 2296
  let that = new util.types();
  let result = that.isArrayBufferView(new Int8Array([]));
G
Gloria 已提交
2297 2298 2299
  ```


2300
### isArgumentsObject<sup>8+</sup>
G
Gloria 已提交
2301

2302
isArgumentsObject(value: Object): boolean
G
Gloria 已提交
2303

2304
Checks whether the input value is of the **arguments** type.
G
Gloria 已提交
2305 2306 2307

**System capability**: SystemCapability.Utils.Lang

2308 2309 2310 2311 2312 2313
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

G
Gloria 已提交
2314 2315
**Return value**

2316 2317 2318
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
G
Gloria 已提交
2319 2320 2321 2322

**Example**

  ```js
2323 2324 2325 2326 2327
  let that = new util.types();
  function foo() {
      var result = that.isArgumentsObject(arguments);
  }
  let f = foo();
G
Gloria 已提交
2328 2329 2330
  ```


2331
### isArrayBuffer<sup>8+</sup>
G
Gloria 已提交
2332

2333
isArrayBuffer(value: Object): boolean
G
Gloria 已提交
2334

2335
Checks whether the input value is of the **ArrayBuffer** type.
G
Gloria 已提交
2336 2337 2338 2339 2340

**System capability**: SystemCapability.Utils.Lang

**Parameters**

2341 2342 2343
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2344 2345 2346

**Return value**

2347 2348 2349
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
G
Gloria 已提交
2350 2351 2352 2353

**Example**

  ```js
2354 2355
  let that = new util.types();
  let result = that.isArrayBuffer(new ArrayBuffer(0));
G
Gloria 已提交
2356 2357 2358
  ```


2359
### isAsyncFunction<sup>8+</sup>
G
Gloria 已提交
2360

2361
isAsyncFunction(value: Object): boolean
G
Gloria 已提交
2362

2363
Checks whether the input value is an asynchronous function.
G
Gloria 已提交
2364 2365 2366 2367 2368

**System capability**: SystemCapability.Utils.Lang

**Parameters**

2369 2370 2371
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2372 2373 2374

**Return value**

2375 2376 2377
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
G
Gloria 已提交
2378 2379 2380 2381

**Example**

  ```js
2382 2383
  let that = new util.types();
  let result = that.isAsyncFunction(async function foo() {});
G
Gloria 已提交
2384 2385 2386
  ```


2387
### isBooleanObject<sup>8+</sup>
G
Gloria 已提交
2388

2389
isBooleanObject(value: Object): boolean
G
Gloria 已提交
2390

2391
Checks whether the input value is of the **Boolean** type.
G
Gloria 已提交
2392 2393 2394

**System capability**: SystemCapability.Utils.Lang

2395 2396 2397 2398 2399 2400
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

G
Gloria 已提交
2401 2402
**Return value**

2403 2404 2405
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
G
Gloria 已提交
2406 2407 2408 2409

**Example**

  ```js
2410 2411
  let that = new util.types();
  let result = that.isBooleanObject(new Boolean(true));
G
Gloria 已提交
2412 2413 2414
  ```


2415
### isBoxedPrimitive<sup>8+</sup>
G
Gloria 已提交
2416

2417
isBoxedPrimitive(value: Object): boolean
G
Gloria 已提交
2418

2419
Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.
G
Gloria 已提交
2420 2421 2422

**System capability**: SystemCapability.Utils.Lang

2423 2424 2425 2426 2427 2428
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

G
Gloria 已提交
2429 2430
**Return value**

2431 2432 2433
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
G
Gloria 已提交
2434 2435 2436 2437

**Example**

  ```js
2438 2439
  let that = new util.types();
  let result = that.isBoxedPrimitive(new Boolean(false));
G
Gloria 已提交
2440 2441 2442
  ```


2443
### isDataView<sup>8+</sup>
G
Gloria 已提交
2444

2445
isDataView(value: Object): boolean
G
Gloria 已提交
2446

2447
Checks whether the input value is of the **DataView** type.
G
Gloria 已提交
2448 2449 2450 2451 2452

**System capability**: SystemCapability.Utils.Lang

**Parameters**

2453 2454 2455
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2456 2457 2458

**Return value**

2459 2460 2461
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
G
Gloria 已提交
2462 2463 2464 2465

**Example**

  ```js
2466 2467 2468
  let that = new util.types();
  const ab = new ArrayBuffer(20);
  let result = that.isDataView(new DataView(ab));
G
Gloria 已提交
2469 2470 2471
  ```


2472
### isDate<sup>8+</sup>
G
Gloria 已提交
2473

2474
isDate(value: Object): boolean
G
Gloria 已提交
2475

2476
Checks whether the input value is of the **Date** type.
G
Gloria 已提交
2477 2478 2479 2480 2481

**System capability**: SystemCapability.Utils.Lang

**Parameters**

2482 2483 2484
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2485 2486 2487

**Return value**

2488 2489 2490
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
G
Gloria 已提交
2491 2492 2493 2494

**Example**

  ```js
2495 2496
  let that = new util.types();
  let result = that.isDate(new Date());
G
Gloria 已提交
2497 2498 2499
  ```


2500
### isExternal<sup>8+</sup>
G
Gloria 已提交
2501

2502
isExternal(value: Object): boolean
G
Gloria 已提交
2503

2504
Checks whether the input value is of the **native external** type.
G
Gloria 已提交
2505 2506 2507 2508 2509

**System capability**: SystemCapability.Utils.Lang

**Parameters**

2510 2511 2512
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2513 2514 2515

**Return value**

2516 2517 2518
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
G
Gloria 已提交
2519 2520 2521 2522

**Example**

  ```js
2523 2524
  let that = new util.types();
  let result = that.isExternal(true);
W
wusongqing 已提交
2525
  ```
Z
zengyawen 已提交
2526 2527


2528
### isFloat32Array<sup>8+</sup>
Z
zengyawen 已提交
2529

2530
isFloat32Array(value: Object): boolean
Z
zengyawen 已提交
2531

2532
Checks whether the input value is of the **Float32Array** type.
Z
zengyawen 已提交
2533

W
wusongqing 已提交
2534 2535
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
2536 2537
**Parameters**

2538 2539 2540
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2541

W
wusongqing 已提交
2542
**Return value**
2543

2544 2545 2546
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.|
Z
zengyawen 已提交
2547

W
wusongqing 已提交
2548
**Example**
G
Gloria 已提交
2549

2550
  ```js
2551 2552
  let that = new util.types();
  let result = that.isFloat32Array(new Float32Array());
W
wusongqing 已提交
2553
  ```
Z
zengyawen 已提交
2554 2555


2556
### isFloat64Array<sup>8+</sup>
Z
zengyawen 已提交
2557

2558
isFloat64Array(value: Object): boolean
Z
zengyawen 已提交
2559

2560
Checks whether the input value is of the **Float64Array** type.
Z
zengyawen 已提交
2561

W
wusongqing 已提交
2562 2563
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
2564 2565
**Parameters**

2566 2567 2568
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2569

W
wusongqing 已提交
2570
**Return value**
2571

2572 2573 2574
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
Z
zengyawen 已提交
2575

W
wusongqing 已提交
2576
**Example**
G
Gloria 已提交
2577

2578
  ```js
2579 2580
  let that = new util.types();
  let result = that.isFloat64Array(new Float64Array());
W
wusongqing 已提交
2581
  ```
Z
zengyawen 已提交
2582 2583


2584
### isGeneratorFunction<sup>8+</sup>
Z
zengyawen 已提交
2585

2586
isGeneratorFunction(value: Object): boolean
Z
zengyawen 已提交
2587

2588
Checks whether the input value is a generator function.
Z
zengyawen 已提交
2589

G
Gloria 已提交
2590
**System capability**: SystemCapability.Utils.Lang
Z
zengyawen 已提交
2591

G
Gloria 已提交
2592
**Parameters**
Z
zengyawen 已提交
2593

2594 2595 2596
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
Z
zengyawen 已提交
2597

G
Gloria 已提交
2598
**Return value**
Z
zengyawen 已提交
2599

2600 2601 2602
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
W
wusongqing 已提交
2603

G
Gloria 已提交
2604
**Example**
Z
zengyawen 已提交
2605

G
Gloria 已提交
2606
  ```js
2607 2608
  let that = new util.types();
  let result = that.isGeneratorFunction(function* foo() {});
G
Gloria 已提交
2609
  ```
Z
zengyawen 已提交
2610

W
wusongqing 已提交
2611

2612
### isGeneratorObject<sup>8+</sup>
W
wusongqing 已提交
2613

2614
isGeneratorObject(value: Object): boolean
2615

2616
Checks whether the input value is a generator object.
2617

W
wusongqing 已提交
2618 2619 2620
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2621

W
wusongqing 已提交
2622 2623
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2624 2625 2626 2627 2628 2629 2630
| value | Object | Yes| Object to check.|

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.|
W
wusongqing 已提交
2631

W
wusongqing 已提交
2632
**Example**
2633

2634
  ```js
2635 2636 2637 2638
  let that = new util.types();
  function* foo() {}
  const generator = foo();
  let result = that.isGeneratorObject(generator);
W
wusongqing 已提交
2639 2640 2641
  ```


2642
### isInt8Array<sup>8+</sup>
W
wusongqing 已提交
2643

2644
isInt8Array(value: Object): boolean
W
wusongqing 已提交
2645

2646
Checks whether the input value is of the **Int8Array** type.
2647

W
wusongqing 已提交
2648 2649
**System capability**: SystemCapability.Utils.Lang

2650 2651 2652 2653 2654 2655
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

W
wusongqing 已提交
2656
**Return value**
2657

W
wusongqing 已提交
2658 2659
| Type| Description|
| -------- | -------- |
2660
| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2661

W
wusongqing 已提交
2662
**Example**
2663

2664
  ```js
2665 2666
  let that = new util.types();
  let result = that.isInt8Array(new Int8Array([]));
W
wusongqing 已提交
2667 2668 2669
  ```


2670
### isInt16Array<sup>8+</sup>
W
wusongqing 已提交
2671

2672
isInt16Array(value: Object): boolean
W
wusongqing 已提交
2673

2674
Checks whether the input value is of the **Int16Array** type.
2675

W
wusongqing 已提交
2676 2677 2678
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2679

W
wusongqing 已提交
2680 2681
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2682
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2683

W
wusongqing 已提交
2684
**Return value**
2685

W
wusongqing 已提交
2686 2687
| Type| Description|
| -------- | -------- |
2688
| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2689

W
wusongqing 已提交
2690
**Example**
G
Gloria 已提交
2691

2692
  ```js
2693 2694
  let that = new util.types();
  let result = that.isInt16Array(new Int16Array([]));
W
wusongqing 已提交
2695 2696 2697
  ```


2698
### isInt32Array<sup>8+</sup>
W
wusongqing 已提交
2699

2700
isInt32Array(value: Object): boolean
W
wusongqing 已提交
2701

2702
Checks whether the input value is of the **Int32Array** type.
2703

W
wusongqing 已提交
2704 2705 2706
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2707

W
wusongqing 已提交
2708 2709
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2710
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2711

W
wusongqing 已提交
2712
**Return value**
2713

W
wusongqing 已提交
2714 2715
| Type| Description|
| -------- | -------- |
2716
| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2717

W
wusongqing 已提交
2718
**Example**
2719

2720
  ```js
2721 2722
  let that = new util.types();
  let result = that.isInt32Array(new Int32Array([]));
W
wusongqing 已提交
2723 2724 2725
  ```


2726
### isMap<sup>8+</sup>
W
wusongqing 已提交
2727

2728
isMap(value: Object): boolean
W
wusongqing 已提交
2729

2730
Checks whether the input value is of the **Map** type.
2731

W
wusongqing 已提交
2732 2733
**System capability**: SystemCapability.Utils.Lang

2734 2735 2736 2737 2738 2739
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

W
wusongqing 已提交
2740 2741
**Return value**

W
wusongqing 已提交
2742 2743
| Type| Description|
| -------- | -------- |
2744
| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
W
wusongqing 已提交
2745

W
wusongqing 已提交
2746
**Example**
2747

2748
  ```js
2749 2750
  let that = new util.types();
  let result = that.isMap(new Map());
W
wusongqing 已提交
2751 2752 2753
  ```


2754
### isMapIterator<sup>8+</sup>
W
wusongqing 已提交
2755

2756
isMapIterator(value: Object): boolean
W
wusongqing 已提交
2757

2758
Checks whether the input value is of the **MapIterator** type.
2759

W
wusongqing 已提交
2760 2761
**System capability**: SystemCapability.Utils.Lang

2762 2763 2764 2765 2766 2767 2768
**Parameters**


| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

W
wusongqing 已提交
2769
**Return value**
2770

W
wusongqing 已提交
2771 2772
| Type| Description|
| -------- | -------- |
2773
| boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
W
wusongqing 已提交
2774

W
wusongqing 已提交
2775
**Example**
2776

2777
  ```js
2778 2779 2780
  let that = new util.types();
  const map = new Map();
  let result = that.isMapIterator(map.keys());
W
wusongqing 已提交
2781 2782 2783
  ```


2784
### isNativeError<sup>8+</sup>
W
wusongqing 已提交
2785

2786
isNativeError(value: Object): boolean
W
wusongqing 已提交
2787

2788
Checks whether the input value is of the **Error** type.
2789

W
wusongqing 已提交
2790 2791 2792
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2793

W
wusongqing 已提交
2794 2795
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2796
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2797

W
wusongqing 已提交
2798
**Return value**
2799

W
wusongqing 已提交
2800 2801
| Type| Description|
| -------- | -------- |
2802
| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
W
wusongqing 已提交
2803

W
wusongqing 已提交
2804
**Example**
W
wusongqing 已提交
2805

2806
  ```js
2807 2808
  let that = new util.types();
  let result = that.isNativeError(new TypeError());
W
wusongqing 已提交
2809 2810 2811
  ```


2812
### isNumberObject<sup>8+</sup>
W
wusongqing 已提交
2813

2814
isNumberObject(value: Object): boolean
W
wusongqing 已提交
2815

2816
Checks whether the input value is a number object.
2817

W
wusongqing 已提交
2818 2819 2820
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2821

W
wusongqing 已提交
2822 2823
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2824
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2825

W
wusongqing 已提交
2826
**Return value**
2827

W
wusongqing 已提交
2828 2829
| Type| Description|
| -------- | -------- |
2830
| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
W
wusongqing 已提交
2831

W
wusongqing 已提交
2832
**Example**
2833

2834
  ```js
2835 2836
  let that = new util.types();
  let result = that.isNumberObject(new Number(0));
W
wusongqing 已提交
2837 2838 2839
  ```


2840
### isPromise<sup>8+</sup>
W
wusongqing 已提交
2841

2842
isPromise(value: Object): boolean
W
wusongqing 已提交
2843

2844
Checks whether the input value is a promise.
2845

W
wusongqing 已提交
2846 2847 2848
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2849

W
wusongqing 已提交
2850 2851
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2852
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2853

W
wusongqing 已提交
2854
**Return value**
2855

W
wusongqing 已提交
2856 2857
| Type| Description|
| -------- | -------- |
2858
| boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
Z
zengyawen 已提交
2859

W
wusongqing 已提交
2860
**Example**
2861

2862
  ```js
2863 2864
  let that = new util.types();
  let result = that.isPromise(Promise.resolve(1));
W
wusongqing 已提交
2865
  ```
Z
zengyawen 已提交
2866 2867


2868
### isProxy<sup>8+</sup>
Z
zengyawen 已提交
2869

2870
isProxy(value: Object): boolean
Z
zengyawen 已提交
2871

2872
Checks whether the input value is a proxy.
2873

W
wusongqing 已提交
2874 2875 2876
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2877

W
wusongqing 已提交
2878 2879
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2880
| value | Object | Yes| Object to check.|
Z
zengyawen 已提交
2881

W
wusongqing 已提交
2882
**Return value**
2883

W
wusongqing 已提交
2884 2885
| Type| Description|
| -------- | -------- |
2886
| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
W
wusongqing 已提交
2887

W
wusongqing 已提交
2888
**Example**
2889

2890
  ```js
2891 2892 2893 2894
  let that = new util.types();
  const target = {};
  const proxy = new Proxy(target, {});
  let result = that.isProxy(proxy);
W
wusongqing 已提交
2895 2896 2897
  ```


2898
### isRegExp<sup>8+</sup>
W
wusongqing 已提交
2899

2900 2901 2902
isRegExp(value: Object): boolean

Checks whether the input value is of the **RegExp** type.
2903

W
wusongqing 已提交
2904 2905 2906
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2907

W
wusongqing 已提交
2908 2909
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2910
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2911

W
wusongqing 已提交
2912
**Return value**
2913

W
wusongqing 已提交
2914 2915
| Type| Description|
| -------- | -------- |
2916
| boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.|
W
wusongqing 已提交
2917

W
wusongqing 已提交
2918
**Example**
G
Gloria 已提交
2919

2920
  ```js
2921 2922
  let that = new util.types();
  let result = that.isRegExp(new RegExp('abc'));
W
wusongqing 已提交
2923 2924 2925
  ```


2926
### isSet<sup>8+</sup>
W
wusongqing 已提交
2927

2928
isSet(value: Object): boolean
W
wusongqing 已提交
2929

2930
Checks whether the input value is of the **Set** type.
2931

W
wusongqing 已提交
2932 2933 2934
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2935

W
wusongqing 已提交
2936 2937
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2938
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2939

W
wusongqing 已提交
2940
**Return value**
2941

W
wusongqing 已提交
2942 2943
| Type| Description|
| -------- | -------- |
2944
| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
W
wusongqing 已提交
2945

W
wusongqing 已提交
2946
**Example**
2947

2948
  ```js
2949 2950
  let that = new util.types();
  let result = that.isSet(new Set());
W
wusongqing 已提交
2951 2952
  ```

G
Gloria 已提交
2953

2954
### isSetIterator<sup>8+</sup>
W
wusongqing 已提交
2955

2956
isSetIterator(value: Object): boolean
W
wusongqing 已提交
2957

2958
Checks whether the input value is of the **SetIterator** type.
W
wusongqing 已提交
2959

G
Gloria 已提交
2960 2961
**System capability**: SystemCapability.Utils.Lang

2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.|

G
Gloria 已提交
2974 2975 2976
**Example**

  ```js
2977 2978 2979
  let that = new util.types();
  const set = new Set();
  let result = that.isSetIterator(set.keys());
G
Gloria 已提交
2980 2981 2982
  ```


2983
### isStringObject<sup>8+</sup>
G
Gloria 已提交
2984

2985 2986 2987
isStringObject(value: Object): boolean

Checks whether the input value is a string object.
G
Gloria 已提交
2988 2989 2990 2991 2992

**System capability**: SystemCapability.Utils.Lang

**Parameters**

2993 2994 2995
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2996 2997 2998

**Return value**

2999 3000 3001
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
G
Gloria 已提交
3002 3003 3004 3005

**Example**

  ```js
3006 3007
  let that = new util.types();
  let result = that.isStringObject(new String('foo'));
G
Gloria 已提交
3008 3009 3010
  ```


3011
### isSymbolObjec<sup>8+</sup>
G
Gloria 已提交
3012

3013
isSymbolObject(value: Object): boolean
G
Gloria 已提交
3014

3015
Checks whether the input value is a symbol object.
G
Gloria 已提交
3016 3017 3018 3019 3020

**System capability**: SystemCapability.Utils.Lang

**Parameters**

3021 3022 3023
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
3024 3025 3026

**Return value**

3027 3028 3029
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
G
Gloria 已提交
3030 3031 3032 3033

**Example**

  ```js
3034 3035 3036
  let that = new util.types();
  const symbols = Symbol('foo');
  let result = that.isSymbolObject(Object(symbols));
G
Gloria 已提交
3037 3038 3039
  ```


3040
### isTypedArray<sup>8+</sup>
G
Gloria 已提交
3041

3042
isTypedArray(value: Object): boolean
G
Gloria 已提交
3043

3044 3045 3046
Checks whether the input value is of the **TypedArray** type.

**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
G
Gloria 已提交
3047 3048 3049 3050 3051

**System capability**: SystemCapability.Utils.Lang

**Parameters**

3052 3053 3054
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
3055 3056 3057

**Return value**

3058 3059 3060
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
G
Gloria 已提交
3061 3062 3063 3064

**Example**

  ```js
3065 3066
  let that = new util.types();
  let result = that.isTypedArray(new Float64Array([]));
G
Gloria 已提交
3067 3068 3069
  ```


3070
### isUint8Array<sup>8+</sup>
G
Gloria 已提交
3071

3072
isUint8Array(value: Object): boolean
G
Gloria 已提交
3073

3074
Checks whether the input value is of the **Uint8Array** type.
G
Gloria 已提交
3075 3076 3077 3078 3079

**System capability**: SystemCapability.Utils.Lang

**Parameters**

3080 3081 3082
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
3083 3084 3085

**Return value**

3086 3087 3088
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
G
Gloria 已提交
3089 3090 3091 3092

**Example**

  ```js
3093 3094
  let that = new util.types();
  let result = that.isUint8Array(new Uint8Array([]));
G
Gloria 已提交
3095 3096 3097
  ```


3098
### isUint8ClampedArray<sup>8+</sup>
G
Gloria 已提交
3099

3100
isUint8ClampedArray(value: Object): boolean
G
Gloria 已提交
3101

3102
Checks whether the input value is of the **Uint8ClampedArray** type.
G
Gloria 已提交
3103 3104 3105 3106 3107

**System capability**: SystemCapability.Utils.Lang

**Parameters**

3108 3109 3110
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
3111 3112 3113

**Return value**

3114 3115 3116
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
G
Gloria 已提交
3117 3118 3119 3120

**Example**

  ```js
3121 3122
  let that = new util.types();
  let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
G
Gloria 已提交
3123 3124 3125
  ```


3126
### isUint16Array<sup>8+</sup>
G
Gloria 已提交
3127

3128
isUint16Array(value: Object): boolean
G
Gloria 已提交
3129

3130
Checks whether the input value is of the **Uint16Array** type.
G
Gloria 已提交
3131 3132 3133 3134 3135

**System capability**: SystemCapability.Utils.Lang

**Parameters**

3136 3137 3138
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
3139 3140 3141

**Return value**

3142 3143 3144
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
G
Gloria 已提交
3145 3146 3147 3148

**Example**

  ```js
3149 3150
  let that = new util.types();
  let result = that.isUint16Array(new Uint16Array([]));
G
Gloria 已提交
3151 3152 3153
  ```


3154
### isUint32Array<sup>8+</sup>
G
Gloria 已提交
3155

3156
isUint32Array(value: Object): boolean
G
Gloria 已提交
3157

3158
Checks whether the input value is of the **Uint32Array** type.
G
Gloria 已提交
3159

3160
**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
3161

3162
**Parameters**
W
wusongqing 已提交
3163

3164 3165 3166
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
3167

3168 3169 3170 3171 3172
**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3173 3174

**Example**
3175

3176
  ```js
3177 3178
  let that = new util.types();
  let result = that.isUint32Array(new Uint32Array([]));
W
wusongqing 已提交
3179 3180 3181
  ```


3182
### isWeakMap<sup>8+</sup>
Z
zengyawen 已提交
3183

3184
isWeakMap(value: Object): boolean
Z
zengyawen 已提交
3185

3186
Checks whether the input value is of the **WeakMap** type.
3187

W
wusongqing 已提交
3188 3189 3190
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3191

W
wusongqing 已提交
3192 3193
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3194
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3195

W
wusongqing 已提交
3196
**Return value**
3197

W
wusongqing 已提交
3198 3199
| Type| Description|
| -------- | -------- |
3200
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
W
wusongqing 已提交
3201

W
wusongqing 已提交
3202
**Example**
G
Gloria 已提交
3203

3204
  ```js
3205 3206
  let that = new util.types();
  let result = that.isWeakMap(new WeakMap());
W
wusongqing 已提交
3207 3208 3209
  ```


3210
### isWeakSet<sup>8+</sup>
W
wusongqing 已提交
3211

3212
isWeakSet(value: Object): boolean
W
wusongqing 已提交
3213

3214
Checks whether the input value is of the **WeakSet** type.
3215

W
wusongqing 已提交
3216 3217 3218
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3219

W
wusongqing 已提交
3220 3221
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3222
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3223

W
wusongqing 已提交
3224
**Return value**
3225

W
wusongqing 已提交
3226 3227
| Type| Description|
| -------- | -------- |
3228
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
W
wusongqing 已提交
3229

W
wusongqing 已提交
3230
**Example**
3231

3232
  ```js
3233 3234
  let that = new util.types();
  let result = that.isWeakSet(new WeakSet());
W
wusongqing 已提交
3235 3236 3237
  ```


3238
### isBigInt64Array<sup>8+</sup>
Z
zengyawen 已提交
3239

3240
isBigInt64Array(value: Object): boolean
Z
zengyawen 已提交
3241

3242
Checks whether the input value is of the **BigInt64Array** type.
3243

W
wusongqing 已提交
3244 3245 3246
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3247

W
wusongqing 已提交
3248 3249
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3250
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3251

W
wusongqing 已提交
3252
**Return value**
3253

W
wusongqing 已提交
3254 3255
| Type| Description|
| -------- | -------- |
3256
| boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3257

W
wusongqing 已提交
3258
**Example**
3259

3260
  ```js
3261 3262
  let that = new util.types();
  let result = that.isBigInt64Array(new BigInt64Array([]));
W
wusongqing 已提交
3263 3264 3265
  ```


3266
### isBigUint64Array<sup>8+</sup>
Z
zengyawen 已提交
3267

3268
isBigUint64Array(value: Object): boolean
Z
zengyawen 已提交
3269

3270
Checks whether the input value is of the **BigUint64Array** type.
3271

W
wusongqing 已提交
3272 3273 3274
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3275

W
wusongqing 已提交
3276 3277
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3278
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3279

W
wusongqing 已提交
3280
**Return value**
3281

W
wusongqing 已提交
3282 3283
| Type| Description|
| -------- | -------- |
3284
| boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3285

W
wusongqing 已提交
3286
**Example**
3287

3288
  ```js
3289 3290
  let that = new util.types();
  let result = that.isBigUint64Array(new BigUint64Array([]));
W
wusongqing 已提交
3291 3292 3293
  ```


3294
### isModuleNamespaceObject<sup>8+</sup>
W
wusongqing 已提交
3295

3296
isModuleNamespaceObject(value: Object): boolean
W
wusongqing 已提交
3297

3298
Checks whether the input value is a module namespace object.
3299

W
wusongqing 已提交
3300 3301 3302
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3303

W
wusongqing 已提交
3304 3305
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3306
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3307

W
wusongqing 已提交
3308
**Return value**
3309

W
wusongqing 已提交
3310 3311
| Type| Description|
| -------- | -------- |
3312
| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.|
W
wusongqing 已提交
3313

W
wusongqing 已提交
3314
**Example**
3315

3316
  ```js
3317 3318 3319
  import url from '@ohos.url'
  let that = new util.types();
  let result = that.isModuleNamespaceObject(url);
W
wusongqing 已提交
3320 3321 3322
  ```


3323
### isSharedArrayBuffer<sup>8+</sup>
Z
zengyawen 已提交
3324

3325
isSharedArrayBuffer(value: Object): boolean
Z
zengyawen 已提交
3326

3327
Checks whether the input value is of the **SharedArrayBuffer** type.
3328

W
wusongqing 已提交
3329 3330 3331
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3332

W
wusongqing 已提交
3333 3334
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3335
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3336

W
wusongqing 已提交
3337
**Return value**
3338

W
wusongqing 已提交
3339 3340
| Type| Description|
| -------- | -------- |
3341
| boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
3342

W
wusongqing 已提交
3343
**Example**
3344

3345
  ```js
3346 3347
  let that = new util.types();
  let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
W
wusongqing 已提交
3348 3349
  ```

3350
## LruBuffer<sup>(deprecated)</sup>
W
wusongqing 已提交
3351

3352 3353 3354
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache<sup>9+</sup>](#lrucache9) instead.
W
wusongqing 已提交
3355

3356
### Attributes
W
wusongqing 已提交
3357

W
wusongqing 已提交
3358 3359
**System capability**: SystemCapability.Utils.Lang

3360 3361 3362 3363
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Total number of values in this buffer.|

W
wusongqing 已提交
3364
**Example**
3365

3366
  ```js
3367 3368 3369 3370
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(1,8);
  let result = pro.length;
W
wusongqing 已提交
3371 3372
  ```

3373
### constructor<sup>(deprecated)</sup>
W
wusongqing 已提交
3374

3375
constructor(capacity?: number)
W
wusongqing 已提交
3376

3377
A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
W
wusongqing 已提交
3378

3379 3380
> **NOTE**
>
G
Gloria 已提交
3381
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.constructor<sup>9+</sup>](#constructor9-3) instead.
W
wusongqing 已提交
3382

W
wusongqing 已提交
3383 3384 3385
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3386

W
wusongqing 已提交
3387 3388
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3389
| capacity | number | No| Capacity of the **LruBuffer** to create.|
W
wusongqing 已提交
3390

W
wusongqing 已提交
3391
**Example**
3392

3393
  ```js
3394
  let lrubuffer= new util.LruBuffer();
W
wusongqing 已提交
3395 3396
  ```

3397
### updateCapacity<sup>(deprecated)</sup>
W
wusongqing 已提交
3398

3399
updateCapacity(newCapacity: number): void
W
wusongqing 已提交
3400

3401
Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
W
wusongqing 已提交
3402

3403 3404
> **NOTE**
>
G
Gloria 已提交
3405
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.updateCapacity<sup>9+</sup>](#updatecapacity9) instead.
W
wusongqing 已提交
3406

W
wusongqing 已提交
3407 3408 3409
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3410

W
wusongqing 已提交
3411 3412
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3413
| newCapacity | number | Yes| New capacity of the **LruBuffer**.|
W
wusongqing 已提交
3414

W
wusongqing 已提交
3415
**Example**
3416

3417
  ```js
3418 3419
  let pro = new util.LruBuffer();
  let result = pro.updateCapacity(100);
W
wusongqing 已提交
3420 3421
  ```

3422
### toString<sup>(deprecated)</sup>
W
wusongqing 已提交
3423

3424
toString(): string
W
wusongqing 已提交
3425

3426
Obtains the string representation of this **LruBuffer** object.
W
wusongqing 已提交
3427

3428 3429
> **NOTE**
>
G
Gloria 已提交
3430
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.toString<sup>9+</sup>](#tostring9) instead.
W
wusongqing 已提交
3431

W
wusongqing 已提交
3432 3433 3434
**System capability**: SystemCapability.Utils.Lang

**Return value**
3435

W
wusongqing 已提交
3436 3437
| Type| Description|
| -------- | -------- |
3438
| string | String representation of this **LruBuffer** object.|
W
wusongqing 已提交
3439

W
wusongqing 已提交
3440
**Example**
3441

3442
  ```js
3443 3444 3445 3446 3447
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  pro.remove(20);
  let result = pro.toString();
W
wusongqing 已提交
3448 3449
  ```

3450
### getCapacity<sup>(deprecated)</sup>
W
wusongqing 已提交
3451

3452
getCapacity(): number
W
wusongqing 已提交
3453

3454
Obtains the capacity of this buffer.
W
wusongqing 已提交
3455

3456 3457
> **NOTE**
>
G
Gloria 已提交
3458
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCapacity<sup>9+</sup>](#getcapacity9) instead.
W
wusongqing 已提交
3459

W
wusongqing 已提交
3460 3461 3462
**System capability**: SystemCapability.Utils.Lang

**Return value**
3463

W
wusongqing 已提交
3464 3465
| Type| Description|
| -------- | -------- |
3466
| number | Capacity of this buffer.|
W
wusongqing 已提交
3467

W
wusongqing 已提交
3468
**Example**
3469
  ```js
3470 3471
  let pro = new util.LruBuffer();
  let result = pro.getCapacity();
W
wusongqing 已提交
3472 3473
  ```

3474
### clear<sup>(deprecated)</sup>
W
wusongqing 已提交
3475

3476
clear(): void
W
wusongqing 已提交
3477

3478
Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations.
Z
zengyawen 已提交
3479

3480 3481
> **NOTE**
>
G
Gloria 已提交
3482
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.clear<sup>9+</sup>](#clear9) instead.
Z
zengyawen 已提交
3483

W
wusongqing 已提交
3484 3485
**System capability**: SystemCapability.Utils.Lang

3486
**Example**
3487

3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.length;
  pro.clear();
  ```

### getCreateCount<sup>(deprecated)</sup>

getCreateCount(): number

Obtains the number of return values for **createDefault()**.

> **NOTE**
>
G
Gloria 已提交
3503
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
3504 3505

**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
3506

W
wusongqing 已提交
3507
**Return value**
3508

W
wusongqing 已提交
3509 3510
| Type| Description|
| -------- | -------- |
3511
| number | Number of return values for **createDefault()**.|
W
wusongqing 已提交
3512

W
wusongqing 已提交
3513
**Example**
3514

3515
  ```js
3516 3517 3518
  let pro = new util.LruBuffer();
  pro.put(1,8);
  let result = pro.getCreateCount();
W
wusongqing 已提交
3519 3520
  ```

3521
### getMissCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3522

3523
getMissCount(): number
W
wusongqing 已提交
3524

3525
Obtains the number of times that the queried values are mismatched.
W
wusongqing 已提交
3526

3527 3528
> **NOTE**
>
G
Gloria 已提交
3529
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMissCount<sup>9+</sup>](#getmisscount9) instead.
W
wusongqing 已提交
3530

W
wusongqing 已提交
3531 3532 3533
**System capability**: SystemCapability.Utils.Lang

**Return value**
3534

W
wusongqing 已提交
3535 3536
| Type| Description|
| -------- | -------- |
3537
| number | Number of times that the queried values are mismatched.|
W
wusongqing 已提交
3538

W
wusongqing 已提交
3539
**Example**
3540

3541
  ```js
3542 3543 3544 3545
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  let result = pro.getMissCount();
W
wusongqing 已提交
3546 3547
  ```

3548
### getRemovalCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3549

3550
getRemovalCount(): number
W
wusongqing 已提交
3551

3552
Obtains the number of removals from this buffer.
W
wusongqing 已提交
3553

3554 3555
> **NOTE**
>
G
Gloria 已提交
3556
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
W
wusongqing 已提交
3557

W
wusongqing 已提交
3558 3559 3560
**System capability**: SystemCapability.Utils.Lang

**Return value**
3561

W
wusongqing 已提交
3562 3563
| Type| Description|
| -------- | -------- |
3564
| number | Number of removals from the buffer.|
W
wusongqing 已提交
3565

W
wusongqing 已提交
3566
**Example**
3567

3568
  ```js
3569 3570 3571 3572 3573
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.updateCapacity(2);
  pro.put(50,22);
  let result = pro.getRemovalCount();
W
wusongqing 已提交
3574 3575
  ```

3576
### getMatchCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3577

3578
getMatchCount(): number
W
wusongqing 已提交
3579

3580
Obtains the number of times that the queried values are matched.
W
wusongqing 已提交
3581

3582 3583
> **NOTE**
>
G
Gloria 已提交
3584
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
W
wusongqing 已提交
3585

W
wusongqing 已提交
3586 3587 3588
**System capability**: SystemCapability.Utils.Lang

**Return value**
3589

W
wusongqing 已提交
3590 3591
| Type| Description|
| -------- | -------- |
3592
| number | Number of times that the queried values are matched.|
W
wusongqing 已提交
3593

W
wusongqing 已提交
3594
**Example**
3595

3596
  ```js
3597 3598 3599 3600
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  let result = pro.getMatchCount();
W
wusongqing 已提交
3601 3602
  ```

3603
### getPutCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3604

3605
getPutCount(): number
W
wusongqing 已提交
3606

3607
Obtains the number of additions to this buffer.
W
wusongqing 已提交
3608

3609 3610
> **NOTE**
>
G
Gloria 已提交
3611
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getPutCount<sup>9+</sup>](#getputcount9) instead.
W
wusongqing 已提交
3612

W
wusongqing 已提交
3613 3614 3615
**System capability**: SystemCapability.Utils.Lang

**Return value**
3616

W
wusongqing 已提交
3617 3618
| Type| Description|
| -------- | -------- |
3619
| number | Number of additions to the buffer.|
W
wusongqing 已提交
3620

W
wusongqing 已提交
3621
**Example**
3622

3623
  ```js
3624 3625 3626
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.getPutCount();
W
wusongqing 已提交
3627 3628
  ```

3629
### isEmpty<sup>(deprecated)</sup>
W
wusongqing 已提交
3630

3631
isEmpty(): boolean
W
wusongqing 已提交
3632

3633
Checks whether this buffer is empty.
W
wusongqing 已提交
3634

3635 3636
> **NOTE**
>
G
Gloria 已提交
3637
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.isEmpty<sup>9+</sup>](#isempty9) instead.
W
wusongqing 已提交
3638

W
wusongqing 已提交
3639 3640 3641
**System capability**: SystemCapability.Utils.Lang

**Return value**
3642

W
wusongqing 已提交
3643 3644
| Type| Description|
| -------- | -------- |
3645
| boolean | Returns **true** if the buffer does not contain any value.|
W
wusongqing 已提交
3646

W
wusongqing 已提交
3647
**Example**
3648

3649
  ```js
3650 3651 3652
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.isEmpty();
W
wusongqing 已提交
3653 3654
  ```

3655
### get<sup>(deprecated)</sup>
W
wusongqing 已提交
3656

3657
get(key: K): V | undefined
W
wusongqing 已提交
3658

3659
Obtains the value of the specified key.
W
wusongqing 已提交
3660

3661 3662
> **NOTE**
>
G
Gloria 已提交
3663
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.get<sup>9+</sup>](#get9) instead.
W
wusongqing 已提交
3664

W
wusongqing 已提交
3665 3666 3667
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3668

W
wusongqing 已提交
3669 3670
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3671
| key | K | Yes| Key based on which the value is queried.|
W
wusongqing 已提交
3672

W
wusongqing 已提交
3673
**Return value**
3674

W
wusongqing 已提交
3675 3676
| Type| Description|
| -------- | -------- |
3677
| V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
W
wusongqing 已提交
3678

W
wusongqing 已提交
3679
**Example**
3680

3681
  ```js
3682 3683 3684
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result  = pro.get(2);
W
wusongqing 已提交
3685 3686
  ```

3687
### put<sup>(deprecated)</sup>
W
wusongqing 已提交
3688

3689
put(key: K,value: V): V
W
wusongqing 已提交
3690

3691
Adds a key-value pair to this buffer.
W
wusongqing 已提交
3692

3693 3694
> **NOTE**
>
G
Gloria 已提交
3695
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.put<sup>9+</sup>](#put9) instead.
W
wusongqing 已提交
3696

W
wusongqing 已提交
3697 3698 3699
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3700

W
wusongqing 已提交
3701 3702
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3703 3704
| key | K | Yes| Key of the key-value pair to add.|
| value | V | Yes| Value of the key-value pair to add.|
W
wusongqing 已提交
3705

W
wusongqing 已提交
3706
**Return value**
3707

W
wusongqing 已提交
3708 3709
| Type| Description|
| -------- | -------- |
3710
| 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. |
W
wusongqing 已提交
3711

W
wusongqing 已提交
3712
**Example**
3713

3714
  ```js
3715 3716
  let pro = new util.LruBuffer();
  let result = pro.put(2,10);
W
wusongqing 已提交
3717 3718
  ```

3719
### values<sup>(deprecated)</sup>
W
wusongqing 已提交
3720

3721
values(): V[]
W
wusongqing 已提交
3722

3723
Obtains all values in this buffer, listed from the most to the least recently accessed.
Z
zengyawen 已提交
3724

3725 3726
> **NOTE**
>
G
Gloria 已提交
3727
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.values<sup>9+</sup>](#values9) instead.
Z
zengyawen 已提交
3728

W
wusongqing 已提交
3729 3730 3731
**System capability**: SystemCapability.Utils.Lang

**Return value**
3732

W
wusongqing 已提交
3733 3734
| Type| Description|
| -------- | -------- |
3735
| V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|
W
wusongqing 已提交
3736

W
wusongqing 已提交
3737
**Example**
3738

3739
  ```js
3740 3741 3742 3743 3744
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(2,"anhu");
  pro.put("afaf","grfb");
  let result = pro.values();
W
wusongqing 已提交
3745 3746
  ```

3747
### keys<sup>(deprecated)</sup>
W
wusongqing 已提交
3748

3749
keys(): K[]
W
wusongqing 已提交
3750

3751
Obtains all keys in this buffer, listed from the most to the least recently accessed.
Z
zengyawen 已提交
3752

3753 3754
> **NOTE**
>
G
Gloria 已提交
3755
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.keys<sup>9+</sup>](#keys9) instead.
Z
zengyawen 已提交
3756

W
wusongqing 已提交
3757 3758 3759
**System capability**: SystemCapability.Utils.Lang

**Return value**
3760

W
wusongqing 已提交
3761 3762
| Type| Description|
| -------- | -------- |
3763
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
W
wusongqing 已提交
3764

W
wusongqing 已提交
3765
**Example**
G
Gloria 已提交
3766

3767
  ```js
3768 3769 3770
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.keys();
W
wusongqing 已提交
3771 3772
  ```

3773
### remove<sup>(deprecated)</sup>
W
wusongqing 已提交
3774

3775
remove(key: K): V | undefined
W
wusongqing 已提交
3776

3777
Removes the specified key and its value from this buffer.
W
wusongqing 已提交
3778

3779 3780
> **NOTE**
>
G
Gloria 已提交
3781
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.remove<sup>9+</sup>](#remove9) instead.
W
wusongqing 已提交
3782

W
wusongqing 已提交
3783 3784 3785
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3786

W
wusongqing 已提交
3787 3788
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3789
| key | K | Yes| Key to remove.|
W
wusongqing 已提交
3790

W
wusongqing 已提交
3791
**Return value**
3792

W
wusongqing 已提交
3793 3794
| Type| Description|
| -------- | -------- |
3795
| 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.|
W
wusongqing 已提交
3796

W
wusongqing 已提交
3797
**Example**
3798
  ```js
3799 3800 3801
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.remove(20);
W
wusongqing 已提交
3802 3803
  ```

3804
### afterRemoval<sup>(deprecated)</sup>
W
wusongqing 已提交
3805

3806
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
W
wusongqing 已提交
3807

3808
Performs subsequent operations after a value is removed.
W
wusongqing 已提交
3809

3810 3811
> **NOTE**
>
G
Gloria 已提交
3812
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.afterRemoval<sup>9+</sup>](#afterremoval9) instead.
W
wusongqing 已提交
3813

W
wusongqing 已提交
3814 3815 3816
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3817

W
wusongqing 已提交
3818 3819
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
3820
| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity.|
3821 3822 3823
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.|
| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
W
wusongqing 已提交
3824

W
wusongqing 已提交
3825
**Example**
3826

3827
  ```js
3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844
  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);
W
wusongqing 已提交
3845 3846
  ```

3847
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
3848

3849
contains(key: K): boolean
W
wusongqing 已提交
3850

3851
Checks whether this buffer contains the specified key.
W
wusongqing 已提交
3852

3853 3854 3855

> **NOTE**
>
G
Gloria 已提交
3856
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.contains<sup>9+</sup>](#contains9) instead.
W
wusongqing 已提交
3857

W
wusongqing 已提交
3858 3859 3860
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3861

W
wusongqing 已提交
3862 3863
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3864
| key | K | Yes| Key to check.|
W
wusongqing 已提交
3865

W
wusongqing 已提交
3866
**Return value**
3867

W
wusongqing 已提交
3868 3869
| Type| Description|
| -------- | -------- |
3870
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
W
wusongqing 已提交
3871

W
wusongqing 已提交
3872
**Example**
3873

3874
  ```js
3875 3876 3877
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.contains(20);
W
wusongqing 已提交
3878 3879
  ```

3880
### createDefault<sup>(deprecated)</sup>
W
wusongqing 已提交
3881

3882
createDefault(key: K): V
W
wusongqing 已提交
3883

3884
Creates a value if the value of the specified key is not available.
W
wusongqing 已提交
3885

3886 3887
> **NOTE**
>
G
Gloria 已提交
3888
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.createDefault<sup>9+</sup>](#createdefault9) instead.
W
wusongqing 已提交
3889

W
wusongqing 已提交
3890 3891 3892
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3893

W
wusongqing 已提交
3894 3895
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3896
| key | K | Yes| Key of which the value is missing.|
W
wusongqing 已提交
3897

W
wusongqing 已提交
3898
**Return value**
3899

W
wusongqing 已提交
3900 3901
| Type| Description|
| -------- | -------- |
3902
| V | Value of the key.|
W
wusongqing 已提交
3903

W
wusongqing 已提交
3904
**Example**
3905

3906
  ```js
3907 3908
  let pro = new util.LruBuffer();
  let result = pro.createDefault(50);
W
wusongqing 已提交
3909 3910
  ```

3911
### entries<sup>(deprecated)</sup>
W
wusongqing 已提交
3912

3913
entries(): IterableIterator&lt;[K,V]&gt;
W
wusongqing 已提交
3914

3915
Obtains a new iterator object that contains all key-value pairs in this object.
W
wusongqing 已提交
3916

3917 3918
> **NOTE**
>
G
Gloria 已提交
3919
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.entries<sup>9+</sup>](#entries9) instead.
W
wusongqing 已提交
3920

W
wusongqing 已提交
3921 3922 3923
**System capability**: SystemCapability.Utils.Lang

**Return value**
3924

W
wusongqing 已提交
3925 3926
| Type| Description|
| -------- | -------- |
3927
| [K,&nbsp;V] | Iterable array.|
W
wusongqing 已提交
3928

W
wusongqing 已提交
3929
**Example**
3930

3931
  ```js
3932 3933 3934
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.entries();
W
wusongqing 已提交
3935 3936
  ```

3937
### [Symbol.iterator]<sup>(deprecated)</sup>
W
wusongqing 已提交
3938

3939
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
W
wusongqing 已提交
3940

3941
Obtains a two-dimensional array in key-value pairs.
W
wusongqing 已提交
3942

3943 3944
> **NOTE**
>
G
Gloria 已提交
3945
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
W
wusongqing 已提交
3946

W
wusongqing 已提交
3947 3948 3949
**System capability**: SystemCapability.Utils.Lang

**Return value**
3950

W
wusongqing 已提交
3951 3952
| Type| Description|
| -------- | -------- |
3953
| [K,&nbsp;V] | Two-dimensional array in key-value pairs.|
W
wusongqing 已提交
3954

W
wusongqing 已提交
3955
**Example**
3956

3957
  ```js
3958 3959 3960
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro[Symbol.iterator]();
W
wusongqing 已提交
3961 3962
  ```

3963
## Scope<sup>(deprecated)</sup>
W
wusongqing 已提交
3964

3965 3966 3967
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper<sup>9+</sup>](#scopehelper9) instead.
W
wusongqing 已提交
3968

3969 3970 3971 3972 3973 3974 3975 3976
### constructor<sup>(deprecated)</sup>

constructor(lowerObj: ScopeType, upperObj: ScopeType)

A constructor used to create a **Scope** object with the specified upper and lower limits.

> **NOTE**
>
G
Gloria 已提交
3977
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.constructor<sup>9+</sup>](#constructor9-4) instead.
Z
zengyawen 已提交
3978 3979


W
wusongqing 已提交
3980 3981 3982
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3983

W
wusongqing 已提交
3984 3985
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3986 3987
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
W
wusongqing 已提交
3988

W
wusongqing 已提交
3989
**Example**
3990
  ```js
3991 3992 3993
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
3994 3995
  ```

3996
### toString<sup>(deprecated)</sup>
W
wusongqing 已提交
3997

3998
toString(): string
W
wusongqing 已提交
3999

4000
Obtains a string representation that contains this **Scope**.
Z
zengyawen 已提交
4001

4002 4003
> **NOTE**
>
G
Gloria 已提交
4004
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.toString<sup>9+</sup>](#tostring9-1) instead.
Z
zengyawen 已提交
4005

W
wusongqing 已提交
4006 4007 4008
**System capability**: SystemCapability.Utils.Lang

**Return value**
4009

W
wusongqing 已提交
4010 4011
| Type| Description|
| -------- | -------- |
4012
| string | String representation containing the **Scope**.|
W
wusongqing 已提交
4013

W
wusongqing 已提交
4014
**Example**
4015

4016
  ```js
4017 4018 4019 4020
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.toString();
W
wusongqing 已提交
4021 4022
  ```

4023
### intersect<sup>(deprecated)</sup>
W
wusongqing 已提交
4024

4025
intersect(range: Scope): Scope
W
wusongqing 已提交
4026

4027
Obtains the intersection of this **Scope** and the given **Scope**.
Z
zengyawen 已提交
4028

4029 4030
> **NOTE**
>
G
Gloria 已提交
4031
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9) instead.
Z
zengyawen 已提交
4032

W
wusongqing 已提交
4033 4034 4035
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4036

W
wusongqing 已提交
4037 4038
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4039
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
4040

W
wusongqing 已提交
4041
**Return value**
4042

W
wusongqing 已提交
4043 4044
| Type| Description|
| -------- | -------- |
4045
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
4046

W
wusongqing 已提交
4047
**Example**
4048

4049
  ```js
4050 4051 4052 4053 4054 4055 4056
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let tempMiDF = new Temperature(35);
  let tempMidS = new Temperature(39);
  let rangeFir = new util.Scope(tempMiDF, tempMidS);
  range.intersect(rangeFir );
W
wusongqing 已提交
4057 4058
  ```

4059
### intersect<sup>(deprecated)</sup>
W
wusongqing 已提交
4060

4061
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
W
wusongqing 已提交
4062

4063
Obtains the intersection of this **Scope** and the given lower and upper limits.
W
wusongqing 已提交
4064

4065 4066
> **NOTE**
>
G
Gloria 已提交
4067
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9-1) instead.
W
wusongqing 已提交
4068

W
wusongqing 已提交
4069 4070 4071
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4072

W
wusongqing 已提交
4073 4074
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4075 4076
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
4077

W
wusongqing 已提交
4078
**Return value**
4079

W
wusongqing 已提交
4080 4081
| Type| Description|
| -------- | -------- |
4082
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
4083

W
wusongqing 已提交
4084
**Example**
4085

4086
  ```js
4087 4088 4089 4090 4091 4092
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let tempMidS = new Temperature(39);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.intersect(tempMiDF, tempMidS);
W
wusongqing 已提交
4093 4094
  ```

4095
### getUpper<sup>(deprecated)</sup>
W
wusongqing 已提交
4096

4097
getUpper(): ScopeType
W
wusongqing 已提交
4098

4099
Obtains the upper limit of this **Scope**.
W
wusongqing 已提交
4100

4101 4102
> **NOTE**
>
G
Gloria 已提交
4103
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getUpper<sup>9+</sup>](#getupper9) instead.
W
wusongqing 已提交
4104

W
wusongqing 已提交
4105 4106 4107
**System capability**: SystemCapability.Utils.Lang

**Return value**
4108

W
wusongqing 已提交
4109 4110
| Type| Description|
| -------- | -------- |
4111
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
W
wusongqing 已提交
4112

W
wusongqing 已提交
4113
**Example**
4114

4115
  ```js
4116 4117 4118 4119
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getUpper();
W
wusongqing 已提交
4120 4121
  ```

4122
### getLower<sup>(deprecated)</sup>
W
wusongqing 已提交
4123

4124
getLower(): ScopeType
W
wusongqing 已提交
4125

4126
Obtains the lower limit of this **Scope**.
W
wusongqing 已提交
4127

4128 4129
> **NOTE**
>
G
Gloria 已提交
4130
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getLower<sup>9+</sup>](#getlower9) instead.
W
wusongqing 已提交
4131

W
wusongqing 已提交
4132 4133 4134
**System capability**: SystemCapability.Utils.Lang

**Return value**
4135

W
wusongqing 已提交
4136 4137
| Type| Description|
| -------- | -------- |
4138
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
W
wusongqing 已提交
4139

W
wusongqing 已提交
4140
**Example**
4141

4142
  ```js
4143 4144 4145 4146
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getLower();
W
wusongqing 已提交
4147 4148
  ```

4149
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
4150

4151
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
W
wusongqing 已提交
4152

4153
Obtains the union set of this **Scope** and the given lower and upper limits.
Z
zengyawen 已提交
4154

4155 4156
> **NOTE**
>
G
Gloria 已提交
4157
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9) instead.
Z
zengyawen 已提交
4158

W
wusongqing 已提交
4159 4160 4161
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4162

W
wusongqing 已提交
4163 4164
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4165 4166
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
4167

W
wusongqing 已提交
4168
**Return value**
4169

W
wusongqing 已提交
4170 4171
| Type| Description|
| -------- | -------- |
4172
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
4173

W
wusongqing 已提交
4174
**Example**
4175

4176
  ```js
4177 4178 4179 4180 4181 4182
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let tempMidS = new Temperature(39);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.expand(tempMiDF, tempMidS);
W
wusongqing 已提交
4183 4184
  ```

4185
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
4186

4187
expand(range: Scope): Scope
W
wusongqing 已提交
4188

4189
Obtains the union set of this **Scope** and the given **Scope**.
Z
zengyawen 已提交
4190

4191 4192
> **NOTE**
>
G
Gloria 已提交
4193
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-1) instead.
Z
zengyawen 已提交
4194

W
wusongqing 已提交
4195 4196 4197
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4198

W
wusongqing 已提交
4199 4200
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4201
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
4202

W
wusongqing 已提交
4203
**Return value**
4204

W
wusongqing 已提交
4205 4206
| Type| Description|
| -------- | -------- |
4207
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
4208

W
wusongqing 已提交
4209
**Example**
4210

4211
  ```js
4212 4213 4214 4215 4216 4217 4218
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let tempMidS = new Temperature(39);
  let range = new util.Scope(tempLower, tempUpper);
  let rangeFir = new util.Scope(tempMiDF, tempMidS);
  let result = range.expand(rangeFir);
W
wusongqing 已提交
4219 4220
  ```

4221
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
4222

4223
expand(value: ScopeType): Scope
W
wusongqing 已提交
4224

4225
Obtains the union set of this **Scope** and the given value.
W
wusongqing 已提交
4226

4227 4228
> **NOTE**
>
G
Gloria 已提交
4229
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-2) instead.
W
wusongqing 已提交
4230

W
wusongqing 已提交
4231 4232 4233
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4234

W
wusongqing 已提交
4235 4236
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4237
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
4238

W
wusongqing 已提交
4239
**Return value**
4240

W
wusongqing 已提交
4241 4242
| Type| Description|
| -------- | -------- |
4243
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.|
W
wusongqing 已提交
4244

W
wusongqing 已提交
4245
**Example**
4246

4247
  ```js
4248 4249 4250 4251 4252
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.expand(tempMiDF);
W
wusongqing 已提交
4253 4254
  ```

4255
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
4256

4257
contains(value: ScopeType): boolean
W
wusongqing 已提交
4258

4259
Checks whether a value is within this **Scope**.
W
wusongqing 已提交
4260

4261 4262
> **NOTE**
>
G
Gloria 已提交
4263
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-1) instead.
W
wusongqing 已提交
4264

W
wusongqing 已提交
4265 4266 4267
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4268

W
wusongqing 已提交
4269 4270
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4271
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
4272

W
wusongqing 已提交
4273
**Return value**
4274

W
wusongqing 已提交
4275 4276
| Type| Description|
| -------- | -------- |
4277
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
4278

W
wusongqing 已提交
4279
**Example**
4280

4281
  ```js
4282 4283 4284 4285 4286
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let range = new util.Scope(tempLower, tempUpper);
  range.contains(tempMiDF);
W
wusongqing 已提交
4287 4288
  ```

4289
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
4290

4291
contains(range: Scope): boolean
W
wusongqing 已提交
4292

4293
Checks whether a range is within this **Scope**.
W
wusongqing 已提交
4294

4295 4296
> **NOTE**
>
G
Gloria 已提交
4297
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-2) instead.
W
wusongqing 已提交
4298

W
wusongqing 已提交
4299 4300 4301
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4302

W
wusongqing 已提交
4303 4304
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4305
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
4306

W
wusongqing 已提交
4307
**Return value**
4308

W
wusongqing 已提交
4309 4310
| Type| Description|
| -------- | -------- |
4311
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
4312

W
wusongqing 已提交
4313
**Example**
4314

4315
  ```js
4316 4317 4318 4319 4320 4321 4322
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let tempLess = new Temperature(20);
  let tempMore = new Temperature(45);
  let rangeSec = new util.Scope(tempLess, tempMore);
  let result = range.contains(rangeSec);
W
wusongqing 已提交
4323 4324
  ```

4325
### clamp<sup>(deprecated)</sup>
W
wusongqing 已提交
4326 4327


4328
clamp(value: ScopeType): ScopeType
W
wusongqing 已提交
4329

4330 4331 4332 4333
Limits a value to this **Scope**.

> **NOTE**
>
G
Gloria 已提交
4334
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.clamp<sup>9+</sup>](#clamp9) instead.
W
wusongqing 已提交
4335

W
wusongqing 已提交
4336 4337 4338
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4339

W
wusongqing 已提交
4340 4341
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4342
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
4343

W
wusongqing 已提交
4344
**Return value**
4345

W
wusongqing 已提交
4346 4347
| Type| Description|
| -------- | -------- |
4348
| [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**.|
W
wusongqing 已提交
4349

W
wusongqing 已提交
4350
**Example**
4351

4352
  ```js
4353 4354 4355 4356 4357
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.clamp(tempMiDF);
W
wusongqing 已提交
4358 4359 4360
  ```


4361
## Base64<sup>(deprecated)</sup>
W
wusongqing 已提交
4362

4363 4364 4365
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper<sup>9+</sup>](#base64helper9) instead.
W
wusongqing 已提交
4366

4367
### constructor<sup>(deprecated)</sup>
W
wusongqing 已提交
4368

4369
constructor()
4370

4371
A constructor used to create a **Base64** object.
W
wusongqing 已提交
4372

4373 4374
> **NOTE**
>
G
Gloria 已提交
4375
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.constructor<sup>9+</sup>](#constructor9-5) instead.
4376

4377
**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
4378

W
wusongqing 已提交
4379
**Example**
4380

4381
  ```js
4382
  let base64 = new  util.Base64();
W
wusongqing 已提交
4383 4384
  ```

4385
### encodeSync<sup>(deprecated)</sup>
W
wusongqing 已提交
4386

4387
encodeSync(src: Uint8Array): Uint8Array
W
wusongqing 已提交
4388

4389
Encodes the input content.
W
wusongqing 已提交
4390

4391 4392
> **NOTE**
>
G
Gloria 已提交
4393
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeSync<sup>9+</sup>](#encodesync9) instead.
W
wusongqing 已提交
4394

W
wusongqing 已提交
4395 4396 4397
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4398

W
wusongqing 已提交
4399 4400
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4401
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
4402

W
wusongqing 已提交
4403
**Return value**
4404

W
wusongqing 已提交
4405 4406
| Type| Description|
| -------- | -------- |
4407
| Uint8Array | Uint8Array encoded.|
W
wusongqing 已提交
4408

W
wusongqing 已提交
4409
**Example**
4410

4411
  ```js
4412 4413 4414
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeSync(array);
W
wusongqing 已提交
4415 4416
  ```

4417
### encodeToStringSync<sup>(deprecated)</sup>
W
wusongqing 已提交
4418

4419
encodeToStringSync(src: Uint8Array): string
W
wusongqing 已提交
4420

4421
Encodes the input content.
W
wusongqing 已提交
4422

4423 4424
> **NOTE**
>
G
Gloria 已提交
4425
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
W
wusongqing 已提交
4426

W
wusongqing 已提交
4427 4428 4429
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4430

W
wusongqing 已提交
4431 4432
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4433
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
4434

W
wusongqing 已提交
4435
**Return value**
4436

W
wusongqing 已提交
4437 4438
| Type| Description|
| -------- | -------- |
4439
| string | String encoded from the Uint8Array.|
Z
zengyawen 已提交
4440

W
wusongqing 已提交
4441
**Example**
4442

4443
  ```js
4444 4445 4446
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeToStringSync(array);
4447 4448
  ```

4449
### decodeSync<sup>(deprecated)</sup>
4450

4451
decodeSync(src: Uint8Array | string): Uint8Array
4452

4453
Decodes the input content.
4454

4455 4456
> **NOTE**
>
G
Gloria 已提交
4457
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decodeSync<sup>9+</sup>](#decodesync9) instead.
4458 4459 4460 4461 4462 4463 4464

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4465
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.|
4466 4467 4468 4469 4470

**Return value**

| Type| Description|
| -------- | -------- |
4471
| Uint8Array | Uint8Array decoded.|
4472 4473

**Example**
4474

4475
  ```js
4476 4477 4478
  let that = new util.Base64();
  let buff = 'czEz';
  let result = that.decodeSync(buff);
4479 4480
  ```

4481
### encode<sup>(deprecated)</sup>
4482

4483
encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
4484

4485
Encodes the input content asynchronously.
4486

4487 4488
> **NOTE**
>
G
Gloria 已提交
4489
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encode<sup>9+</sup>](#encode9) instead.
4490 4491 4492 4493 4494 4495 4496

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4497
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
4498 4499 4500 4501 4502

**Return value**

| Type| Description|
| -------- | -------- |
4503
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
4504 4505

**Example**
4506

4507
  ```js
4508 4509 4510 4511 4512 4513 4514 4515
  let that = new util.Base64();
  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())
      }
  })
4516 4517
  ```

4518
### encodeToString<sup>(deprecated)</sup>
4519

4520
encodeToString(src: Uint8Array): Promise&lt;string&gt;
4521

4522
Encodes the input content asynchronously.
4523

4524 4525
> **NOTE**
>
G
Gloria 已提交
4526
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToString<sup>9+</sup>](#encodetostring9) instead.
4527 4528 4529 4530 4531 4532 4533

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4534
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
4535 4536 4537 4538 4539

**Return value**

| Type| Description|
| -------- | -------- |
4540
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
4541 4542

**Example**
4543

4544
  ```js
4545 4546 4547 4548 4549
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  that.encodeToString(array).then(val=>{    
      console.log(val)
  })
4550 4551
  ```

4552 4553
### decode<sup>(deprecated)</sup>

4554

4555
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
4556

4557
Decodes the input content asynchronously.
4558

4559 4560
> **NOTE**
>
G
Gloria 已提交
4561
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decode<sup>9+</sup>](#decode9) instead.
4562 4563 4564 4565 4566 4567 4568

**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4569
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.|
4570 4571 4572 4573 4574

**Return value**

| Type| Description|
| -------- | -------- |
4575
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
4576 4577

**Example**
4578

4579
  ```js
4580 4581 4582 4583 4584 4585 4586 4587
  let that = new util.Base64();
  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())
      }
  })
W
wusongqing 已提交
4588
  ```