js-apis-util.md 107.1 KB
Newer Older
W
wusongqing 已提交
1
# util
Z
zengyawen 已提交
2 3


W
wusongqing 已提交
4 5
> **NOTE**
>
W
wusongqing 已提交
6
> 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 已提交
7

W
wusongqing 已提交
8

W
wusongqing 已提交
9
This module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types.
W
wusongqing 已提交
10 11 12


## Modules to Import
Z
zengyawen 已提交
13 14 15 16 17

```
import util from '@ohos.util';
```

G
Gloria 已提交
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 46 47 48 49 50
## util.format<sup>9+</sup>

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [util.format9+](#utilformat9) instead.
Z
zengyawen 已提交
51

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

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

W
wusongqing 已提交
56 57 58
**System capability**: SystemCapability.Utils.Lang

**Parameters**
59

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

W
wusongqing 已提交
65
**Return value**
66

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

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

G
Gloria 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
## util.errnoToString<sup>9+</sup>

errnoToString(errno: number): string

Obtains detailed information about a system error code.

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

**Parameters**

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

**Return value**

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

**Example**

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

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

G
Gloria 已提交
107 108 109
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [util.errnoToString9+](#utilerrnotostring9) instead.
W
wusongqing 已提交
110 111

getErrorString(errno: number): string
Z
zengyawen 已提交
112 113 114

Obtains detailed information about a system error code.

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

**Parameters**
118

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

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

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

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

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

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

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

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

**Parameters**
178

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

**Return value**
184

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

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

G
Gloria 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
## util.promiseWrapper<sup>(deprecated)</sup>

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

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use **[util.promisify9+](#utilpromisify9)** instead.

Processes an asynchronous function and returns a promise.

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

**Parameters**

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

**Return value**

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

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
## 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**
  ```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**
  ```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**
  ```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 已提交
312 313 314 315
## TextDecoder

### Attributes

W
wusongqing 已提交
316 317
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
318 319 320 321 322
| 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 已提交
323

G
Gloria 已提交
324
### constructor<sup>9+</sup>
W
wusongqing 已提交
325

G
Gloria 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
constructor()

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

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

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

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

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

**Parameters**

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

  **Table 1.1** options

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

**Example**

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

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

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
W
wusongqing 已提交
364

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

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

W
wusongqing 已提交
369 370 371
**System capability**: SystemCapability.Utils.Lang

**Parameters**
372

W
wusongqing 已提交
373 374 375 376
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.|
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
W
wusongqing 已提交
377 378

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

W
wusongqing 已提交
380 381 382 383
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fatal | boolean | No| Whether to display fatal errors.|
| ignoreBOM | boolean | No| Whether to ignore the BOM.|
W
wusongqing 已提交
384

W
wusongqing 已提交
385
**Example**
386
  ```js
387
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
W
wusongqing 已提交
388 389 390 391
  ```

### decode

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

Z
zengyawen 已提交
394
Decodes the input content.
Z
zengyawen 已提交
395

W
wusongqing 已提交
396 397 398
**System capability**: SystemCapability.Utils.Lang

**Parameters**
399

W
wusongqing 已提交
400 401
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
402
| input | Uint8Array | Yes| Uint8Array to decode.|
W
wusongqing 已提交
403
| options | Object | No| Options related to decoding.|
W
wusongqing 已提交
404 405

  **Table 2** options
W
wusongqing 已提交
406

W
wusongqing 已提交
407 408 409
| 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 已提交
410

W
wusongqing 已提交
411
**Return value**
412

W
wusongqing 已提交
413 414 415
| Type| Description|
| -------- | -------- |
| string | Data decoded.|
Z
zengyawen 已提交
416

W
wusongqing 已提交
417
**Example**
418
  ```js
419 420
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  let result = new Uint8Array(6);
W
wusongqing 已提交
421 422 423 424 425 426 427
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
  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.|

  **Table 2** options

| 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**
  ```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 已提交
472 473
  console.log("retStr = " + retStr);
  ```
Z
zengyawen 已提交
474 475


W
wusongqing 已提交
476
## TextEncoder
Z
zengyawen 已提交
477

W
wusongqing 已提交
478
### Attributes
Z
zengyawen 已提交
479

W
wusongqing 已提交
480 481
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
482 483 484
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
Z
zengyawen 已提交
485 486


W
wusongqing 已提交
487
### constructor
Z
zengyawen 已提交
488

W
wusongqing 已提交
489
constructor()
Z
zengyawen 已提交
490

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

W
wusongqing 已提交
493 494 495
**System capability**: SystemCapability.Utils.Lang

**Example**
496
  ```js
497
  let textEncoder = new util.TextEncoder();
W
wusongqing 已提交
498 499
  ```

G
Gloria 已提交
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
### encodeInto<sup>9+</sup>

encodeInto(input?: string): Uint8Array

Encodes the input content.

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

**Parameters**

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

**Return value**

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

**Example**

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

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

G
Gloria 已提交
531 532 533
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeInto9+](#encodeinto9) instead.
W
wusongqing 已提交
534

X
xdmal 已提交
535
encode(input?: string): Uint8Array
Z
zengyawen 已提交
536

Z
zengyawen 已提交
537
Encodes the input content.
Z
zengyawen 已提交
538

W
wusongqing 已提交
539 540 541
**System capability**: SystemCapability.Utils.Lang

**Parameters**
542

W
wusongqing 已提交
543 544 545
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| input | string | Yes| String to encode.|
W
wusongqing 已提交
546

W
wusongqing 已提交
547
**Return value**
548

W
wusongqing 已提交
549 550 551
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
W
wusongqing 已提交
552

W
wusongqing 已提交
553
**Example**
554
  ```js
555 556 557
  let textEncoder = new util.TextEncoder();
  let buffer = new ArrayBuffer(20);
  let result = new Uint8Array(buffer);
W
wusongqing 已提交
558 559 560
  result = textEncoder.encode("\uD800¥¥");
  ```

G
Gloria 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
### 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 已提交
593

G
Gloria 已提交
594 595 596
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeIntoUint8Array9+](#encodeintouint8array9) instead.
W
wusongqing 已提交
597

X
xdmal 已提交
598
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
Z
zengyawen 已提交
599 600 601

Stores the UTF-8 encoded text.

W
wusongqing 已提交
602 603 604
**System capability**: SystemCapability.Utils.Lang

**Parameters**
605

W
wusongqing 已提交
606 607 608 609
| 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 已提交
610

W
wusongqing 已提交
611
**Return value**
612

W
wusongqing 已提交
613 614 615
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
Z
zengyawen 已提交
616

W
wusongqing 已提交
617
**Example**
618
  ```js
619 620 621 622
  let that = new util.TextEncoder()
  let buffer = new ArrayBuffer(4)
  let dest = new Uint8Array(buffer)
  let result = new Object()
S
shikai-123 已提交
623
  result = that.encodeInto('abcd', dest)
W
wusongqing 已提交
624
  ```
Z
zengyawen 已提交
625

W
wusongqing 已提交
626
## RationalNumber<sup>8+</sup>
Z
zengyawen 已提交
627

G
Gloria 已提交
628
### constructor<sup>9+</sup>
Z
zengyawen 已提交
629

G
Gloria 已提交
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
constructor()

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

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

**Example**

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

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

parseRationalNumber(numerator: number,denominator: number)

Parses a rational number. Previously, this processing is an internal action of the deprecated constructor.

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

**Parameters**

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

**Example**

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

G
ge-yafang 已提交
664
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
665 666 667 668

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
Z
zengyawen 已提交
669

X
xdmal 已提交
670
constructor(numerator: number,denominator: number)
Z
zengyawen 已提交
671

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

W
wusongqing 已提交
674 675 676
**System capability**: SystemCapability.Utils.Lang

**Parameters**
677

W
wusongqing 已提交
678 679 680 681
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| numerator | number | Yes| Numerator, which is an integer.|
| denominator | number | Yes| Denominator, which is an integer.|
Z
zengyawen 已提交
682

W
wusongqing 已提交
683
**Example**
G
Gloria 已提交
684

685
  ```js
686
  let rationalNumber = new util.RationalNumber(1,2);
W
wusongqing 已提交
687
  ```
Z
zengyawen 已提交
688

W
wusongqing 已提交
689
### createRationalFromString<sup>8+</sup>
Z
zengyawen 已提交
690

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

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

W
wusongqing 已提交
695 696 697
**System capability**: SystemCapability.Utils.Lang

**Parameters**
698

W
wusongqing 已提交
699 700 701
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rationalString | string | Yes| String used to create the **RationalNumber** object.|
Z
zengyawen 已提交
702

W
wusongqing 已提交
703
**Return value**
704

W
wusongqing 已提交
705 706 707
| Type| Description|
| -------- | -------- |
| object | **RationalNumber** object created.|
Z
zengyawen 已提交
708

W
wusongqing 已提交
709
**Example**
710
  ```js
711 712
  let rationalNumber = new util.RationalNumber(1,2);
  let rational = util.RationalNumber.createRationalFromString("3/4");
W
wusongqing 已提交
713
  ```
Z
zengyawen 已提交
714

G
Gloria 已提交
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
### compare<sup>9+</sup>

compare​(another: RationalNumber): number​

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

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

**Parameters**

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

**Return value**

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

**Example**

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

### compareTo<sup>8+</sup><sup>(deprecated)</sup>
Z
zengyawen 已提交
744

G
Gloria 已提交
745 746 747
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [compare9+](#compare9) instead.
Z
zengyawen 已提交
748

X
xdmal 已提交
749
compareTo​(another: RationalNumber): number​
Z
zengyawen 已提交
750

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

W
wusongqing 已提交
753 754 755
**System capability**: SystemCapability.Utils.Lang

**Parameters**
756

W
wusongqing 已提交
757 758 759
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
Z
zengyawen 已提交
760

W
wusongqing 已提交
761
**Return value**
762

W
wusongqing 已提交
763 764 765
| 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 已提交
766

W
wusongqing 已提交
767
**Example**
768
  ```js
769 770 771
  let rationalNumber = new util.RationalNumber(1,2);
  let rational = util.RationalNumber.createRationalFromString("3/4");
  let result = rationalNumber.compareTo(rational);
W
wusongqing 已提交
772
  ```
Z
zengyawen 已提交
773

W
wusongqing 已提交
774
### valueOf<sup>8+</sup>
Z
zengyawen 已提交
775

X
xdmal 已提交
776
valueOf(): number
Z
zengyawen 已提交
777

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

W
wusongqing 已提交
780 781 782
**System capability**: SystemCapability.Utils.Lang

**Return value**
783

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

W
wusongqing 已提交
788
**Example**
789
  ```js
790 791
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.valueOf();
W
wusongqing 已提交
792
  ```
Z
zengyawen 已提交
793

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

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

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

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

**Parameters**
803

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

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

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

W
wusongqing 已提交
814
**Example**
815
  ```js
816 817 818
  let rationalNumber = new util.RationalNumber(1,2);
  let rational = util.RationalNumber.createRationalFromString("3/4");
  let result = rationalNumber.equals(rational);
W
wusongqing 已提交
819
  ```
Z
zengyawen 已提交
820

G
Gloria 已提交
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
### getCommonFactor<sup>9+</sup>

getCommonFactor(number1: number,number2: number): number

Obtains the greatest common divisor of two specified integers.

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

**Parameters**

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

**Return value**

| Type  | Description                          |
| ------ | ------------------------------ |
| number | Greatest common divisor obtained.|
Z
zengyawen 已提交
841

G
Gloria 已提交
842 843 844 845 846 847 848
**Example**

  ```js
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonFactor(4,6);
  ```

G
ge-yafang 已提交
849
### getCommonDivisor<sup>(deprecated)</sup>
G
Gloria 已提交
850 851 852
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getCommonFactor9+](#getcommonfactor9) instead.
Z
zengyawen 已提交
853

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

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

W
wusongqing 已提交
858 859 860
**System capability**: SystemCapability.Utils.Lang

**Parameters**
861

W
wusongqing 已提交
862 863 864 865
| 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 已提交
866

W
wusongqing 已提交
867
**Return value**
868

W
wusongqing 已提交
869 870 871
| Type| Description|
| -------- | -------- |
| number | Greatest common divisor obtained.|
Z
zengyawen 已提交
872

W
wusongqing 已提交
873
**Example**
874
  ```js
875 876
  let rationalNumber = new util.RationalNumber(1,2);
  let result = util.RationalNumber.getCommonDivisor(4,6);
W
wusongqing 已提交
877
  ```
Z
zengyawen 已提交
878

W
wusongqing 已提交
879
### getNumerator<sup>8+</sup>
Z
zengyawen 已提交
880

X
xdmal 已提交
881
getNumerator​(): number
Z
zengyawen 已提交
882

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

W
wusongqing 已提交
885 886 887 888
**System capability**: SystemCapability.Utils.Lang

**Return value**

W
wusongqing 已提交
889 890 891
| Type| Description|
| -------- | -------- |
| number | Numerator of this **RationalNumber** object.|
Z
zengyawen 已提交
892

W
wusongqing 已提交
893
**Example**
894
  ```js
895 896
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.getNumerator();
W
wusongqing 已提交
897
  ```
Z
zengyawen 已提交
898

W
wusongqing 已提交
899
### getDenominator<sup>8+</sup>
Z
zengyawen 已提交
900

X
xdmal 已提交
901
getDenominator​(): number
Z
zengyawen 已提交
902

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

W
wusongqing 已提交
905 906 907
**System capability**: SystemCapability.Utils.Lang

**Return value**
908

W
wusongqing 已提交
909 910 911
| Type| Description|
| -------- | -------- |
| number | Denominator of this **RationalNumber** object.|
Z
zengyawen 已提交
912

W
wusongqing 已提交
913
**Example**
914
  ```js
915 916
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.getDenominator();
W
wusongqing 已提交
917
  ```
Z
zengyawen 已提交
918

W
wusongqing 已提交
919
### isZero<sup>8+</sup>
Z
zengyawen 已提交
920

W
wusongqing 已提交
921
isZero​():boolean
Z
zengyawen 已提交
922

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

W
wusongqing 已提交
925 926 927
**System capability**: SystemCapability.Utils.Lang

**Return value**
928

W
wusongqing 已提交
929 930 931
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
Z
zengyawen 已提交
932

W
wusongqing 已提交
933
**Example**
934
  ```js
935 936
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.isZero();
W
wusongqing 已提交
937
  ```
Z
zengyawen 已提交
938

W
wusongqing 已提交
939
### isNaN<sup>8+</sup>
Z
zengyawen 已提交
940

X
xdmal 已提交
941
isNaN​(): boolean
Z
zengyawen 已提交
942

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

W
wusongqing 已提交
945 946 947
**System capability**: SystemCapability.Utils.Lang

**Return value**
948

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

W
wusongqing 已提交
953
**Example**
954
  ```js
955 956
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.isNaN();
W
wusongqing 已提交
957
  ```
Z
zengyawen 已提交
958

W
wusongqing 已提交
959
### isFinite<sup>8+</sup>
Z
zengyawen 已提交
960

W
wusongqing 已提交
961
isFinite​():boolean
Z
zengyawen 已提交
962

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

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

**Return value**
968

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

W
wusongqing 已提交
973
**Example**
974
  ```js
975 976
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.isFinite();
W
wusongqing 已提交
977
  ```
Z
zengyawen 已提交
978

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

X
xdmal 已提交
981
toString​(): string
Z
zengyawen 已提交
982

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

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

**Return value**
988

W
wusongqing 已提交
989 990 991
| 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 已提交
992

W
wusongqing 已提交
993
**Example**
994
  ```js
995 996
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.toString();
W
wusongqing 已提交
997
  ```
Z
zengyawen 已提交
998

G
Gloria 已提交
999 1000

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

W
wusongqing 已提交
1002
### Attributes
Z
zengyawen 已提交
1003

W
wusongqing 已提交
1004 1005
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
1006 1007 1008
| Name  | Type  | Readable| Writable| Description                  |
| ------ | ------ | ---- | ---- | ---------------------- |
| length | number | Yes  | No  | Total number of values in this buffer. |
Z
zengyawen 已提交
1009

W
wusongqing 已提交
1010
**Example**
G
Gloria 已提交
1011

1012
  ```js
G
Gloria 已提交
1013 1014 1015 1016
let pro = new util.LRUCache();
pro.put(2,10);
pro.put(1,8);
let result = pro.length;
W
wusongqing 已提交
1017
  ```
Z
zengyawen 已提交
1018

G
Gloria 已提交
1019
### constructor<sup>9+</sup>
Z
zengyawen 已提交
1020

X
xdmal 已提交
1021
constructor(capacity?: number)
Z
zengyawen 已提交
1022

G
Gloria 已提交
1023
A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
Z
zengyawen 已提交
1024

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

**Parameters**
1028

G
Gloria 已提交
1029 1030 1031
| Name  | Type  | Mandatory| Description                        |
| -------- | ------ | ---- | ---------------------------- |
| capacity | number | No  | Capacity of the **LruBuffer** to create.|
Z
zengyawen 已提交
1032

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

1035
  ```js
G
Gloria 已提交
1036
let lrubuffer= new util.LRUCache();
W
wusongqing 已提交
1037
  ```
Z
zengyawen 已提交
1038 1039


G
Gloria 已提交
1040
### updateCapacity<sup>9+</sup>
Z
zengyawen 已提交
1041

X
xdmal 已提交
1042
updateCapacity(newCapacity: number): void
Z
zengyawen 已提交
1043

W
wusongqing 已提交
1044
Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
Z
zengyawen 已提交
1045

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

**Parameters**
1049

G
Gloria 已提交
1050 1051 1052
| Name     | Type  | Mandatory| Description                        |
| ----------- | ------ | ---- | ---------------------------- |
| newCapacity | number | Yes  | New capacity of the **LruBuffer**.|
Z
zengyawen 已提交
1053

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

1056
  ```js
G
Gloria 已提交
1057 1058
let pro = new util.LRUCache();
let result = pro.updateCapacity(100);
W
wusongqing 已提交
1059
  ```
Z
zengyawen 已提交
1060 1061


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

X
xdmal 已提交
1064
toString(): string
Z
zengyawen 已提交
1065

W
wusongqing 已提交
1066
Obtains the string representation of this **LruBuffer** object.
Z
zengyawen 已提交
1067

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

**Return value**
1071

G
Gloria 已提交
1072 1073
| Type  | Description                      |
| ------ | -------------------------- |
W
wusongqing 已提交
1074
| string | String representation of this **LruBuffer** object.|
W
wusongqing 已提交
1075

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

1078
  ```js
G
Gloria 已提交
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 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 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 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 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 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
let pro = new util.LRUCache();
pro.put(2,10);
pro.get(2);
pro.remove(20);
let result = pro.toString();
  ```


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

getCapacity(): number

Obtains the capacity of this buffer.

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

**Return value**

| Type  | Description                  |
| ------ | ---------------------- |
| number | Capacity of this buffer.|

**Example**

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


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

clear(): void

Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations.

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

**Example**

  ```js
let pro = new util.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

Obtains the number of removals from this buffer.

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

**Return value**

| Type  | Description                      |
| ------ | -------------------------- |
| number | Number of removals from the buffer.|

**Example**

  ```js
let pro = new util.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

Obtains the number of additions to this buffer.

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

**Return value**

| Type  | Description                        |
| ------ | ---------------------------- |
| number | Number of additions to the buffer.|

**Example**

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


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

isEmpty(): boolean

Checks whether this buffer is empty.

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

**Return value**

| Type   | Description                                    |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the buffer does not contain any value.|

**Example**

  ```js
let pro = new util.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                                                        |
| ------------------------ | ------------------------------------------------------------ |
| V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|

**Example**

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


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

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

Adds a key-value pair to this buffer.

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

**Parameters**

| Name| Type| Mandatory| Description                      |
| ------ | ---- | ---- | -------------------------- |
| key    | K    | Yes  | Key of the key-value pair to add.            |
| value  | V    | Yes  | Value of the key-value pair to add.|

**Return value**

| Type| Description                                                        |
| ---- | ------------------------------------------------------------ |
| V    | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. |

**Example**

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

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

values(): V[]

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

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

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
| V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|

**Example**

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


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

keys(): K[]

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

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

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|

**Example**

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


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

remove(key: K): V | undefined

Removes the specified key and its value from this buffer.

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

**Parameters**

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

**Return value**

| Type                    | Description                                                        |
| ------------------------ | ------------------------------------------------------------ |
| V&nbsp;\|&nbsp;undefined | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.|

**Example**

  ```js
let pro = new util.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                                                        |
| -------- | ------- | ---- | ------------------------------------------------------------ |
| isEvict  | boolean | No  | Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.   |
| key      | K       | Yes  | Key removed.                                              |
| value    | V       | Yes  | Value removed.                                              |
| newValue | V       | No  | New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|

**Example**

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

contains(key: K): boolean

Checks whether this buffer contains the specified key.

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

**Parameters**

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

**Return value**

| Type   | Description                                      |
| ------- | ------------------------------------------ |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|

**Example**

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


### 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 已提交
1544
## LruBuffer<sup>(deprecated)</sup>
G
Gloria 已提交
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [LRUCache9+](#lrucache9) instead.

### Attributes

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

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

**Example**
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(1,8);
  let result = pro.length;
  ```

G
ge-yafang 已提交
1566
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.

constructor(capacity?: number)

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

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

**Parameters**

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

**Example**
  ```js
  let lrubuffer= new util.LruBuffer();
  ```

G
ge-yafang 已提交
1589
### updateCapacity<sup>(deprecated)</sup>
G
Gloria 已提交
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [updateCapacity9+](#updatecapacity9) instead.

updateCapacity(newCapacity: number): void

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

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

**Parameters**

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

**Example**
  ```js
  let pro = new util.LruBuffer();
  let result = pro.updateCapacity(100);
  ```

G
ge-yafang 已提交
1613
### toString<sup>(deprecated)</sup>
G
Gloria 已提交
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [toString9+](#tostring9) instead.

toString(): string

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

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

**Return value**

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

**Example**
  ```js
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1634 1635 1636
  pro.put(2,10);
  pro.get(2);
  pro.remove(20);
1637
  let result = pro.toString();
W
wusongqing 已提交
1638 1639
  ```

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

G
Gloria 已提交
1642 1643 1644
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getCapacity9+](#getcapacity9) instead.
W
wusongqing 已提交
1645

X
xdmal 已提交
1646
getCapacity(): number
W
wusongqing 已提交
1647 1648 1649

Obtains the capacity of this buffer.

W
wusongqing 已提交
1650 1651 1652
**System capability**: SystemCapability.Utils.Lang

**Return value**
1653

W
wusongqing 已提交
1654 1655 1656
| Type| Description|
| -------- | -------- |
| number | Capacity of this buffer.|
W
wusongqing 已提交
1657

W
wusongqing 已提交
1658
**Example**
1659
  ```js
1660 1661
  let pro = new util.LruBuffer();
  let result = pro.getCapacity();
W
wusongqing 已提交
1662
  ```
Z
zengyawen 已提交
1663

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

G
Gloria 已提交
1666 1667 1668
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [clear9+](#clear9) instead.
Z
zengyawen 已提交
1669

X
xdmal 已提交
1670
clear(): void
Z
zengyawen 已提交
1671

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

W
wusongqing 已提交
1674 1675 1676
**System capability**: SystemCapability.Utils.Lang

**Example**
1677
  ```js
1678
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1679
  pro.put(2,10);
1680
  let result = pro.length;
W
wusongqing 已提交
1681 1682
  pro.clear();
  ```
Z
zengyawen 已提交
1683

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

G
Gloria 已提交
1686 1687 1688
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getCreateCount9+](#getcreatecount9) instead.
Z
zengyawen 已提交
1689

X
xdmal 已提交
1690
getCreateCount(): number
W
wusongqing 已提交
1691 1692 1693

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

W
wusongqing 已提交
1694 1695 1696
**System capability**: SystemCapability.Utils.Lang

**Return value**
1697

W
wusongqing 已提交
1698 1699 1700
| Type| Description|
| -------- | -------- |
| number | Number of return values for **createDefault()**.|
W
wusongqing 已提交
1701

W
wusongqing 已提交
1702
**Example**
1703
  ```js
1704
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1705
  pro.put(1,8);
1706
  let result = pro.getCreateCount();
W
wusongqing 已提交
1707 1708
  ```

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

G
Gloria 已提交
1711 1712 1713
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getMissCount9+](#getmisscount9) instead.
W
wusongqing 已提交
1714

X
xdmal 已提交
1715
getMissCount(): number
W
wusongqing 已提交
1716 1717 1718

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

W
wusongqing 已提交
1719 1720 1721
**System capability**: SystemCapability.Utils.Lang

**Return value**
1722

W
wusongqing 已提交
1723 1724 1725
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are mismatched.|
W
wusongqing 已提交
1726

W
wusongqing 已提交
1727
**Example**
1728
  ```js
1729
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1730 1731
  pro.put(2,10);
  pro.get(2);
1732
  let result = pro.getMissCount();
W
wusongqing 已提交
1733 1734
  ```

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

G
Gloria 已提交
1737 1738 1739
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getRemovalCount9+](#getremovalcount9) instead.
W
wusongqing 已提交
1740

X
xdmal 已提交
1741
getRemovalCount(): number
W
wusongqing 已提交
1742 1743 1744

Obtains the number of removals from this buffer.

W
wusongqing 已提交
1745 1746 1747
**System capability**: SystemCapability.Utils.Lang

**Return value**
1748

W
wusongqing 已提交
1749 1750 1751
| Type| Description|
| -------- | -------- |
| number | Number of removals from the buffer.|
W
wusongqing 已提交
1752

W
wusongqing 已提交
1753
**Example**
1754
  ```js
1755
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1756 1757 1758
  pro.put(2,10);
  pro.updateCapacity(2);
  pro.put(50,22);
1759
  let result = pro.getRemovalCount();
W
wusongqing 已提交
1760 1761
  ```

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

G
Gloria 已提交
1764 1765 1766
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getMatchCount9+](#getmatchcount9) instead.
W
wusongqing 已提交
1767

X
xdmal 已提交
1768
getMatchCount(): number
W
wusongqing 已提交
1769 1770 1771

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

W
wusongqing 已提交
1772 1773 1774
**System capability**: SystemCapability.Utils.Lang

**Return value**
1775

W
wusongqing 已提交
1776 1777 1778
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are matched.|
W
wusongqing 已提交
1779

W
wusongqing 已提交
1780
**Example**
1781
  ```js
1782
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1783 1784
  pro.put(2,10);
  pro.get(2);
1785
  let result = pro.getMatchCount();
W
wusongqing 已提交
1786 1787
  ```

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

G
Gloria 已提交
1790 1791 1792
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getPutCount9+](#getputcount9) instead.
W
wusongqing 已提交
1793

X
xdmal 已提交
1794
getPutCount(): number
W
wusongqing 已提交
1795 1796 1797

Obtains the number of additions to this buffer.

W
wusongqing 已提交
1798 1799 1800
**System capability**: SystemCapability.Utils.Lang

**Return value**
1801

W
wusongqing 已提交
1802 1803 1804
| Type| Description|
| -------- | -------- |
| number | Number of additions to the buffer.|
W
wusongqing 已提交
1805

W
wusongqing 已提交
1806
**Example**
1807
  ```js
1808
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1809
  pro.put(2,10);
1810
  let result = pro.getPutCount();
W
wusongqing 已提交
1811 1812
  ```

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

G
Gloria 已提交
1815 1816 1817
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [isEmpty9+](#isempty9) instead.
W
wusongqing 已提交
1818

X
xdmal 已提交
1819
isEmpty(): boolean
W
wusongqing 已提交
1820 1821 1822

Checks whether this buffer is empty.

W
wusongqing 已提交
1823 1824 1825
**System capability**: SystemCapability.Utils.Lang

**Return value**
1826

W
wusongqing 已提交
1827 1828 1829
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer does not contain any value.|
W
wusongqing 已提交
1830

W
wusongqing 已提交
1831
**Example**
1832
  ```js
1833
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1834
  pro.put(2,10);
1835
  let result = pro.isEmpty();
W
wusongqing 已提交
1836 1837
  ```

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

G
Gloria 已提交
1840 1841 1842
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [get9+](#get9) instead.
W
wusongqing 已提交
1843

W
wusongqing 已提交
1844
get(key: K): V | undefined
Z
zengyawen 已提交
1845 1846 1847

Obtains the value of the specified key.

W
wusongqing 已提交
1848 1849 1850
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1851

W
wusongqing 已提交
1852 1853 1854
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key based on which the value is queried.|
W
wusongqing 已提交
1855

W
wusongqing 已提交
1856
**Return value**
1857

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

W
wusongqing 已提交
1862
**Example**
1863
  ```js
1864
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1865
  pro.put(2,10);
1866
  let result  = pro.get(2);
W
wusongqing 已提交
1867 1868
  ```

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

G
Gloria 已提交
1871 1872 1873
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [put9+](#put9) instead.
W
wusongqing 已提交
1874

X
xdmal 已提交
1875
put(key: K,value: V): V
Z
zengyawen 已提交
1876 1877 1878

Adds a key-value pair to this buffer.

W
wusongqing 已提交
1879 1880 1881
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1882

W
wusongqing 已提交
1883 1884 1885 1886
| 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 已提交
1887

W
wusongqing 已提交
1888
**Return value**
1889

W
wusongqing 已提交
1890 1891 1892
| 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 已提交
1893

W
wusongqing 已提交
1894
**Example**
1895
  ```js
1896 1897
  let pro = new util.LruBuffer();
  let result = pro.put(2,10);
W
wusongqing 已提交
1898
  ```
Z
zengyawen 已提交
1899

G
ge-yafang 已提交
1900
### values<sup>(deprecated)</sup>
G
Gloria 已提交
1901 1902 1903 1904

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [values9+](#values9) instead.
Z
zengyawen 已提交
1905

X
xdmal 已提交
1906
values(): V[]
W
wusongqing 已提交
1907 1908

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

W
wusongqing 已提交
1910 1911 1912
**System capability**: SystemCapability.Utils.Lang

**Return value**
1913

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

W
wusongqing 已提交
1918
**Example**
1919
  ```js
1920
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1921 1922 1923
  pro.put(2,10);
  pro.put(2,"anhu");
  pro.put("afaf","grfb");
1924
  let result = pro.values();
W
wusongqing 已提交
1925
  ```
Z
zengyawen 已提交
1926

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

G
Gloria 已提交
1929 1930 1931
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [keys9+](#keys9) instead.
W
wusongqing 已提交
1932

X
xdmal 已提交
1933
keys(): K[]
Z
zengyawen 已提交
1934 1935 1936

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

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

**Return value**
1940

W
wusongqing 已提交
1941 1942
| Type| Description|
| -------- | -------- |
G
Gloria 已提交
1943
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
W
wusongqing 已提交
1944

W
wusongqing 已提交
1945
**Example**
1946
  ```js
1947
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1948
  pro.put(2,10);
1949
  let result = pro.keys();
W
wusongqing 已提交
1950 1951
  ```

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

G
Gloria 已提交
1954 1955 1956
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [remove9+](#remove9) instead.
W
wusongqing 已提交
1957

W
wusongqing 已提交
1958
remove(key: K): V | undefined
W
wusongqing 已提交
1959 1960 1961

Removes the specified key and its value from this buffer.

W
wusongqing 已提交
1962 1963 1964
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1965

W
wusongqing 已提交
1966 1967 1968
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to remove.|
W
wusongqing 已提交
1969

W
wusongqing 已提交
1970
**Return value**
1971

W
wusongqing 已提交
1972 1973
| Type| Description|
| -------- | -------- |
G
Gloria 已提交
1974
| 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 已提交
1975

W
wusongqing 已提交
1976
**Example**
1977
  ```js
1978
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1979
  pro.put(2,10);
1980
  let result = pro.remove(20);
W
wusongqing 已提交
1981 1982
  ```

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

G
Gloria 已提交
1985 1986 1987
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [afterRemoval9+](#afterremoval9) instead.
W
wusongqing 已提交
1988

X
xdmal 已提交
1989
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
W
wusongqing 已提交
1990 1991 1992

Performs subsequent operations after a value is removed.

W
wusongqing 已提交
1993 1994 1995
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1996

W
wusongqing 已提交
1997 1998 1999 2000 2001 2002
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.|
| newValue | V | No| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
W
wusongqing 已提交
2003

W
wusongqing 已提交
2004
**Example**
2005
  ```js
2006 2007
  let arr = [];
  class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
W
wusongqing 已提交
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
  {
  	constructor()
  	{
  		super();
  	}
  	afterRemoval(isEvict, key, value, newValue)
  	{
  		if (isEvict === false)
  		{
  			arr = [key, value, newValue];
  		}
  	}
  }
2021
  let lru = new ChildLruBuffer();
S
shikai-123 已提交
2022
  lru.afterRemoval(false,10,30,null);
W
wusongqing 已提交
2023 2024
  ```

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

G
Gloria 已提交
2027 2028 2029
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead.
W
wusongqing 已提交
2030

X
xdmal 已提交
2031
contains(key: K): boolean
W
wusongqing 已提交
2032 2033

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

W
wusongqing 已提交
2035 2036 2037
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2038

W
wusongqing 已提交
2039 2040 2041
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to check.|
Z
zengyawen 已提交
2042

W
wusongqing 已提交
2043
**Return value**
2044

W
wusongqing 已提交
2045 2046 2047
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
Z
zengyawen 已提交
2048

W
wusongqing 已提交
2049
**Example**
2050
  ```js
2051
  let pro = new util.LruBuffer();
W
wusongqing 已提交
2052
  pro.put(2,10);
2053
  let result = pro.contains(20);
W
wusongqing 已提交
2054
  ```
Z
zengyawen 已提交
2055

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

G
Gloria 已提交
2058 2059 2060
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [createDefault9+](#createdefault9) instead.
W
wusongqing 已提交
2061

X
xdmal 已提交
2062
createDefault(key: K): V
Z
zengyawen 已提交
2063 2064 2065

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

W
wusongqing 已提交
2066 2067 2068
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2069

W
wusongqing 已提交
2070 2071 2072
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key of which the value is missing.|
Z
zengyawen 已提交
2073

W
wusongqing 已提交
2074
**Return value**
2075

W
wusongqing 已提交
2076 2077 2078
| Type| Description|
| -------- | -------- |
| V | Value of the key.|
Z
zengyawen 已提交
2079

W
wusongqing 已提交
2080
**Example**
2081
  ```js
G
Gloria 已提交
2082 2083 2084 2085
  let pro = new util.LruBuffer();
  let result = pro.createDefault(50);
  ```

G
ge-yafang 已提交
2086
### entries<sup>(deprecated)</sup>
G
Gloria 已提交
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [entries9+](#entries9) instead.

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

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

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

**Return value**

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

**Example**
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.entries();
  ```

G
ge-yafang 已提交
2111
### [Symbol.iterator]<sup>(deprecated)</sup>
G
Gloria 已提交
2112 2113 2114

> **NOTE**
>
G
ge-yafang 已提交
2115
> This API is deprecated since API version 9. You are advised to use [Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
G
Gloria 已提交
2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 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 2276 2277 2278 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 2316 2317 2318 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 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429

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

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

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

**Return value**

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

**Example**
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro[Symbol.iterator]();
  ```

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

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

The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
```js
interface ScopeComparable{
    compareTo(other: ScopeComparable): boolean;
}
type ScopeType = ScopeComparable | number;
```


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


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

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

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

constructor(lowerObj: ScopeType, upperObj: ScopeType)

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

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

**Parameters**

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

**Example**

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


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

toString(): string

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

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

**Return value**

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

**Example**

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


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

intersect(range: ScopeHelper): ScopeHelper

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

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

**Parameters**

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

**Return value**

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

**Example**

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


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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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


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

getUpper(): ScopeType

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

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

**Return value**

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

**Example**

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


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

getLower(): ScopeType

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

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

**Return value**

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

**Example**

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


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

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

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

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

**Parameters**

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

**Return value**

| Type                          | Description                                |
| ------------------------------ | ------------------------------------ |
| [ScopeHelper9+](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.|

**Example**

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


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

expand(range: ScopeHelper): ScopeHelper

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

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

**Parameters**

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

**Return value**

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

**Example**

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


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

expand(value: ScopeType): ScopeHelper

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

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

**Parameters**

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

**Return value**

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

**Example**

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


G
Gloria 已提交
2433
### contains<sup>9+</sup>
Z
zengyawen 已提交
2434

G
Gloria 已提交
2435
contains(value: ScopeType): boolean
Z
zengyawen 已提交
2436

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

W
wusongqing 已提交
2439 2440
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
2441 2442 2443 2444 2445 2446
**Parameters**

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

W
wusongqing 已提交
2447
**Return value**
2448

G
Gloria 已提交
2449 2450 2451
| Type   | Description                                               |
| ------- | --------------------------------------------------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
Z
zengyawen 已提交
2452

W
wusongqing 已提交
2453
**Example**
G
Gloria 已提交
2454

2455
  ```js
G
Gloria 已提交
2456 2457 2458 2459 2460
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 已提交
2461
  ```
Z
zengyawen 已提交
2462 2463


G
Gloria 已提交
2464
### contains<sup>9+</sup>
Z
zengyawen 已提交
2465

G
Gloria 已提交
2466
contains(range: ScopeHelper): boolean
Z
zengyawen 已提交
2467

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

W
wusongqing 已提交
2470 2471
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
2472 2473 2474 2475 2476 2477
**Parameters**

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

W
wusongqing 已提交
2478
**Return value**
2479

G
Gloria 已提交
2480 2481 2482
| Type   | Description                                                 |
| ------- | ----------------------------------------------------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
Z
zengyawen 已提交
2483

W
wusongqing 已提交
2484
**Example**
G
Gloria 已提交
2485

2486
  ```js
G
Gloria 已提交
2487 2488 2489 2490 2491 2492 2493
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 已提交
2494
  ```
Z
zengyawen 已提交
2495 2496


G
Gloria 已提交
2497
### clamp<sup>9+</sup>
Z
zengyawen 已提交
2498

G
Gloria 已提交
2499
clamp(value: ScopeType): ScopeType
Z
zengyawen 已提交
2500

G
Gloria 已提交
2501
Limits a value to this **Scope**.
Z
zengyawen 已提交
2502

G
Gloria 已提交
2503
**System capability**: SystemCapability.Utils.Lang
Z
zengyawen 已提交
2504

G
Gloria 已提交
2505
**Parameters**
Z
zengyawen 已提交
2506

G
Gloria 已提交
2507 2508 2509
| Name| Type                    | Mandatory| Description          |
| ------ | ------------------------ | ---- | -------------- |
| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|
Z
zengyawen 已提交
2510

G
Gloria 已提交
2511
**Return value**
Z
zengyawen 已提交
2512

G
Gloria 已提交
2513 2514 2515
| 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 已提交
2516

G
Gloria 已提交
2517
**Example**
Z
zengyawen 已提交
2518

G
Gloria 已提交
2519 2520 2521 2522 2523 2524 2525
  ```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 已提交
2526

G
ge-yafang 已提交
2527
## Scope<sup>(deprecated)</sup>
G
Gloria 已提交
2528 2529 2530 2531 2532

> **NOTE**
>
> This class is deprecated since API version 9. You are advised to use [ScopeHelper9+](#scopehelper9) instead.

G
ge-yafang 已提交
2533
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
2534 2535 2536 2537

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
W
wusongqing 已提交
2538

X
xdmal 已提交
2539
constructor(lowerObj: ScopeType, upperObj: ScopeType)
W
wusongqing 已提交
2540 2541 2542

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

W
wusongqing 已提交
2543 2544 2545
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2546

W
wusongqing 已提交
2547 2548 2549 2550
| 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 已提交
2551

W
wusongqing 已提交
2552
**Example**
2553
  ```js
2554 2555 2556
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
2557 2558
  ```

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

G
Gloria 已提交
2561 2562 2563
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [toString9+](#tostring9) instead.
W
wusongqing 已提交
2564

X
xdmal 已提交
2565
toString(): string
W
wusongqing 已提交
2566 2567 2568

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

W
wusongqing 已提交
2569 2570 2571
**System capability**: SystemCapability.Utils.Lang

**Return value**
2572

W
wusongqing 已提交
2573 2574 2575
| Type| Description|
| -------- | -------- |
| string | String representation containing the **Scope**.|
W
wusongqing 已提交
2576

W
wusongqing 已提交
2577
**Example**
2578
  ```js
2579 2580 2581 2582
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.toString();
W
wusongqing 已提交
2583 2584
  ```

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

G
Gloria 已提交
2587 2588 2589
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead.
W
wusongqing 已提交
2590

X
xdmal 已提交
2591
intersect(range: Scope): Scope
W
wusongqing 已提交
2592 2593 2594

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

W
wusongqing 已提交
2595 2596 2597
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2598

W
wusongqing 已提交
2599 2600
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
ge-yafang 已提交
2601
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
2602

W
wusongqing 已提交
2603
**Return value**
2604

W
wusongqing 已提交
2605 2606
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2607
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
2608

W
wusongqing 已提交
2609
**Example**
G
Gloria 已提交
2610

2611
  ```js
2612 2613 2614 2615 2616 2617
  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 已提交
2618 2619 2620
  range.intersect(rangeFir );
  ```

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

G
Gloria 已提交
2623 2624 2625
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [intersect9+](#intersect9) instead.
W
wusongqing 已提交
2626

W
wusongqing 已提交
2627
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
W
wusongqing 已提交
2628 2629 2630

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

W
wusongqing 已提交
2631 2632 2633
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2634

W
wusongqing 已提交
2635 2636 2637 2638
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
2639

W
wusongqing 已提交
2640
**Return value**
2641

W
wusongqing 已提交
2642 2643
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2644
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
2645

W
wusongqing 已提交
2646
**Example**
2647
  ```js
2648 2649 2650 2651 2652 2653
  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 已提交
2654 2655
  ```

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

G
Gloria 已提交
2658 2659 2660
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getUpper9+](#getupper9) instead.
W
wusongqing 已提交
2661

X
xdmal 已提交
2662
getUpper(): ScopeType
W
wusongqing 已提交
2663 2664 2665

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

W
wusongqing 已提交
2666 2667 2668 2669
**System capability**: SystemCapability.Utils.Lang

**Return value**

W
wusongqing 已提交
2670 2671 2672
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
W
wusongqing 已提交
2673

W
wusongqing 已提交
2674
**Example**
2675
  ```js
2676 2677 2678 2679
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getUpper();
W
wusongqing 已提交
2680 2681
  ```

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

G
Gloria 已提交
2684 2685 2686
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [getLower9+](#getlower9) instead.
W
wusongqing 已提交
2687

X
xdmal 已提交
2688
getLower(): ScopeType
W
wusongqing 已提交
2689 2690 2691

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

W
wusongqing 已提交
2692 2693 2694
**System capability**: SystemCapability.Utils.Lang

**Return value**
2695

W
wusongqing 已提交
2696 2697 2698
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
W
wusongqing 已提交
2699

W
wusongqing 已提交
2700
**Example**
2701
  ```js
2702 2703 2704 2705
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getLower();
W
wusongqing 已提交
2706 2707
  ```

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

G
Gloria 已提交
2710 2711 2712
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead.
W
wusongqing 已提交
2713

X
xdmal 已提交
2714
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
W
wusongqing 已提交
2715 2716 2717

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

W
wusongqing 已提交
2718 2719 2720
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2721

W
wusongqing 已提交
2722 2723 2724 2725
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
2726

W
wusongqing 已提交
2727
**Return value**
2728

W
wusongqing 已提交
2729 2730
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2731
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
2732

W
wusongqing 已提交
2733
**Example**
W
wusongqing 已提交
2734

2735
  ```js
2736 2737 2738 2739 2740 2741
  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 已提交
2742 2743
  ```

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

G
Gloria 已提交
2746 2747 2748
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead.
W
wusongqing 已提交
2749

W
wusongqing 已提交
2750
expand(range: Scope): Scope
W
wusongqing 已提交
2751 2752 2753

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

W
wusongqing 已提交
2754 2755 2756
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2757

W
wusongqing 已提交
2758 2759
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
ge-yafang 已提交
2760
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
2761

W
wusongqing 已提交
2762
**Return value**
2763

W
wusongqing 已提交
2764 2765
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2766
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
2767

W
wusongqing 已提交
2768
**Example**
2769
  ```js
2770 2771 2772 2773 2774 2775 2776
  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 已提交
2777 2778
  ```

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

G
Gloria 已提交
2781 2782 2783
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [expand9+](#expand9) instead.
W
wusongqing 已提交
2784

X
xdmal 已提交
2785
expand(value: ScopeType): Scope
W
wusongqing 已提交
2786 2787 2788

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

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

**Parameters**
2792

W
wusongqing 已提交
2793 2794 2795
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
2796

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

W
wusongqing 已提交
2799 2800
| Type| Description|
| -------- | -------- |
G
ge-yafang 已提交
2801
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.|
Z
zengyawen 已提交
2802

W
wusongqing 已提交
2803
**Example**
2804
  ```js
2805 2806 2807 2808 2809
  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 已提交
2810
  ```
Z
zengyawen 已提交
2811

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

G
Gloria 已提交
2814 2815 2816
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead.
Z
zengyawen 已提交
2817

X
xdmal 已提交
2818
contains(value: ScopeType): boolean
Z
zengyawen 已提交
2819

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

W
wusongqing 已提交
2822 2823 2824
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2825

W
wusongqing 已提交
2826 2827 2828
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
Z
zengyawen 已提交
2829

W
wusongqing 已提交
2830
**Return value**
2831

W
wusongqing 已提交
2832 2833 2834
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
2835

W
wusongqing 已提交
2836
**Example**
2837
  ```js
2838 2839 2840 2841
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
2842 2843 2844
  range.contains(tempMiDF);
  ```

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

G
Gloria 已提交
2847 2848 2849
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [contains9+](#contains9) instead.
W
wusongqing 已提交
2850

X
xdmal 已提交
2851
contains(range: Scope): boolean
W
wusongqing 已提交
2852 2853 2854

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

W
wusongqing 已提交
2855 2856 2857
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2858

W
wusongqing 已提交
2859 2860
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
ge-yafang 已提交
2861
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
2862

W
wusongqing 已提交
2863
**Return value**
2864

W
wusongqing 已提交
2865 2866 2867
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
2868

W
wusongqing 已提交
2869
**Example**
G
Gloria 已提交
2870

2871
  ```js
2872 2873 2874 2875 2876 2877 2878
  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 已提交
2879 2880
  ```

G
ge-yafang 已提交
2881
### clamp<sup>(deprecated)</sup>
W
wusongqing 已提交
2882

G
Gloria 已提交
2883 2884 2885
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [clamp9+](#clamp9) instead.
W
wusongqing 已提交
2886

X
xdmal 已提交
2887
clamp(value: ScopeType): ScopeType
W
wusongqing 已提交
2888 2889 2890

Limits a value to this **Scope**.

W
wusongqing 已提交
2891 2892 2893
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2894

W
wusongqing 已提交
2895 2896 2897
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
2898

W
wusongqing 已提交
2899
**Return value**
2900

W
wusongqing 已提交
2901 2902 2903
| 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 已提交
2904

W
wusongqing 已提交
2905
**Example**
2906
  ```js
2907 2908 2909 2910 2911
  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 已提交
2912 2913
  ```

G
Gloria 已提交
2914 2915 2916
## Base64Helper<sup>9+</sup>

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

G
Gloria 已提交
2918
constructor()
W
wusongqing 已提交
2919

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

G
Gloria 已提交
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 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
**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 已提交
3116
## Base64<sup>(deprecated)</sup>
G
Gloria 已提交
3117 3118 3119 3120 3121

> **NOTE**
>
> This class is deprecated since API version 9. You are advised to use [Base64Helper9+](#base64helper9) instead.

G
ge-yafang 已提交
3122
### constructor<sup>(deprecated)</sup>
G
Gloria 已提交
3123 3124 3125 3126

> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [constructor9+](#constructor9) instead.
W
wusongqing 已提交
3127 3128 3129 3130 3131

constructor()

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

W
wusongqing 已提交
3132 3133 3134
**System capability**: SystemCapability.Utils.Lang

**Example**
3135
  ```js
3136
  let base64 = new  util.Base64();
W
wusongqing 已提交
3137 3138
  ```

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

G
Gloria 已提交
3141 3142 3143
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeSync9+](#encodesync9) instead.
W
wusongqing 已提交
3144

X
xdmal 已提交
3145
encodeSync(src: Uint8Array): Uint8Array
Z
zengyawen 已提交
3146 3147 3148

Encodes the input content.

W
wusongqing 已提交
3149 3150 3151
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3152

W
wusongqing 已提交
3153 3154 3155
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
3156

W
wusongqing 已提交
3157
**Return value**
3158

W
wusongqing 已提交
3159 3160 3161
| Type| Description|
| -------- | -------- |
| Uint8Array | Uint8Array encoded.|
W
wusongqing 已提交
3162

W
wusongqing 已提交
3163
**Example**
G
Gloria 已提交
3164

3165
  ```js
3166 3167 3168
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeSync(array);
W
wusongqing 已提交
3169 3170
  ```

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

G
Gloria 已提交
3173 3174 3175
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeToStringSync9+](#encodetostringsync9) instead.
W
wusongqing 已提交
3176

X
xdmal 已提交
3177
encodeToStringSync(src: Uint8Array): string
W
wusongqing 已提交
3178 3179 3180

Encodes the input content.

W
wusongqing 已提交
3181 3182 3183
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3184

W
wusongqing 已提交
3185 3186 3187
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
3188

W
wusongqing 已提交
3189
**Return value**
3190

W
wusongqing 已提交
3191 3192 3193
| Type| Description|
| -------- | -------- |
| string | String encoded from the Uint8Array.|
W
wusongqing 已提交
3194

W
wusongqing 已提交
3195
**Example**
3196
  ```js
3197 3198 3199
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeToStringSync(array);
W
wusongqing 已提交
3200 3201
  ```

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

G
Gloria 已提交
3204 3205 3206
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [decodeSync9+](#decodesync9) instead.
W
wusongqing 已提交
3207

W
wusongqing 已提交
3208
decodeSync(src: Uint8Array | string): Uint8Array
Z
zengyawen 已提交
3209 3210 3211

Decodes the input content.

W
wusongqing 已提交
3212 3213 3214
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3215

W
wusongqing 已提交
3216 3217
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
3218
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.|
W
wusongqing 已提交
3219

W
wusongqing 已提交
3220
**Return value**
3221

W
wusongqing 已提交
3222 3223 3224
| Type| Description|
| -------- | -------- |
| Uint8Array | Uint8Array decoded.|
W
wusongqing 已提交
3225

W
wusongqing 已提交
3226
**Example**
3227
  ```js
3228 3229 3230
  let that = new util.Base64();
  let buff = 'czEz';
  let result = that.decodeSync(buff);
W
wusongqing 已提交
3231 3232
  ```

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

G
Gloria 已提交
3235 3236 3237
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encode9+](#encode9) instead.
W
wusongqing 已提交
3238

X
xdmal 已提交
3239
encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
3240 3241 3242

Encodes the input content asynchronously.

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

**Parameters**
3246

W
wusongqing 已提交
3247 3248 3249
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
W
wusongqing 已提交
3250

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

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

W
wusongqing 已提交
3257
**Example**
3258
  ```js
3259 3260 3261
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let rarray = new Uint8Array([99,122,69,122]);
W
wusongqing 已提交
3262 3263
  that.encode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
S
shikai-123 已提交
3264
          console.log(val[i].toString())
W
wusongqing 已提交
3265 3266 3267 3268
      }
  })
  ```

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

G
Gloria 已提交
3271 3272 3273
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [encodeToString9+](#encodetostring9) instead.
W
wusongqing 已提交
3274

X
xdmal 已提交
3275
encodeToString(src: Uint8Array): Promise&lt;string&gt;
W
wusongqing 已提交
3276 3277 3278

Encodes the input content asynchronously.

W
wusongqing 已提交
3279 3280 3281
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3282

W
wusongqing 已提交
3283 3284 3285
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
W
wusongqing 已提交
3286

W
wusongqing 已提交
3287
**Return value**
3288

W
wusongqing 已提交
3289 3290 3291
| Type| Description|
| -------- | -------- |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
W
wusongqing 已提交
3292

W
wusongqing 已提交
3293
**Example**
3294
  ```js
3295 3296
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
W
wusongqing 已提交
3297 3298 3299 3300 3301
  that.encodeToString(array).then(val=>{    
      console.log(val)
  })
  ```

G
ge-yafang 已提交
3302
### decode<sup>(deprecated)</sup>
W
wusongqing 已提交
3303

G
Gloria 已提交
3304 3305 3306
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [decode9+](#decode9) instead.
W
wusongqing 已提交
3307

W
wusongqing 已提交
3308
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
3309 3310 3311

Decodes the input content asynchronously.

W
wusongqing 已提交
3312 3313 3314
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3315

W
wusongqing 已提交
3316 3317
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
3318
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.|
W
wusongqing 已提交
3319

W
wusongqing 已提交
3320
**Return value**
3321

W
wusongqing 已提交
3322 3323 3324
| Type| Description|
| -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
W
wusongqing 已提交
3325

W
wusongqing 已提交
3326
**Example**
3327
  ```js
3328 3329 3330
  let that = new util.Base64();
  let array = new Uint8Array([99,122,69,122]);
  let rarray = new Uint8Array([115,49,51]);
W
wusongqing 已提交
3331 3332
  that.decode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
S
shikai-123 已提交
3333
          console.log(val[i].toString())
W
wusongqing 已提交
3334 3335 3336 3337
      }
  })
  ```

3338
## types<sup>8+</sup>
W
wusongqing 已提交
3339 3340 3341 3342 3343 3344


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

constructor()

W
wusongqing 已提交
3345
A constructor used to create a **Types** object.
W
wusongqing 已提交
3346

W
wusongqing 已提交
3347 3348 3349
**System capability**: SystemCapability.Utils.Lang

**Example**
3350
  ```js
3351
  let type = new util.types();
W
wusongqing 已提交
3352 3353 3354 3355 3356
  ```


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

X
xdmal 已提交
3357
isAnyArrayBuffer(value: Object): boolean
W
wusongqing 已提交
3358 3359 3360

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

W
wusongqing 已提交
3361 3362 3363
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3364

W
wusongqing 已提交
3365 3366 3367
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3368

W
wusongqing 已提交
3369
**Return value**
3370

W
wusongqing 已提交
3371 3372 3373
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
3374

W
wusongqing 已提交
3375
**Example**
3376
  ```js
3377 3378
  let that = new util.types();
  let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
W
wusongqing 已提交
3379 3380 3381 3382 3383
  ```


### isArrayBufferView<sup>8+</sup>

X
xdmal 已提交
3384
isArrayBufferView(value: Object): boolean
W
wusongqing 已提交
3385 3386 3387 3388 3389

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 已提交
3390 3391 3392
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3393

W
wusongqing 已提交
3394 3395 3396
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3397

W
wusongqing 已提交
3398
**Return value**
3399

W
wusongqing 已提交
3400 3401 3402
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
W
wusongqing 已提交
3403

W
wusongqing 已提交
3404
**Example**
3405
  ```js
3406 3407
  let that = new util.types();
  let result = that.isArrayBufferView(new Int8Array([]));
W
wusongqing 已提交
3408 3409 3410 3411 3412
  ```


### isArgumentsObject<sup>8+</sup>

X
xdmal 已提交
3413
isArgumentsObject(value: Object): boolean
W
wusongqing 已提交
3414 3415 3416

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

W
wusongqing 已提交
3417 3418 3419
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3420

W
wusongqing 已提交
3421 3422 3423
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3424

W
wusongqing 已提交
3425
**Return value**
3426

W
wusongqing 已提交
3427 3428 3429
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
W
wusongqing 已提交
3430

W
wusongqing 已提交
3431
**Example**
3432
  ```js
3433
  let that = new util.types();
W
wusongqing 已提交
3434 3435 3436
  function foo() {
      var result = that.isArgumentsObject(arguments);
  }
3437
  let f = foo();
W
wusongqing 已提交
3438 3439 3440 3441 3442
  ```


### isArrayBuffer<sup>8+</sup>

X
xdmal 已提交
3443
isArrayBuffer(value: Object): boolean
W
wusongqing 已提交
3444 3445 3446

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

W
wusongqing 已提交
3447 3448 3449
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3450

W
wusongqing 已提交
3451 3452 3453
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3454

W
wusongqing 已提交
3455
**Return value**
3456

W
wusongqing 已提交
3457 3458 3459
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
3460

W
wusongqing 已提交
3461
**Example**
3462
  ```js
3463 3464
  let that = new util.types();
  let result = that.isArrayBuffer(new ArrayBuffer(0));
W
wusongqing 已提交
3465 3466 3467 3468 3469
  ```


### isAsyncFunction<sup>8+</sup>

X
xdmal 已提交
3470
isAsyncFunction(value: Object): boolean
Z
zengyawen 已提交
3471 3472 3473

Checks whether the input value is an asynchronous function.

W
wusongqing 已提交
3474 3475 3476
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3477

W
wusongqing 已提交
3478 3479 3480
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3481

W
wusongqing 已提交
3482
**Return value**
3483

W
wusongqing 已提交
3484 3485 3486
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
W
wusongqing 已提交
3487

W
wusongqing 已提交
3488
**Example**
3489
  ```js
3490 3491
  let that = new util.types();
  let result = that.isAsyncFunction(async function foo() {});
W
wusongqing 已提交
3492 3493 3494 3495 3496
  ```


### isBooleanObject<sup>8+</sup>

X
xdmal 已提交
3497
isBooleanObject(value: Object): boolean
W
wusongqing 已提交
3498 3499 3500

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

W
wusongqing 已提交
3501 3502 3503
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3504

W
wusongqing 已提交
3505 3506 3507
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3508

W
wusongqing 已提交
3509
**Return value**
3510

W
wusongqing 已提交
3511 3512 3513
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
W
wusongqing 已提交
3514

W
wusongqing 已提交
3515
**Example**
3516
  ```js
3517 3518
  let that = new util.types();
  let result = that.isBooleanObject(new Boolean(true));
W
wusongqing 已提交
3519 3520 3521 3522 3523
  ```


### isBoxedPrimitive<sup>8+</sup>

X
xdmal 已提交
3524
isBoxedPrimitive(value: Object): boolean
W
wusongqing 已提交
3525 3526 3527

Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.

W
wusongqing 已提交
3528 3529 3530
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3531

W
wusongqing 已提交
3532 3533 3534
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3535

W
wusongqing 已提交
3536
**Return value**
3537

W
wusongqing 已提交
3538 3539 3540
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
W
wusongqing 已提交
3541

W
wusongqing 已提交
3542
**Example**
3543
  ```js
3544 3545
  let that = new util.types();
  let result = that.isBoxedPrimitive(new Boolean(false));
W
wusongqing 已提交
3546 3547 3548 3549 3550
  ```


### isDataView<sup>8+</sup>

X
xdmal 已提交
3551
isDataView(value: Object): boolean
W
wusongqing 已提交
3552 3553 3554

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

W
wusongqing 已提交
3555 3556 3557
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3558

W
wusongqing 已提交
3559 3560 3561
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3562

W
wusongqing 已提交
3563
**Return value**
3564

W
wusongqing 已提交
3565 3566 3567
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
W
wusongqing 已提交
3568

W
wusongqing 已提交
3569
**Example**
3570
  ```js
3571
  let that = new util.types();
W
wusongqing 已提交
3572
  const ab = new ArrayBuffer(20);
3573
  let result = that.isDataView(new DataView(ab));
W
wusongqing 已提交
3574 3575 3576 3577 3578
  ```


### isDate<sup>8+</sup>

X
xdmal 已提交
3579
isDate(value: Object): boolean
W
wusongqing 已提交
3580 3581 3582

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

W
wusongqing 已提交
3583 3584 3585
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3586

W
wusongqing 已提交
3587 3588 3589
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3590

W
wusongqing 已提交
3591
**Return value**
3592

W
wusongqing 已提交
3593 3594 3595
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
W
wusongqing 已提交
3596

W
wusongqing 已提交
3597
**Example**
3598
  ```js
3599 3600
  let that = new util.types();
  let result = that.isDate(new Date());
W
wusongqing 已提交
3601 3602 3603 3604 3605
  ```


### isExternal<sup>8+</sup>

X
xdmal 已提交
3606
isExternal(value: Object): boolean
W
wusongqing 已提交
3607 3608 3609

Checks whether the input value is of the **native external** type.

W
wusongqing 已提交
3610 3611 3612
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3613

W
wusongqing 已提交
3614 3615 3616
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3617

W
wusongqing 已提交
3618
**Return value**
3619

W
wusongqing 已提交
3620 3621 3622
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
W
wusongqing 已提交
3623

W
wusongqing 已提交
3624
**Example**
3625
  ```js
3626 3627
  let that = new util.types();
  let result = that.isExternal(true);
W
wusongqing 已提交
3628 3629 3630 3631 3632
  ```


### isFloat32Array<sup>8+</sup>

X
xdmal 已提交
3633
isFloat32Array(value: Object): boolean
W
wusongqing 已提交
3634 3635 3636

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

W
wusongqing 已提交
3637 3638 3639
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3640

W
wusongqing 已提交
3641 3642 3643
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3644

W
wusongqing 已提交
3645
**Return value**
3646

W
wusongqing 已提交
3647 3648 3649
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3650

W
wusongqing 已提交
3651
**Example**
3652
  ```js
3653 3654
  let that = new util.types();
  let result = that.isFloat32Array(new Float32Array());
W
wusongqing 已提交
3655 3656 3657 3658 3659
  ```


### isFloat64Array<sup>8+</sup>

X
xdmal 已提交
3660
isFloat64Array(value: Object): boolean
W
wusongqing 已提交
3661 3662 3663

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

W
wusongqing 已提交
3664 3665 3666
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3667

W
wusongqing 已提交
3668 3669 3670
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3671

W
wusongqing 已提交
3672
**Return value**
3673

W
wusongqing 已提交
3674 3675 3676
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3677

W
wusongqing 已提交
3678
**Example**
3679
  ```js
3680 3681
  let that = new util.types();
  let result = that.isFloat64Array(new Float64Array());
W
wusongqing 已提交
3682 3683 3684 3685 3686
  ```


### isGeneratorFunction<sup>8+</sup>

X
xdmal 已提交
3687
isGeneratorFunction(value: Object): boolean
Z
zengyawen 已提交
3688 3689 3690

Checks whether the input value is a generator function.

W
wusongqing 已提交
3691 3692 3693
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3694

W
wusongqing 已提交
3695 3696 3697
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3698

W
wusongqing 已提交
3699
**Return value**
3700

W
wusongqing 已提交
3701 3702 3703
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
W
wusongqing 已提交
3704

W
wusongqing 已提交
3705
**Example**
3706
  ```js
3707 3708
  let that = new util.types();
  let result = that.isGeneratorFunction(function* foo() {});
W
wusongqing 已提交
3709 3710 3711 3712 3713
  ```


### isGeneratorObject<sup>8+</sup>

X
xdmal 已提交
3714
isGeneratorObject(value: Object): boolean
Z
zengyawen 已提交
3715 3716 3717

Checks whether the input value is a generator object.

W
wusongqing 已提交
3718 3719 3720
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3721

W
wusongqing 已提交
3722 3723 3724
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3725

W
wusongqing 已提交
3726
**Return value**
3727

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

W
wusongqing 已提交
3732
**Example**
3733
  ```js
3734
  let that = new util.types();
W
wusongqing 已提交
3735 3736
  function* foo() {}
  const generator = foo();
3737
  let result = that.isGeneratorObject(generator);
W
wusongqing 已提交
3738 3739 3740 3741 3742
  ```


### isInt8Array<sup>8+</sup>

X
xdmal 已提交
3743
isInt8Array(value: Object): boolean
W
wusongqing 已提交
3744 3745 3746

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

W
wusongqing 已提交
3747 3748 3749
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3750

W
wusongqing 已提交
3751 3752 3753
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3754

W
wusongqing 已提交
3755
**Return value**
3756

W
wusongqing 已提交
3757 3758 3759
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3760

W
wusongqing 已提交
3761
**Example**
3762
  ```js
3763 3764
  let that = new util.types();
  let result = that.isInt8Array(new Int8Array([]));
W
wusongqing 已提交
3765 3766 3767 3768 3769
  ```


### isInt16Array<sup>8+</sup>

X
xdmal 已提交
3770
isInt16Array(value: Object): boolean
W
wusongqing 已提交
3771 3772 3773

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

W
wusongqing 已提交
3774 3775 3776
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3777

W
wusongqing 已提交
3778 3779 3780
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3781

W
wusongqing 已提交
3782
**Return value**
3783

W
wusongqing 已提交
3784 3785 3786
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3787

W
wusongqing 已提交
3788
**Example**
3789
  ```js
3790 3791
  let that = new util.types();
  let result = that.isInt16Array(new Int16Array([]));
W
wusongqing 已提交
3792 3793 3794 3795 3796
  ```


### isInt32Array<sup>8+</sup>

X
xdmal 已提交
3797
isInt32Array(value: Object): boolean
W
wusongqing 已提交
3798 3799 3800

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

W
wusongqing 已提交
3801 3802 3803
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3804

W
wusongqing 已提交
3805 3806 3807
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3808

W
wusongqing 已提交
3809
**Return value**
3810

W
wusongqing 已提交
3811 3812 3813
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3814

W
wusongqing 已提交
3815
**Example**
3816
  ```js
3817 3818
  let that = new util.types();
  let result = that.isInt32Array(new Int32Array([]));
W
wusongqing 已提交
3819 3820 3821 3822 3823
  ```


### isMap<sup>8+</sup>

X
xdmal 已提交
3824
isMap(value: Object): boolean
W
wusongqing 已提交
3825 3826 3827

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

W
wusongqing 已提交
3828 3829 3830
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3831

W
wusongqing 已提交
3832 3833 3834
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3835

W
wusongqing 已提交
3836
**Return value**
3837

W
wusongqing 已提交
3838 3839 3840
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
W
wusongqing 已提交
3841

W
wusongqing 已提交
3842
**Example**
3843
  ```js
3844 3845
  let that = new util.types();
  let result = that.isMap(new Map());
W
wusongqing 已提交
3846 3847 3848 3849 3850
  ```


### isMapIterator<sup>8+</sup>

X
xdmal 已提交
3851
isMapIterator(value: Object): boolean
W
wusongqing 已提交
3852 3853 3854

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

W
wusongqing 已提交
3855 3856 3857
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3858

W
wusongqing 已提交
3859 3860 3861
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3862

W
wusongqing 已提交
3863
**Return value**
3864

W
wusongqing 已提交
3865 3866 3867
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
W
wusongqing 已提交
3868

W
wusongqing 已提交
3869
**Example**
3870
  ```js
3871
  let that = new util.types();
W
wusongqing 已提交
3872
  const map = new Map();
3873
  let result = that.isMapIterator(map.keys());
W
wusongqing 已提交
3874 3875 3876 3877 3878
  ```


### isNativeError<sup>8+</sup>

X
xdmal 已提交
3879
isNativeError(value: Object): boolean
W
wusongqing 已提交
3880 3881 3882

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

W
wusongqing 已提交
3883 3884 3885
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3886

W
wusongqing 已提交
3887 3888 3889
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3890

W
wusongqing 已提交
3891
**Return value**
3892

W
wusongqing 已提交
3893 3894 3895
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
W
wusongqing 已提交
3896

W
wusongqing 已提交
3897
**Example**
3898
  ```js
3899 3900
  let that = new util.types();
  let result = that.isNativeError(new TypeError());
W
wusongqing 已提交
3901 3902 3903 3904 3905
  ```


### isNumberObject<sup>8+</sup>

X
xdmal 已提交
3906
isNumberObject(value: Object): boolean
Z
zengyawen 已提交
3907 3908 3909

Checks whether the input value is a number object.

W
wusongqing 已提交
3910 3911 3912
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3913

W
wusongqing 已提交
3914 3915 3916
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3917

W
wusongqing 已提交
3918
**Return value**
3919

W
wusongqing 已提交
3920 3921 3922
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
W
wusongqing 已提交
3923

W
wusongqing 已提交
3924
**Example**
3925
  ```js
3926 3927
  let that = new util.types();
  let result = that.isNumberObject(new Number(0));
W
wusongqing 已提交
3928 3929 3930 3931 3932
  ```


### isPromise<sup>8+</sup>

X
xdmal 已提交
3933
isPromise(value: Object): boolean
Z
zengyawen 已提交
3934 3935 3936

Checks whether the input value is a promise.

W
wusongqing 已提交
3937 3938 3939
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3940

W
wusongqing 已提交
3941 3942 3943
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3944

W
wusongqing 已提交
3945
**Return value**
3946

W
wusongqing 已提交
3947 3948 3949
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
W
wusongqing 已提交
3950

W
wusongqing 已提交
3951
**Example**
3952
  ```js
3953 3954
  let that = new util.types();
  let result = that.isPromise(Promise.resolve(1));
W
wusongqing 已提交
3955 3956 3957 3958 3959
  ```


### isProxy<sup>8+</sup>

X
xdmal 已提交
3960
isProxy(value: Object): boolean
Z
zengyawen 已提交
3961 3962 3963

Checks whether the input value is a proxy.

W
wusongqing 已提交
3964 3965 3966
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3967

W
wusongqing 已提交
3968 3969 3970
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3971

W
wusongqing 已提交
3972
**Return value**
3973

W
wusongqing 已提交
3974 3975 3976
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
W
wusongqing 已提交
3977

W
wusongqing 已提交
3978
**Example**
3979
  ```js
3980
  let that = new util.types();
W
wusongqing 已提交
3981 3982
  const target = {};
  const proxy = new Proxy(target, {});
3983
  let result = that.isProxy(proxy);
W
wusongqing 已提交
3984 3985 3986 3987 3988
  ```


### isRegExp<sup>8+</sup>

X
xdmal 已提交
3989
isRegExp(value: Object): boolean
W
wusongqing 已提交
3990 3991 3992

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

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 of the **RegExp** type; returns **false** otherwise.|
W
wusongqing 已提交
4006

W
wusongqing 已提交
4007
**Example**
4008
  ```js
4009 4010
  let that = new util.types();
  let result = that.isRegExp(new RegExp('abc'));
W
wusongqing 已提交
4011 4012 4013 4014 4015
  ```


### isSet<sup>8+</sup>

X
xdmal 已提交
4016
isSet(value: Object): boolean
W
wusongqing 已提交
4017 4018 4019

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

W
wusongqing 已提交
4020 4021 4022
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4023

W
wusongqing 已提交
4024 4025 4026
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4027

W
wusongqing 已提交
4028
**Return value**
4029

W
wusongqing 已提交
4030 4031 4032
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
W
wusongqing 已提交
4033

W
wusongqing 已提交
4034
**Example**
4035
  ```js
4036 4037
  let that = new util.types();
  let result = that.isSet(new Set());
W
wusongqing 已提交
4038 4039 4040 4041 4042
  ```


### isSetIterator<sup>8+</sup>

X
xdmal 已提交
4043
isSetIterator(value: Object): boolean
W
wusongqing 已提交
4044 4045 4046

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

W
wusongqing 已提交
4047 4048 4049
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4050

W
wusongqing 已提交
4051 4052 4053
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4054

W
wusongqing 已提交
4055
**Return value**
4056

W
wusongqing 已提交
4057 4058 4059
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.|
W
wusongqing 已提交
4060

W
wusongqing 已提交
4061
**Example**
4062
  ```js
4063
  let that = new util.types();
W
wusongqing 已提交
4064
  const set = new Set();
4065
  let result = that.isSetIterator(set.keys());
W
wusongqing 已提交
4066 4067 4068 4069 4070
  ```


### isStringObject<sup>8+</sup>

X
xdmal 已提交
4071
isStringObject(value: Object): boolean
Z
zengyawen 已提交
4072 4073 4074

Checks whether the input value is a string object.

W
wusongqing 已提交
4075 4076 4077
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4078

W
wusongqing 已提交
4079 4080 4081
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4082

W
wusongqing 已提交
4083
**Return value**
4084

W
wusongqing 已提交
4085 4086 4087
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
W
wusongqing 已提交
4088

W
wusongqing 已提交
4089
**Example**
4090
  ```js
4091 4092
  let that = new util.types();
  let result = that.isStringObject(new String('foo'));
W
wusongqing 已提交
4093 4094 4095 4096 4097
  ```


### isSymbolObjec<sup>8+</sup>

X
xdmal 已提交
4098
isSymbolObject(value: Object): boolean
Z
zengyawen 已提交
4099 4100 4101

Checks whether the input value is a symbol object.

W
wusongqing 已提交
4102 4103 4104
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4105

W
wusongqing 已提交
4106 4107 4108
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4109

W
wusongqing 已提交
4110
**Return value**
4111

W
wusongqing 已提交
4112 4113 4114
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
W
wusongqing 已提交
4115

W
wusongqing 已提交
4116
**Example**
4117
  ```js
4118
  let that = new util.types();
W
wusongqing 已提交
4119
  const symbols = Symbol('foo');
4120
  let result = that.isSymbolObject(Object(symbols));
W
wusongqing 已提交
4121 4122 4123 4124 4125
  ```


### isTypedArray<sup>8+</sup>

X
xdmal 已提交
4126
isTypedArray(value: Object): boolean
W
wusongqing 已提交
4127 4128 4129 4130 4131

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 已提交
4132 4133 4134
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4135

W
wusongqing 已提交
4136 4137 4138
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4139

W
wusongqing 已提交
4140
**Return value**
4141

W
wusongqing 已提交
4142 4143 4144
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
W
wusongqing 已提交
4145

W
wusongqing 已提交
4146
**Example**
4147
  ```js
4148 4149
  let that = new util.types();
  let result = that.isTypedArray(new Float64Array([]));
W
wusongqing 已提交
4150 4151 4152 4153 4154
  ```


### isUint8Array<sup>8+</sup>

X
xdmal 已提交
4155
isUint8Array(value: Object): boolean
W
wusongqing 已提交
4156 4157 4158

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

W
wusongqing 已提交
4159 4160 4161
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4162

W
wusongqing 已提交
4163 4164 4165
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4166

W
wusongqing 已提交
4167
**Return value**
4168

W
wusongqing 已提交
4169 4170 4171
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
W
wusongqing 已提交
4172

W
wusongqing 已提交
4173
**Example**
4174
  ```js
4175 4176
  let that = new util.types();
  let result = that.isUint8Array(new Uint8Array([]));
W
wusongqing 已提交
4177 4178 4179 4180 4181
  ```


### isUint8ClampedArray<sup>8+</sup>

X
xdmal 已提交
4182
isUint8ClampedArray(value: Object): boolean
W
wusongqing 已提交
4183 4184 4185

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

W
wusongqing 已提交
4186 4187 4188
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4189

W
wusongqing 已提交
4190 4191 4192
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4193

W
wusongqing 已提交
4194
**Return value**
4195

W
wusongqing 已提交
4196 4197 4198
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
W
wusongqing 已提交
4199

W
wusongqing 已提交
4200
**Example**
4201
  ```js
4202 4203
  let that = new util.types();
  let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
W
wusongqing 已提交
4204 4205 4206 4207 4208
  ```


### isUint16Array<sup>8+</sup>

X
xdmal 已提交
4209
isUint16Array(value: Object): boolean
W
wusongqing 已提交
4210 4211 4212

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

W
wusongqing 已提交
4213 4214 4215
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4216

W
wusongqing 已提交
4217 4218 4219
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4220

W
wusongqing 已提交
4221
**Return value**
4222

W
wusongqing 已提交
4223 4224 4225
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
W
wusongqing 已提交
4226

W
wusongqing 已提交
4227
**Example**
4228
  ```js
4229 4230
  let that = new util.types();
  let result = that.isUint16Array(new Uint16Array([]));
W
wusongqing 已提交
4231 4232 4233 4234 4235
  ```


### isUint32Array<sup>8+</sup>

X
xdmal 已提交
4236
isUint32Array(value: Object): boolean
W
wusongqing 已提交
4237 4238 4239

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

W
wusongqing 已提交
4240 4241 4242
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4243

W
wusongqing 已提交
4244 4245 4246
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4247

W
wusongqing 已提交
4248
**Return value**
4249

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

W
wusongqing 已提交
4254
**Example**
4255
  ```js
4256 4257
  let that = new util.types();
  let result = that.isUint32Array(new Uint32Array([]));
W
wusongqing 已提交
4258 4259 4260 4261 4262
  ```


### isWeakMap<sup>8+</sup>

X
xdmal 已提交
4263
isWeakMap(value: Object): boolean
W
wusongqing 已提交
4264 4265 4266

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

W
wusongqing 已提交
4267 4268 4269
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4270

W
wusongqing 已提交
4271 4272 4273
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4274

W
wusongqing 已提交
4275
**Return value**
4276

W
wusongqing 已提交
4277 4278 4279
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
W
wusongqing 已提交
4280

W
wusongqing 已提交
4281
**Example**
4282
  ```js
4283 4284
  let that = new util.types();
  let result = that.isWeakMap(new WeakMap());
W
wusongqing 已提交
4285 4286 4287 4288 4289
  ```


### isWeakSet<sup>8+</sup>

X
xdmal 已提交
4290
isWeakSet(value: Object): boolean
W
wusongqing 已提交
4291 4292 4293

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

W
wusongqing 已提交
4294 4295 4296
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4297

W
wusongqing 已提交
4298 4299 4300
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
4301

W
wusongqing 已提交
4302
**Return value**
4303

W
wusongqing 已提交
4304 4305 4306
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
Z
zengyawen 已提交
4307

W
wusongqing 已提交
4308
**Example**
4309
  ```js
4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420
  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**
  ```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**
  ```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**
  ```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**
  ```js
  let that = new util.types();
  let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
W
wusongqing 已提交
4421
  ```
G
Gloria 已提交
4422
  <!--no_check-->