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

G
Gloria 已提交
3
The **util** module provides common utility functions, such as [TextEncoder](#textencoder) and [TextDecoder](#textdecoder) for string encoding and decoding, [RationalNumber<sup>8+</sup>](#rationalnumber8) for rational number operations, [LRUCache<sup>9+</sup>](#lrucache9) for cache management, [ScopeHelper<sup>9+</sup>](#scopehelper9) for range determination, [Base64Helper<sup>9+</sup>](#base64helper9) for Base64 encoding and decoding, and [types<sup>8+</sup>](#types8) for built-in object type check.
Z
zengyawen 已提交
4

W
wusongqing 已提交
5 6
> **NOTE**
>
W
wusongqing 已提交
7
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8

W
wusongqing 已提交
9 10

## Modules to Import
Z
zengyawen 已提交
11

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

G
Gloria 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28
## util.format<sup>9+</sup>

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

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

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

**Parameters**

| Name | Type    | Mandatory| Description          |
| ------- | -------- | ---- | -------------- |
| format  | string   | Yes  | String.|
G
Gloria 已提交
29
| ...args | Object[] | No  | Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
G
Gloria 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

**Return value**

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

**Example**

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

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

errnoToString(errno: number): string

Obtains detailed information about a system error code.

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

G
Gloria 已提交
90
Calls back an asynchronous function. In the callback, the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved), and the second parameter indicates the resolved value.
Z
zengyawen 已提交
91

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

**Parameters**

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

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

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

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

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

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

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

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

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

**Parameters**
128

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

**Return value**
134

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

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

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

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**
182

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**
211

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

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

parseUUID(uuid: string): Uint8Array

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

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

**Parameters**

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

**Return value**

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

**Example**
240

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

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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


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

getErrorString(errno: number): string

Obtains detailed information about a system error code.

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

Processes an asynchronous function and returns a promise.

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

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

**Parameters**

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

**Return value**

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


W
wusongqing 已提交
338 339
## TextDecoder

G
Gloria 已提交
340 341
Provides APIs to decode byte arrays into strings. It supports multiple formats, including UTF-8, UTF-16LE, UTF-16BE, ISO-8859, and Windows-1251.

W
wusongqing 已提交
342 343
### Attributes

W
wusongqing 已提交
344 345
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
346 347 348 349 350
| 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 已提交
351

G
Gloria 已提交
352
### constructor<sup>9+</sup>
W
wusongqing 已提交
353

G
Gloria 已提交
354 355 356 357 358 359 360 361
constructor()

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

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

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

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

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

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

G
Gloria 已提交
368 369 370 371
**Parameters**

| Name  | Type  | Mandatory| Description                                            |
| -------- | ------ | ---- | ------------------------------------------------ |
G
Gloria 已提交
372
| encoding | string | No  | Encoding format. The default format is **'utf-8'**.                     |
G
Gloria 已提交
373 374
| options  | Object | No  | Encoding-related options, which include **fatal** and **ignoreBOM**.|

375
**Table 1.1** options
G
Gloria 已提交
376 377 378

| Name     | Type| Mandatory| Description              |
| --------- | -------- | ---- | ------------------ |
G
Gloria 已提交
379 380
| fatal     | boolean  | No  | Whether to display fatal errors. The default value is **false**.|
| ignoreBOM | boolean  | No  | Whether to ignore the BOM. The default value is **false**. |
G
Gloria 已提交
381 382 383

**Example**

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

389
### decodeWithStream<sup>9+</sup>
W
wusongqing 已提交
390

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

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

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

**Parameters**
398

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

404
**Table 2** options
W
wusongqing 已提交
405

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

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

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

W
wusongqing 已提交
416
**Example**
417

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
  let retStr = textDecoder.decodeWithStream( result , {stream: false});
429 430 431
  console.log("retStr = " + retStr);
  ```

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

434
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean })
435

436 437 438 439 440 441 442 443 444 445 446 447
A constructor used to create a **TextDecoder** object.

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

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
448
| encoding | string | No| Encoding format. The default format is **'utf-8'**.|
449 450 451 452 453 454
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|

  **Table 1** options

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
455 456
| fatal | boolean | No| Whether to display fatal errors. The default value is **false**.|
| ignoreBOM | boolean | No| Whether to ignore the BOM. The default value is **false**.|
457 458 459 460 461 462 463 464 465 466

**Example**

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

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

decode(input: Uint8Array, options?: { stream?: false }): string
467 468 469

Decodes the input content.

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

474 475 476 477 478 479 480 481 482
**System capability**: SystemCapability.Utils.Lang

**Parameters**

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

483
**Table 2** options
484 485 486

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
487
| 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**.|
488 489 490 491 492 493 494 495

**Return value**

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

**Example**
496

497 498 499 500 501 502 503 504 505 506
  ```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:");
507
  let retStr = textDecoder.decode( result , {stream: false});
W
wusongqing 已提交
508 509
  console.log("retStr = " + retStr);
  ```
Z
zengyawen 已提交
510

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

G
Gloria 已提交
513 514
Provides APIs to encode strings into byte arrays. It supports multiple formats, including UTF-8, UTF-16LE, and UTF-16BE. When **TextEncoder** is used for encoding, the number of bytes occupied by a character varies according to the encoding format. For example, a Chinese character usually occupies three bytes in UTF-8 encoding format but two bytes in UTF-16LE or UTF-16BE encoding format. Therefore, when using **TextEncoder**, you must explicitly specify the encoding format to obtain the required encoding result.

W
wusongqing 已提交
515
### Attributes
Z
zengyawen 已提交
516

W
wusongqing 已提交
517 518
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
519 520
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
G
Gloria 已提交
521
| encoding | string | Yes| No| Encoding format. The default format is **'utf-8'**.|
Z
zengyawen 已提交
522

G
Gloria 已提交
523

W
wusongqing 已提交
524
### constructor
Z
zengyawen 已提交
525

W
wusongqing 已提交
526
constructor()
Z
zengyawen 已提交
527

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

W
wusongqing 已提交
530 531 532
**System capability**: SystemCapability.Utils.Lang

**Example**
533

534
  ```js
535
  let textEncoder = new util.TextEncoder();
W
wusongqing 已提交
536 537
  ```

538
### constructor<sup>9+</sup>
G
Gloria 已提交
539

540
constructor(encoding?: string)
G
Gloria 已提交
541

542
A constructor used to create a **TextEncoder** object.
G
Gloria 已提交
543 544 545 546 547

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

**Parameters**

548 549
| Name| Type| Mandatory| Description|
| ----- | ---- | ---- | ---- |
550
| encoding | string | No| Encoding format. The default format is **'utf-8'**.|
G
Gloria 已提交
551 552 553 554

**Example**

  ```js
555
  let textEncoder = new util.TextEncoder("utf-8");
G
Gloria 已提交
556 557
  ```

558
### encodeInto<sup>9+</sup>
W
wusongqing 已提交
559

560
encodeInto(input?: string): Uint8Array
Z
zengyawen 已提交
561

Z
zengyawen 已提交
562
Encodes the input content.
Z
zengyawen 已提交
563

W
wusongqing 已提交
564 565 566
**System capability**: SystemCapability.Utils.Lang

**Parameters**
567

568 569
| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
570
| input  | string | No  | String to encode. The default value is an empty string.|
W
wusongqing 已提交
571

W
wusongqing 已提交
572
**Return value**
573

574 575
| Type      | Description              |
| ---------- | ------------------ |
W
wusongqing 已提交
576
| Uint8Array | Encoded text.|
W
wusongqing 已提交
577

W
wusongqing 已提交
578
**Example**
579

580
  ```js
581 582 583 584
let textEncoder = new util.TextEncoder();
let buffer = new ArrayBuffer(20);
let result = new Uint8Array(buffer);
result = textEncoder.encodeInto("\uD800¥¥");
W
wusongqing 已提交
585 586
  ```

G
Gloria 已提交
587 588
### encodeIntoUint8Array<sup>9+</sup>

G
Gloria 已提交
589
encodeIntoUint8Array(input: string, dest: Uint8Array): { read: number; written: number }
G
Gloria 已提交
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614

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()
615
result = that.encodeIntoUint8Array('abcd', dest)
G
Gloria 已提交
616 617 618
  ```

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

G
Gloria 已提交
620
encodeInto(input: string, dest: Uint8Array): { read: number; written: number }
Z
zengyawen 已提交
621 622 623

Stores the UTF-8 encoded text.

624 625 626 627
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeIntoUint8Array<sup>9+</sup>](#encodeintouint8array9) instead.

W
wusongqing 已提交
628 629 630
**System capability**: SystemCapability.Utils.Lang

**Parameters**
631

W
wusongqing 已提交
632 633 634 635
| 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 已提交
636

W
wusongqing 已提交
637
**Return value**
638

W
wusongqing 已提交
639 640 641
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
Z
zengyawen 已提交
642

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

652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
### encode<sup>(deprecated)</sup>

encode(input?: string): Uint8Array

Encodes the input content.

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

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
668
| input | string | No| String to encode. The default value is an empty string.|
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683

**Return value**

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

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

W
wusongqing 已提交
684
## RationalNumber<sup>8+</sup>
Z
zengyawen 已提交
685

G
Gloria 已提交
686
Provides APIs to compare rational numbers and obtain numerators and denominators. For example, the **toString()** API can be used to convert a rational number into a string.
G
Gloria 已提交
687

G
Gloria 已提交
688
### constructor<sup>9+</sup>
Z
zengyawen 已提交
689

G
Gloria 已提交
690 691 692 693 694 695 696 697
constructor()

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

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

**Example**

698
```js
G
Gloria 已提交
699
let rationalNumber = new util.RationalNumber();
700
```
G
Gloria 已提交
701 702 703

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

704
parseRationalNumber(numerator: number,denominator: number): RationalNumber
G
Gloria 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718

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

719 720 721
```js
let rationalNumber = util.RationalNumber.parseRationalNumber(1,2)
```
G
Gloria 已提交
722

W
wusongqing 已提交
723
### createRationalFromString<sup>8+</sup>
Z
zengyawen 已提交
724

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

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

W
wusongqing 已提交
729 730 731
**System capability**: SystemCapability.Utils.Lang

**Parameters**
732

W
wusongqing 已提交
733 734 735
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rationalString | string | Yes| String used to create the **RationalNumber** object.|
Z
zengyawen 已提交
736

W
wusongqing 已提交
737
**Return value**
738

W
wusongqing 已提交
739 740 741
| Type| Description|
| -------- | -------- |
| object | **RationalNumber** object created.|
Z
zengyawen 已提交
742

W
wusongqing 已提交
743
**Example**
744 745 746 747 748

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

G
Gloria 已提交
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
### compare<sup>9+</sup>

compare​(another: RationalNumber): number​

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

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

**Parameters**

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

**Return value**

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

**Example**

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

W
wusongqing 已提交
778
### valueOf<sup>8+</sup>
Z
zengyawen 已提交
779

X
xdmal 已提交
780
valueOf(): number
Z
zengyawen 已提交
781

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

W
wusongqing 已提交
784 785 786
**System capability**: SystemCapability.Utils.Lang

**Return value**
787

W
wusongqing 已提交
788 789 790
| Type| Description|
| -------- | -------- |
| number | An integer or a floating-point number.|
Z
zengyawen 已提交
791

W
wusongqing 已提交
792
**Example**
793 794 795 796 797

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

W
wusongqing 已提交
799
### equals<sup>8+</sup>
Z
zengyawen 已提交
800

X
xdmal 已提交
801
equals​(obj: Object): boolean
Z
zengyawen 已提交
802

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

W
wusongqing 已提交
805 806 807
**System capability**: SystemCapability.Utils.Lang

**Parameters**
808

W
wusongqing 已提交
809 810 811
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | Object | Yes| Object used to compare with this **RationalNumber** object.|
Z
zengyawen 已提交
812

W
wusongqing 已提交
813
**Return value**
814

W
wusongqing 已提交
815 816 817
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the two objects are equal; returns **false** otherwise.|
Z
zengyawen 已提交
818

W
wusongqing 已提交
819
**Example**
820 821 822 823 824 825

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

G
Gloria 已提交
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
### 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 已提交
847

G
Gloria 已提交
848 849
**Example**

850
```js
G
Gloria 已提交
851 852
let rationalNumber = new util.RationalNumber(1,2);
let result = util.RationalNumber.getCommonFactor(4,6);
853
```
G
Gloria 已提交
854

W
wusongqing 已提交
855
### getNumerator<sup>8+</sup>
Z
zengyawen 已提交
856

X
xdmal 已提交
857
getNumerator​(): number
Z
zengyawen 已提交
858

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

W
wusongqing 已提交
861 862 863 864
**System capability**: SystemCapability.Utils.Lang

**Return value**

W
wusongqing 已提交
865 866 867
| Type| Description|
| -------- | -------- |
| number | Numerator of this **RationalNumber** object.|
Z
zengyawen 已提交
868

W
wusongqing 已提交
869
**Example**
870 871 872 873 874

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

W
wusongqing 已提交
876
### getDenominator<sup>8+</sup>
Z
zengyawen 已提交
877

X
xdmal 已提交
878
getDenominator​(): number
Z
zengyawen 已提交
879

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

W
wusongqing 已提交
882 883 884
**System capability**: SystemCapability.Utils.Lang

**Return value**
885

W
wusongqing 已提交
886 887 888
| Type| Description|
| -------- | -------- |
| number | Denominator of this **RationalNumber** object.|
Z
zengyawen 已提交
889

W
wusongqing 已提交
890
**Example**
891 892 893 894 895

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

W
wusongqing 已提交
897
### isZero<sup>8+</sup>
Z
zengyawen 已提交
898

W
wusongqing 已提交
899
isZero​():boolean
Z
zengyawen 已提交
900

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

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

**Return value**
906

W
wusongqing 已提交
907 908 909
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
Z
zengyawen 已提交
910

W
wusongqing 已提交
911
**Example**
912 913 914 915 916

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

W
wusongqing 已提交
918
### isNaN<sup>8+</sup>
Z
zengyawen 已提交
919

X
xdmal 已提交
920
isNaN​(): boolean
Z
zengyawen 已提交
921

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

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

**Return value**
927

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

W
wusongqing 已提交
932
**Example**
933 934 935 936 937

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

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

W
wusongqing 已提交
941
isFinite​():boolean
Z
zengyawen 已提交
942

W
wusongqing 已提交
943
Checks whether this **RationalNumber** object represents a finite value.
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 represents a finite value (the denominator is not **0**); returns **false** otherwise.|
Z
zengyawen 已提交
952

W
wusongqing 已提交
953
**Example**
954 955 956 957 958

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

W
wusongqing 已提交
960
### toString<sup>8+</sup>
Z
zengyawen 已提交
961

X
xdmal 已提交
962
toString​(): string
Z
zengyawen 已提交
963

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

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

**Return value**
969

W
wusongqing 已提交
970 971 972
| 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 已提交
973

W
wusongqing 已提交
974
**Example**
975 976 977 978 979

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

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

constructor(numerator: number,denominator: number)

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

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

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

**Parameters**

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

**Example**

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

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

compareTo​(another: RationalNumber): number​

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

Obtains the greatest common divisor of two specified integers.

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

G
Gloria 已提交
1072 1073
Provides APIs to discard the least recently used data to make rooms for new elements when the cache is full. This class uses the Least Recently Used (LRU) algorithm, which believes that the recently used data may be accessed again in the near future and the least accessed data is the least valuable data and should be removed from the cache.

W
wusongqing 已提交
1074
### Attributes
Z
zengyawen 已提交
1075

W
wusongqing 已提交
1076 1077
**System capability**: SystemCapability.Utils.Lang

G
Gloria 已提交
1078 1079
| Name  | Type  | Readable| Writable| Description                  |
| ------ | ------ | ---- | ---- | ---------------------- |
1080
| length | number | Yes  | No  | Total number of values in this cache.|
Z
zengyawen 已提交
1081

W
wusongqing 已提交
1082
**Example**
G
Gloria 已提交
1083

1084
```js
G
Gloria 已提交
1085 1086 1087 1088
let pro = new util.LRUCache();
pro.put(2,10);
pro.put(1,8);
let result = pro.length;
1089
```
Z
zengyawen 已提交
1090

G
Gloria 已提交
1091
### constructor<sup>9+</sup>
Z
zengyawen 已提交
1092

X
xdmal 已提交
1093
constructor(capacity?: number)
Z
zengyawen 已提交
1094

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

W
wusongqing 已提交
1097 1098 1099
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1100

G
Gloria 已提交
1101 1102
| Name  | Type  | Mandatory| Description                        |
| -------- | ------ | ---- | ---------------------------- |
G
Gloria 已提交
1103
| capacity | number | No  | Capacity of the **LruCache** to create. The default value is **64**.|
Z
zengyawen 已提交
1104

W
wusongqing 已提交
1105
**Example**
G
Gloria 已提交
1106

1107
```js
G
Gloria 已提交
1108
let lrubuffer= new util.LRUCache();
1109
```
Z
zengyawen 已提交
1110 1111


G
Gloria 已提交
1112
### updateCapacity<sup>9+</sup>
Z
zengyawen 已提交
1113

X
xdmal 已提交
1114
updateCapacity(newCapacity: number): void
Z
zengyawen 已提交
1115

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

W
wusongqing 已提交
1118 1119 1120
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1121

G
Gloria 已提交
1122 1123
| Name     | Type  | Mandatory| Description                        |
| ----------- | ------ | ---- | ---------------------------- |
1124
| newCapacity | number | Yes  | New capacity of the **LruCache**.|
Z
zengyawen 已提交
1125

W
wusongqing 已提交
1126
**Example**
G
Gloria 已提交
1127

1128
```js
G
Gloria 已提交
1129
let pro = new util.LRUCache();
G
Gloria 已提交
1130
pro.updateCapacity(100);
1131
```
Z
zengyawen 已提交
1132 1133


G
Gloria 已提交
1134
### toString<sup>9+</sup>
Z
zengyawen 已提交
1135

X
xdmal 已提交
1136
toString(): string
Z
zengyawen 已提交
1137

1138
Obtains the string representation of this **LruCache** object.
Z
zengyawen 已提交
1139

W
wusongqing 已提交
1140 1141 1142
**System capability**: SystemCapability.Utils.Lang

**Return value**
1143

G
Gloria 已提交
1144 1145
| Type  | Description                      |
| ------ | -------------------------- |
1146
| string | String representation of this **LruCache** object.|
W
wusongqing 已提交
1147

W
wusongqing 已提交
1148
**Example**
G
Gloria 已提交
1149

1150
```js
G
Gloria 已提交
1151 1152 1153 1154 1155
let pro = new util.LRUCache();
pro.put(2,10);
pro.get(2);
pro.remove(20);
let result = pro.toString();
1156
```
G
Gloria 已提交
1157 1158 1159 1160 1161 1162


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

getCapacity(): number

1163
Obtains the capacity of this cache.
G
Gloria 已提交
1164 1165 1166 1167 1168 1169 1170

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

**Return value**

| Type  | Description                  |
| ------ | ---------------------- |
1171
| number | Capacity of this cache.|
G
Gloria 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184

**Example**

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


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

clear(): void

1185
Clears key-value pairs from this cache. The **afterRemoval()** method will be called to perform subsequent operations.
G
Gloria 已提交
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

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

1250
Obtains the number of removals from this cache.
G
Gloria 已提交
1251 1252 1253 1254 1255 1256 1257

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

**Return value**

| Type  | Description                      |
| ------ | -------------------------- |
1258
| number | Number of removals from the cache.|
G
Gloria 已提交
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

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

1299
Obtains the number of additions to this cache.
G
Gloria 已提交
1300 1301 1302 1303 1304 1305 1306

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

**Return value**

| Type  | Description                        |
| ------ | ---------------------------- |
1307
| number | Number of additions to the cache.|
G
Gloria 已提交
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321

**Example**

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


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

isEmpty(): boolean

1322
Checks whether this cache is empty.
G
Gloria 已提交
1323 1324 1325 1326 1327 1328 1329

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

**Return value**

| Type   | Description                                    |
| ------- | ---------------------------------------- |
1330
| boolean | Returns **true** if the cache does not contain any value.|
G
Gloria 已提交
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

**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                                                        |
| ------------------------ | ------------------------------------------------------------ |
1359
| V \| undefined | Returns the value of the key if a match is found in the cache; returns **undefined** otherwise.|
G
Gloria 已提交
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373

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

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

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

1402
Obtains all values in this cache, listed from the most to the least recently accessed.
G
Gloria 已提交
1403 1404 1405 1406 1407 1408 1409

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

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
1410
| V&nbsp;[] | All values in the cache, listed from the most to the least recently accessed.|
G
Gloria 已提交
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426

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

1427
Obtains all keys in this cache, listed from the most to the least recently accessed.
G
Gloria 已提交
1428 1429 1430 1431 1432 1433 1434

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

**Return value**

| Type     | Description                                                        |
| --------- | ------------------------------------------------------------ |
1435
| K&nbsp;[] | All keys in the cache, listed from the most to the least recently accessed.|
G
Gloria 已提交
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449

**Example**

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


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

remove(key: K): V | undefined

1450
Removes the specified key and its value from this cache.
G
Gloria 已提交
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463

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

**Parameters**

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

**Return value**

| Type                    | Description                                                        |
| ------------------------ | ------------------------------------------------------------ |
1464
| V&nbsp;\|&nbsp;undefined | Returns an **Optional** object containing the removed key-value pair if the key exists in the cache; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.|
G
Gloria 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486

**Example**

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


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

afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void

Performs subsequent operations after a value is removed.

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

**Parameters**

| Name  | Type   | Mandatory| Description                                                        |
| -------- | ------- | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
1487
| isEvict  | boolean | Yes  | Whether the cache capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity.   |
G
Gloria 已提交
1488 1489
| key      | K       | Yes  | Key removed.                                              |
| value    | V       | Yes  | Value removed.                                              |
1490
| newValue | V       | Yes  | New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
G
Gloria 已提交
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

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

1517
contains(key: K): boolean
G
Gloria 已提交
1518

1519
Checks whether this cache contains the specified key.
G
Gloria 已提交
1520 1521 1522 1523 1524

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

**Parameters**

1525 1526
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
1527
| key    | K | Yes  | Key to check.|
G
Gloria 已提交
1528 1529 1530 1531 1532

**Return value**

| Type   | Description                                      |
| ------- | ------------------------------------------ |
1533
| boolean | Returns **true** if the cache contains the specified key; returns **false** otherwise.|
G
Gloria 已提交
1534 1535 1536 1537 1538 1539

**Example**

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


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

1617
## ScopeComparable<sup>8+</sup>
G
Gloria 已提交
1618

1619
The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
G
Gloria 已提交
1620 1621 1622

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

1623
### compareTo<sup>8+</sup>
G
Gloria 已提交
1624

1625
compareTo(other: ScopeComparable): boolean;
1626

1627
Compares two values and returns a Boolean value.
G
Gloria 已提交
1628

1629
**System capability**: SystemCapability.Utils.Lang
G
Gloria 已提交
1630

1631
**Parameters**
G
Gloria 已提交
1632

1633 1634 1635
| Name| Type| Mandatory| Description          |
| ------ | ---- | ---- | -------------- |
| other  | [ScopeComparable](#scopecomparable8) | Yes | The other value to be compared with the current value.|
G
Gloria 已提交
1636

1637
**Return value**
1638

1639 1640 1641
| Type| Description              |
| ---- | ------------------ |
| boolean | If the current value is greater than or equal to the input value, **true** is returned. Otherwise, **false** is returned.|
G
Gloria 已提交
1642

1643
**Example**
G
Gloria 已提交
1644

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

1647 1648
```js
class Temperature{
1649 1650 1651
    // If ArkTS is used for development, add the following code:
    // private readonly _temp: Temperature;
    constructor(value) {
1652 1653
       this._temp = value;
    }
1654
    compareTo(value) {
1655 1656
       return this._temp >= value.getTemp();
    }
1657
    getTemp() {
1658 1659
       return this._temp;
    }
1660
    toString() {
1661 1662 1663 1664
       return this._temp.toString();
    }
}
```
1665

1666
## ScopeType<sup>8+</sup>
G
Gloria 已提交
1667

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

1670
**System capability**: SystemCapability.Utils.Lang
G
Gloria 已提交
1671

1672 1673 1674 1675
| Type| Description|
| -------- | -------- |
| number | The value type is a number.|
| [ScopeComparable](#scopecomparable8) | The value type is ScopeComparable.|
G
Gloria 已提交
1676

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

G
Gloria 已提交
1679 1680
Provides APIs to define the valid range of a field. The constructor of this class creates comparable objects with lower and upper limits.

1681 1682 1683 1684 1685
### constructor<sup>9+</sup>

constructor(lowerObj: ScopeType, upperObj: ScopeType)

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

G
Gloria 已提交
1687 1688 1689 1690
**System capability**: SystemCapability.Utils.Lang

**Parameters**

1691 1692 1693 1694
| Name  | Type                    | Mandatory| Description                  |
| -------- | ------------------------ | ---- | ---------------------- |
| lowerObj | [ScopeType](#scopetype8) | Yes  | Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes  | Upper limit of the **Scope** object.|
G
Gloria 已提交
1695 1696

**Example**
1697

G
Gloria 已提交
1698
  ```js
1699 1700 1701
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
G
Gloria 已提交
1702 1703 1704
  ```


1705
### toString<sup>9+</sup>
G
Gloria 已提交
1706

1707
toString(): string
G
Gloria 已提交
1708

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

G
Gloria 已提交
1711 1712 1713 1714
**System capability**: SystemCapability.Utils.Lang

**Return value**

1715 1716 1717
| Type  | Description                                  |
| ------ | -------------------------------------- |
| string | String representation containing the **Scope**.|
G
Gloria 已提交
1718 1719

**Example**
1720

G
Gloria 已提交
1721
  ```js
1722 1723 1724 1725
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.toString();
W
wusongqing 已提交
1726 1727 1728
  ```


1729
### intersect<sup>9+</sup>
W
wusongqing 已提交
1730

1731
intersect(range: ScopeHelper): ScopeHelper
W
wusongqing 已提交
1732

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

W
wusongqing 已提交
1735 1736
**System capability**: SystemCapability.Utils.Lang

1737 1738 1739 1740 1741 1742
**Parameters**

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

W
wusongqing 已提交
1743
**Return value**
1744

1745 1746 1747
| Type                          | Description                          |
| ------------------------------ | ------------------------------ |
| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
1748

W
wusongqing 已提交
1749
**Example**
1750

1751
  ```js
1752 1753 1754 1755 1756 1757 1758
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
range.intersect(rangeFir);
W
wusongqing 已提交
1759
  ```
Z
zengyawen 已提交
1760 1761


1762
### intersect<sup>9+</sup>
Z
zengyawen 已提交
1763

1764
intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper
Z
zengyawen 已提交
1765

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

W
wusongqing 已提交
1768 1769
**System capability**: SystemCapability.Utils.Lang

1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
**Parameters**

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

**Return value**

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

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

1785
  ```js
1786 1787 1788 1789 1790 1791
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.intersect(tempMiDF, tempMidS);
W
wusongqing 已提交
1792
  ```
Z
zengyawen 已提交
1793 1794


1795
### getUpper<sup>9+</sup>
W
wusongqing 已提交
1796

1797
getUpper(): ScopeType
W
wusongqing 已提交
1798

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

W
wusongqing 已提交
1801 1802 1803
**System capability**: SystemCapability.Utils.Lang

**Return value**
1804

1805 1806 1807
| Type                    | Description                  |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
W
wusongqing 已提交
1808

W
wusongqing 已提交
1809
**Example**
1810

1811
  ```js
1812 1813 1814 1815
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getUpper();
W
wusongqing 已提交
1816 1817 1818
  ```


1819
### getLower<sup>9+</sup>
W
wusongqing 已提交
1820

1821
getLower(): ScopeType
W
wusongqing 已提交
1822

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

W
wusongqing 已提交
1825 1826 1827
**System capability**: SystemCapability.Utils.Lang

**Return value**
1828

1829 1830 1831
| Type                    | Description                  |
| ------------------------ | ---------------------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
W
wusongqing 已提交
1832

W
wusongqing 已提交
1833
**Example**
1834

1835
  ```js
1836 1837 1838 1839
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.getLower();
W
wusongqing 已提交
1840 1841 1842
  ```


1843
### expand<sup>9+</sup>
W
wusongqing 已提交
1844

1845
expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper
W
wusongqing 已提交
1846

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

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

1851 1852 1853 1854 1855 1856 1857
**Parameters**

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

W
wusongqing 已提交
1858
**Return value**
1859

1860 1861 1862
| Type                        | Description                                |
| ---------------------------- | ------------------------------------ |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
1863

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

1866
  ```js
1867 1868 1869 1870 1871 1872
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.expand(tempMiDF, tempMidS);
W
wusongqing 已提交
1873 1874 1875
  ```


1876
### expand<sup>9+</sup>
W
wusongqing 已提交
1877

1878
expand(range: ScopeHelper): ScopeHelper
W
wusongqing 已提交
1879

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

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

1884 1885 1886 1887 1888 1889
**Parameters**

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

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

1892 1893 1894
| Type                        | Description                              |
| ---------------------------- | ---------------------------------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
1895

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

1898
  ```js
1899 1900 1901 1902 1903 1904 1905
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let tempMidS = new Temperature(39);
let range = new util.ScopeHelper(tempLower, tempUpper);
let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
let result = range.expand(rangeFir);
W
wusongqing 已提交
1906 1907 1908
  ```


1909
### expand<sup>9+</sup>
W
wusongqing 已提交
1910

1911
expand(value: ScopeType): ScopeHelper
W
wusongqing 已提交
1912

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

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

1917 1918 1919 1920 1921 1922
**Parameters**

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

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

1925 1926 1927
| Type                        | Description                            |
| ---------------------------- | -------------------------------- |
| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given value.|
W
wusongqing 已提交
1928

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

1931
  ```js
1932 1933 1934 1935 1936
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 已提交
1937 1938 1939
  ```


1940
### contains<sup>9+</sup>
W
wusongqing 已提交
1941

1942
contains(value: ScopeType): boolean
W
wusongqing 已提交
1943

1944
Checks whether a value is within this **Scope**.
1945

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

1948 1949 1950 1951 1952 1953
**Parameters**

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

W
wusongqing 已提交
1954
**Return value**
1955

1956 1957 1958
| Type   | Description                                               |
| ------- | --------------------------------------------------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
1959

W
wusongqing 已提交
1960
**Example**
1961

1962
  ```js
1963 1964 1965 1966
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
G
Gloria 已提交
1967
let result = range.contains(tempMiDF);
W
wusongqing 已提交
1968 1969 1970
  ```


1971
### contains<sup>9+</sup>
Z
zengyawen 已提交
1972

1973
contains(range: ScopeHelper): boolean
Z
zengyawen 已提交
1974

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

W
wusongqing 已提交
1977 1978 1979
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1980

1981 1982 1983
| Name| Type                        | Mandatory| Description              |
| ------ | ---------------------------- | ---- | ------------------ |
| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
W
wusongqing 已提交
1984

W
wusongqing 已提交
1985
**Return value**
1986

1987 1988 1989
| Type   | Description                                                 |
| ------- | ----------------------------------------------------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
1990

W
wusongqing 已提交
1991
**Example**
1992

1993
  ```js
1994 1995 1996 1997 1998 1999 2000
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 已提交
2001 2002 2003
  ```


2004
### clamp<sup>9+</sup>
Z
zengyawen 已提交
2005

2006
clamp(value: ScopeType): ScopeType
Z
zengyawen 已提交
2007

2008
Limits a value to this **Scope**.
2009

W
wusongqing 已提交
2010 2011 2012
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2013

2014 2015 2016
| Name| Type                    | Mandatory| Description          |
| ------ | ------------------------ | ---- | -------------- |
| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|
Z
zengyawen 已提交
2017

W
wusongqing 已提交
2018
**Return value**
2019

2020 2021 2022
| Type                    | Description                                                        |
| ------------------------ | ------------------------------------------------------------ |
| [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.|
Z
zengyawen 已提交
2023

W
wusongqing 已提交
2024
**Example**
2025

2026
  ```js
2027 2028 2029 2030 2031
let tempLower = new Temperature(30);
let tempUpper = new Temperature(40);
let tempMiDF = new Temperature(35);
let range = new util.ScopeHelper(tempLower, tempUpper);
let result = range.clamp(tempMiDF);
W
wusongqing 已提交
2032
  ```
Z
zengyawen 已提交
2033

2034
## Base64Helper<sup>9+</sup>
G
Gloria 已提交
2035

G
Gloria 已提交
2036 2037
The Base64 encoding table contains 62 characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). During encoding, the original data is divided into groups of three bytes, and each group contains a 6-bit number. Then, the corresponding characters in the Base64 encoding table are used to represent these numbers. If the last group contains only one or two bytes, the equal sign (=) is used for padding.

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

2040
constructor()
Z
zengyawen 已提交
2041

2042
A constructor used to create a **Base64Helper** instance.
2043

W
wusongqing 已提交
2044 2045
**System capability**: SystemCapability.Utils.Lang

2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065
**Example**

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

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

encodeSync(src: Uint8Array): Uint8Array

Encodes the input content.

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

**Parameters**

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

W
wusongqing 已提交
2066
**Return value**
2067

2068 2069 2070
| Type      | Description                         |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array encoded.|
Z
zengyawen 已提交
2071

W
wusongqing 已提交
2072
**Example**
2073

2074
  ```js
2075 2076 2077
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let result = that.encodeSync(array);
W
wusongqing 已提交
2078
  ```
Z
zengyawen 已提交
2079 2080


2081
### encodeToStringSync<sup>9+</sup>
Z
zengyawen 已提交
2082

2083
encodeToStringSync(src: Uint8Array, options?: Type): string
Z
zengyawen 已提交
2084

2085
Encodes the input content.
2086

W
wusongqing 已提交
2087 2088
**System capability**: SystemCapability.Utils.Lang

2089 2090 2091 2092 2093
**Parameters**

| Name| Type      | Mandatory| Description               |
| ------ | ---------- | ---- | ------------------- |
| src    | Uint8Array | Yes  | Uint8Array to encode.|
2094
| options<sup>10+</sup>    | [Type](#type10) | No  | Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the output contains a maximum of 76 characters, ended with '\r\n'.|
2095

W
wusongqing 已提交
2096
**Return value**
2097

2098 2099 2100
| Type  | Description                |
| ------ | -------------------- |
| string | String encoded from the Uint8Array.|
W
wusongqing 已提交
2101

W
wusongqing 已提交
2102
**Example**
2103 2104 2105

  ```js
let that = new util.Base64Helper();
2106 2107
let array = new Uint8Array([77,97,110,105,115,100,105,115,116,105,110,103,117,105,115,104,101,100,110,111,116,111,110,108,121,98,121,104,105,115,114,101,97,115,111,110,98,117,116,98,121,116,104,105,115,115,105,110,103,117,108,97,114,112,97,115,115,105,111,110,102,114,111,109,111,116,104,101,114,97,110,105,109,97,108,115,119,104,105,99,104,105,115,97,108,117,115,116,111,102,116,104,101,109,105,110,100,101,120,99,101,101,100,115,116,104,101,115,104,111,114,116,118,101,104,101,109,101,110,99,101,111,102,97,110,121,99,97,114,110,97,108,112,108,101,97,115,117,114,101]);
let result = that.encodeToStringSync(array, util.Type.MIME);
W
wusongqing 已提交
2108 2109 2110
  ```


2111
### decodeSync<sup>9+</sup>
W
wusongqing 已提交
2112

2113
decodeSync(src: Uint8Array | string, options?: Type): Uint8Array
W
wusongqing 已提交
2114

2115
Decodes the input content.
2116

W
wusongqing 已提交
2117 2118 2119
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2120

2121 2122 2123
| Name| Type                          | Mandatory| Description                         |
| ------ | ------------------------------ | ---- | ----------------------------- |
| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode.|
2124
| options<sup>10+</sup>    | [Type](#type10) | No  | Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the input contains a maximum of 76 characters, ended with '\r\n'.|
W
wusongqing 已提交
2125

W
wusongqing 已提交
2126
**Return value**
2127

2128 2129 2130
| Type      | Description                         |
| ---------- | ----------------------------- |
| Uint8Array | Uint8Array decoded.|
W
wusongqing 已提交
2131

W
wusongqing 已提交
2132
**Example**
2133

2134
  ```js
2135
let that = new util.Base64Helper();
2136 2137
let buff = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
let result = that.decodeSync(buff, util.Type.MIME);
W
wusongqing 已提交
2138 2139 2140
  ```


2141
### encode<sup>9+</sup>
W
wusongqing 已提交
2142

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

2145
Encodes the input content asynchronously.
2146

W
wusongqing 已提交
2147 2148 2149
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2150

2151 2152 2153 2154 2155 2156 2157 2158 2159
| Name| Type      | Mandatory| Description                   |
| ------ | ---------- | ---- | ----------------------- |
| src    | Uint8Array | Yes  | Uint8Array to encode asynchronously.|

**Return value**

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

W
wusongqing 已提交
2161
**Example**
2162

2163
  ```js
2164 2165 2166 2167 2168 2169 2170 2171
let that = new util.Base64Helper();
let array = new Uint8Array([115,49,51]);
let rarray = new Uint8Array([99,122,69,122]);
that.encode(array).then(val=>{    
    for (var i = 0; i < rarray.length; i++) {        
        console.log(val[i].toString())
    }
})
W
wusongqing 已提交
2172 2173 2174
  ```


2175
### encodeToString<sup>9+</sup>
Z
zengyawen 已提交
2176

2177
encodeToString(src: Uint8Array, options?: Type): Promise&lt;string&gt;
2178

2179
Encodes the input content asynchronously.
2180

W
wusongqing 已提交
2181 2182 2183
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2184

2185 2186 2187
| Name| Type      | Mandatory| Description                   |
| ------ | ---------- | ---- | ----------------------- |
| src    | Uint8Array | Yes  | Uint8Array to encode asynchronously.|
2188
| options<sup>10+</sup>    | [Type](#type10) | No  |  Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The output can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the output contains a maximum of 76 characters, ended with '\r\n'.|
Z
zengyawen 已提交
2189

W
wusongqing 已提交
2190
**Return value**
2191

2192 2193 2194
| Type                 | Description                    |
| --------------------- | ------------------------ |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
Z
zengyawen 已提交
2195

W
wusongqing 已提交
2196
**Example**
2197

2198
  ```js
2199
let that = new util.Base64Helper();
2200 2201 2202
let array = new Uint8Array([77,97,110,105,115,100,105,115,116,105,110,103,117,105,115,104,101,100,110,111,116,111,110,108,121,98,121,104,105,115,114,101,97,115,111,110,98,117,116,98,121,116,104,105,115,115,105,110,103,117,108,97,114,112,97,115,115,105,111,110,102,114,111,109,111,116,104,101,114,97,110,105,109,97,108,115,119,104,105,99,104,105,115,97,108,117,115,116,111,102,116,104,101,109,105,110,100,101,120,99,101,101,100,115,116,104,101,115,104,111,114,116,118,101,104,101,109,101,110,99,101,111,102,97,110,121,99,97,114,110,97,108,112,108,101,97,115,117,114,101]);
that.encodeToString(array, util.Type.MIME).then(val=>{
  // Add information as required.
2203
})
W
wusongqing 已提交
2204
  ```
Z
zengyawen 已提交
2205 2206


2207
### decode<sup>9+</sup>
Z
zengyawen 已提交
2208

2209
decode(src: Uint8Array | string, options?: Type): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
2210

2211
Decodes the input content asynchronously.
2212

W
wusongqing 已提交
2213 2214 2215
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2216

2217 2218 2219
| Name| Type                          | Mandatory| Description                             |
| ------ | ------------------------------ | ---- | --------------------------------- |
| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode asynchronously.|
2220
| options<sup>10+</sup>    | [Type](#type10) | No  | Encoding format.<br>The following values are available:<br>- **util.Type.BASIC** (default value): The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). There is no carriage return or line feed character.<br>- **util.Type.MIME**: The input can contain 64 printable characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). Each line of the input contains a maximum of 76 characters, ended with '\r\n'.|
Z
zengyawen 已提交
2221

W
wusongqing 已提交
2222
**Return value**
2223

2224 2225 2226
| Type                     | Description                             |
| ------------------------- | --------------------------------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
Z
zengyawen 已提交
2227

W
wusongqing 已提交
2228
**Example**
2229

2230
  ```js
2231
let that = new util.Base64Helper();
2232 2233 2234
let array = 'TWFuaXNkaXN0aW5ndWlzaGVkbm90b25seWJ5aGlzcmVhc29uYnV0Ynl0aGlzc2luZ3VsYXJwYXNz\r\naW9uZnJvbW90aGVyYW5pbWFsc3doaWNoaXNhbHVzdG9mdGhlbWluZGV4Y2VlZHN0aGVzaG9ydHZl\r\naGVtZW5jZW9mYW55Y2FybmFscGxlYXN1cmU=\r\n';
that.decode(array, util.Type.MIME).then(val=>{
  // Add information as required.
2235
})
G
Gloria 已提交
2236 2237
  ```

2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250

## Type<sup>10+</sup>

Enumerates the Base64 encoding formats.

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

| Name  | Value                    | Description            |
| -------- | ------------------------ | ---------------- |
| BASIC | 0 | Basic format.|
| MIME | 1 | MIME format.|


2251
## types<sup>8+</sup>
G
Gloria 已提交
2252

G
Gloria 已提交
2253 2254
Provides APIs to check different types of built-in objects, such as ArrayBuffer, Map, and Set, so as to avoid exceptions or crashes caused by type errors.

2255
### constructor<sup>8+</sup>
G
Gloria 已提交
2256

2257
constructor()
G
Gloria 已提交
2258

2259
A constructor used to create a **Types** object.
2260

G
Gloria 已提交
2261 2262 2263
**System capability**: SystemCapability.Utils.Lang

**Example**
2264

G
Gloria 已提交
2265
  ```js
2266
  let type = new util.types();
G
Gloria 已提交
2267 2268 2269
  ```


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

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

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

G
Gloria 已提交
2276 2277
**System capability**: SystemCapability.Utils.Lang

2278 2279 2280 2281 2282 2283
**Parameters**

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

G
Gloria 已提交
2284 2285 2286 2287
**Return value**

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

**Example**
2291

G
Gloria 已提交
2292
  ```js
2293 2294
  let that = new util.types();
  let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
G
Gloria 已提交
2295 2296 2297
  ```


2298
### isArrayBufferView<sup>8+</sup>
G
Gloria 已提交
2299

2300
isArrayBufferView(value: Object): boolean
G
Gloria 已提交
2301

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

2304
**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
G
Gloria 已提交
2305 2306 2307 2308 2309

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

**Parameters**

2310 2311 2312 2313 2314 2315 2316 2317 2318
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|

**Return value**

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

**Example**

  ```js
2323 2324
  let that = new util.types();
  let result = that.isArrayBufferView(new Int8Array([]));
G
Gloria 已提交
2325 2326 2327
  ```


2328
### isArgumentsObject<sup>8+</sup>
G
Gloria 已提交
2329

2330
isArgumentsObject(value: Object): boolean
G
Gloria 已提交
2331

2332
Checks whether the input value is of the **arguments** type.
G
Gloria 已提交
2333 2334 2335

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

2336 2337 2338 2339 2340 2341
**Parameters**

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

G
Gloria 已提交
2342 2343
**Return value**

2344 2345 2346
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
G
Gloria 已提交
2347 2348 2349 2350

**Example**

  ```js
2351 2352 2353 2354 2355
  let that = new util.types();
  function foo() {
      var result = that.isArgumentsObject(arguments);
  }
  let f = foo();
G
Gloria 已提交
2356 2357 2358
  ```


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

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

2363
Checks whether the input value is of the **ArrayBuffer** type.
G
Gloria 已提交
2364 2365 2366 2367 2368

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

**Parameters**

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

**Return value**

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

**Example**

  ```js
2382 2383
  let that = new util.types();
  let result = that.isArrayBuffer(new ArrayBuffer(0));
G
Gloria 已提交
2384 2385 2386
  ```


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

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

2391
Checks whether the input value is an asynchronous function.
G
Gloria 已提交
2392 2393 2394 2395 2396

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

**Parameters**

2397 2398 2399
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
2400 2401 2402

**Return value**

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

**Example**

  ```js
2410 2411
  let that = new util.types();
  let result = that.isAsyncFunction(async function foo() {});
G
Gloria 已提交
2412 2413 2414
  ```


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

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

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

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

2423 2424 2425 2426 2427 2428
**Parameters**

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

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

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

**Example**

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


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

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

2447
Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.
G
Gloria 已提交
2448 2449 2450

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

2451 2452 2453 2454 2455 2456
**Parameters**

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

G
Gloria 已提交
2457 2458
**Return value**

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

**Example**

  ```js
2466 2467
  let that = new util.types();
  let result = that.isBoxedPrimitive(new Boolean(false));
G
Gloria 已提交
2468 2469 2470
  ```


2471
### isDataView<sup>8+</sup>
G
Gloria 已提交
2472

2473
isDataView(value: Object): boolean
G
Gloria 已提交
2474

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

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

**Parameters**

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

**Return value**

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

**Example**

  ```js
2494 2495 2496
  let that = new util.types();
  const ab = new ArrayBuffer(20);
  let result = that.isDataView(new DataView(ab));
G
Gloria 已提交
2497 2498 2499
  ```


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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

  ```js
2523 2524
  let that = new util.types();
  let result = that.isDate(new Date());
G
Gloria 已提交
2525 2526 2527
  ```


2528
### isExternal<sup>8+</sup>
G
Gloria 已提交
2529

2530
isExternal(value: Object): boolean
G
Gloria 已提交
2531

2532
Checks whether the input value is of the **native external** type.
G
Gloria 已提交
2533 2534 2535 2536 2537

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

**Parameters**

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

**Return value**

2544 2545 2546
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
G
Gloria 已提交
2547 2548 2549 2550

**Example**

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


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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

W
wusongqing 已提交
2598
**Return value**
2599

2600 2601 2602
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
Z
zengyawen 已提交
2603

W
wusongqing 已提交
2604
**Example**
G
Gloria 已提交
2605

2606
  ```js
2607 2608
  let that = new util.types();
  let result = that.isFloat64Array(new Float64Array());
W
wusongqing 已提交
2609
  ```
Z
zengyawen 已提交
2610 2611


2612
### isGeneratorFunction<sup>8+</sup>
Z
zengyawen 已提交
2613

2614
isGeneratorFunction(value: Object): boolean
Z
zengyawen 已提交
2615

2616
Checks whether the input value is a generator function.
Z
zengyawen 已提交
2617

G
Gloria 已提交
2618
**System capability**: SystemCapability.Utils.Lang
Z
zengyawen 已提交
2619

G
Gloria 已提交
2620
**Parameters**
Z
zengyawen 已提交
2621

2622 2623 2624
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
Z
zengyawen 已提交
2625

G
Gloria 已提交
2626
**Return value**
Z
zengyawen 已提交
2627

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

G
Gloria 已提交
2632
**Example**
Z
zengyawen 已提交
2633

G
Gloria 已提交
2634
  ```js
2635 2636
  let that = new util.types();
  let result = that.isGeneratorFunction(function* foo() {});
G
Gloria 已提交
2637
  ```
Z
zengyawen 已提交
2638

W
wusongqing 已提交
2639

2640
### isGeneratorObject<sup>8+</sup>
W
wusongqing 已提交
2641

2642
isGeneratorObject(value: Object): boolean
2643

2644
Checks whether the input value is a generator object.
2645

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

**Parameters**
2649

W
wusongqing 已提交
2650 2651
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2652 2653 2654 2655 2656 2657 2658
| value | Object | Yes| Object to check.|

**Return value**

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

W
wusongqing 已提交
2660
**Example**
2661

2662
  ```js
2663 2664 2665 2666
  let that = new util.types();
  function* foo() {}
  const generator = foo();
  let result = that.isGeneratorObject(generator);
W
wusongqing 已提交
2667 2668 2669
  ```


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

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

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

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

2678 2679 2680 2681 2682 2683
**Parameters**

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

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

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

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

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


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

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

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

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

**Parameters**
2707

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

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

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

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

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


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

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

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

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

**Parameters**
2735

W
wusongqing 已提交
2736 2737
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2738
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2739

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

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

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

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


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

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

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

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

2762 2763 2764 2765 2766 2767
**Parameters**

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

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

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

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

2776
  ```js
2777 2778
  let that = new util.types();
  let result = that.isMap(new Map());
W
wusongqing 已提交
2779 2780 2781
  ```


2782
### isMapIterator<sup>8+</sup>
W
wusongqing 已提交
2783

2784
isMapIterator(value: Object): boolean
W
wusongqing 已提交
2785

2786
Checks whether the input value is of the **MapIterator** type.
2787

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

2790 2791 2792 2793 2794 2795 2796
**Parameters**


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

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

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

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

2805
  ```js
2806 2807 2808
  let that = new util.types();
  const map = new Map();
  let result = that.isMapIterator(map.keys());
W
wusongqing 已提交
2809 2810 2811
  ```


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

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

2816
Checks whether the input value is of the **Error** type.
2817

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

**Parameters**
2821

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

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

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

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

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


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

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

2844
Checks whether the input value is a number object.
2845

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

**Parameters**
2849

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

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

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

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

2862
  ```js
2863 2864
  let that = new util.types();
  let result = that.isNumberObject(new Number(0));
W
wusongqing 已提交
2865 2866 2867
  ```


2868
### isPromise<sup>8+</sup>
W
wusongqing 已提交
2869

2870
isPromise(value: Object): boolean
W
wusongqing 已提交
2871

2872
Checks whether the input value is a promise.
2873

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

**Parameters**
2877

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

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

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

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

2890
  ```js
2891 2892
  let that = new util.types();
  let result = that.isPromise(Promise.resolve(1));
W
wusongqing 已提交
2893
  ```
Z
zengyawen 已提交
2894 2895


2896
### isProxy<sup>8+</sup>
Z
zengyawen 已提交
2897

2898
isProxy(value: Object): boolean
Z
zengyawen 已提交
2899

2900
Checks whether the input value is a proxy.
2901

W
wusongqing 已提交
2902 2903 2904
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2905

W
wusongqing 已提交
2906 2907
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2908
| value | Object | Yes| Object to check.|
Z
zengyawen 已提交
2909

W
wusongqing 已提交
2910
**Return value**
2911

W
wusongqing 已提交
2912 2913
| Type| Description|
| -------- | -------- |
2914
| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
W
wusongqing 已提交
2915

W
wusongqing 已提交
2916
**Example**
2917

2918
  ```js
2919 2920 2921 2922
  let that = new util.types();
  const target = {};
  const proxy = new Proxy(target, {});
  let result = that.isProxy(proxy);
W
wusongqing 已提交
2923 2924 2925
  ```


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

2928 2929 2930
isRegExp(value: Object): boolean

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

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

**Parameters**
2935

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

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

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

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

2948
  ```js
2949 2950
  let that = new util.types();
  let result = that.isRegExp(new RegExp('abc'));
W
wusongqing 已提交
2951 2952 2953
  ```


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

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

2958
Checks whether the input value is of the **Set** type.
2959

W
wusongqing 已提交
2960 2961 2962
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2963

W
wusongqing 已提交
2964 2965
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
2966
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2967

W
wusongqing 已提交
2968
**Return value**
2969

W
wusongqing 已提交
2970 2971
| Type| Description|
| -------- | -------- |
2972
| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
W
wusongqing 已提交
2973

W
wusongqing 已提交
2974
**Example**
2975

2976
  ```js
2977 2978
  let that = new util.types();
  let result = that.isSet(new Set());
W
wusongqing 已提交
2979 2980
  ```

G
Gloria 已提交
2981

2982
### isSetIterator<sup>8+</sup>
W
wusongqing 已提交
2983

2984
isSetIterator(value: Object): boolean
W
wusongqing 已提交
2985

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

G
Gloria 已提交
2988 2989
**System capability**: SystemCapability.Utils.Lang

2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001
**Parameters**

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

**Return value**

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

G
Gloria 已提交
3002 3003 3004
**Example**

  ```js
3005 3006 3007
  let that = new util.types();
  const set = new Set();
  let result = that.isSetIterator(set.keys());
G
Gloria 已提交
3008 3009 3010
  ```


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

3013 3014 3015
isStringObject(value: Object): boolean

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

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

**Parameters**

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

**Return value**

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

**Example**

  ```js
3034 3035
  let that = new util.types();
  let result = that.isStringObject(new String('foo'));
G
Gloria 已提交
3036 3037 3038
  ```


3039
### isSymbolObjec<sup>8+</sup>
G
Gloria 已提交
3040

3041
isSymbolObject(value: Object): boolean
G
Gloria 已提交
3042

3043
Checks whether the input value is a symbol object.
G
Gloria 已提交
3044 3045 3046 3047 3048

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

**Parameters**

3049 3050 3051
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
3052 3053 3054

**Return value**

3055 3056 3057
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
G
Gloria 已提交
3058 3059 3060 3061

**Example**

  ```js
3062 3063 3064
  let that = new util.types();
  const symbols = Symbol('foo');
  let result = that.isSymbolObject(Object(symbols));
G
Gloria 已提交
3065 3066 3067
  ```


3068
### isTypedArray<sup>8+</sup>
G
Gloria 已提交
3069

3070
isTypedArray(value: Object): boolean
G
Gloria 已提交
3071

3072 3073 3074
Checks whether the input value is of the **TypedArray** type.

**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
G
Gloria 已提交
3075 3076 3077 3078 3079

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

**Parameters**

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

**Return value**

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

**Example**

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


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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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


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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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


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

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

3158
Checks whether the input value is of the **Uint16Array** type.
G
Gloria 已提交
3159 3160 3161 3162 3163

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

**Parameters**

3164 3165 3166
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
G
Gloria 已提交
3167 3168 3169

**Return value**

3170 3171 3172
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
G
Gloria 已提交
3173 3174 3175 3176

**Example**

  ```js
3177 3178
  let that = new util.types();
  let result = that.isUint16Array(new Uint16Array([]));
G
Gloria 已提交
3179 3180 3181
  ```


3182
### isUint32Array<sup>8+</sup>
G
Gloria 已提交
3183

3184
isUint32Array(value: Object): boolean
G
Gloria 已提交
3185

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

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

3190
**Parameters**
W
wusongqing 已提交
3191

3192 3193 3194
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
3195

3196 3197 3198 3199 3200
**Return value**

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

**Example**
3203

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


3210
### isWeakMap<sup>8+</sup>
Z
zengyawen 已提交
3211

3212
isWeakMap(value: Object): boolean
Z
zengyawen 已提交
3213

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

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

**Parameters**
3219

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

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

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

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

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


3238
### isWeakSet<sup>8+</sup>
W
wusongqing 已提交
3239

3240
isWeakSet(value: Object): boolean
W
wusongqing 已提交
3241

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

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

**Parameters**
3247

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

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

W
wusongqing 已提交
3254 3255
| Type| Description|
| -------- | -------- |
3256
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
W
wusongqing 已提交
3257

W
wusongqing 已提交
3258
**Example**
3259

3260
  ```js
3261 3262
  let that = new util.types();
  let result = that.isWeakSet(new WeakSet());
W
wusongqing 已提交
3263 3264 3265
  ```


3266
### isBigInt64Array<sup>8+</sup>
Z
zengyawen 已提交
3267

3268
isBigInt64Array(value: Object): boolean
Z
zengyawen 已提交
3269

3270
Checks whether the input value is of the **BigInt64Array** type.
3271

W
wusongqing 已提交
3272 3273 3274
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3275

W
wusongqing 已提交
3276 3277
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3278
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3279

W
wusongqing 已提交
3280
**Return value**
3281

W
wusongqing 已提交
3282 3283
| Type| Description|
| -------- | -------- |
3284
| boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3285

W
wusongqing 已提交
3286
**Example**
3287

3288
  ```js
3289 3290
  let that = new util.types();
  let result = that.isBigInt64Array(new BigInt64Array([]));
W
wusongqing 已提交
3291 3292 3293
  ```


3294
### isBigUint64Array<sup>8+</sup>
Z
zengyawen 已提交
3295

3296
isBigUint64Array(value: Object): boolean
Z
zengyawen 已提交
3297

3298
Checks whether the input value is of the **BigUint64Array** type.
3299

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

**Parameters**
3303

W
wusongqing 已提交
3304 3305
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3306
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3307

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

W
wusongqing 已提交
3310 3311
| Type| Description|
| -------- | -------- |
3312
| boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.|
W
wusongqing 已提交
3313

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

3316
  ```js
3317 3318
  let that = new util.types();
  let result = that.isBigUint64Array(new BigUint64Array([]));
W
wusongqing 已提交
3319 3320 3321
  ```


3322
### isModuleNamespaceObject<sup>8+</sup>
W
wusongqing 已提交
3323

3324
isModuleNamespaceObject(value: Object): boolean
W
wusongqing 已提交
3325

3326
Checks whether the input value is a module namespace object.
3327

W
wusongqing 已提交
3328 3329 3330
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3331

W
wusongqing 已提交
3332 3333
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3334
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3335

W
wusongqing 已提交
3336
**Return value**
3337

W
wusongqing 已提交
3338 3339
| Type| Description|
| -------- | -------- |
3340
| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.|
W
wusongqing 已提交
3341

W
wusongqing 已提交
3342
**Example**
3343

3344
  ```js
3345 3346 3347
  import url from '@ohos.url'
  let that = new util.types();
  let result = that.isModuleNamespaceObject(url);
W
wusongqing 已提交
3348 3349 3350
  ```


3351
### isSharedArrayBuffer<sup>8+</sup>
Z
zengyawen 已提交
3352

3353
isSharedArrayBuffer(value: Object): boolean
Z
zengyawen 已提交
3354

3355
Checks whether the input value is of the **SharedArrayBuffer** type.
3356

W
wusongqing 已提交
3357 3358 3359
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3360

W
wusongqing 已提交
3361 3362
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3363
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
3364

W
wusongqing 已提交
3365
**Return value**
3366

W
wusongqing 已提交
3367 3368
| Type| Description|
| -------- | -------- |
3369
| boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
3370

W
wusongqing 已提交
3371
**Example**
3372

3373
  ```js
3374 3375
  let that = new util.types();
  let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
W
wusongqing 已提交
3376 3377
  ```

3378
## LruBuffer<sup>(deprecated)</sup>
W
wusongqing 已提交
3379

3380 3381 3382
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache<sup>9+</sup>](#lrucache9) instead.
W
wusongqing 已提交
3383

3384
### Attributes
W
wusongqing 已提交
3385

W
wusongqing 已提交
3386 3387
**System capability**: SystemCapability.Utils.Lang

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

W
wusongqing 已提交
3392
**Example**
3393

3394
  ```js
3395 3396 3397 3398
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(1,8);
  let result = pro.length;
W
wusongqing 已提交
3399 3400
  ```

3401
### constructor<sup>(deprecated)</sup>
W
wusongqing 已提交
3402

3403
constructor(capacity?: number)
W
wusongqing 已提交
3404

3405
A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
W
wusongqing 已提交
3406

3407 3408
> **NOTE**
>
G
Gloria 已提交
3409
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.constructor<sup>9+</sup>](#constructor9-3) instead.
W
wusongqing 已提交
3410

W
wusongqing 已提交
3411 3412 3413
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3414

W
wusongqing 已提交
3415 3416
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
3417
| capacity | number | No| Capacity of the **LruBuffer** to create. The default value is **64**.|
W
wusongqing 已提交
3418

W
wusongqing 已提交
3419
**Example**
3420

3421
  ```js
3422
  let lrubuffer= new util.LruBuffer();
W
wusongqing 已提交
3423 3424
  ```

3425
### updateCapacity<sup>(deprecated)</sup>
W
wusongqing 已提交
3426

3427
updateCapacity(newCapacity: number): void
W
wusongqing 已提交
3428

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

3431 3432
> **NOTE**
>
G
Gloria 已提交
3433
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.updateCapacity<sup>9+</sup>](#updatecapacity9) instead.
W
wusongqing 已提交
3434

W
wusongqing 已提交
3435 3436 3437
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3438

W
wusongqing 已提交
3439 3440
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3441
| newCapacity | number | Yes| New capacity of the **LruBuffer**.|
W
wusongqing 已提交
3442

W
wusongqing 已提交
3443
**Example**
3444

3445
  ```js
3446 3447
  let pro = new util.LruBuffer();
  let result = pro.updateCapacity(100);
W
wusongqing 已提交
3448 3449
  ```

3450
### toString<sup>(deprecated)</sup>
W
wusongqing 已提交
3451

3452
toString(): string
W
wusongqing 已提交
3453

3454
Obtains the string representation of this **LruBuffer** object.
W
wusongqing 已提交
3455

3456 3457
> **NOTE**
>
G
Gloria 已提交
3458
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.toString<sup>9+</sup>](#tostring9) instead.
W
wusongqing 已提交
3459

W
wusongqing 已提交
3460 3461 3462
**System capability**: SystemCapability.Utils.Lang

**Return value**
3463

W
wusongqing 已提交
3464 3465
| Type| Description|
| -------- | -------- |
3466
| string | String representation of this **LruBuffer** object.|
W
wusongqing 已提交
3467

W
wusongqing 已提交
3468
**Example**
3469

3470
  ```js
3471 3472 3473 3474 3475
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  pro.remove(20);
  let result = pro.toString();
W
wusongqing 已提交
3476 3477
  ```

3478
### getCapacity<sup>(deprecated)</sup>
W
wusongqing 已提交
3479

3480
getCapacity(): number
W
wusongqing 已提交
3481

3482
Obtains the capacity of this buffer.
W
wusongqing 已提交
3483

3484 3485
> **NOTE**
>
G
Gloria 已提交
3486
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCapacity<sup>9+</sup>](#getcapacity9) instead.
W
wusongqing 已提交
3487

W
wusongqing 已提交
3488 3489 3490
**System capability**: SystemCapability.Utils.Lang

**Return value**
3491

W
wusongqing 已提交
3492 3493
| Type| Description|
| -------- | -------- |
3494
| number | Capacity of this buffer.|
W
wusongqing 已提交
3495

W
wusongqing 已提交
3496
**Example**
3497
  ```js
3498 3499
  let pro = new util.LruBuffer();
  let result = pro.getCapacity();
W
wusongqing 已提交
3500 3501
  ```

3502
### clear<sup>(deprecated)</sup>
W
wusongqing 已提交
3503

3504
clear(): void
W
wusongqing 已提交
3505

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

3508 3509
> **NOTE**
>
G
Gloria 已提交
3510
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.clear<sup>9+</sup>](#clear9) instead.
Z
zengyawen 已提交
3511

W
wusongqing 已提交
3512 3513
**System capability**: SystemCapability.Utils.Lang

3514
**Example**
3515

3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530
  ```js
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.length;
  pro.clear();
  ```

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

getCreateCount(): number

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

> **NOTE**
>
G
Gloria 已提交
3531
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
3532 3533

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

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

W
wusongqing 已提交
3537 3538
| Type| Description|
| -------- | -------- |
3539
| number | Number of return values for **createDefault()**.|
W
wusongqing 已提交
3540

W
wusongqing 已提交
3541
**Example**
3542

3543
  ```js
3544 3545 3546
  let pro = new util.LruBuffer();
  pro.put(1,8);
  let result = pro.getCreateCount();
W
wusongqing 已提交
3547 3548
  ```

3549
### getMissCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3550

3551
getMissCount(): number
W
wusongqing 已提交
3552

3553
Obtains the number of times that the queried values are mismatched.
W
wusongqing 已提交
3554

3555 3556
> **NOTE**
>
G
Gloria 已提交
3557
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMissCount<sup>9+</sup>](#getmisscount9) instead.
W
wusongqing 已提交
3558

W
wusongqing 已提交
3559 3560 3561
**System capability**: SystemCapability.Utils.Lang

**Return value**
3562

W
wusongqing 已提交
3563 3564
| Type| Description|
| -------- | -------- |
3565
| number | Number of times that the queried values are mismatched.|
W
wusongqing 已提交
3566

W
wusongqing 已提交
3567
**Example**
3568

3569
  ```js
3570 3571 3572 3573
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  let result = pro.getMissCount();
W
wusongqing 已提交
3574 3575
  ```

3576
### getRemovalCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3577

3578
getRemovalCount(): number
W
wusongqing 已提交
3579

3580
Obtains the number of removals from this buffer.
W
wusongqing 已提交
3581

3582 3583
> **NOTE**
>
G
Gloria 已提交
3584
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
W
wusongqing 已提交
3585

W
wusongqing 已提交
3586 3587 3588
**System capability**: SystemCapability.Utils.Lang

**Return value**
3589

W
wusongqing 已提交
3590 3591
| Type| Description|
| -------- | -------- |
3592
| number | Number of removals from the buffer.|
W
wusongqing 已提交
3593

W
wusongqing 已提交
3594
**Example**
3595

3596
  ```js
3597 3598 3599 3600 3601
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.updateCapacity(2);
  pro.put(50,22);
  let result = pro.getRemovalCount();
W
wusongqing 已提交
3602 3603
  ```

3604
### getMatchCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3605

3606
getMatchCount(): number
W
wusongqing 已提交
3607

3608
Obtains the number of times that the queried values are matched.
W
wusongqing 已提交
3609

3610 3611
> **NOTE**
>
G
Gloria 已提交
3612
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
W
wusongqing 已提交
3613

W
wusongqing 已提交
3614 3615 3616
**System capability**: SystemCapability.Utils.Lang

**Return value**
3617

W
wusongqing 已提交
3618 3619
| Type| Description|
| -------- | -------- |
3620
| number | Number of times that the queried values are matched.|
W
wusongqing 已提交
3621

W
wusongqing 已提交
3622
**Example**
3623

3624
  ```js
3625 3626 3627 3628
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  let result = pro.getMatchCount();
W
wusongqing 已提交
3629 3630
  ```

3631
### getPutCount<sup>(deprecated)</sup>
W
wusongqing 已提交
3632

3633
getPutCount(): number
W
wusongqing 已提交
3634

3635
Obtains the number of additions to this buffer.
W
wusongqing 已提交
3636

3637 3638
> **NOTE**
>
G
Gloria 已提交
3639
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getPutCount<sup>9+</sup>](#getputcount9) instead.
W
wusongqing 已提交
3640

W
wusongqing 已提交
3641 3642 3643
**System capability**: SystemCapability.Utils.Lang

**Return value**
3644

W
wusongqing 已提交
3645 3646
| Type| Description|
| -------- | -------- |
3647
| number | Number of additions to the buffer.|
W
wusongqing 已提交
3648

W
wusongqing 已提交
3649
**Example**
3650

3651
  ```js
3652 3653 3654
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.getPutCount();
W
wusongqing 已提交
3655 3656
  ```

3657
### isEmpty<sup>(deprecated)</sup>
W
wusongqing 已提交
3658

3659
isEmpty(): boolean
W
wusongqing 已提交
3660

3661
Checks whether this buffer is empty.
W
wusongqing 已提交
3662

3663 3664
> **NOTE**
>
G
Gloria 已提交
3665
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.isEmpty<sup>9+</sup>](#isempty9) instead.
W
wusongqing 已提交
3666

W
wusongqing 已提交
3667 3668 3669
**System capability**: SystemCapability.Utils.Lang

**Return value**
3670

W
wusongqing 已提交
3671 3672
| Type| Description|
| -------- | -------- |
3673
| boolean | Returns **true** if the buffer does not contain any value.|
W
wusongqing 已提交
3674

W
wusongqing 已提交
3675
**Example**
3676

3677
  ```js
3678 3679 3680
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.isEmpty();
W
wusongqing 已提交
3681 3682
  ```

3683
### get<sup>(deprecated)</sup>
W
wusongqing 已提交
3684

3685
get(key: K): V | undefined
W
wusongqing 已提交
3686

3687
Obtains the value of the specified key.
W
wusongqing 已提交
3688

3689 3690
> **NOTE**
>
G
Gloria 已提交
3691
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.get<sup>9+</sup>](#get9) instead.
W
wusongqing 已提交
3692

W
wusongqing 已提交
3693 3694 3695
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3696

W
wusongqing 已提交
3697 3698
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3699
| key | K | Yes| Key based on which the value is queried.|
W
wusongqing 已提交
3700

W
wusongqing 已提交
3701
**Return value**
3702

W
wusongqing 已提交
3703 3704
| Type| Description|
| -------- | -------- |
3705
| V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
W
wusongqing 已提交
3706

W
wusongqing 已提交
3707
**Example**
3708

3709
  ```js
3710 3711 3712
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result  = pro.get(2);
W
wusongqing 已提交
3713 3714
  ```

3715
### put<sup>(deprecated)</sup>
W
wusongqing 已提交
3716

3717
put(key: K,value: V): V
W
wusongqing 已提交
3718

3719
Adds a key-value pair to this buffer.
W
wusongqing 已提交
3720

3721 3722
> **NOTE**
>
G
Gloria 已提交
3723
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.put<sup>9+</sup>](#put9) instead.
W
wusongqing 已提交
3724

W
wusongqing 已提交
3725 3726 3727
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3728

W
wusongqing 已提交
3729 3730
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3731 3732
| key | K | Yes| Key of the key-value pair to add.|
| value | V | Yes| Value of the key-value pair to add.|
W
wusongqing 已提交
3733

W
wusongqing 已提交
3734
**Return value**
3735

W
wusongqing 已提交
3736 3737
| Type| Description|
| -------- | -------- |
3738
| V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. |
W
wusongqing 已提交
3739

W
wusongqing 已提交
3740
**Example**
3741

3742
  ```js
3743 3744
  let pro = new util.LruBuffer();
  let result = pro.put(2,10);
W
wusongqing 已提交
3745 3746
  ```

3747
### values<sup>(deprecated)</sup>
W
wusongqing 已提交
3748

3749
values(): V[]
W
wusongqing 已提交
3750

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

3753 3754
> **NOTE**
>
G
Gloria 已提交
3755
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.values<sup>9+</sup>](#values9) instead.
Z
zengyawen 已提交
3756

W
wusongqing 已提交
3757 3758 3759
**System capability**: SystemCapability.Utils.Lang

**Return value**
3760

W
wusongqing 已提交
3761 3762
| Type| Description|
| -------- | -------- |
3763
| V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|
W
wusongqing 已提交
3764

W
wusongqing 已提交
3765
**Example**
3766

3767
  ```js
3768 3769 3770 3771 3772
  let pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(2,"anhu");
  pro.put("afaf","grfb");
  let result = pro.values();
W
wusongqing 已提交
3773 3774
  ```

3775
### keys<sup>(deprecated)</sup>
W
wusongqing 已提交
3776

3777
keys(): K[]
W
wusongqing 已提交
3778

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

3781 3782
> **NOTE**
>
G
Gloria 已提交
3783
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.keys<sup>9+</sup>](#keys9) instead.
Z
zengyawen 已提交
3784

W
wusongqing 已提交
3785 3786 3787
**System capability**: SystemCapability.Utils.Lang

**Return value**
3788

W
wusongqing 已提交
3789 3790
| Type| Description|
| -------- | -------- |
3791
| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
W
wusongqing 已提交
3792

W
wusongqing 已提交
3793
**Example**
G
Gloria 已提交
3794

3795
  ```js
3796 3797 3798
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.keys();
W
wusongqing 已提交
3799 3800
  ```

3801
### remove<sup>(deprecated)</sup>
W
wusongqing 已提交
3802

3803
remove(key: K): V | undefined
W
wusongqing 已提交
3804

3805
Removes the specified key and its value from this buffer.
W
wusongqing 已提交
3806

3807 3808
> **NOTE**
>
G
Gloria 已提交
3809
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.remove<sup>9+</sup>](#remove9) instead.
W
wusongqing 已提交
3810

W
wusongqing 已提交
3811 3812 3813
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3814

W
wusongqing 已提交
3815 3816
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3817
| key | K | Yes| Key to remove.|
W
wusongqing 已提交
3818

W
wusongqing 已提交
3819
**Return value**
3820

W
wusongqing 已提交
3821 3822
| Type| Description|
| -------- | -------- |
3823
| 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 已提交
3824

W
wusongqing 已提交
3825
**Example**
3826
  ```js
3827 3828 3829
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.remove(20);
W
wusongqing 已提交
3830 3831
  ```

3832
### afterRemoval<sup>(deprecated)</sup>
W
wusongqing 已提交
3833

3834
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
W
wusongqing 已提交
3835

3836
Performs subsequent operations after a value is removed.
W
wusongqing 已提交
3837

3838 3839
> **NOTE**
>
G
Gloria 已提交
3840
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.afterRemoval<sup>9+</sup>](#afterremoval9) instead.
W
wusongqing 已提交
3841

W
wusongqing 已提交
3842 3843 3844
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3845

W
wusongqing 已提交
3846 3847
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
G
Gloria 已提交
3848
| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity.|
3849 3850 3851
| key | K | Yes| Key removed.|
| value | V | Yes| Value removed.|
| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
W
wusongqing 已提交
3852

W
wusongqing 已提交
3853
**Example**
3854

3855
  ```js
3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872
  let arr = [];
  class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
  {
  	constructor()
  	{
  		super();
  	}
  	afterRemoval(isEvict, key, value, newValue)
  	{
  		if (isEvict === false)
  		{
  			arr = [key, value, newValue];
  		}
  	}
  }
  let lru = new ChildLruBuffer();
  lru.afterRemoval(false,10,30,null);
W
wusongqing 已提交
3873 3874
  ```

3875
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
3876

3877
contains(key: K): boolean
W
wusongqing 已提交
3878

3879
Checks whether this buffer contains the specified key.
W
wusongqing 已提交
3880

3881 3882 3883

> **NOTE**
>
G
Gloria 已提交
3884
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.contains<sup>9+</sup>](#contains9) instead.
W
wusongqing 已提交
3885

W
wusongqing 已提交
3886 3887 3888
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3889

W
wusongqing 已提交
3890 3891
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3892
| key | K | Yes| Key to check.|
W
wusongqing 已提交
3893

W
wusongqing 已提交
3894
**Return value**
3895

W
wusongqing 已提交
3896 3897
| Type| Description|
| -------- | -------- |
3898
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
W
wusongqing 已提交
3899

W
wusongqing 已提交
3900
**Example**
3901

3902
  ```js
3903 3904 3905
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.contains(20);
W
wusongqing 已提交
3906 3907
  ```

3908
### createDefault<sup>(deprecated)</sup>
W
wusongqing 已提交
3909

3910
createDefault(key: K): V
W
wusongqing 已提交
3911

3912
Creates a value if the value of the specified key is not available.
W
wusongqing 已提交
3913

3914 3915
> **NOTE**
>
G
Gloria 已提交
3916
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.createDefault<sup>9+</sup>](#createdefault9) instead.
W
wusongqing 已提交
3917

W
wusongqing 已提交
3918 3919 3920
**System capability**: SystemCapability.Utils.Lang

**Parameters**
3921

W
wusongqing 已提交
3922 3923
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
3924
| key | K | Yes| Key of which the value is missing.|
W
wusongqing 已提交
3925

W
wusongqing 已提交
3926
**Return value**
3927

W
wusongqing 已提交
3928 3929
| Type| Description|
| -------- | -------- |
3930
| V | Value of the key.|
W
wusongqing 已提交
3931

W
wusongqing 已提交
3932
**Example**
3933

3934
  ```js
3935 3936
  let pro = new util.LruBuffer();
  let result = pro.createDefault(50);
W
wusongqing 已提交
3937 3938
  ```

3939
### entries<sup>(deprecated)</sup>
W
wusongqing 已提交
3940

3941
entries(): IterableIterator&lt;[K,V]&gt;
W
wusongqing 已提交
3942

3943
Obtains a new iterator object that contains all key-value pairs in this object.
W
wusongqing 已提交
3944

3945 3946
> **NOTE**
>
G
Gloria 已提交
3947
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.entries<sup>9+</sup>](#entries9) instead.
W
wusongqing 已提交
3948

W
wusongqing 已提交
3949 3950 3951
**System capability**: SystemCapability.Utils.Lang

**Return value**
3952

W
wusongqing 已提交
3953 3954
| Type| Description|
| -------- | -------- |
3955
| [K,&nbsp;V] | Iterable array.|
W
wusongqing 已提交
3956

W
wusongqing 已提交
3957
**Example**
3958

3959
  ```js
3960 3961 3962
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro.entries();
W
wusongqing 已提交
3963 3964
  ```

3965
### [Symbol.iterator]<sup>(deprecated)</sup>
W
wusongqing 已提交
3966

3967
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
W
wusongqing 已提交
3968

3969
Obtains a two-dimensional array in key-value pairs.
W
wusongqing 已提交
3970

3971 3972
> **NOTE**
>
G
Gloria 已提交
3973
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
W
wusongqing 已提交
3974

W
wusongqing 已提交
3975 3976 3977
**System capability**: SystemCapability.Utils.Lang

**Return value**
3978

W
wusongqing 已提交
3979 3980
| Type| Description|
| -------- | -------- |
3981
| [K,&nbsp;V] | Two-dimensional array in key-value pairs.|
W
wusongqing 已提交
3982

W
wusongqing 已提交
3983
**Example**
3984

3985
  ```js
3986 3987 3988
  let pro = new util.LruBuffer();
  pro.put(2,10);
  let result = pro[Symbol.iterator]();
W
wusongqing 已提交
3989 3990
  ```

3991
## Scope<sup>(deprecated)</sup>
W
wusongqing 已提交
3992

3993 3994 3995
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper<sup>9+</sup>](#scopehelper9) instead.
W
wusongqing 已提交
3996

3997 3998 3999 4000 4001 4002 4003 4004
### constructor<sup>(deprecated)</sup>

constructor(lowerObj: ScopeType, upperObj: ScopeType)

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

> **NOTE**
>
G
Gloria 已提交
4005
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.constructor<sup>9+</sup>](#constructor9-4) instead.
Z
zengyawen 已提交
4006 4007


W
wusongqing 已提交
4008 4009 4010
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4011

W
wusongqing 已提交
4012 4013
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4014 4015
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
W
wusongqing 已提交
4016

W
wusongqing 已提交
4017
**Example**
4018
  ```js
4019 4020 4021
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
4022 4023
  ```

4024
### toString<sup>(deprecated)</sup>
W
wusongqing 已提交
4025

4026
toString(): string
W
wusongqing 已提交
4027

4028
Obtains a string representation that contains this **Scope**.
Z
zengyawen 已提交
4029

4030 4031
> **NOTE**
>
G
Gloria 已提交
4032
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.toString<sup>9+</sup>](#tostring9-1) instead.
Z
zengyawen 已提交
4033

W
wusongqing 已提交
4034 4035 4036
**System capability**: SystemCapability.Utils.Lang

**Return value**
4037

W
wusongqing 已提交
4038 4039
| Type| Description|
| -------- | -------- |
4040
| string | String representation containing the **Scope**.|
W
wusongqing 已提交
4041

W
wusongqing 已提交
4042
**Example**
4043

4044
  ```js
4045 4046 4047 4048
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.toString();
W
wusongqing 已提交
4049 4050
  ```

4051
### intersect<sup>(deprecated)</sup>
W
wusongqing 已提交
4052

4053
intersect(range: Scope): Scope
W
wusongqing 已提交
4054

4055
Obtains the intersection of this **Scope** and the given **Scope**.
Z
zengyawen 已提交
4056

4057 4058
> **NOTE**
>
G
Gloria 已提交
4059
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9) instead.
Z
zengyawen 已提交
4060

W
wusongqing 已提交
4061 4062 4063
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4064

W
wusongqing 已提交
4065 4066
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4067
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
4068

W
wusongqing 已提交
4069
**Return value**
4070

W
wusongqing 已提交
4071 4072
| Type| Description|
| -------- | -------- |
4073
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
4074

W
wusongqing 已提交
4075
**Example**
4076

4077
  ```js
4078 4079 4080 4081 4082 4083 4084
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let tempMiDF = new Temperature(35);
  let tempMidS = new Temperature(39);
  let rangeFir = new util.Scope(tempMiDF, tempMidS);
  range.intersect(rangeFir );
W
wusongqing 已提交
4085 4086
  ```

4087
### intersect<sup>(deprecated)</sup>
W
wusongqing 已提交
4088

4089
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
W
wusongqing 已提交
4090

4091
Obtains the intersection of this **Scope** and the given lower and upper limits.
W
wusongqing 已提交
4092

4093 4094
> **NOTE**
>
G
Gloria 已提交
4095
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9-1) instead.
W
wusongqing 已提交
4096

W
wusongqing 已提交
4097 4098 4099
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4100

W
wusongqing 已提交
4101 4102
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4103 4104
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
4105

W
wusongqing 已提交
4106
**Return value**
4107

W
wusongqing 已提交
4108 4109
| Type| Description|
| -------- | -------- |
4110
| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
4111

W
wusongqing 已提交
4112
**Example**
4113

4114
  ```js
4115 4116 4117 4118 4119 4120
  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 已提交
4121 4122
  ```

4123
### getUpper<sup>(deprecated)</sup>
W
wusongqing 已提交
4124

4125
getUpper(): ScopeType
W
wusongqing 已提交
4126

4127
Obtains the upper limit of this **Scope**.
W
wusongqing 已提交
4128

4129 4130
> **NOTE**
>
G
Gloria 已提交
4131
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getUpper<sup>9+</sup>](#getupper9) instead.
W
wusongqing 已提交
4132

W
wusongqing 已提交
4133 4134 4135
**System capability**: SystemCapability.Utils.Lang

**Return value**
4136

W
wusongqing 已提交
4137 4138
| Type| Description|
| -------- | -------- |
4139
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
W
wusongqing 已提交
4140

W
wusongqing 已提交
4141
**Example**
4142

4143
  ```js
4144 4145 4146 4147
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getUpper();
W
wusongqing 已提交
4148 4149
  ```

4150
### getLower<sup>(deprecated)</sup>
W
wusongqing 已提交
4151

4152
getLower(): ScopeType
W
wusongqing 已提交
4153

4154
Obtains the lower limit of this **Scope**.
W
wusongqing 已提交
4155

4156 4157
> **NOTE**
>
G
Gloria 已提交
4158
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getLower<sup>9+</sup>](#getlower9) instead.
W
wusongqing 已提交
4159

W
wusongqing 已提交
4160 4161 4162
**System capability**: SystemCapability.Utils.Lang

**Return value**
4163

W
wusongqing 已提交
4164 4165
| Type| Description|
| -------- | -------- |
4166
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
W
wusongqing 已提交
4167

W
wusongqing 已提交
4168
**Example**
4169

4170
  ```js
4171 4172 4173 4174
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getLower();
W
wusongqing 已提交
4175 4176
  ```

4177
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
4178

4179
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
W
wusongqing 已提交
4180

4181
Obtains the union set of this **Scope** and the given lower and upper limits.
Z
zengyawen 已提交
4182

4183 4184
> **NOTE**
>
G
Gloria 已提交
4185
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9) instead.
Z
zengyawen 已提交
4186

W
wusongqing 已提交
4187 4188 4189
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4190

W
wusongqing 已提交
4191 4192
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4193 4194
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
4195

W
wusongqing 已提交
4196
**Return value**
4197

W
wusongqing 已提交
4198 4199
| Type| Description|
| -------- | -------- |
4200
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
4201

W
wusongqing 已提交
4202
**Example**
4203

4204
  ```js
4205 4206 4207 4208 4209 4210
  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 已提交
4211 4212
  ```

4213
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
4214

4215
expand(range: Scope): Scope
W
wusongqing 已提交
4216

4217
Obtains the union set of this **Scope** and the given **Scope**.
Z
zengyawen 已提交
4218

4219 4220
> **NOTE**
>
G
Gloria 已提交
4221
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-1) instead.
Z
zengyawen 已提交
4222

W
wusongqing 已提交
4223 4224 4225
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4226

W
wusongqing 已提交
4227 4228
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4229
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
4230

W
wusongqing 已提交
4231
**Return value**
4232

W
wusongqing 已提交
4233 4234
| Type| Description|
| -------- | -------- |
4235
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
4236

W
wusongqing 已提交
4237
**Example**
4238

4239
  ```js
4240 4241 4242 4243 4244 4245 4246
  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 已提交
4247 4248
  ```

4249
### expand<sup>(deprecated)</sup>
W
wusongqing 已提交
4250

4251
expand(value: ScopeType): Scope
W
wusongqing 已提交
4252

4253
Obtains the union set of this **Scope** and the given value.
W
wusongqing 已提交
4254

4255 4256
> **NOTE**
>
G
Gloria 已提交
4257
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-2) instead.
W
wusongqing 已提交
4258

W
wusongqing 已提交
4259 4260 4261
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4262

W
wusongqing 已提交
4263 4264
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4265
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
4266

W
wusongqing 已提交
4267
**Return value**
4268

W
wusongqing 已提交
4269 4270
| Type| Description|
| -------- | -------- |
4271
| [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.|
W
wusongqing 已提交
4272

W
wusongqing 已提交
4273
**Example**
4274

4275
  ```js
4276 4277 4278 4279 4280
  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 已提交
4281 4282
  ```

4283
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
4284

4285
contains(value: ScopeType): boolean
W
wusongqing 已提交
4286

4287
Checks whether a value is within this **Scope**.
W
wusongqing 已提交
4288

4289 4290
> **NOTE**
>
G
Gloria 已提交
4291
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-1) instead.
W
wusongqing 已提交
4292

W
wusongqing 已提交
4293 4294 4295
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4296

W
wusongqing 已提交
4297 4298
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4299
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
4300

W
wusongqing 已提交
4301
**Return value**
4302

W
wusongqing 已提交
4303 4304
| Type| Description|
| -------- | -------- |
4305
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
4306

W
wusongqing 已提交
4307
**Example**
4308

4309
  ```js
4310 4311 4312 4313 4314
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let range = new util.Scope(tempLower, tempUpper);
  range.contains(tempMiDF);
W
wusongqing 已提交
4315 4316
  ```

4317
### contains<sup>(deprecated)</sup>
W
wusongqing 已提交
4318

4319
contains(range: Scope): boolean
W
wusongqing 已提交
4320

4321
Checks whether a range is within this **Scope**.
W
wusongqing 已提交
4322

4323 4324
> **NOTE**
>
G
Gloria 已提交
4325
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-2) instead.
W
wusongqing 已提交
4326

W
wusongqing 已提交
4327 4328 4329
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4330

W
wusongqing 已提交
4331 4332
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4333
| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
W
wusongqing 已提交
4334

W
wusongqing 已提交
4335
**Return value**
4336

W
wusongqing 已提交
4337 4338
| Type| Description|
| -------- | -------- |
4339
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
4340

W
wusongqing 已提交
4341
**Example**
4342

4343
  ```js
4344 4345 4346 4347 4348 4349 4350
  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 已提交
4351 4352
  ```

4353
### clamp<sup>(deprecated)</sup>
W
wusongqing 已提交
4354 4355


4356
clamp(value: ScopeType): ScopeType
W
wusongqing 已提交
4357

4358 4359 4360 4361
Limits a value to this **Scope**.

> **NOTE**
>
G
Gloria 已提交
4362
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.clamp<sup>9+</sup>](#clamp9) instead.
W
wusongqing 已提交
4363

W
wusongqing 已提交
4364 4365 4366
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4367

W
wusongqing 已提交
4368 4369
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4370
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
4371

W
wusongqing 已提交
4372
**Return value**
4373

W
wusongqing 已提交
4374 4375
| Type| Description|
| -------- | -------- |
4376
| [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 已提交
4377

W
wusongqing 已提交
4378
**Example**
4379

4380
  ```js
4381 4382 4383 4384 4385
  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 已提交
4386 4387 4388
  ```


4389
## Base64<sup>(deprecated)</sup>
W
wusongqing 已提交
4390

4391 4392 4393
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper<sup>9+</sup>](#base64helper9) instead.
W
wusongqing 已提交
4394

4395
### constructor<sup>(deprecated)</sup>
W
wusongqing 已提交
4396

4397
constructor()
4398

4399
A constructor used to create a **Base64** object.
W
wusongqing 已提交
4400

4401 4402
> **NOTE**
>
G
Gloria 已提交
4403
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.constructor<sup>9+</sup>](#constructor9-5) instead.
4404

4405
**System capability**: SystemCapability.Utils.Lang
W
wusongqing 已提交
4406

W
wusongqing 已提交
4407
**Example**
4408

4409
  ```js
4410
  let base64 = new  util.Base64();
W
wusongqing 已提交
4411 4412
  ```

4413
### encodeSync<sup>(deprecated)</sup>
W
wusongqing 已提交
4414

4415
encodeSync(src: Uint8Array): Uint8Array
W
wusongqing 已提交
4416

4417
Encodes the input content.
W
wusongqing 已提交
4418

4419 4420
> **NOTE**
>
G
Gloria 已提交
4421
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeSync<sup>9+</sup>](#encodesync9) instead.
W
wusongqing 已提交
4422

W
wusongqing 已提交
4423 4424 4425
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4426

W
wusongqing 已提交
4427 4428
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4429
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
4430

W
wusongqing 已提交
4431
**Return value**
4432

W
wusongqing 已提交
4433 4434
| Type| Description|
| -------- | -------- |
4435
| Uint8Array | Uint8Array encoded.|
W
wusongqing 已提交
4436

W
wusongqing 已提交
4437
**Example**
4438

4439
  ```js
4440 4441 4442
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeSync(array);
W
wusongqing 已提交
4443 4444
  ```

4445
### encodeToStringSync<sup>(deprecated)</sup>
W
wusongqing 已提交
4446

4447
encodeToStringSync(src: Uint8Array): string
W
wusongqing 已提交
4448

4449
Encodes the input content.
W
wusongqing 已提交
4450

4451 4452
> **NOTE**
>
G
Gloria 已提交
4453
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
W
wusongqing 已提交
4454

W
wusongqing 已提交
4455 4456 4457
**System capability**: SystemCapability.Utils.Lang

**Parameters**
4458

W
wusongqing 已提交
4459 4460
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4461
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
4462

W
wusongqing 已提交
4463
**Return value**
4464

W
wusongqing 已提交
4465 4466
| Type| Description|
| -------- | -------- |
4467
| string | String encoded from the Uint8Array.|
Z
zengyawen 已提交
4468

W
wusongqing 已提交
4469
**Example**
4470

4471
  ```js
4472 4473 4474
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeToStringSync(array);
4475 4476
  ```

4477
### decodeSync<sup>(deprecated)</sup>
4478

4479
decodeSync(src: Uint8Array | string): Uint8Array
4480

4481
Decodes the input content.
4482

4483 4484
> **NOTE**
>
G
Gloria 已提交
4485
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decodeSync<sup>9+</sup>](#decodesync9) instead.
4486 4487 4488 4489 4490 4491 4492

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4493
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.|
4494 4495 4496 4497 4498

**Return value**

| Type| Description|
| -------- | -------- |
4499
| Uint8Array | Uint8Array decoded.|
4500 4501

**Example**
4502

4503
  ```js
4504 4505 4506
  let that = new util.Base64();
  let buff = 'czEz';
  let result = that.decodeSync(buff);
4507 4508
  ```

4509
### encode<sup>(deprecated)</sup>
4510

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

4513
Encodes the input content asynchronously.
4514

4515 4516
> **NOTE**
>
G
Gloria 已提交
4517
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encode<sup>9+</sup>](#encode9) instead.
4518 4519 4520 4521 4522 4523 4524

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4525
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
4526 4527 4528 4529 4530

**Return value**

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

**Example**
4534

4535
  ```js
4536 4537 4538 4539 4540 4541 4542 4543
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let rarray = new Uint8Array([99,122,69,122]);
  that.encode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
          console.log(val[i].toString())
      }
  })
4544 4545
  ```

4546
### encodeToString<sup>(deprecated)</sup>
4547

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

4550
Encodes the input content asynchronously.
4551

4552 4553
> **NOTE**
>
G
Gloria 已提交
4554
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToString<sup>9+</sup>](#encodetostring9) instead.
4555 4556 4557 4558 4559 4560 4561

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4562
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
4563 4564 4565 4566 4567

**Return value**

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

**Example**
4571

4572
  ```js
4573 4574 4575 4576 4577
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  that.encodeToString(array).then(val=>{    
      console.log(val)
  })
4578 4579
  ```

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

4582

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

4585
Decodes the input content asynchronously.
4586

4587 4588
> **NOTE**
>
G
Gloria 已提交
4589
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decode<sup>9+</sup>](#decode9) instead.
4590 4591 4592 4593 4594 4595 4596

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
4597
| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.|
4598 4599 4600 4601 4602

**Return value**

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

**Example**
4606

4607
  ```js
4608 4609 4610 4611 4612 4613 4614 4615
  let that = new util.Base64();
  let array = new Uint8Array([99,122,69,122]);
  let rarray = new Uint8Array([115,49,51]);
  that.decode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
          console.log(val[i].toString())
      }
  })
W
wusongqing 已提交
4616
  ```