js-apis-util.md 109.3 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.util (Utilities)
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
## util.format<sup>9+</sup>

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

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

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

**Parameters**

| Name | Type    | Mandatory| Description          |
| ------- | -------- | ---- | -------------- |
| format  | string   | Yes  | String.|
| ...args | Object[] | No  | Values to format. The formatted values will be replaced the wildcard in the string. |

**Return value**

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

**Example**

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

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

W
wusongqing 已提交
46
printf(format: string,  ...args: Object[]): string
Z
zengyawen 已提交
47

G
Gloria 已提交
48
Formats the specified values and inserts them into the string by replacing the wildcard in the string.
Z
zengyawen 已提交
49

50 51 52 53
> **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.

W
wusongqing 已提交
54 55 56
**System capability**: SystemCapability.Utils.Lang

**Parameters**
57

W
wusongqing 已提交
58 59
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
60
| format | string | Yes| String.|
61
| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.|
W
wusongqing 已提交
62

W
wusongqing 已提交
63
**Return value**
64

W
wusongqing 已提交
65 66
| Type| Description|
| -------- | -------- |
G
Gloria 已提交
67
| string | String containing the formatted values.|
W
wusongqing 已提交
68

W
wusongqing 已提交
69
**Example**
70

71
  ```js
72
  let res = util.printf("%s", "hello world!");
W
wusongqing 已提交
73 74 75
  console.log(res);
  ```

G
Gloria 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
## 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**

98
```js
G
Gloria 已提交
99 100 101
let errnum = 10; // 10 is a system error code.
let result = util.errnoToString(errnum);
console.log("result = " + result);
102
```
G
Gloria 已提交
103 104

## util.getErrorString<sup>(deprecated)</sup>
W
wusongqing 已提交
105 106

getErrorString(errno: number): string
Z
zengyawen 已提交
107 108 109

Obtains detailed information about a system error code.

110 111 112 113
> **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.

W
wusongqing 已提交
114 115 116
**System capability**: SystemCapability.Utils.Lang

**Parameters**
117

W
wusongqing 已提交
118 119 120
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errno | number | Yes| Error code generated.|
W
wusongqing 已提交
121

W
wusongqing 已提交
122
**Return value**
123

W
wusongqing 已提交
124 125 126
| Type| Description|
| -------- | -------- |
| string | Detailed information about the error code.|
W
wusongqing 已提交
127

W
wusongqing 已提交
128
**Example**
129

130
  ```js
131 132
  let errnum = 10; // 10 is a system error code.
  let result = util.getErrorString(errnum);
W
wusongqing 已提交
133 134 135 136 137 138 139
  console.log("result = " + result);
  ```

## util.callbackWrapper

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

G
Gloria 已提交
140
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 已提交
141

W
wusongqing 已提交
142 143 144 145
**System capability**: SystemCapability.Utils.Lang

**Parameters**

W
wusongqing 已提交
146 147 148
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|
Z
zengyawen 已提交
149

W
wusongqing 已提交
150
**Return value**
151

W
wusongqing 已提交
152 153 154
| 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 已提交
155

W
wusongqing 已提交
156
**Example**
157

158
  ```js
W
wusongqing 已提交
159 160 161
  async function promiseFn() {
      return Promise.reject('value');
  }
162 163
  let err = "type err";
  let cb = util.callbackWrapper(promiseFn);
W
wusongqing 已提交
164 165 166
  cb((err, ret) => {
      console.log(err);
      console.log(ret);
S
shikai-123 已提交
167
  }, err)
W
wusongqing 已提交
168 169
  ```

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

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

W
wusongqing 已提交
174
Processes an asynchronous function and returns a promise.
S
shikai-123 已提交
175 176 177 178

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

**Parameters**
179

S
shikai-123 已提交
180 181 182 183 184
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|

**Return value**
185

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

W
wusongqing 已提交
190
**Example**
191

192
  ```js
S
shikai-123 已提交
193 194 195 196 197 198
  function aysnFun(str1, str2) {
    if (typeof str1 === 'object' && typeof str2 === 'object') {
      return str2
    } else {
      return str1
    }
W
wusongqing 已提交
199
  }
S
shikai-123 已提交
200
  let newPromiseObj = util.promisify(aysnFun);
S
shikai-123 已提交
201 202
  newPromiseObj({ err: "type error" }, {value:'HelloWorld'}).then(res => {
    console.log(res);
W
wusongqing 已提交
203 204 205
  })
  ```

G
Gloria 已提交
206 207 208 209
## util.promiseWrapper<sup>(deprecated)</sup>

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

210 211
Processes an asynchronous function and returns a promise.

G
Gloria 已提交
212 213
> **NOTE**
>
214
> This API is unavailable. You are advised to use [util.promisify<sup>9+</sup>](#utilpromisify9) instead.
G
Gloria 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229

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

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
## util.randomUUID<sup>9+</sup>

randomUUID(entropyCache?: boolean): string

Uses a secure random number generator to generate a random universally unique identifier (UUID) of RFC 4122 version 4.

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

**Parameters**

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

**Return value**

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

**Example**
251

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
  ```js
  let uuid = util.randomUUID(true);
  console.log("RFC 4122 Version 4 UUID:" + uuid);
  // Output:
  // RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
  ```

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

randomBinaryUUID(entropyCache?: boolean): Uint8Array

Uses a secure random number generator to generate a random binary UUID of RFC 4122 version 4.

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

**Parameters**

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

**Return value**

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

**Example**
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
  ```js
  let uuid = util.randomBinaryUUID(true);
  console.log(JSON.stringify(uuid));
  // Output:
  // 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150
  ```

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

parseUUID(uuid: string): Uint8Array

Parses a UUID from a string, as described in RFC 4122 version 4.

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

**Parameters**

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

**Return value**

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

**Example**
309

310 311 312 313 314 315 316
  ```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
  ```

W
wusongqing 已提交
317 318 319 320
## TextDecoder

### Attributes

W
wusongqing 已提交
321 322
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
323 324 325 326 327
| 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 已提交
328

G
Gloria 已提交
329
### constructor<sup>9+</sup>
W
wusongqing 已提交
330

G
Gloria 已提交
331 332 333 334 335 336 337 338 339 340 341 342
constructor()

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

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

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

create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean },): TextDecoder;

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

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

G
Gloria 已提交
345 346 347 348 349 350 351
**Parameters**

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

352
**Table 1.1** options
G
Gloria 已提交
353 354 355 356 357 358 359 360

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

**Example**

361
```js
G
Gloria 已提交
362 363
let textDecoder = new util.TextDecoder()
textDecoder.create('utf-8', { ignoreBOM : true });
364
```
G
Gloria 已提交
365 366 367

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

S
shikai-123 已提交
368
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
W
wusongqing 已提交
369 370 371

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

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

W
wusongqing 已提交
376 377 378
**System capability**: SystemCapability.Utils.Lang

**Parameters**
379

W
wusongqing 已提交
380 381 382 383
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.|
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
W
wusongqing 已提交
384 385

  **Table 1** options
W
wusongqing 已提交
386

W
wusongqing 已提交
387 388 389 390
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fatal | boolean | No| Whether to display fatal errors.|
| ignoreBOM | boolean | No| Whether to ignore the BOM.|
W
wusongqing 已提交
391

W
wusongqing 已提交
392
**Example**
393

394
  ```js
395
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
W
wusongqing 已提交
396 397 398 399
  ```

### decode

S
shikai-123 已提交
400
decode(input: Uint8Array, options?: { stream?: false }): string
Z
zengyawen 已提交
401

Z
zengyawen 已提交
402
Decodes the input content.
Z
zengyawen 已提交
403

W
wusongqing 已提交
404 405 406
**System capability**: SystemCapability.Utils.Lang

**Parameters**
407

W
wusongqing 已提交
408 409
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
410
| input | Uint8Array | Yes| Uint8Array to decode.|
W
wusongqing 已提交
411
| options | Object | No| Options related to decoding.|
W
wusongqing 已提交
412

413
**Table 2** options
W
wusongqing 已提交
414

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

W
wusongqing 已提交
419
**Return value**
420

W
wusongqing 已提交
421 422 423
| Type| Description|
| -------- | -------- |
| string | Data decoded.|
Z
zengyawen 已提交
424

W
wusongqing 已提交
425
**Example**
426

427
  ```js
428 429
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  let result = new Uint8Array(6);
W
wusongqing 已提交
430 431 432 433 434 435 436
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
  let retStr = textDecoder.decode( result , {stream: false});
  console.log("retStr = " + retStr);
  ```


### decodeWithStream<sup>9+</sup>

decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string

Decodes the input content.

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

**Parameters**

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

457
**Table 2** options
458 459 460 461 462 463 464 465 466 467 468 469

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| stream | boolean | No| Whether to allow data blocks in subsequent **decodeWithStream()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|

**Return value**

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

**Example**
470

471 472 473 474 475 476 477 478 479 480 481
  ```js
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  let result = new Uint8Array(6);
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
  let retStr = textDecoder.decodeWithStream( result , {stream: false});
W
wusongqing 已提交
482 483
  console.log("retStr = " + retStr);
  ```
Z
zengyawen 已提交
484 485


W
wusongqing 已提交
486
## TextEncoder
Z
zengyawen 已提交
487

W
wusongqing 已提交
488
### Attributes
Z
zengyawen 已提交
489

W
wusongqing 已提交
490 491
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
492 493 494
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
Z
zengyawen 已提交
495 496


W
wusongqing 已提交
497
### constructor
Z
zengyawen 已提交
498

W
wusongqing 已提交
499
constructor()
Z
zengyawen 已提交
500

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

W
wusongqing 已提交
503 504 505
**System capability**: SystemCapability.Utils.Lang

**Example**
506

507
  ```js
508
  let textEncoder = new util.TextEncoder();
W
wusongqing 已提交
509 510
  ```

G
Gloria 已提交
511 512 513 514 515 516 517 518 519 520 521 522
### encodeInto<sup>9+</sup>

encodeInto(input?: string): Uint8Array

Encodes the input content.

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

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
523
| input  | string | No  | String to encode.|
G
Gloria 已提交
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540

**Return value**

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

**Example**

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

### encode<sup>(deprecated)</sup>
W
wusongqing 已提交
541

X
xdmal 已提交
542
encode(input?: string): Uint8Array
Z
zengyawen 已提交
543

Z
zengyawen 已提交
544
Encodes the input content.
Z
zengyawen 已提交
545

546 547 548 549
> **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.

W
wusongqing 已提交
550 551 552
**System capability**: SystemCapability.Utils.Lang

**Parameters**
553

W
wusongqing 已提交
554 555
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
556
| input | string | No| String to encode.|
W
wusongqing 已提交
557

W
wusongqing 已提交
558
**Return value**
559

W
wusongqing 已提交
560 561 562
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
W
wusongqing 已提交
563

W
wusongqing 已提交
564
**Example**
565
  ```js
566 567 568
  let textEncoder = new util.TextEncoder();
  let buffer = new ArrayBuffer(20);
  let result = new Uint8Array(buffer);
W
wusongqing 已提交
569 570 571
  result = textEncoder.encode("\uD800¥¥");
  ```

G
Gloria 已提交
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
### encodeIntoUint8Array<sup>9+</sup>

encodeIntoUint8Array(input: string, dest: Uint8Array, ): { read: number; written: number }

Stores the UTF-8 encoded text.

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

**Parameters**

| Name| Type      | Mandatory| Description                                                   |
| ------ | ---------- | ---- | ------------------------------------------------------- |
| input  | string     | Yes  | String to encode.                                     |
| dest   | Uint8Array | Yes  | **Uint8Array** instance used to store the UTF-8 encoded text.|

**Return value**

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

**Example**

  ```js
let that = new util.TextEncoder()
let buffer = new ArrayBuffer(4)
let dest = new Uint8Array(buffer)
let result = new Object()
result = that.encodeInto('abcd', dest)
  ```

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

X
xdmal 已提交
605
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
Z
zengyawen 已提交
606 607 608

Stores the UTF-8 encoded text.

609 610 611 612
> **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 已提交
613 614 615
**System capability**: SystemCapability.Utils.Lang

**Parameters**
616

W
wusongqing 已提交
617 618 619 620
| 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 已提交
621

W
wusongqing 已提交
622
**Return value**
623

W
wusongqing 已提交
624 625 626
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
Z
zengyawen 已提交
627

W
wusongqing 已提交
628
**Example**
629
  ```js
630 631 632 633
  let that = new util.TextEncoder()
  let buffer = new ArrayBuffer(4)
  let dest = new Uint8Array(buffer)
  let result = new Object()
S
shikai-123 已提交
634
  result = that.encodeInto('abcd', dest)
W
wusongqing 已提交
635
  ```
Z
zengyawen 已提交
636

W
wusongqing 已提交
637
## RationalNumber<sup>8+</sup>
Z
zengyawen 已提交
638

G
Gloria 已提交
639
### constructor<sup>9+</sup>
Z
zengyawen 已提交
640

G
Gloria 已提交
641 642 643 644 645 646 647 648
constructor()

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

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

**Example**

649
```js
G
Gloria 已提交
650
let rationalNumber = new util.RationalNumber();
651
```
G
Gloria 已提交
652 653 654

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

655
parseRationalNumber(numerator: number,denominator: number): RationalNumber
G
Gloria 已提交
656 657 658 659 660 661 662 663 664 665 666 667 668 669

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

670 671 672
```js
let rationalNumber = util.RationalNumber.parseRationalNumber(1,2)
```
G
Gloria 已提交
673

G
ge-yafang 已提交
674
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
675

X
xdmal 已提交
676
constructor(numerator: number,denominator: number)
Z
zengyawen 已提交
677

W
wusongqing 已提交
678
A constructor used to create a **RationalNumber** object.
Z
zengyawen 已提交
679

680 681 682 683
> **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.

W
wusongqing 已提交
684 685 686
**System capability**: SystemCapability.Utils.Lang

**Parameters**
687

W
wusongqing 已提交
688 689 690 691
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| numerator | number | Yes| Numerator, which is an integer.|
| denominator | number | Yes| Denominator, which is an integer.|
Z
zengyawen 已提交
692

W
wusongqing 已提交
693
**Example**
G
Gloria 已提交
694

695 696 697
```js
let rationalNumber = new util.RationalNumber(1,2);
```
Z
zengyawen 已提交
698

W
wusongqing 已提交
699
### createRationalFromString<sup>8+</sup>
Z
zengyawen 已提交
700

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

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

W
wusongqing 已提交
705 706 707
**System capability**: SystemCapability.Utils.Lang

**Parameters**
708

W
wusongqing 已提交
709 710 711
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rationalString | string | Yes| String used to create the **RationalNumber** object.|
Z
zengyawen 已提交
712

W
wusongqing 已提交
713
**Return value**
714

W
wusongqing 已提交
715 716 717
| Type| Description|
| -------- | -------- |
| object | **RationalNumber** object created.|
Z
zengyawen 已提交
718

W
wusongqing 已提交
719
**Example**
720 721 722 723 724

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

G
Gloria 已提交
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
### 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);
  ```

754
### compareTo<sup>(deprecated)</sup>
Z
zengyawen 已提交
755

X
xdmal 已提交
756
compareTo​(another: RationalNumber): number​
Z
zengyawen 已提交
757

W
wusongqing 已提交
758
Compares this **RationalNumber** object with a given object.
Z
zengyawen 已提交
759

760 761 762 763
> **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.

W
wusongqing 已提交
764 765 766
**System capability**: SystemCapability.Utils.Lang

**Parameters**
767

W
wusongqing 已提交
768 769 770
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
Z
zengyawen 已提交
771

W
wusongqing 已提交
772
**Return value**
773

W
wusongqing 已提交
774 775 776
| 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.|
Z
zengyawen 已提交
777

W
wusongqing 已提交
778
**Example**
779 780 781 782 783 784

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

W
wusongqing 已提交
786
### valueOf<sup>8+</sup>
Z
zengyawen 已提交
787

X
xdmal 已提交
788
valueOf(): number
Z
zengyawen 已提交
789

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

W
wusongqing 已提交
792 793 794
**System capability**: SystemCapability.Utils.Lang

**Return value**
795

W
wusongqing 已提交
796 797 798
| Type| Description|
| -------- | -------- |
| number | An integer or a floating-point number.|
Z
zengyawen 已提交
799

W
wusongqing 已提交
800
**Example**
801 802 803 804 805

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

W
wusongqing 已提交
807
### equals<sup>8+</sup>
Z
zengyawen 已提交
808

X
xdmal 已提交
809
equals​(obj: Object): boolean
Z
zengyawen 已提交
810

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

W
wusongqing 已提交
813 814 815
**System capability**: SystemCapability.Utils.Lang

**Parameters**
816

W
wusongqing 已提交
817 818 819
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | Object | Yes| Object used to compare with this **RationalNumber** object.|
Z
zengyawen 已提交
820

W
wusongqing 已提交
821
**Return value**
822

W
wusongqing 已提交
823 824 825
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the two objects are equal; returns **false** otherwise.|
Z
zengyawen 已提交
826

W
wusongqing 已提交
827
**Example**
828 829 830 831 832 833

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

G
Gloria 已提交
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
### 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 已提交
855

G
Gloria 已提交
856 857
**Example**

858
```js
G
Gloria 已提交
859 860
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonFactor(4,6);
861
```
G
Gloria 已提交
862

G
ge-yafang 已提交
863
### getCommonDivisor<sup>(deprecated)</sup>
Z
zengyawen 已提交
864

X
xdmal 已提交
865
static getCommonDivisor​(number1: number,number2: number): number
Z
zengyawen 已提交
866

W
wusongqing 已提交
867
Obtains the greatest common divisor of two specified integers.
Z
zengyawen 已提交
868

869 870 871 872
> **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.

W
wusongqing 已提交
873 874 875
**System capability**: SystemCapability.Utils.Lang

**Parameters**
876

W
wusongqing 已提交
877 878 879 880
| 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.|
Z
zengyawen 已提交
881

W
wusongqing 已提交
882
**Return value**
883

W
wusongqing 已提交
884 885 886
| Type| Description|
| -------- | -------- |
| number | Greatest common divisor obtained.|
Z
zengyawen 已提交
887

W
wusongqing 已提交
888
**Example**
889 890 891 892 893

```js
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonDivisor(4,6);
```
Z
zengyawen 已提交
894

W
wusongqing 已提交
895
### getNumerator<sup>8+</sup>
Z
zengyawen 已提交
896

X
xdmal 已提交
897
getNumerator​(): number
Z
zengyawen 已提交
898

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

W
wusongqing 已提交
901 902 903 904
**System capability**: SystemCapability.Utils.Lang

**Return value**

W
wusongqing 已提交
905 906 907
| Type| Description|
| -------- | -------- |
| number | Numerator of this **RationalNumber** object.|
Z
zengyawen 已提交
908

W
wusongqing 已提交
909
**Example**
910 911 912 913 914

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

W
wusongqing 已提交
916
### getDenominator<sup>8+</sup>
Z
zengyawen 已提交
917

X
xdmal 已提交
918
getDenominator​(): number
Z
zengyawen 已提交
919

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

W
wusongqing 已提交
922 923 924
**System capability**: SystemCapability.Utils.Lang

**Return value**
925

W
wusongqing 已提交
926 927 928
| Type| Description|
| -------- | -------- |
| number | Denominator of this **RationalNumber** object.|
Z
zengyawen 已提交
929

W
wusongqing 已提交
930
**Example**
931 932 933 934 935

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

W
wusongqing 已提交
937
### isZero<sup>8+</sup>
Z
zengyawen 已提交
938

W
wusongqing 已提交
939
isZero​():boolean
Z
zengyawen 已提交
940

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

W
wusongqing 已提交
943 944 945
**System capability**: SystemCapability.Utils.Lang

**Return value**
946

W
wusongqing 已提交
947 948 949
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
Z
zengyawen 已提交
950

W
wusongqing 已提交
951
**Example**
952 953 954 955 956

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

W
wusongqing 已提交
958
### isNaN<sup>8+</sup>
Z
zengyawen 已提交
959

X
xdmal 已提交
960
isNaN​(): boolean
Z
zengyawen 已提交
961

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

W
wusongqing 已提交
964 965 966
**System capability**: SystemCapability.Utils.Lang

**Return value**
967

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

W
wusongqing 已提交
972
**Example**
973 974 975 976 977

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

W
wusongqing 已提交
979
### isFinite<sup>8+</sup>
Z
zengyawen 已提交
980

W
wusongqing 已提交
981
isFinite​():boolean
Z
zengyawen 已提交
982

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

W
wusongqing 已提交
985 986 987
**System capability**: SystemCapability.Utils.Lang

**Return value**
988

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

W
wusongqing 已提交
993
**Example**
994 995 996 997 998

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

W
wusongqing 已提交
1000
### toString<sup>8+</sup>
Z
zengyawen 已提交
1001

X
xdmal 已提交
1002
toString​(): string
Z
zengyawen 已提交
1003

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

W
wusongqing 已提交
1006 1007 1008
**System capability**: SystemCapability.Utils.Lang

**Return value**
1009

W
wusongqing 已提交
1010 1011 1012
| 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 已提交
1013

W
wusongqing 已提交
1014
**Example**
1015 1016 1017 1018 1019

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

G
Gloria 已提交
1021 1022

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

W
wusongqing 已提交
1024
### Attributes
Z
zengyawen 已提交
1025

W
wusongqing 已提交
1026 1027
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
1028 1029
| Name  | Type  | Readable| Writable| Description                  |
| ------ | ------ | ---- | ---- | ---------------------- |
1030
| length | number | Yes  | No  | Total number of values in this cache.|
Z
zengyawen 已提交
1031

W
wusongqing 已提交
1032
**Example**
G
Gloria 已提交
1033

1034
```js
G
Gloria 已提交
1035 1036 1037 1038
let pro = new util.LRUCache();
pro.put(2,10);
pro.put(1,8);
let result = pro.length;
1039
```
Z
zengyawen 已提交
1040

G
Gloria 已提交
1041
### constructor<sup>9+</sup>
Z
zengyawen 已提交
1042

X
xdmal 已提交
1043
constructor(capacity?: number)
Z
zengyawen 已提交
1044

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

W
wusongqing 已提交
1047 1048 1049
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1050

G
Gloria 已提交
1051 1052
| Name  | Type  | Mandatory| Description                        |
| -------- | ------ | ---- | ---------------------------- |
1053
| capacity | number | No  | Capacity of the **LruCache** to create.|
Z
zengyawen 已提交
1054

W
wusongqing 已提交
1055
**Example**
G
Gloria 已提交
1056

1057
```js
G
Gloria 已提交
1058
let lrubuffer= new util.LRUCache();
1059
```
Z
zengyawen 已提交
1060 1061


G
Gloria 已提交
1062
### updateCapacity<sup>9+</sup>
Z
zengyawen 已提交
1063

X
xdmal 已提交
1064
updateCapacity(newCapacity: number): void
Z
zengyawen 已提交
1065

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

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

**Parameters**
1071

G
Gloria 已提交
1072 1073
| Name     | Type  | Mandatory| Description                        |
| ----------- | ------ | ---- | ---------------------------- |
1074
| newCapacity | number | Yes  | New capacity of the **LruCache**.|
Z
zengyawen 已提交
1075

W
wusongqing 已提交
1076
**Example**
G
Gloria 已提交
1077

1078
```js
G
Gloria 已提交
1079 1080
let pro = new util.LRUCache();
let result = pro.updateCapacity(100);
1081
```
Z
zengyawen 已提交
1082 1083


G
Gloria 已提交
1084
### toString<sup>9+</sup>
Z
zengyawen 已提交
1085

X
xdmal 已提交
1086
toString(): string
Z
zengyawen 已提交
1087

1088
Obtains the string representation of this **LruCache** object.
Z
zengyawen 已提交
1089

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

**Return value**
1093

G
Gloria 已提交
1094 1095
| Type  | Description                      |
| ------ | -------------------------- |
1096
| string | String representation of this **LruCache** object.|
W
wusongqing 已提交
1097

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

1100
```js
G
Gloria 已提交
1101 1102 1103 1104 1105
let pro = new util.LRUCache();
pro.put(2,10);
pro.get(2);
pro.remove(20);
let result = pro.toString();
1106
```
G
Gloria 已提交
1107 1108 1109 1110 1111 1112


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

getCapacity(): number

1113
Obtains the capacity of this cache.
G
Gloria 已提交
1114 1115 1116 1117 1118 1119 1120

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

**Return value**

| Type  | Description                  |
| ------ | ---------------------- |
1121
| number | Capacity of this cache.|
G
Gloria 已提交
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134

**Example**

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


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

clear(): void

1135
Clears key-value pairs from this cache. The **afterRemoval()** method will be called to perform subsequent operations.
G
Gloria 已提交
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199

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

1200
Obtains the number of removals from this cache.
G
Gloria 已提交
1201 1202 1203 1204 1205 1206 1207

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

**Return value**

| Type  | Description                      |
| ------ | -------------------------- |
1208
| number | Number of removals from the cache.|
G
Gloria 已提交
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 1242 1243 1244 1245 1246 1247 1248

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

1249
Obtains the number of additions to this cache.
G
Gloria 已提交
1250 1251 1252 1253 1254 1255 1256

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

**Return value**

| Type  | Description                        |
| ------ | ---------------------------- |
1257
| number | Number of additions to the cache.|
G
Gloria 已提交
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271

**Example**

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


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

isEmpty(): boolean

1272
Checks whether this cache is empty.
G
Gloria 已提交
1273 1274 1275 1276 1277 1278 1279

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

**Return value**

| Type   | Description                                    |
| ------- | ---------------------------------------- |
1280
| boolean | Returns **true** if the cache does not contain any value.|
G
Gloria 已提交
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308

**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                                                        |
| ------------------------ | ------------------------------------------------------------ |
1309
| V \| undefined | Returns the value of the key if a match is found in the cache; returns **undefined** otherwise.|
G
Gloria 已提交
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323

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

1324
Adds a key-value pair to this cache.
G
Gloria 已提交
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 1351

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

1352
Obtains all values in this cache, listed from the most to the least recently accessed.
G
Gloria 已提交
1353 1354 1355 1356 1357 1358 1359

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

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
1360
| V&nbsp;[] | All values in the cache, listed from the most to the least recently accessed.|
G
Gloria 已提交
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376

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

1377
Obtains all keys in this cache, listed from the most to the least recently accessed.
G
Gloria 已提交
1378 1379 1380 1381 1382 1383 1384

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

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
1385
| K&nbsp;[] | All keys in the cache, listed from the most to the least recently accessed.|
G
Gloria 已提交
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399

**Example**

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


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

remove(key: K): V | undefined

1400
Removes the specified key and its value from this cache.
G
Gloria 已提交
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413

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

**Parameters**

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

**Return value**

| Type                    | Description                                                        |
| ------------------------ | ------------------------------------------------------------ |
1414
| 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 已提交
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436

**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                                                        |
| -------- | ------- | ---- | ------------------------------------------------------------ |
1437
| isEvict  | boolean | Yes  | Whether the cache capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.   |
G
Gloria 已提交
1438 1439
| key      | K       | Yes  | Key removed.                                              |
| value    | V       | Yes  | Value removed.                                              |
1440
| 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 已提交
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466

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

1467
contains(key: object): boolean
G
Gloria 已提交
1468

1469
Checks whether this cache contains the specified key.
G
Gloria 已提交
1470 1471 1472 1473 1474

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

**Parameters**

1475 1476 1477
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| key    | object | Yes  | Key to check.|
G
Gloria 已提交
1478 1479 1480 1481 1482

**Return value**

| Type   | Description                                      |
| ------- | ------------------------------------------ |
1483
| boolean | Returns **true** if the cache contains the specified key; returns **false** otherwise.|
G
Gloria 已提交
1484 1485 1486 1487 1488 1489

**Example**

  ```js
let pro = new util.LRUCache();
pro.put(2,10);
1490 1491
let obj = {1:"key"};
let result = pro.contains(obj);
G
Gloria 已提交
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 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
  ```


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

G
ge-yafang 已提交
1567
## LruBuffer<sup>(deprecated)</sup>
G
Gloria 已提交
1568 1569 1570

> **NOTE**
>
1571
> 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.
G
Gloria 已提交
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581

### Attributes

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

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Total number of values in this buffer.|

**Example**
1582

G
Gloria 已提交
1583 1584 1585 1586 1587 1588 1589
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(1,8);
  let result = pro.length;
  ```

G
ge-yafang 已提交
1590
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
1591 1592 1593 1594 1595

constructor(capacity?: number)

A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.

1596 1597 1598 1599
> **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.

G
Gloria 已提交
1600 1601 1602 1603 1604 1605 1606 1607 1608
**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| capacity | number | No| Capacity of the **LruBuffer** to create.|

**Example**
1609

G
Gloria 已提交
1610 1611 1612 1613
  ```js
  let lrubuffer= new util.LruBuffer();
  ```

G
ge-yafang 已提交
1614
### updateCapacity<sup>(deprecated)</sup>
G
Gloria 已提交
1615 1616 1617 1618 1619

updateCapacity(newCapacity: number): void

Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.

1620 1621 1622 1623
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [updateCapacity<sup>9+</sup>](#updatecapacity9) instead.

G
Gloria 已提交
1624 1625 1626 1627 1628 1629 1630 1631 1632
**System capability**: SystemCapability.Utils.Lang

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newCapacity | number | Yes| New capacity of the **LruBuffer**.|

**Example**
1633

G
Gloria 已提交
1634 1635 1636 1637 1638
  ```js
  let pro = new util.LruBuffer();
  let result = pro.updateCapacity(100);
  ```

G
ge-yafang 已提交
1639
### toString<sup>(deprecated)</sup>
G
Gloria 已提交
1640 1641 1642 1643 1644

toString(): string

Obtains the string representation of this **LruBuffer** object.

1645 1646 1647 1648
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead.

G
Gloria 已提交
1649 1650 1651 1652 1653 1654 1655 1656 1657
**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type| Description|
| -------- | -------- |
| string | String representation of this **LruBuffer** object.|

**Example**
1658

G
Gloria 已提交
1659 1660
  ```js
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1661 1662 1663
  pro.put(2,10);
  pro.get(2);
  pro.remove(20);
1664
  let result = pro.toString();
W
wusongqing 已提交
1665 1666
  ```

G
ge-yafang 已提交
1667
### getCapacity<sup>(deprecated)</sup>
W
wusongqing 已提交
1668

X
xdmal 已提交
1669
getCapacity(): number
W
wusongqing 已提交
1670 1671 1672

Obtains the capacity of this buffer.

1673 1674 1675 1676
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCapacity<sup>9+</sup>](#getcapacity9) instead.

W
wusongqing 已提交
1677 1678 1679
**System capability**: SystemCapability.Utils.Lang

**Return value**
1680

W
wusongqing 已提交
1681 1682 1683
| Type| Description|
| -------- | -------- |
| number | Capacity of this buffer.|
W
wusongqing 已提交
1684

W
wusongqing 已提交
1685
**Example**
1686
  ```js
1687 1688
  let pro = new util.LruBuffer();
  let result = pro.getCapacity();
W
wusongqing 已提交
1689
  ```
Z
zengyawen 已提交
1690

G
ge-yafang 已提交
1691
### clear<sup>(deprecated)</sup>
Z
zengyawen 已提交
1692

X
xdmal 已提交
1693
clear(): void
Z
zengyawen 已提交
1694

W
wusongqing 已提交
1695
Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations.
Z
zengyawen 已提交
1696

1697 1698 1699 1700
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clear<sup>9+</sup>](#clear9) instead.

W
wusongqing 已提交
1701 1702 1703
**System capability**: SystemCapability.Utils.Lang

**Example**
1704

1705
  ```js
1706
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1707
  pro.put(2,10);
1708
  let result = pro.length;
W
wusongqing 已提交
1709 1710
  pro.clear();
  ```
Z
zengyawen 已提交
1711

G
ge-yafang 已提交
1712
### getCreateCount<sup>(deprecated)</sup>
Z
zengyawen 已提交
1713

X
xdmal 已提交
1714
getCreateCount(): number
W
wusongqing 已提交
1715 1716 1717

Obtains the number of return values for **createDefault()**.

1718 1719 1720 1721
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCreateCount<sup>9+</sup>](#getcreatecount9) instead.

W
wusongqing 已提交
1722 1723 1724
**System capability**: SystemCapability.Utils.Lang

**Return value**
1725

W
wusongqing 已提交
1726 1727 1728
| Type| Description|
| -------- | -------- |
| number | Number of return values for **createDefault()**.|
W
wusongqing 已提交
1729

W
wusongqing 已提交
1730
**Example**
1731

1732
  ```js
1733
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1734
  pro.put(1,8);
1735
  let result = pro.getCreateCount();
W
wusongqing 已提交
1736 1737
  ```

G
ge-yafang 已提交
1738
### getMissCount<sup>(deprecated)</sup>
W
wusongqing 已提交
1739

X
xdmal 已提交
1740
getMissCount(): number
W
wusongqing 已提交
1741 1742 1743

Obtains the number of times that the queried values are mismatched.

1744 1745 1746 1747
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMissCount<sup>9+</sup>](#getmisscount9) instead.

W
wusongqing 已提交
1748 1749 1750
**System capability**: SystemCapability.Utils.Lang

**Return value**
1751

W
wusongqing 已提交
1752 1753 1754
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are mismatched.|
W
wusongqing 已提交
1755

W
wusongqing 已提交
1756
**Example**
1757

1758
  ```js
1759
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1760 1761
  pro.put(2,10);
  pro.get(2);
1762
  let result = pro.getMissCount();
W
wusongqing 已提交
1763 1764
  ```

G
ge-yafang 已提交
1765
### getRemovalCount<sup>(deprecated)</sup>
W
wusongqing 已提交
1766

X
xdmal 已提交
1767
getRemovalCount(): number
W
wusongqing 已提交
1768 1769 1770

Obtains the number of removals from this buffer.

1771 1772 1773 1774
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.

W
wusongqing 已提交
1775 1776 1777
**System capability**: SystemCapability.Utils.Lang

**Return value**
1778

W
wusongqing 已提交
1779 1780 1781
| Type| Description|
| -------- | -------- |
| number | Number of removals from the buffer.|
W
wusongqing 已提交
1782

W
wusongqing 已提交
1783
**Example**
1784

1785
  ```js
1786
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1787 1788 1789
  pro.put(2,10);
  pro.updateCapacity(2);
  pro.put(50,22);
1790
  let result = pro.getRemovalCount();
W
wusongqing 已提交
1791 1792
  ```

G
ge-yafang 已提交
1793
### getMatchCount<sup>(deprecated)</sup>
W
wusongqing 已提交
1794

X
xdmal 已提交
1795
getMatchCount(): number
W
wusongqing 已提交
1796 1797 1798

Obtains the number of times that the queried values are matched.

1799 1800 1801 1802
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getMatchCount<sup>9+</sup>](#getmatchcount9) instead.

W
wusongqing 已提交
1803 1804 1805
**System capability**: SystemCapability.Utils.Lang

**Return value**
1806

W
wusongqing 已提交
1807 1808 1809
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are matched.|
W
wusongqing 已提交
1810

W
wusongqing 已提交
1811
**Example**
1812

1813
  ```js
1814
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1815 1816
  pro.put(2,10);
  pro.get(2);
1817
  let result = pro.getMatchCount();
W
wusongqing 已提交
1818 1819
  ```

G
ge-yafang 已提交
1820
### getPutCount<sup>(deprecated)</sup>
W
wusongqing 已提交
1821

X
xdmal 已提交
1822
getPutCount(): number
W
wusongqing 已提交
1823 1824 1825

Obtains the number of additions to this buffer.

1826 1827 1828 1829
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getPutCount<sup>9+</sup>](#getputcount9) instead.

W
wusongqing 已提交
1830 1831 1832
**System capability**: SystemCapability.Utils.Lang

**Return value**
1833

W
wusongqing 已提交
1834 1835 1836
| Type| Description|
| -------- | -------- |
| number | Number of additions to the buffer.|
W
wusongqing 已提交
1837

W
wusongqing 已提交
1838
**Example**
1839

1840
  ```js
1841
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1842
  pro.put(2,10);
1843
  let result = pro.getPutCount();
W
wusongqing 已提交
1844 1845
  ```

G
ge-yafang 已提交
1846
### isEmpty<sup>(deprecated)</sup>
W
wusongqing 已提交
1847

X
xdmal 已提交
1848
isEmpty(): boolean
W
wusongqing 已提交
1849 1850 1851

Checks whether this buffer is empty.

1852 1853 1854 1855
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isEmpty<sup>9+</sup>](#isempty9) instead.

W
wusongqing 已提交
1856 1857 1858
**System capability**: SystemCapability.Utils.Lang

**Return value**
1859

W
wusongqing 已提交
1860 1861 1862
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer does not contain any value.|
W
wusongqing 已提交
1863

W
wusongqing 已提交
1864
**Example**
1865

1866
  ```js
1867
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1868
  pro.put(2,10);
1869
  let result = pro.isEmpty();
W
wusongqing 已提交
1870 1871
  ```

G
ge-yafang 已提交
1872
### get<sup>(deprecated)</sup>
W
wusongqing 已提交
1873

W
wusongqing 已提交
1874
get(key: K): V | undefined
Z
zengyawen 已提交
1875 1876 1877

Obtains the value of the specified key.

1878 1879 1880 1881
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [get<sup>9+</sup>](#get9) instead.

W
wusongqing 已提交
1882 1883 1884
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1885

W
wusongqing 已提交
1886 1887 1888
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key based on which the value is queried.|
W
wusongqing 已提交
1889

W
wusongqing 已提交
1890
**Return value**
1891

W
wusongqing 已提交
1892 1893
| Type| Description|
| -------- | -------- |
G
Gloria 已提交
1894
| V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
W
wusongqing 已提交
1895

W
wusongqing 已提交
1896
**Example**
1897

1898
  ```js
1899
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1900
  pro.put(2,10);
1901
  let result  = pro.get(2);
W
wusongqing 已提交
1902 1903
  ```

G
ge-yafang 已提交
1904
### put<sup>(deprecated)</sup>
W
wusongqing 已提交
1905

X
xdmal 已提交
1906
put(key: K,value: V): V
Z
zengyawen 已提交
1907 1908 1909

Adds a key-value pair to this buffer.

1910 1911 1912 1913
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [put<sup>9+</sup>](#put9) instead.

W
wusongqing 已提交
1914 1915 1916
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1917

W
wusongqing 已提交
1918 1919 1920 1921
| 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.|
Z
zengyawen 已提交
1922

W
wusongqing 已提交
1923
**Return value**
1924

W
wusongqing 已提交
1925 1926 1927
| 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. |
Z
zengyawen 已提交
1928

W
wusongqing 已提交
1929
**Example**
1930

1931
  ```js
1932 1933
  let pro = new util.LruBuffer();
  let result = pro.put(2,10);
W
wusongqing 已提交
1934
  ```
Z
zengyawen 已提交
1935

G
ge-yafang 已提交
1936
### values<sup>(deprecated)</sup>
G
Gloria 已提交
1937

X
xdmal 已提交
1938
values(): V[]
W
wusongqing 已提交
1939 1940

Obtains all values in this buffer, listed from the most to the least recently accessed.
Z
zengyawen 已提交
1941

1942 1943 1944 1945
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [values<sup>9+</sup>](#values9) instead.

W
wusongqing 已提交
1946 1947 1948
**System capability**: SystemCapability.Utils.Lang

**Return value**
1949

W
wusongqing 已提交
1950 1951
| Type| Description|
| -------- | -------- |
G
Gloria 已提交
1952
| V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|
Z
zengyawen 已提交
1953

W
wusongqing 已提交
1954
**Example**
1955

1956
  ```js
1957
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1958 1959 1960
  pro.put(2,10);
  pro.put(2,"anhu");
  pro.put("afaf","grfb");
1961
  let result = pro.values();
W
wusongqing 已提交
1962
  ```
Z
zengyawen 已提交
1963

G
ge-yafang 已提交
1964
### keys<sup>(deprecated)</sup>
Z
zengyawen 已提交
1965

X
xdmal 已提交
1966
keys(): K[]
Z
zengyawen 已提交
1967 1968 1969

Obtains all keys in this buffer, listed from the most to the least recently accessed.

1970 1971 1972 1973
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [keys<sup>9+</sup>](#keys9) instead.

W
wusongqing 已提交
1974 1975 1976
**System capability**: SystemCapability.Utils.Lang

**Return value**
1977

W
wusongqing 已提交
1978 1979
| Type| Description|
| -------- | -------- |
G
Gloria 已提交
1980
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
W
wusongqing 已提交
1981

W
wusongqing 已提交
1982
**Example**
1983
  ```js
1984
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1985
  pro.put(2,10);
1986
  let result = pro.keys();
W
wusongqing 已提交
1987 1988
  ```

G
ge-yafang 已提交
1989
### remove<sup>(deprecated)</sup>
W
wusongqing 已提交
1990

W
wusongqing 已提交
1991
remove(key: K): V | undefined
W
wusongqing 已提交
1992 1993 1994

Removes the specified key and its value from this buffer.

1995 1996 1997 1998
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [remove<sup>9+</sup>](#remove9) instead.

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

**Parameters**
2002

W
wusongqing 已提交
2003 2004 2005
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to remove.|
W
wusongqing 已提交
2006

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

W
wusongqing 已提交
2009 2010
| Type| Description|
| -------- | -------- |
G
Gloria 已提交
2011
| 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 已提交
2012

W
wusongqing 已提交
2013
**Example**
2014
  ```js
2015
  let pro = new util.LruBuffer();
W
wusongqing 已提交
2016
  pro.put(2,10);
2017
  let result = pro.remove(20);
W
wusongqing 已提交
2018 2019
  ```

G
ge-yafang 已提交
2020
### afterRemoval<sup>(deprecated)</sup>
W
wusongqing 已提交
2021

X
xdmal 已提交
2022
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
W
wusongqing 已提交
2023 2024 2025

Performs subsequent operations after a value is removed.

2026 2027 2028 2029
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [afterRemoval<sup>9+</sup>](#afterremoval9) instead.

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

**Parameters**
2033

W
wusongqing 已提交
2034 2035
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2036
| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
W
wusongqing 已提交
2037 2038
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.|
2039
| 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 已提交
2040

W
wusongqing 已提交
2041
**Example**
2042

2043
  ```js
2044 2045
  let arr = [];
  class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
W
wusongqing 已提交
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058
  {
  	constructor()
  	{
  		super();
  	}
  	afterRemoval(isEvict, key, value, newValue)
  	{
  		if (isEvict === false)
  		{
  			arr = [key, value, newValue];
  		}
  	}
  }
2059
  let lru = new ChildLruBuffer();
S
shikai-123 已提交
2060
  lru.afterRemoval(false,10,30,null);
W
wusongqing 已提交
2061 2062
  ```

G
ge-yafang 已提交
2063
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
2064

X
xdmal 已提交
2065
contains(key: K): boolean
W
wusongqing 已提交
2066 2067

Checks whether this buffer contains the specified key.
Z
zengyawen 已提交
2068

2069 2070 2071 2072 2073

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

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

**Parameters**
2077

W
wusongqing 已提交
2078 2079 2080
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to check.|
Z
zengyawen 已提交
2081

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

W
wusongqing 已提交
2084 2085 2086
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
Z
zengyawen 已提交
2087

W
wusongqing 已提交
2088
**Example**
2089

2090
  ```js
2091
  let pro = new util.LruBuffer();
W
wusongqing 已提交
2092
  pro.put(2,10);
2093
  let result = pro.contains(20);
W
wusongqing 已提交
2094
  ```
Z
zengyawen 已提交
2095

G
ge-yafang 已提交
2096
### createDefault<sup>(deprecated)</sup>
Z
zengyawen 已提交
2097

X
xdmal 已提交
2098
createDefault(key: K): V
Z
zengyawen 已提交
2099 2100 2101

Creates a value if the value of the specified key is not available.

2102 2103 2104 2105
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createDefault<sup>9+</sup>](#createdefault9) instead.

W
wusongqing 已提交
2106 2107 2108
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2109

W
wusongqing 已提交
2110 2111 2112
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key of which the value is missing.|
Z
zengyawen 已提交
2113

W
wusongqing 已提交
2114
**Return value**
2115

W
wusongqing 已提交
2116 2117 2118
| Type| Description|
| -------- | -------- |
| V | Value of the key.|
Z
zengyawen 已提交
2119

W
wusongqing 已提交
2120
**Example**
2121

2122
  ```js
G
Gloria 已提交
2123 2124 2125 2126
  let pro = new util.LruBuffer();
  let result = pro.createDefault(50);
  ```

G
ge-yafang 已提交
2127
### entries<sup>(deprecated)</sup>
G
Gloria 已提交
2128 2129 2130 2131 2132

entries(): IterableIterator&lt;[K,V]&gt;

Obtains a new iterator object that contains all key-value pairs in this object.

2133 2134 2135 2136
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [entries<sup>9+</sup>](#entries9) instead.

G
Gloria 已提交
2137 2138 2139 2140 2141 2142 2143 2144 2145
**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type| Description|
| -------- | -------- |
| [K,&nbsp;V] | Iterable array.|

**Example**
2146

G
Gloria 已提交
2147 2148 2149 2150 2151 2152
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.entries();
  ```

G
ge-yafang 已提交
2153
### [Symbol.iterator]<sup>(deprecated)</sup>
G
Gloria 已提交
2154 2155 2156 2157 2158

[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;

Obtains a two-dimensional array in key-value pairs.

2159 2160 2161 2162
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.

G
Gloria 已提交
2163 2164 2165 2166 2167 2168 2169 2170 2171
**System capability**: SystemCapability.Utils.Lang

**Return value**

| Type| Description|
| -------- | -------- |
| [K,&nbsp;V] | Two-dimensional array in key-value pairs.|

**Example**
2172

G
Gloria 已提交
2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro[Symbol.iterator]();
  ```

### ScopeType<sup>8+</sup>

Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**.

The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
2184

G
Gloria 已提交
2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275
```js
interface ScopeComparable{
    compareTo(other: ScopeComparable): boolean;
}
type ScopeType = ScopeComparable | number;
```


Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#scopetype8) object.


Example
```js
class Temperature{
    constructor(value){
       // If TS is used for development, add the following code:
       // private readonly _temp: Temperature;
       this._temp = value;
    }
    compareTo(value){
       return this._temp >= value.getTemp();
    }
    getTemp(){
       return this._temp;
    }
    toString(){
       return this._temp.toString();
    }
}
```

## ScopeHelper<sup>9+</sup>

### constructor<sup>9+</sup>

constructor(lowerObj: ScopeType, upperObj: ScopeType)

A constructor used to create a **ScopeHelper** object with the specified upper and lower limits.

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

**Parameters**

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

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
  ```


### toString<sup>9+</sup>

toString(): string

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

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

**Return value**

| Type  | Description                                  |
| ------ | -------------------------------------- |
| string | String representation containing the **Scope**.|

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.toString();
  ```


### intersect<sup>9+</sup>

intersect(range: ScopeHelper): ScopeHelper

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

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

**Parameters**

2276 2277 2278
| Name| Type                        | Mandatory| Description              |
| ------ | ---------------------------- | ---- | ------------------ |
| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
G
Gloria 已提交
2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315

**Return value**

| Type                          | Description                          |
| ------------------------------ | ------------------------------ |
| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given **Scope**.|

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
range.intersect(rangeFir );
  ```


### intersect<sup>9+</sup>

intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper

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

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

**Parameters**

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

**Return value**

2316 2317 2318
| Type                        | Description                                    |
| ---------------------------- | ---------------------------------------- |
| [ScopeHelper](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.|
G
Gloria 已提交
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.intersect(tempMiDF, tempMidS);
  ```


### getUpper<sup>9+</sup>

getUpper(): ScopeType

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

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

**Return value**

| Type                    | Description                  |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getUpper();
  ```


### getLower<sup>9+</sup>

getLower(): ScopeType

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

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

**Return value**

| Type                    | Description                  |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getLower();
  ```


### expand<sup>9+</sup>

expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper

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

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

**Parameters**

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

**Return value**

2397 2398 2399
| Type                        | Description                                |
| ---------------------------- | ------------------------------------ |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.|
G
Gloria 已提交
2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF, tempMidS);
  ```


### expand<sup>9+</sup>

expand(range: ScopeHelper): ScopeHelper

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

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

**Parameters**

2423 2424 2425
| Name| Type                        | Mandatory| Description              |
| ------ | ---------------------------- | ---- | ------------------ |
| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
G
Gloria 已提交
2426 2427 2428

**Return value**

2429 2430 2431
| Type                        | Description                              |
| ---------------------------- | ---------------------------------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given **Scope**.|
G
Gloria 已提交
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
let result = range.expand(rangeFir);
  ```


### expand<sup>9+</sup>

expand(value: ScopeType): ScopeHelper

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

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

**Parameters**

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

**Return value**

2462 2463 2464
| Type                        | Description                            |
| ---------------------------- | -------------------------------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given value.|
G
Gloria 已提交
2465 2466 2467 2468 2469 2470 2471 2472 2473

**Example**

  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF);
W
wusongqing 已提交
2474
  ```
Z
zengyawen 已提交
2475 2476


G
Gloria 已提交
2477
### contains<sup>9+</sup>
Z
zengyawen 已提交
2478

G
Gloria 已提交
2479
contains(value: ScopeType): boolean
Z
zengyawen 已提交
2480

G
Gloria 已提交
2481
Checks whether a value is within this **Scope**.
Z
zengyawen 已提交
2482

W
wusongqing 已提交
2483 2484
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
2485 2486 2487 2488 2489 2490
**Parameters**

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

W
wusongqing 已提交
2491
**Return value**
2492

G
Gloria 已提交
2493 2494 2495
| Type   | Description                                               |
| ------- | --------------------------------------------------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
Z
zengyawen 已提交
2496

W
wusongqing 已提交
2497
**Example**
G
Gloria 已提交
2498

2499
  ```js
G
Gloria 已提交
2500 2501 2502 2503 2504
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 已提交
2505
  ```
Z
zengyawen 已提交
2506 2507


G
Gloria 已提交
2508
### contains<sup>9+</sup>
Z
zengyawen 已提交
2509

G
Gloria 已提交
2510
contains(range: ScopeHelper): boolean
Z
zengyawen 已提交
2511

G
Gloria 已提交
2512
Checks whether a range is within this **Scope**.
Z
zengyawen 已提交
2513

W
wusongqing 已提交
2514 2515
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
2516 2517
**Parameters**

2518 2519 2520
| Name| Type                        | Mandatory| Description              |
| ------ | ---------------------------- | ---- | ------------------ |
| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
G
Gloria 已提交
2521

W
wusongqing 已提交
2522
**Return value**
2523

G
Gloria 已提交
2524 2525 2526
| Type   | Description                                                 |
| ------- | ----------------------------------------------------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
Z
zengyawen 已提交
2527

W
wusongqing 已提交
2528
**Example**
G
Gloria 已提交
2529

2530
  ```js
G
Gloria 已提交
2531 2532 2533 2534 2535 2536 2537
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 已提交
2538
  ```
Z
zengyawen 已提交
2539 2540


G
Gloria 已提交
2541
### clamp<sup>9+</sup>
Z
zengyawen 已提交
2542

G
Gloria 已提交
2543
clamp(value: ScopeType): ScopeType
Z
zengyawen 已提交
2544

G
Gloria 已提交
2545
Limits a value to this **Scope**.
Z
zengyawen 已提交
2546

G
Gloria 已提交
2547
**System capability**: SystemCapability.Utils.Lang
Z
zengyawen 已提交
2548

G
Gloria 已提交
2549
**Parameters**
Z
zengyawen 已提交
2550

G
Gloria 已提交
2551 2552 2553
| Name| Type                    | Mandatory| Description          |
| ------ | ------------------------ | ---- | -------------- |
| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|
Z
zengyawen 已提交
2554

G
Gloria 已提交
2555
**Return value**
Z
zengyawen 已提交
2556

G
Gloria 已提交
2557 2558 2559
| 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**.|
W
wusongqing 已提交
2560

G
Gloria 已提交
2561
**Example**
Z
zengyawen 已提交
2562

G
Gloria 已提交
2563 2564 2565 2566 2567 2568 2569
  ```js
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.clamp(tempMiDF);
  ```
Z
zengyawen 已提交
2570

G
ge-yafang 已提交
2571
## Scope<sup>(deprecated)</sup>
G
Gloria 已提交
2572 2573 2574

> **NOTE**
>
2575
> 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.
G
Gloria 已提交
2576

G
ge-yafang 已提交
2577
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
2578

X
xdmal 已提交
2579
constructor(lowerObj: ScopeType, upperObj: ScopeType)
W
wusongqing 已提交
2580 2581 2582

A constructor used to create a **Scope** object with the specified upper and lower limits.

2583 2584 2585 2586 2587
> **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.


W
wusongqing 已提交
2588 2589 2590
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2591

W
wusongqing 已提交
2592 2593 2594 2595
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
W
wusongqing 已提交
2596

W
wusongqing 已提交
2597
**Example**
2598
  ```js
2599 2600 2601
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
2602 2603
  ```

G
ge-yafang 已提交
2604
### toString<sup>(deprecated)</sup>
W
wusongqing 已提交
2605

X
xdmal 已提交
2606
toString(): string
W
wusongqing 已提交
2607 2608 2609

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

2610 2611 2612 2613
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [toString<sup>9+</sup>](#tostring9) instead.

W
wusongqing 已提交
2614 2615 2616
**System capability**: SystemCapability.Utils.Lang

**Return value**
2617

W
wusongqing 已提交
2618 2619 2620
| Type| Description|
| -------- | -------- |
| string | String representation containing the **Scope**.|
W
wusongqing 已提交
2621

W
wusongqing 已提交
2622
**Example**
2623

2624
  ```js
2625 2626 2627 2628
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.toString();
W
wusongqing 已提交
2629 2630
  ```

G
ge-yafang 已提交
2631
### intersect<sup>(deprecated)</sup>
W
wusongqing 已提交
2632

X
xdmal 已提交
2633
intersect(range: Scope): Scope
W
wusongqing 已提交
2634 2635 2636

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

2637 2638 2639 2640
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead.

W
wusongqing 已提交
2641 2642 2643
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2644

W
wusongqing 已提交
2645 2646
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
ge-yafang 已提交
2647
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
2648

W
wusongqing 已提交
2649
**Return value**
2650

W
wusongqing 已提交
2651 2652
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2653
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
2654

W
wusongqing 已提交
2655
**Example**
G
Gloria 已提交
2656

2657
  ```js
2658 2659 2660 2661 2662 2663
  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);
W
wusongqing 已提交
2664 2665 2666
  range.intersect(rangeFir );
  ```

G
ge-yafang 已提交
2667
### intersect<sup>(deprecated)</sup>
W
wusongqing 已提交
2668

W
wusongqing 已提交
2669
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
W
wusongqing 已提交
2670 2671 2672

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

2673 2674 2675 2676
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [intersect<sup>9+</sup>](#intersect9) instead.

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

**Parameters**
2680

W
wusongqing 已提交
2681 2682 2683 2684
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
2685

W
wusongqing 已提交
2686
**Return value**
2687

W
wusongqing 已提交
2688 2689
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2690
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
2691

W
wusongqing 已提交
2692
**Example**
2693

2694
  ```js
2695 2696 2697 2698 2699 2700
  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 已提交
2701 2702
  ```

G
ge-yafang 已提交
2703
### getUpper<sup>(deprecated)</sup>
W
wusongqing 已提交
2704

X
xdmal 已提交
2705
getUpper(): ScopeType
W
wusongqing 已提交
2706 2707 2708

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

2709 2710 2711 2712
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getUpper<sup>9+</sup>](#getupper9) instead.

W
wusongqing 已提交
2713 2714 2715 2716
**System capability**: SystemCapability.Utils.Lang

**Return value**

W
wusongqing 已提交
2717 2718 2719
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
W
wusongqing 已提交
2720

W
wusongqing 已提交
2721
**Example**
2722

2723
  ```js
2724 2725 2726 2727
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getUpper();
W
wusongqing 已提交
2728 2729
  ```

G
ge-yafang 已提交
2730
### getLower<sup>(deprecated)</sup>
W
wusongqing 已提交
2731

X
xdmal 已提交
2732
getLower(): ScopeType
W
wusongqing 已提交
2733 2734 2735

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

2736 2737 2738 2739
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getLower<sup>9+</sup>](#getlower9) instead.

W
wusongqing 已提交
2740 2741 2742
**System capability**: SystemCapability.Utils.Lang

**Return value**
2743

W
wusongqing 已提交
2744 2745 2746
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
W
wusongqing 已提交
2747

W
wusongqing 已提交
2748
**Example**
2749

2750
  ```js
2751 2752 2753 2754
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getLower();
W
wusongqing 已提交
2755 2756
  ```

G
ge-yafang 已提交
2757
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
2758

X
xdmal 已提交
2759
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
W
wusongqing 已提交
2760 2761 2762

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

2763 2764 2765 2766
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.

W
wusongqing 已提交
2767 2768 2769
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2770

W
wusongqing 已提交
2771 2772 2773 2774
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
2775

W
wusongqing 已提交
2776
**Return value**
2777

W
wusongqing 已提交
2778 2779
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2780
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
2781

W
wusongqing 已提交
2782
**Example**
W
wusongqing 已提交
2783

2784
  ```js
2785 2786 2787 2788 2789 2790
  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 已提交
2791 2792
  ```

G
ge-yafang 已提交
2793
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
2794

W
wusongqing 已提交
2795
expand(range: Scope): Scope
W
wusongqing 已提交
2796 2797 2798

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

2799 2800 2801 2802
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.

W
wusongqing 已提交
2803 2804 2805
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2806

W
wusongqing 已提交
2807 2808
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
ge-yafang 已提交
2809
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
2810

W
wusongqing 已提交
2811
**Return value**
2812

W
wusongqing 已提交
2813 2814
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2815
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
2816

W
wusongqing 已提交
2817
**Example**
2818

2819
  ```js
2820 2821 2822 2823 2824 2825 2826
  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 已提交
2827 2828
  ```

G
ge-yafang 已提交
2829
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
2830

X
xdmal 已提交
2831
expand(value: ScopeType): Scope
W
wusongqing 已提交
2832 2833 2834

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

2835 2836 2837 2838
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [expand<sup>9+</sup>](#expand9) instead.

W
wusongqing 已提交
2839 2840 2841
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2842

W
wusongqing 已提交
2843 2844 2845
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
2846

W
wusongqing 已提交
2847
**Return value**
2848

W
wusongqing 已提交
2849 2850
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2851
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.|
Z
zengyawen 已提交
2852

W
wusongqing 已提交
2853
**Example**
2854

2855
  ```js
2856 2857 2858 2859 2860
  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 已提交
2861
  ```
Z
zengyawen 已提交
2862

G
ge-yafang 已提交
2863
### contains<sup>(deprecated)</sup>
Z
zengyawen 已提交
2864

X
xdmal 已提交
2865
contains(value: ScopeType): boolean
Z
zengyawen 已提交
2866

W
wusongqing 已提交
2867
Checks whether a value is within this **Scope**.
Z
zengyawen 已提交
2868

2869 2870 2871 2872
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead.

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

**Parameters**
2876

W
wusongqing 已提交
2877 2878 2879
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
Z
zengyawen 已提交
2880

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

W
wusongqing 已提交
2883 2884 2885
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
2886

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

2889
  ```js
2890 2891 2892 2893
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
2894 2895 2896
  range.contains(tempMiDF);
  ```

G
ge-yafang 已提交
2897
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
2898

X
xdmal 已提交
2899
contains(range: Scope): boolean
W
wusongqing 已提交
2900 2901 2902

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

2903 2904 2905 2906
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [contains<sup>9+</sup>](#contains9) instead.

W
wusongqing 已提交
2907 2908 2909
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2910

W
wusongqing 已提交
2911 2912
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
ge-yafang 已提交
2913
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
2914

W
wusongqing 已提交
2915
**Return value**
2916

W
wusongqing 已提交
2917 2918 2919
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
2920

W
wusongqing 已提交
2921
**Example**
G
Gloria 已提交
2922

2923
  ```js
2924 2925 2926 2927 2928 2929 2930
  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 已提交
2931 2932
  ```

G
ge-yafang 已提交
2933
### clamp<sup>(deprecated)</sup>
W
wusongqing 已提交
2934 2935


X
xdmal 已提交
2936
clamp(value: ScopeType): ScopeType
W
wusongqing 已提交
2937 2938 2939

Limits a value to this **Scope**.

2940 2941 2942 2943
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [clamp<sup>9+</sup>](#clamp9) instead.

W
wusongqing 已提交
2944 2945 2946
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2947

W
wusongqing 已提交
2948 2949 2950
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
2951

W
wusongqing 已提交
2952
**Return value**
2953

W
wusongqing 已提交
2954 2955 2956
| 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**.|
W
wusongqing 已提交
2957

W
wusongqing 已提交
2958
**Example**
2959

2960
  ```js
2961 2962 2963 2964 2965
  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 已提交
2966 2967
  ```

G
Gloria 已提交
2968 2969 2970
## Base64Helper<sup>9+</sup>

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

G
Gloria 已提交
2972
constructor()
W
wusongqing 已提交
2973

G
Gloria 已提交
2974
A constructor used to create a **Base64Helper** instance.
W
wusongqing 已提交
2975

G
Gloria 已提交
2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169
**System capability**: SystemCapability.Utils.Lang

**Example**

  ```js
let base64 = new  util.Base64Helper();
  ```

### encodeSync<sup>9+</sup>

encodeSync(src: Uint8Array): Uint8Array

Encodes the input content.

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

**Parameters**

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

**Return value**

| Type      | Description                         |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array encoded.|

**Example**

  ```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeSync(array);
  ```


### encodeToStringSync<sup>9+</sup>

encodeToStringSync(src: Uint8Array): string

Encodes the input content.

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

**Parameters**

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

**Return value**

| Type  | Description                |
| ------ | -------------------- |
| string | String encoded from the Uint8Array.|

**Example**

  ```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeToStringSync(array);
  ```


### decodeSync<sup>9+</sup>

decodeSync(src: Uint8Array | string): Uint8Array

Decodes the input content.

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

**Parameters**

| Name| Type                          | Mandatory| Description                         |
| ------ | ------------------------------ | ---- | ----------------------------- |
| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode.|

**Return value**

| Type      | Description                         |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array decoded.|

**Example**

  ```js
let that = new util.Base64Helper();
let buff = 'czEz';
let result = that.decodeSync(buff);
  ```


### encode<sup>9+</sup>

encode(src: Uint8Array): Promise&lt;Uint8Array&gt;

Encodes the input content asynchronously.

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

**Parameters**

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

**Return value**

| Type                     | Description                             |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|

**Example**

  ```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let rarray = new Uint8Array([99,122,69,122]);
that.encode(array).then(val=>{    
    for (var i = 0; i < rarray.length; i++) {        
        console.log(val[i].toString())
    }
})
  ```


### encodeToString<sup>9+</sup>

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

Encodes the input content asynchronously.

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

**Parameters**

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

**Return value**

| Type                 | Description                    |
| --------------------- | ------------------------ |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|

**Example**

  ```js
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
that.encodeToString(array).then(val=>{    
    console.log(val)
})
  ```


### decode<sup>9+</sup>

decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;

Decodes the input content asynchronously.

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

**Parameters**

| Name| Type                          | Mandatory| Description                             |
| ------ | ------------------------------ | ---- | --------------------------------- |
| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode asynchronously.|

**Return value**

| Type                     | Description                             |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|

**Example**

  ```js
let that = new util.Base64Helper();
let array = new Uint8Array([99,122,69,122]);
let rarray = new Uint8Array([115,49,51]);
that.decode(array).then(val=>{    
    for (var i = 0; i < rarray.length; i++) {        
        console.log(val[i].toString())
    }
})
  ```


G
ge-yafang 已提交
3170
## Base64<sup>(deprecated)</sup>
G
Gloria 已提交
3171 3172 3173

> **NOTE**
>
3174
> 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.
G
Gloria 已提交
3175

G
ge-yafang 已提交
3176
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
3177

W
wusongqing 已提交
3178 3179 3180 3181
constructor()

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

3182 3183 3184 3185
> **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.

W
wusongqing 已提交
3186 3187 3188
**System capability**: SystemCapability.Utils.Lang

**Example**
3189

3190
  ```js
3191
  let base64 = new  util.Base64();
W
wusongqing 已提交
3192 3193
  ```

G
ge-yafang 已提交
3194
### encodeSync<sup>(deprecated)</sup>
W
wusongqing 已提交
3195

X
xdmal 已提交
3196
encodeSync(src: Uint8Array): Uint8Array
Z
zengyawen 已提交
3197 3198 3199

Encodes the input content.

3200 3201 3202 3203
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeSync<sup>9+</sup>](#encodesync9) instead.

W
wusongqing 已提交
3204 3205 3206
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3207

W
wusongqing 已提交
3208 3209 3210
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
3211

W
wusongqing 已提交
3212
**Return value**
3213

W
wusongqing 已提交
3214 3215 3216
| Type| Description|
| -------- | -------- |
| Uint8Array | Uint8Array encoded.|
W
wusongqing 已提交
3217

W
wusongqing 已提交
3218
**Example**
G
Gloria 已提交
3219

3220
  ```js
3221 3222 3223
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeSync(array);
W
wusongqing 已提交
3224 3225
  ```

G
ge-yafang 已提交
3226
### encodeToStringSync<sup>(deprecated)</sup>
W
wusongqing 已提交
3227

X
xdmal 已提交
3228
encodeToStringSync(src: Uint8Array): string
W
wusongqing 已提交
3229 3230 3231

Encodes the input content.

3232 3233 3234 3235
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.

W
wusongqing 已提交
3236 3237 3238
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3239

W
wusongqing 已提交
3240 3241 3242
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
3243

W
wusongqing 已提交
3244
**Return value**
3245

W
wusongqing 已提交
3246 3247 3248
| Type| Description|
| -------- | -------- |
| string | String encoded from the Uint8Array.|
W
wusongqing 已提交
3249

W
wusongqing 已提交
3250
**Example**
3251

3252
  ```js
3253 3254 3255
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeToStringSync(array);
W
wusongqing 已提交
3256 3257
  ```

G
ge-yafang 已提交
3258
### decodeSync<sup>(deprecated)</sup>
W
wusongqing 已提交
3259

W
wusongqing 已提交
3260
decodeSync(src: Uint8Array | string): Uint8Array
Z
zengyawen 已提交
3261 3262 3263

Decodes the input content.

3264 3265 3266 3267
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decodeSync<sup>9+</sup>](#decodesync9) instead.

W
wusongqing 已提交
3268 3269 3270
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3271

W
wusongqing 已提交
3272 3273
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
3274
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.|
W
wusongqing 已提交
3275

W
wusongqing 已提交
3276
**Return value**
3277

W
wusongqing 已提交
3278 3279 3280
| Type| Description|
| -------- | -------- |
| Uint8Array | Uint8Array decoded.|
W
wusongqing 已提交
3281

W
wusongqing 已提交
3282
**Example**
3283

3284
  ```js
3285 3286 3287
  let that = new util.Base64();
  let buff = 'czEz';
  let result = that.decodeSync(buff);
W
wusongqing 已提交
3288 3289
  ```

G
ge-yafang 已提交
3290
### encode<sup>(deprecated)</sup>
W
wusongqing 已提交
3291

X
xdmal 已提交
3292
encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
3293 3294 3295

Encodes the input content asynchronously.

3296 3297 3298 3299
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encode<sup>9+</sup>](#encode9) instead.

W
wusongqing 已提交
3300 3301 3302
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3303

W
wusongqing 已提交
3304 3305 3306
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
W
wusongqing 已提交
3307

W
wusongqing 已提交
3308
**Return value**
3309

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

W
wusongqing 已提交
3314
**Example**
3315

3316
  ```js
3317 3318 3319
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let rarray = new Uint8Array([99,122,69,122]);
W
wusongqing 已提交
3320 3321
  that.encode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
S
shikai-123 已提交
3322
          console.log(val[i].toString())
W
wusongqing 已提交
3323 3324 3325 3326
      }
  })
  ```

G
ge-yafang 已提交
3327
### encodeToString<sup>(deprecated)</sup>
W
wusongqing 已提交
3328

X
xdmal 已提交
3329
encodeToString(src: Uint8Array): Promise&lt;string&gt;
W
wusongqing 已提交
3330 3331 3332

Encodes the input content asynchronously.

3333 3334 3335 3336
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [encodeToString<sup>9+</sup>](#encodetostring9) instead.

W
wusongqing 已提交
3337 3338 3339
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3340

W
wusongqing 已提交
3341 3342 3343
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
W
wusongqing 已提交
3344

W
wusongqing 已提交
3345
**Return value**
3346

W
wusongqing 已提交
3347 3348 3349
| Type| Description|
| -------- | -------- |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
W
wusongqing 已提交
3350

W
wusongqing 已提交
3351
**Example**
3352

3353
  ```js
3354 3355
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
W
wusongqing 已提交
3356 3357 3358 3359 3360
  that.encodeToString(array).then(val=>{    
      console.log(val)
  })
  ```

G
ge-yafang 已提交
3361
### decode<sup>(deprecated)</sup>
W
wusongqing 已提交
3362 3363


W
wusongqing 已提交
3364
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
3365 3366 3367

Decodes the input content asynchronously.

3368 3369 3370 3371
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [decode<sup>9+</sup>](#decode9) instead.

W
wusongqing 已提交
3372 3373 3374
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3375

W
wusongqing 已提交
3376 3377
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
3378
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.|
W
wusongqing 已提交
3379

W
wusongqing 已提交
3380
**Return value**
3381

W
wusongqing 已提交
3382 3383 3384
| Type| Description|
| -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
W
wusongqing 已提交
3385

W
wusongqing 已提交
3386
**Example**
3387

3388
  ```js
3389 3390 3391
  let that = new util.Base64();
  let array = new Uint8Array([99,122,69,122]);
  let rarray = new Uint8Array([115,49,51]);
W
wusongqing 已提交
3392 3393
  that.decode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
S
shikai-123 已提交
3394
          console.log(val[i].toString())
W
wusongqing 已提交
3395 3396 3397 3398
      }
  })
  ```

3399
## types<sup>8+</sup>
W
wusongqing 已提交
3400 3401 3402 3403 3404 3405


### constructor<sup>8+</sup>

constructor()

W
wusongqing 已提交
3406
A constructor used to create a **Types** object.
W
wusongqing 已提交
3407

W
wusongqing 已提交
3408 3409 3410
**System capability**: SystemCapability.Utils.Lang

**Example**
3411

3412
  ```js
3413
  let type = new util.types();
W
wusongqing 已提交
3414 3415 3416 3417 3418
  ```


### isAnyArrayBuffer<sup>8+</sup>

X
xdmal 已提交
3419
isAnyArrayBuffer(value: Object): boolean
W
wusongqing 已提交
3420 3421 3422

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

W
wusongqing 已提交
3423 3424 3425
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3426

W
wusongqing 已提交
3427 3428 3429
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3430

W
wusongqing 已提交
3431
**Return value**
3432

W
wusongqing 已提交
3433 3434 3435
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
3436

W
wusongqing 已提交
3437
**Example**
3438

3439
  ```js
3440 3441
  let that = new util.types();
  let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
W
wusongqing 已提交
3442 3443 3444 3445 3446
  ```


### isArrayBufferView<sup>8+</sup>

X
xdmal 已提交
3447
isArrayBufferView(value: Object): boolean
W
wusongqing 已提交
3448 3449 3450 3451 3452

Checks whether the input value is of the **ArrayBufferView** type.

**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.

W
wusongqing 已提交
3453 3454 3455
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3456

W
wusongqing 已提交
3457 3458 3459
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3460

W
wusongqing 已提交
3461
**Return value**
3462

W
wusongqing 已提交
3463 3464 3465
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
W
wusongqing 已提交
3466

W
wusongqing 已提交
3467
**Example**
3468

3469
  ```js
3470 3471
  let that = new util.types();
  let result = that.isArrayBufferView(new Int8Array([]));
W
wusongqing 已提交
3472 3473 3474 3475 3476
  ```


### isArgumentsObject<sup>8+</sup>

X
xdmal 已提交
3477
isArgumentsObject(value: Object): boolean
W
wusongqing 已提交
3478 3479 3480

Checks whether the input value is of the **arguments** type.

W
wusongqing 已提交
3481 3482 3483
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3484

W
wusongqing 已提交
3485 3486 3487
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3488

W
wusongqing 已提交
3489
**Return value**
3490

W
wusongqing 已提交
3491 3492 3493
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
W
wusongqing 已提交
3494

W
wusongqing 已提交
3495
**Example**
3496

3497
  ```js
3498
  let that = new util.types();
W
wusongqing 已提交
3499 3500 3501
  function foo() {
      var result = that.isArgumentsObject(arguments);
  }
3502
  let f = foo();
W
wusongqing 已提交
3503 3504 3505 3506 3507
  ```


### isArrayBuffer<sup>8+</sup>

X
xdmal 已提交
3508
isArrayBuffer(value: Object): boolean
W
wusongqing 已提交
3509 3510 3511

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

W
wusongqing 已提交
3512 3513 3514
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3515

W
wusongqing 已提交
3516 3517 3518
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3519

W
wusongqing 已提交
3520
**Return value**
3521

W
wusongqing 已提交
3522 3523 3524
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
3525

W
wusongqing 已提交
3526
**Example**
3527

3528
  ```js
3529 3530
  let that = new util.types();
  let result = that.isArrayBuffer(new ArrayBuffer(0));
W
wusongqing 已提交
3531 3532 3533 3534 3535
  ```


### isAsyncFunction<sup>8+</sup>

X
xdmal 已提交
3536
isAsyncFunction(value: Object): boolean
Z
zengyawen 已提交
3537 3538 3539

Checks whether the input value is an asynchronous function.

W
wusongqing 已提交
3540 3541 3542
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3543

W
wusongqing 已提交
3544 3545 3546
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3547

W
wusongqing 已提交
3548
**Return value**
3549

W
wusongqing 已提交
3550 3551 3552
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
W
wusongqing 已提交
3553

W
wusongqing 已提交
3554
**Example**
3555

3556
  ```js
3557 3558
  let that = new util.types();
  let result = that.isAsyncFunction(async function foo() {});
W
wusongqing 已提交
3559 3560 3561 3562 3563
  ```


### isBooleanObject<sup>8+</sup>

X
xdmal 已提交
3564
isBooleanObject(value: Object): boolean
W
wusongqing 已提交
3565 3566 3567

Checks whether the input value is of the **Boolean** type.

W
wusongqing 已提交
3568 3569 3570
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3571

W
wusongqing 已提交
3572 3573 3574
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3575

W
wusongqing 已提交
3576
**Return value**
3577

W
wusongqing 已提交
3578 3579 3580
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
W
wusongqing 已提交
3581

W
wusongqing 已提交
3582
**Example**
3583

3584
  ```js
3585 3586
  let that = new util.types();
  let result = that.isBooleanObject(new Boolean(true));
W
wusongqing 已提交
3587 3588 3589 3590 3591
  ```


### isBoxedPrimitive<sup>8+</sup>

X
xdmal 已提交
3592
isBoxedPrimitive(value: Object): boolean
W
wusongqing 已提交
3593 3594 3595

Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.

W
wusongqing 已提交
3596 3597 3598
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3599

W
wusongqing 已提交
3600 3601 3602
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3603

W
wusongqing 已提交
3604
**Return value**
3605

W
wusongqing 已提交
3606 3607 3608
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
W
wusongqing 已提交
3609

W
wusongqing 已提交
3610
**Example**
3611

3612
  ```js
3613 3614
  let that = new util.types();
  let result = that.isBoxedPrimitive(new Boolean(false));
W
wusongqing 已提交
3615 3616 3617 3618 3619
  ```


### isDataView<sup>8+</sup>

X
xdmal 已提交
3620
isDataView(value: Object): boolean
W
wusongqing 已提交
3621 3622 3623

Checks whether the input value is of the **DataView** type.

W
wusongqing 已提交
3624 3625 3626
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3627

W
wusongqing 已提交
3628 3629 3630
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3631

W
wusongqing 已提交
3632
**Return value**
3633

W
wusongqing 已提交
3634 3635 3636
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
W
wusongqing 已提交
3637

W
wusongqing 已提交
3638
**Example**
3639

3640
  ```js
3641
  let that = new util.types();
W
wusongqing 已提交
3642
  const ab = new ArrayBuffer(20);
3643
  let result = that.isDataView(new DataView(ab));
W
wusongqing 已提交
3644 3645 3646 3647 3648
  ```


### isDate<sup>8+</sup>

X
xdmal 已提交
3649
isDate(value: Object): boolean
W
wusongqing 已提交
3650 3651 3652

Checks whether the input value is of the **Date** type.

W
wusongqing 已提交
3653 3654 3655
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3656

W
wusongqing 已提交
3657 3658 3659
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3660

W
wusongqing 已提交
3661
**Return value**
3662

W
wusongqing 已提交
3663 3664 3665
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
W
wusongqing 已提交
3666

W
wusongqing 已提交
3667
**Example**
3668

3669
  ```js
3670 3671
  let that = new util.types();
  let result = that.isDate(new Date());
W
wusongqing 已提交
3672 3673 3674 3675 3676
  ```


### isExternal<sup>8+</sup>

X
xdmal 已提交
3677
isExternal(value: Object): boolean
W
wusongqing 已提交
3678 3679 3680

Checks whether the input value is of the **native external** type.

W
wusongqing 已提交
3681 3682 3683
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3684

W
wusongqing 已提交
3685 3686 3687
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3688

W
wusongqing 已提交
3689
**Return value**
3690

W
wusongqing 已提交
3691 3692 3693
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
W
wusongqing 已提交
3694

W
wusongqing 已提交
3695
**Example**
3696

3697
  ```js
3698 3699
  let that = new util.types();
  let result = that.isExternal(true);
W
wusongqing 已提交
3700 3701 3702 3703 3704
  ```


### isFloat32Array<sup>8+</sup>

X
xdmal 已提交
3705
isFloat32Array(value: Object): boolean
W
wusongqing 已提交
3706 3707 3708

Checks whether the input value is of the **Float32Array** type.

W
wusongqing 已提交
3709 3710 3711
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3712

W
wusongqing 已提交
3713 3714 3715
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3716

W
wusongqing 已提交
3717
**Return value**
3718

W
wusongqing 已提交
3719 3720 3721
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3722

W
wusongqing 已提交
3723
**Example**
3724

3725
  ```js
3726 3727
  let that = new util.types();
  let result = that.isFloat32Array(new Float32Array());
W
wusongqing 已提交
3728 3729 3730 3731 3732
  ```


### isFloat64Array<sup>8+</sup>

X
xdmal 已提交
3733
isFloat64Array(value: Object): boolean
W
wusongqing 已提交
3734 3735 3736

Checks whether the input value is of the **Float64Array** type.

W
wusongqing 已提交
3737 3738 3739
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3740

W
wusongqing 已提交
3741 3742 3743
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3744

W
wusongqing 已提交
3745
**Return value**
3746

W
wusongqing 已提交
3747 3748 3749
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3750

W
wusongqing 已提交
3751
**Example**
3752

3753
  ```js
3754 3755
  let that = new util.types();
  let result = that.isFloat64Array(new Float64Array());
W
wusongqing 已提交
3756 3757 3758 3759 3760
  ```


### isGeneratorFunction<sup>8+</sup>

X
xdmal 已提交
3761
isGeneratorFunction(value: Object): boolean
Z
zengyawen 已提交
3762 3763 3764

Checks whether the input value is a generator function.

W
wusongqing 已提交
3765 3766 3767
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3768

W
wusongqing 已提交
3769 3770 3771
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3772

W
wusongqing 已提交
3773
**Return value**
3774

W
wusongqing 已提交
3775 3776 3777
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
W
wusongqing 已提交
3778

W
wusongqing 已提交
3779
**Example**
3780

3781
  ```js
3782 3783
  let that = new util.types();
  let result = that.isGeneratorFunction(function* foo() {});
W
wusongqing 已提交
3784 3785 3786 3787 3788
  ```


### isGeneratorObject<sup>8+</sup>

X
xdmal 已提交
3789
isGeneratorObject(value: Object): boolean
Z
zengyawen 已提交
3790 3791 3792

Checks whether the input value is a generator object.

W
wusongqing 已提交
3793 3794 3795
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3796

W
wusongqing 已提交
3797 3798 3799
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3800

W
wusongqing 已提交
3801
**Return value**
3802

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

W
wusongqing 已提交
3807
**Example**
3808

3809
  ```js
3810
  let that = new util.types();
W
wusongqing 已提交
3811 3812
  function* foo() {}
  const generator = foo();
3813
  let result = that.isGeneratorObject(generator);
W
wusongqing 已提交
3814 3815 3816 3817 3818
  ```


### isInt8Array<sup>8+</sup>

X
xdmal 已提交
3819
isInt8Array(value: Object): boolean
W
wusongqing 已提交
3820 3821 3822

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

W
wusongqing 已提交
3823 3824 3825
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3826

W
wusongqing 已提交
3827 3828 3829
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3830

W
wusongqing 已提交
3831
**Return value**
3832

W
wusongqing 已提交
3833 3834 3835
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3836

W
wusongqing 已提交
3837
**Example**
3838

3839
  ```js
3840 3841
  let that = new util.types();
  let result = that.isInt8Array(new Int8Array([]));
W
wusongqing 已提交
3842 3843 3844 3845 3846
  ```


### isInt16Array<sup>8+</sup>

X
xdmal 已提交
3847
isInt16Array(value: Object): boolean
W
wusongqing 已提交
3848 3849 3850

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

W
wusongqing 已提交
3851 3852 3853
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3854

W
wusongqing 已提交
3855 3856 3857
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3858

W
wusongqing 已提交
3859
**Return value**
3860

W
wusongqing 已提交
3861 3862 3863
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3864

W
wusongqing 已提交
3865
**Example**
3866

3867
  ```js
3868 3869
  let that = new util.types();
  let result = that.isInt16Array(new Int16Array([]));
W
wusongqing 已提交
3870 3871 3872 3873 3874
  ```


### isInt32Array<sup>8+</sup>

X
xdmal 已提交
3875
isInt32Array(value: Object): boolean
W
wusongqing 已提交
3876 3877 3878

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

W
wusongqing 已提交
3879 3880 3881
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3882

W
wusongqing 已提交
3883 3884 3885
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3886

W
wusongqing 已提交
3887
**Return value**
3888

W
wusongqing 已提交
3889 3890 3891
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3892

W
wusongqing 已提交
3893
**Example**
3894

3895
  ```js
3896 3897
  let that = new util.types();
  let result = that.isInt32Array(new Int32Array([]));
W
wusongqing 已提交
3898 3899 3900 3901 3902
  ```


### isMap<sup>8+</sup>

X
xdmal 已提交
3903
isMap(value: Object): boolean
W
wusongqing 已提交
3904 3905 3906

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

W
wusongqing 已提交
3907 3908 3909
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3910

W
wusongqing 已提交
3911 3912 3913
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3914

W
wusongqing 已提交
3915
**Return value**
3916

W
wusongqing 已提交
3917 3918 3919
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
W
wusongqing 已提交
3920

W
wusongqing 已提交
3921
**Example**
3922

3923
  ```js
3924 3925
  let that = new util.types();
  let result = that.isMap(new Map());
W
wusongqing 已提交
3926 3927 3928 3929 3930
  ```


### isMapIterator<sup>8+</sup>

X
xdmal 已提交
3931
isMapIterator(value: Object): boolean
W
wusongqing 已提交
3932 3933 3934

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

W
wusongqing 已提交
3935 3936 3937
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3938

3939

W
wusongqing 已提交
3940 3941 3942
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3943

W
wusongqing 已提交
3944
**Return value**
3945

W
wusongqing 已提交
3946 3947 3948
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
W
wusongqing 已提交
3949

W
wusongqing 已提交
3950
**Example**
3951

3952
  ```js
3953
  let that = new util.types();
W
wusongqing 已提交
3954
  const map = new Map();
3955
  let result = that.isMapIterator(map.keys());
W
wusongqing 已提交
3956 3957 3958 3959 3960
  ```


### isNativeError<sup>8+</sup>

X
xdmal 已提交
3961
isNativeError(value: Object): boolean
W
wusongqing 已提交
3962 3963 3964

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

W
wusongqing 已提交
3965 3966 3967
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3968

W
wusongqing 已提交
3969 3970 3971
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3972

W
wusongqing 已提交
3973
**Return value**
3974

W
wusongqing 已提交
3975 3976 3977
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
W
wusongqing 已提交
3978

W
wusongqing 已提交
3979
**Example**
3980

3981
  ```js
3982 3983
  let that = new util.types();
  let result = that.isNativeError(new TypeError());
W
wusongqing 已提交
3984 3985 3986 3987 3988
  ```


### isNumberObject<sup>8+</sup>

X
xdmal 已提交
3989
isNumberObject(value: Object): boolean
Z
zengyawen 已提交
3990 3991 3992

Checks whether the input value is a number object.

W
wusongqing 已提交
3993 3994 3995
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3996

W
wusongqing 已提交
3997 3998 3999
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4000

W
wusongqing 已提交
4001
**Return value**
4002

W
wusongqing 已提交
4003 4004 4005
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
W
wusongqing 已提交
4006

W
wusongqing 已提交
4007
**Example**
4008

4009
  ```js
4010 4011
  let that = new util.types();
  let result = that.isNumberObject(new Number(0));
W
wusongqing 已提交
4012 4013 4014 4015 4016
  ```


### isPromise<sup>8+</sup>

X
xdmal 已提交
4017
isPromise(value: Object): boolean
Z
zengyawen 已提交
4018 4019 4020

Checks whether the input value is a promise.

W
wusongqing 已提交
4021 4022 4023
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4024

W
wusongqing 已提交
4025 4026 4027
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4028

W
wusongqing 已提交
4029
**Return value**
4030

W
wusongqing 已提交
4031 4032 4033
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
W
wusongqing 已提交
4034

W
wusongqing 已提交
4035
**Example**
4036

4037
  ```js
4038 4039
  let that = new util.types();
  let result = that.isPromise(Promise.resolve(1));
W
wusongqing 已提交
4040 4041 4042 4043 4044
  ```


### isProxy<sup>8+</sup>

X
xdmal 已提交
4045
isProxy(value: Object): boolean
Z
zengyawen 已提交
4046 4047 4048

Checks whether the input value is a proxy.

W
wusongqing 已提交
4049 4050 4051
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4052

W
wusongqing 已提交
4053 4054 4055
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4056

W
wusongqing 已提交
4057
**Return value**
4058

W
wusongqing 已提交
4059 4060 4061
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
W
wusongqing 已提交
4062

W
wusongqing 已提交
4063
**Example**
4064

4065
  ```js
4066
  let that = new util.types();
W
wusongqing 已提交
4067 4068
  const target = {};
  const proxy = new Proxy(target, {});
4069
  let result = that.isProxy(proxy);
W
wusongqing 已提交
4070 4071 4072 4073 4074
  ```


### isRegExp<sup>8+</sup>

X
xdmal 已提交
4075
isRegExp(value: Object): boolean
W
wusongqing 已提交
4076 4077 4078

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

W
wusongqing 已提交
4079 4080 4081
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4082

W
wusongqing 已提交
4083 4084 4085
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4086

W
wusongqing 已提交
4087
**Return value**
4088

W
wusongqing 已提交
4089 4090 4091
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.|
W
wusongqing 已提交
4092

W
wusongqing 已提交
4093
**Example**
4094

4095
  ```js
4096 4097
  let that = new util.types();
  let result = that.isRegExp(new RegExp('abc'));
W
wusongqing 已提交
4098 4099 4100 4101 4102
  ```


### isSet<sup>8+</sup>

X
xdmal 已提交
4103
isSet(value: Object): boolean
W
wusongqing 已提交
4104 4105 4106

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

W
wusongqing 已提交
4107 4108 4109
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4110

W
wusongqing 已提交
4111 4112 4113
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4114

W
wusongqing 已提交
4115
**Return value**
4116

W
wusongqing 已提交
4117 4118 4119
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
W
wusongqing 已提交
4120

W
wusongqing 已提交
4121
**Example**
4122

4123
  ```js
4124 4125
  let that = new util.types();
  let result = that.isSet(new Set());
W
wusongqing 已提交
4126 4127 4128 4129 4130
  ```


### isSetIterator<sup>8+</sup>

X
xdmal 已提交
4131
isSetIterator(value: Object): boolean
W
wusongqing 已提交
4132 4133 4134

Checks whether the input value is of the **SetIterator** type.

W
wusongqing 已提交
4135 4136 4137
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4138

W
wusongqing 已提交
4139 4140 4141
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4142

W
wusongqing 已提交
4143
**Return value**
4144

W
wusongqing 已提交
4145 4146 4147
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.|
W
wusongqing 已提交
4148

W
wusongqing 已提交
4149
**Example**
4150

4151
  ```js
4152
  let that = new util.types();
W
wusongqing 已提交
4153
  const set = new Set();
4154
  let result = that.isSetIterator(set.keys());
W
wusongqing 已提交
4155 4156 4157 4158 4159
  ```


### isStringObject<sup>8+</sup>

X
xdmal 已提交
4160
isStringObject(value: Object): boolean
Z
zengyawen 已提交
4161 4162 4163

Checks whether the input value is a string object.

W
wusongqing 已提交
4164 4165 4166
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4167

W
wusongqing 已提交
4168 4169 4170
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4171

W
wusongqing 已提交
4172
**Return value**
4173

W
wusongqing 已提交
4174 4175 4176
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
W
wusongqing 已提交
4177

W
wusongqing 已提交
4178
**Example**
4179

4180
  ```js
4181 4182
  let that = new util.types();
  let result = that.isStringObject(new String('foo'));
W
wusongqing 已提交
4183 4184 4185 4186 4187
  ```


### isSymbolObjec<sup>8+</sup>

X
xdmal 已提交
4188
isSymbolObject(value: Object): boolean
Z
zengyawen 已提交
4189 4190 4191

Checks whether the input value is a symbol object.

W
wusongqing 已提交
4192 4193 4194
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4195

W
wusongqing 已提交
4196 4197 4198
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4199

W
wusongqing 已提交
4200
**Return value**
4201

W
wusongqing 已提交
4202 4203 4204
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
W
wusongqing 已提交
4205

W
wusongqing 已提交
4206
**Example**
4207

4208
  ```js
4209
  let that = new util.types();
W
wusongqing 已提交
4210
  const symbols = Symbol('foo');
4211
  let result = that.isSymbolObject(Object(symbols));
W
wusongqing 已提交
4212 4213 4214 4215 4216
  ```


### isTypedArray<sup>8+</sup>

X
xdmal 已提交
4217
isTypedArray(value: Object): boolean
W
wusongqing 已提交
4218 4219 4220 4221 4222

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

W
wusongqing 已提交
4223 4224 4225
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4226

W
wusongqing 已提交
4227 4228 4229
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4230

W
wusongqing 已提交
4231
**Return value**
4232

W
wusongqing 已提交
4233 4234 4235
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
W
wusongqing 已提交
4236

W
wusongqing 已提交
4237
**Example**
4238

4239
  ```js
4240 4241
  let that = new util.types();
  let result = that.isTypedArray(new Float64Array([]));
W
wusongqing 已提交
4242 4243 4244 4245 4246
  ```


### isUint8Array<sup>8+</sup>

X
xdmal 已提交
4247
isUint8Array(value: Object): boolean
W
wusongqing 已提交
4248 4249 4250

Checks whether the input value is of the **Uint8Array** type.

W
wusongqing 已提交
4251 4252 4253
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4254

W
wusongqing 已提交
4255 4256 4257
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4258

W
wusongqing 已提交
4259
**Return value**
4260

W
wusongqing 已提交
4261 4262 4263
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
W
wusongqing 已提交
4264

W
wusongqing 已提交
4265
**Example**
4266

4267
  ```js
4268 4269
  let that = new util.types();
  let result = that.isUint8Array(new Uint8Array([]));
W
wusongqing 已提交
4270 4271 4272 4273 4274
  ```


### isUint8ClampedArray<sup>8+</sup>

X
xdmal 已提交
4275
isUint8ClampedArray(value: Object): boolean
W
wusongqing 已提交
4276 4277 4278

Checks whether the input value is of the **Uint8ClampedArray** type.

W
wusongqing 已提交
4279 4280 4281
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4282

W
wusongqing 已提交
4283 4284 4285
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4286

W
wusongqing 已提交
4287
**Return value**
4288

W
wusongqing 已提交
4289 4290 4291
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
W
wusongqing 已提交
4292

W
wusongqing 已提交
4293
**Example**
4294

4295
  ```js
4296 4297
  let that = new util.types();
  let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
W
wusongqing 已提交
4298 4299 4300 4301 4302
  ```


### isUint16Array<sup>8+</sup>

X
xdmal 已提交
4303
isUint16Array(value: Object): boolean
W
wusongqing 已提交
4304 4305 4306

Checks whether the input value is of the **Uint16Array** type.

W
wusongqing 已提交
4307 4308 4309
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4310

W
wusongqing 已提交
4311 4312 4313
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4314

W
wusongqing 已提交
4315
**Return value**
4316

W
wusongqing 已提交
4317 4318 4319
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
W
wusongqing 已提交
4320

W
wusongqing 已提交
4321
**Example**
4322

4323
  ```js
4324 4325
  let that = new util.types();
  let result = that.isUint16Array(new Uint16Array([]));
W
wusongqing 已提交
4326 4327 4328 4329 4330
  ```


### isUint32Array<sup>8+</sup>

X
xdmal 已提交
4331
isUint32Array(value: Object): boolean
W
wusongqing 已提交
4332 4333 4334

Checks whether the input value is of the **Uint32Array** type.

W
wusongqing 已提交
4335 4336 4337
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4338

W
wusongqing 已提交
4339 4340 4341
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4342

W
wusongqing 已提交
4343
**Return value**
4344

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

W
wusongqing 已提交
4349
**Example**
4350

4351
  ```js
4352 4353
  let that = new util.types();
  let result = that.isUint32Array(new Uint32Array([]));
W
wusongqing 已提交
4354 4355 4356 4357 4358
  ```


### isWeakMap<sup>8+</sup>

X
xdmal 已提交
4359
isWeakMap(value: Object): boolean
W
wusongqing 已提交
4360 4361 4362

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

W
wusongqing 已提交
4363 4364 4365
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4366

W
wusongqing 已提交
4367 4368 4369
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4370

W
wusongqing 已提交
4371
**Return value**
4372

W
wusongqing 已提交
4373 4374 4375
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
W
wusongqing 已提交
4376

W
wusongqing 已提交
4377
**Example**
4378

4379
  ```js
4380 4381
  let that = new util.types();
  let result = that.isWeakMap(new WeakMap());
W
wusongqing 已提交
4382 4383 4384 4385 4386
  ```


### isWeakSet<sup>8+</sup>

X
xdmal 已提交
4387
isWeakSet(value: Object): boolean
W
wusongqing 已提交
4388 4389 4390

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

W
wusongqing 已提交
4391 4392 4393
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4394

W
wusongqing 已提交
4395 4396 4397
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4398

W
wusongqing 已提交
4399
**Return value**
4400

W
wusongqing 已提交
4401 4402 4403
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
Z
zengyawen 已提交
4404

W
wusongqing 已提交
4405
**Example**
4406

4407
  ```js
4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433
  let that = new util.types();
  let result = that.isWeakSet(new WeakSet());
  ```


### isBigInt64Array<sup>8+</sup>

isBigInt64Array(value: Object): boolean

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

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

**Parameters**

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

**Return value**

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

**Example**
4434

4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461
  ```js
  let that = new util.types();
  let result = that.isBigInt64Array(new BigInt64Array([]));
  ```


### isBigUint64Array<sup>8+</sup>

isBigUint64Array(value: Object): boolean

Checks whether the input value is of the **BigUint64Array** type.

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

**Parameters**

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

**Return value**

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

**Example**
4462

4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489
  ```js
  let that = new util.types();
  let result = that.isBigUint64Array(new BigUint64Array([]));
  ```


### isModuleNamespaceObject<sup>8+</sup>

isModuleNamespaceObject(value: Object): boolean

Checks whether the input value is a module namespace object.

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

**Parameters**

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

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.|

**Example**
4490

4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518
  ```js
  import url from '@ohos.url'
  let that = new util.types();
  let result = that.isModuleNamespaceObject(url);
  ```


### isSharedArrayBuffer<sup>8+</sup>

isSharedArrayBuffer(value: Object): boolean

Checks whether the input value is of the **SharedArrayBuffer** type.

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

**Parameters**

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

**Return value**

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

**Example**
4519

4520 4521 4522
  ```js
  let that = new util.types();
  let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
W
wusongqing 已提交
4523
  ```
G
Gloria 已提交
4524
  <!--no_check-->