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


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

W
wusongqing 已提交
8

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


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

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

W
wusongqing 已提交
18
## util.printf
Z
zengyawen 已提交
19

W
wusongqing 已提交
20
printf(format: string,  ...args: Object[]): string
Z
zengyawen 已提交
21 22 23

Prints the input content in a formatted string.

W
wusongqing 已提交
24 25 26
**System capability**: SystemCapability.Utils.Lang

**Parameters**
27

W
wusongqing 已提交
28 29 30 31
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| format | string | Yes| Format of the string to print.|
| ...args | Object[] | No| Data to format.|
W
wusongqing 已提交
32

W
wusongqing 已提交
33
**Return value**
34

W
wusongqing 已提交
35 36 37
| Type| Description|
| -------- | -------- |
| string | String in the specified format.|
W
wusongqing 已提交
38

W
wusongqing 已提交
39
**Example**
40
  ```js
41
  let res = util.printf("%s", "hello world!");
W
wusongqing 已提交
42 43 44 45 46 47 48
  console.log(res);
  ```


## util.getErrorString

getErrorString(errno: number): string
Z
zengyawen 已提交
49 50 51

Obtains detailed information about a system error code.

W
wusongqing 已提交
52 53 54
**System capability**: SystemCapability.Utils.Lang

**Parameters**
55

W
wusongqing 已提交
56 57 58
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| errno | number | Yes| Error code generated.|
W
wusongqing 已提交
59

W
wusongqing 已提交
60
**Return value**
61

W
wusongqing 已提交
62 63 64
| Type| Description|
| -------- | -------- |
| string | Detailed information about the error code.|
W
wusongqing 已提交
65

W
wusongqing 已提交
66
**Example**
67
  ```js
68 69
  let errnum = 10; // 10 is a system error code.
  let result = util.getErrorString(errnum);
W
wusongqing 已提交
70 71 72 73 74 75 76 77 78
  console.log("result = " + result);
  ```


## util.callbackWrapper

callbackWrapper(original: Function): (err: Object, value: Object )=>void

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 已提交
79

W
wusongqing 已提交
80 81 82 83
**System capability**: SystemCapability.Utils.Lang

**Parameters**

W
wusongqing 已提交
84 85 86
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|
Z
zengyawen 已提交
87

W
wusongqing 已提交
88
**Return value**
89

W
wusongqing 已提交
90 91 92
| 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 已提交
93

W
wusongqing 已提交
94
**Example**
95
  ```js
W
wusongqing 已提交
96 97 98
  async function promiseFn() {
      return Promise.reject('value');
  }
99 100
  let err = "type err";
  let cb = util.callbackWrapper(promiseFn);
W
wusongqing 已提交
101 102 103
  cb((err, ret) => {
      console.log(err);
      console.log(ret);
S
shikai-123 已提交
104
  }, err)
W
wusongqing 已提交
105 106 107
  ```


S
shikai-123 已提交
108
## util.promiseWrapper<sup>(deprecated)</sup>
W
wusongqing 已提交
109 110

promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
Z
zengyawen 已提交
111

W
wusongqing 已提交
112 113
> **NOTE**
> This API is deprecated since API version 9. You are advised to use **[util.promisify9+](#utilpromisify9)** instead.
S
shikai-123 已提交
114

Z
zengyawen 已提交
115 116
Processes an asynchronous function and returns a promise version.

W
wusongqing 已提交
117 118 119
**System capability**: SystemCapability.Utils.Lang

**Parameters**
W
wusongqing 已提交
120

W
wusongqing 已提交
121 122 123
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|
W
wusongqing 已提交
124

W
wusongqing 已提交
125
**Return value**
126

W
wusongqing 已提交
127 128
| Type| Description|
| -------- | -------- |
129
| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
W
wusongqing 已提交
130

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

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

W
wusongqing 已提交
135
Processes an asynchronous function and returns a promise.
S
shikai-123 已提交
136 137 138 139

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

**Parameters**
140

S
shikai-123 已提交
141 142 143 144 145
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| original | Function | Yes| Asynchronous function.|

**Return value**
146

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

W
wusongqing 已提交
151
**Example**
152
  ```js
S
shikai-123 已提交
153 154 155 156 157 158
  function aysnFun(str1, str2) {
    if (typeof str1 === 'object' && typeof str2 === 'object') {
      return str2
    } else {
      return str1
    }
W
wusongqing 已提交
159
  }
S
shikai-123 已提交
160
  let newPromiseObj = util.promisify(aysnFun);
S
shikai-123 已提交
161 162
  newPromiseObj({ err: "type error" }, {value:'HelloWorld'}).then(res => {
    console.log(res);
W
wusongqing 已提交
163 164 165
  })
  ```

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
## util.randomUUID<sup>9+</sup>

randomUUID(entropyCache?: boolean): string

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

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

**Parameters**

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

**Return value**

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

**Example**
  ```js
  let uuid = util.randomUUID(true);
  console.log("RFC 4122 Version 4 UUID:" + uuid);
  // Output:
  // RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
  ```

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

randomBinaryUUID(entropyCache?: boolean): Uint8Array

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

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

**Parameters**

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

**Return value**

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

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

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

parseUUID(uuid: string): Uint8Array

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

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

**Parameters**

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

**Return value**

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

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

W
wusongqing 已提交
250 251 252 253
## TextDecoder

### Attributes

W
wusongqing 已提交
254 255
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
256 257 258 259 260
| 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 已提交
261 262 263 264


### constructor

S
shikai-123 已提交
265
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
W
wusongqing 已提交
266 267 268

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

W
wusongqing 已提交
269 270 271
**System capability**: SystemCapability.Utils.Lang

**Parameters**
272

W
wusongqing 已提交
273 274 275 276
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format.|
| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
W
wusongqing 已提交
277 278

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

W
wusongqing 已提交
280 281 282 283
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fatal | boolean | No| Whether to display fatal errors.|
| ignoreBOM | boolean | No| Whether to ignore the BOM.|
W
wusongqing 已提交
284

W
wusongqing 已提交
285
**Example**
286
  ```js
287
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
W
wusongqing 已提交
288 289 290 291 292
  ```


### decode

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

Z
zengyawen 已提交
295
Decodes the input content.
Z
zengyawen 已提交
296

W
wusongqing 已提交
297 298 299
**System capability**: SystemCapability.Utils.Lang

**Parameters**
300

W
wusongqing 已提交
301 302
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
W
wusongqing 已提交
303
| input | Uint8Array | Yes| Uint8Array to decode.|
W
wusongqing 已提交
304
| options | Object | No| Options related to decoding.|
W
wusongqing 已提交
305 306

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

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

W
wusongqing 已提交
312
**Return value**
313

W
wusongqing 已提交
314 315 316
| Type| Description|
| -------- | -------- |
| string | Data decoded.|
Z
zengyawen 已提交
317

W
wusongqing 已提交
318
**Example**
319
  ```js
320 321
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  let result = new Uint8Array(6);
W
wusongqing 已提交
322 323 324 325 326 327 328
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
  let retStr = textDecoder.decode( result , {stream: false});
  console.log("retStr = " + retStr);
  ```


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

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

Decodes the input content.

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

**Parameters**

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

  **Table 2** options

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

**Return value**

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

**Example**
  ```js
  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
  let result = new Uint8Array(6);
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
  let retStr = textDecoder.decodeWithStream( result , {stream: false});
W
wusongqing 已提交
373 374
  console.log("retStr = " + retStr);
  ```
Z
zengyawen 已提交
375 376


W
wusongqing 已提交
377
## TextEncoder
Z
zengyawen 已提交
378

W
wusongqing 已提交
379
### Attributes
Z
zengyawen 已提交
380

W
wusongqing 已提交
381 382
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
383 384 385
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
Z
zengyawen 已提交
386 387


W
wusongqing 已提交
388
### constructor
Z
zengyawen 已提交
389

W
wusongqing 已提交
390
constructor()
Z
zengyawen 已提交
391

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

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

**Example**
397
  ```js
398
  let textEncoder = new util.TextEncoder();
W
wusongqing 已提交
399 400 401 402 403
  ```


### encode

X
xdmal 已提交
404
encode(input?: string): Uint8Array
Z
zengyawen 已提交
405

Z
zengyawen 已提交
406
Encodes the input content.
Z
zengyawen 已提交
407

W
wusongqing 已提交
408 409 410
**System capability**: SystemCapability.Utils.Lang

**Parameters**
411

W
wusongqing 已提交
412 413 414
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| input | string | Yes| String to encode.|
W
wusongqing 已提交
415

W
wusongqing 已提交
416
**Return value**
417

W
wusongqing 已提交
418 419 420
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
W
wusongqing 已提交
421

W
wusongqing 已提交
422
**Example**
423
  ```js
424 425 426
  let textEncoder = new util.TextEncoder();
  let buffer = new ArrayBuffer(20);
  let result = new Uint8Array(buffer);
W
wusongqing 已提交
427 428 429 430 431 432
  result = textEncoder.encode("\uD800¥¥");
  ```


### encodeInto

X
xdmal 已提交
433
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
Z
zengyawen 已提交
434 435 436

Stores the UTF-8 encoded text.

W
wusongqing 已提交
437 438 439
**System capability**: SystemCapability.Utils.Lang

**Parameters**
440

W
wusongqing 已提交
441 442 443 444
| 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 已提交
445

W
wusongqing 已提交
446
**Return value**
447

W
wusongqing 已提交
448 449 450
| Type| Description|
| -------- | -------- |
| Uint8Array | Encoded text.|
Z
zengyawen 已提交
451

W
wusongqing 已提交
452
**Example**
453
  ```js
454 455 456 457
  let that = new util.TextEncoder()
  let buffer = new ArrayBuffer(4)
  let dest = new Uint8Array(buffer)
  let result = new Object()
S
shikai-123 已提交
458
  result = that.encodeInto('abcd', dest)
W
wusongqing 已提交
459
  ```
Z
zengyawen 已提交
460

W
wusongqing 已提交
461
## RationalNumber<sup>8+</sup>
Z
zengyawen 已提交
462 463


W
wusongqing 已提交
464
### constructor<sup>8+</sup>
Z
zengyawen 已提交
465

X
xdmal 已提交
466
constructor(numerator: number,denominator: number)
Z
zengyawen 已提交
467

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

W
wusongqing 已提交
470 471 472
**System capability**: SystemCapability.Utils.Lang

**Parameters**
473

W
wusongqing 已提交
474 475 476 477
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| numerator | number | Yes| Numerator, which is an integer.|
| denominator | number | Yes| Denominator, which is an integer.|
Z
zengyawen 已提交
478

W
wusongqing 已提交
479
**Example**
480
  ```js
481
  let rationalNumber = new util.RationalNumber(1,2);
W
wusongqing 已提交
482
  ```
Z
zengyawen 已提交
483 484


W
wusongqing 已提交
485
### createRationalFromString<sup>8+</sup>
Z
zengyawen 已提交
486

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

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

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

**Parameters**
494

W
wusongqing 已提交
495 496 497
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rationalString | string | Yes| String used to create the **RationalNumber** object.|
Z
zengyawen 已提交
498

W
wusongqing 已提交
499
**Return value**
500

W
wusongqing 已提交
501 502 503
| Type| Description|
| -------- | -------- |
| object | **RationalNumber** object created.|
Z
zengyawen 已提交
504

W
wusongqing 已提交
505
**Example**
506
  ```js
507 508
  let rationalNumber = new util.RationalNumber(1,2);
  let rational = util.RationalNumber.createRationalFromString("3/4");
W
wusongqing 已提交
509
  ```
Z
zengyawen 已提交
510 511


W
wusongqing 已提交
512
### compareTo<sup>8+</sup>
Z
zengyawen 已提交
513

X
xdmal 已提交
514
compareTo​(another: RationalNumber): number​
Z
zengyawen 已提交
515

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

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

**Parameters**
521

W
wusongqing 已提交
522 523 524
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
Z
zengyawen 已提交
525

W
wusongqing 已提交
526
**Return value**
527

W
wusongqing 已提交
528 529 530
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.|
Z
zengyawen 已提交
531

W
wusongqing 已提交
532
**Example**
533
  ```js
534 535 536
  let rationalNumber = new util.RationalNumber(1,2);
  let rational = util.RationalNumber.createRationalFromString("3/4");
  let result = rationalNumber.compareTo(rational);
W
wusongqing 已提交
537
  ```
Z
zengyawen 已提交
538 539


W
wusongqing 已提交
540
### valueOf<sup>8+</sup>
Z
zengyawen 已提交
541

X
xdmal 已提交
542
valueOf(): number
Z
zengyawen 已提交
543

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

W
wusongqing 已提交
546 547 548
**System capability**: SystemCapability.Utils.Lang

**Return value**
549

W
wusongqing 已提交
550 551 552
| Type| Description|
| -------- | -------- |
| number | An integer or a floating-point number.|
Z
zengyawen 已提交
553

W
wusongqing 已提交
554
**Example**
555
  ```js
556 557
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.valueOf();
W
wusongqing 已提交
558
  ```
Z
zengyawen 已提交
559 560


W
wusongqing 已提交
561
### equals<sup>8+</sup>
Z
zengyawen 已提交
562

X
xdmal 已提交
563
equals​(obj: Object): boolean
Z
zengyawen 已提交
564

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

W
wusongqing 已提交
567 568 569
**System capability**: SystemCapability.Utils.Lang

**Parameters**
570

W
wusongqing 已提交
571 572 573
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | Object | Yes| Object used to compare with this **RationalNumber** object.|
Z
zengyawen 已提交
574

W
wusongqing 已提交
575
**Return value**
576

W
wusongqing 已提交
577 578 579
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the two objects are equal; returns **false** otherwise.|
Z
zengyawen 已提交
580

W
wusongqing 已提交
581
**Example**
582
  ```js
583 584 585
  let rationalNumber = new util.RationalNumber(1,2);
  let rational = util.RationalNumber.createRationalFromString("3/4");
  let result = rationalNumber.equals(rational);
W
wusongqing 已提交
586
  ```
Z
zengyawen 已提交
587 588


W
wusongqing 已提交
589
### getCommonDivisor<sup>8+</sup>
Z
zengyawen 已提交
590

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

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

W
wusongqing 已提交
595 596 597
**System capability**: SystemCapability.Utils.Lang

**Parameters**
598

W
wusongqing 已提交
599 600 601 602
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| number1 | number | Yes| The first integer used to get the greatest common divisor.|
| number2 | number | Yes| The second integer used to get the greatest common divisor.|
Z
zengyawen 已提交
603

W
wusongqing 已提交
604
**Return value**
605

W
wusongqing 已提交
606 607 608
| Type| Description|
| -------- | -------- |
| number | Greatest common divisor obtained.|
Z
zengyawen 已提交
609

W
wusongqing 已提交
610
**Example**
611
  ```js
612 613
  let rationalNumber = new util.RationalNumber(1,2);
  let result = util.RationalNumber.getCommonDivisor(4,6);
W
wusongqing 已提交
614
  ```
Z
zengyawen 已提交
615 616


W
wusongqing 已提交
617
### getNumerator<sup>8+</sup>
Z
zengyawen 已提交
618

X
xdmal 已提交
619
getNumerator​(): number
Z
zengyawen 已提交
620

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

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

**Return value**

W
wusongqing 已提交
627 628 629
| Type| Description|
| -------- | -------- |
| number | Numerator of this **RationalNumber** object.|
Z
zengyawen 已提交
630

W
wusongqing 已提交
631
**Example**
632
  ```js
633 634
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.getNumerator();
W
wusongqing 已提交
635
  ```
Z
zengyawen 已提交
636 637


W
wusongqing 已提交
638
### getDenominator<sup>8+</sup>
Z
zengyawen 已提交
639

X
xdmal 已提交
640
getDenominator​(): number
Z
zengyawen 已提交
641

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

W
wusongqing 已提交
644 645 646
**System capability**: SystemCapability.Utils.Lang

**Return value**
647

W
wusongqing 已提交
648 649 650
| Type| Description|
| -------- | -------- |
| number | Denominator of this **RationalNumber** object.|
Z
zengyawen 已提交
651

W
wusongqing 已提交
652
**Example**
653
  ```js
654 655
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.getDenominator();
W
wusongqing 已提交
656
  ```
Z
zengyawen 已提交
657 658


W
wusongqing 已提交
659
### isZero<sup>8+</sup>
Z
zengyawen 已提交
660

W
wusongqing 已提交
661
isZero​():boolean
Z
zengyawen 已提交
662

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

W
wusongqing 已提交
665 666 667
**System capability**: SystemCapability.Utils.Lang

**Return value**
668

W
wusongqing 已提交
669 670 671
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
Z
zengyawen 已提交
672

W
wusongqing 已提交
673
**Example**
674
  ```js
675 676
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.isZero();
W
wusongqing 已提交
677
  ```
Z
zengyawen 已提交
678 679


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

X
xdmal 已提交
682
isNaN​(): boolean
Z
zengyawen 已提交
683

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

W
wusongqing 已提交
686 687 688
**System capability**: SystemCapability.Utils.Lang

**Return value**
689

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

W
wusongqing 已提交
694
**Example**
695
  ```js
696 697
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.isNaN();
W
wusongqing 已提交
698
  ```
Z
zengyawen 已提交
699 700


W
wusongqing 已提交
701
### isFinite<sup>8+</sup>
Z
zengyawen 已提交
702

W
wusongqing 已提交
703
isFinite​():boolean
Z
zengyawen 已提交
704

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

W
wusongqing 已提交
707 708 709
**System capability**: SystemCapability.Utils.Lang

**Return value**
710

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

W
wusongqing 已提交
715
**Example**
716
  ```js
717 718
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.isFinite();
W
wusongqing 已提交
719
  ```
Z
zengyawen 已提交
720 721


W
wusongqing 已提交
722
### toString<sup>8+</sup>
Z
zengyawen 已提交
723

X
xdmal 已提交
724
toString​(): string
Z
zengyawen 已提交
725

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

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

**Return value**
731

W
wusongqing 已提交
732 733 734
| 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 已提交
735

W
wusongqing 已提交
736
**Example**
737
  ```js
738 739
  let rationalNumber = new util.RationalNumber(1,2);
  let result = rationalNumber.toString();
W
wusongqing 已提交
740
  ```
Z
zengyawen 已提交
741

W
wusongqing 已提交
742
## LruBuffer<sup>8+</sup>
Z
zengyawen 已提交
743

W
wusongqing 已提交
744
### Attributes
Z
zengyawen 已提交
745

W
wusongqing 已提交
746 747
**System capability**: SystemCapability.Utils.Lang

W
wusongqing 已提交
748 749 750
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Total number of values in this buffer.|
Z
zengyawen 已提交
751

W
wusongqing 已提交
752
**Example**
753
  ```js
754
  let pro = new util.LruBuffer();
W
wusongqing 已提交
755 756
  pro.put(2,10);
  pro.put(1,8);
757
  let result = pro.length;
W
wusongqing 已提交
758
  ```
Z
zengyawen 已提交
759 760


W
wusongqing 已提交
761
### constructor<sup>8+</sup>
Z
zengyawen 已提交
762

X
xdmal 已提交
763
constructor(capacity?: number)
Z
zengyawen 已提交
764

W
wusongqing 已提交
765
A constructor used to create an **LruBuffer** instance. The default capacity of the buffer is 64.
Z
zengyawen 已提交
766

W
wusongqing 已提交
767 768 769
**System capability**: SystemCapability.Utils.Lang

**Parameters**
770

W
wusongqing 已提交
771 772 773
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| capacity | number | No| Capacity of the **LruBuffer** to create.|
Z
zengyawen 已提交
774

W
wusongqing 已提交
775
**Example**
776
  ```js
777
  let lrubuffer= new util.LruBuffer();
W
wusongqing 已提交
778
  ```
Z
zengyawen 已提交
779 780


W
wusongqing 已提交
781
### updateCapacity<sup>8+</sup>
Z
zengyawen 已提交
782

X
xdmal 已提交
783
updateCapacity(newCapacity: number): void
Z
zengyawen 已提交
784

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

W
wusongqing 已提交
787 788 789
**System capability**: SystemCapability.Utils.Lang

**Parameters**
790

W
wusongqing 已提交
791 792 793
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| newCapacity | number | Yes| New capacity of the **LruBuffer**.|
Z
zengyawen 已提交
794

W
wusongqing 已提交
795
**Example**
796
  ```js
797 798
  let pro = new util.LruBuffer();
  let result = pro.updateCapacity(100);
W
wusongqing 已提交
799
  ```
Z
zengyawen 已提交
800 801


W
wusongqing 已提交
802
### toString<sup>8+</sup>
Z
zengyawen 已提交
803

X
xdmal 已提交
804
toString(): string
Z
zengyawen 已提交
805

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

W
wusongqing 已提交
808 809 810
**System capability**: SystemCapability.Utils.Lang

**Return value**
811

W
wusongqing 已提交
812 813 814
| Type| Description|
| -------- | -------- |
| string | String representation of this **LruBuffer** object.|
W
wusongqing 已提交
815

W
wusongqing 已提交
816
**Example**
817
  ```js
818
  let pro = new util.LruBuffer();
W
wusongqing 已提交
819 820 821
  pro.put(2,10);
  pro.get(2);
  pro.remove(20);
822
  let result = pro.toString();
W
wusongqing 已提交
823 824 825 826 827
  ```


### getCapacity<sup>8+</sup>

X
xdmal 已提交
828
getCapacity(): number
W
wusongqing 已提交
829 830 831

Obtains the capacity of this buffer.

W
wusongqing 已提交
832 833 834
**System capability**: SystemCapability.Utils.Lang

**Return value**
835

W
wusongqing 已提交
836 837 838
| Type| Description|
| -------- | -------- |
| number | Capacity of this buffer.|
W
wusongqing 已提交
839

W
wusongqing 已提交
840
**Example**
841
  ```js
842 843
  let pro = new util.LruBuffer();
  let result = pro.getCapacity();
W
wusongqing 已提交
844
  ```
Z
zengyawen 已提交
845 846


W
wusongqing 已提交
847
### clear<sup>8+</sup>
Z
zengyawen 已提交
848

X
xdmal 已提交
849
clear(): void
Z
zengyawen 已提交
850

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

W
wusongqing 已提交
853 854 855
**System capability**: SystemCapability.Utils.Lang

**Example**
856
  ```js
857
  let pro = new util.LruBuffer();
W
wusongqing 已提交
858
  pro.put(2,10);
859
  let result = pro.length;
W
wusongqing 已提交
860 861
  pro.clear();
  ```
Z
zengyawen 已提交
862 863


W
wusongqing 已提交
864
### getCreateCount<sup>8+</sup>
Z
zengyawen 已提交
865

X
xdmal 已提交
866
getCreateCount(): number
W
wusongqing 已提交
867 868 869

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

W
wusongqing 已提交
870 871 872
**System capability**: SystemCapability.Utils.Lang

**Return value**
873

W
wusongqing 已提交
874 875 876
| Type| Description|
| -------- | -------- |
| number | Number of return values for **createDefault()**.|
W
wusongqing 已提交
877

W
wusongqing 已提交
878
**Example**
879
  ```js
880
  let pro = new util.LruBuffer();
W
wusongqing 已提交
881
  pro.put(1,8);
882
  let result = pro.getCreateCount();
W
wusongqing 已提交
883 884 885 886 887
  ```


### getMissCount<sup>8+</sup>

X
xdmal 已提交
888
getMissCount(): number
W
wusongqing 已提交
889 890 891

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

W
wusongqing 已提交
892 893 894
**System capability**: SystemCapability.Utils.Lang

**Return value**
895

W
wusongqing 已提交
896 897 898
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are mismatched.|
W
wusongqing 已提交
899

W
wusongqing 已提交
900
**Example**
901
  ```js
902
  let pro = new util.LruBuffer();
W
wusongqing 已提交
903 904
  pro.put(2,10);
  pro.get(2);
905
  let result = pro.getMissCount();
W
wusongqing 已提交
906 907 908 909 910
  ```


### getRemovalCount<sup>8+</sup>

X
xdmal 已提交
911
getRemovalCount(): number
W
wusongqing 已提交
912 913 914

Obtains the number of removals from this buffer.

W
wusongqing 已提交
915 916 917
**System capability**: SystemCapability.Utils.Lang

**Return value**
918

W
wusongqing 已提交
919 920 921
| Type| Description|
| -------- | -------- |
| number | Number of removals from the buffer.|
W
wusongqing 已提交
922

W
wusongqing 已提交
923
**Example**
924
  ```js
925
  let pro = new util.LruBuffer();
W
wusongqing 已提交
926 927 928
  pro.put(2,10);
  pro.updateCapacity(2);
  pro.put(50,22);
929
  let result = pro.getRemovalCount();
W
wusongqing 已提交
930 931 932 933 934
  ```


### getMatchCount<sup>8+</sup>

X
xdmal 已提交
935
getMatchCount(): number
W
wusongqing 已提交
936 937 938

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

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

**Return value**
942

W
wusongqing 已提交
943 944 945
| Type| Description|
| -------- | -------- |
| number | Number of times that the queried values are matched.|
W
wusongqing 已提交
946

W
wusongqing 已提交
947
**Example**
948
  ```js
949
  let pro = new util.LruBuffer();
W
wusongqing 已提交
950 951
  pro.put(2,10);
  pro.get(2);
952
  let result = pro.getMatchCount();
W
wusongqing 已提交
953 954 955 956 957
  ```


### getPutCount<sup>8+</sup>

X
xdmal 已提交
958
getPutCount(): number
W
wusongqing 已提交
959 960 961

Obtains the number of additions to this buffer.

W
wusongqing 已提交
962 963 964
**System capability**: SystemCapability.Utils.Lang

**Return value**
965

W
wusongqing 已提交
966 967 968
| Type| Description|
| -------- | -------- |
| number | Number of additions to the buffer.|
W
wusongqing 已提交
969

W
wusongqing 已提交
970
**Example**
971
  ```js
972
  let pro = new util.LruBuffer();
W
wusongqing 已提交
973
  pro.put(2,10);
974
  let result = pro.getPutCount();
W
wusongqing 已提交
975 976 977 978 979
  ```


### isEmpty<sup>8+</sup>

X
xdmal 已提交
980
isEmpty(): boolean
W
wusongqing 已提交
981 982 983

Checks whether this buffer is empty.

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

**Return value**
987

W
wusongqing 已提交
988 989 990
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer does not contain any value.|
W
wusongqing 已提交
991

W
wusongqing 已提交
992
**Example**
993
  ```js
994
  let pro = new util.LruBuffer();
W
wusongqing 已提交
995
  pro.put(2,10);
996
  let result = pro.isEmpty();
W
wusongqing 已提交
997 998 999 1000 1001
  ```


### get<sup>8+</sup>

W
wusongqing 已提交
1002
get(key: K): V | undefined
Z
zengyawen 已提交
1003 1004 1005

Obtains the value of the specified key.

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

**Parameters**
1009

W
wusongqing 已提交
1010 1011 1012
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key based on which the value is queried.|
W
wusongqing 已提交
1013

W
wusongqing 已提交
1014
**Return value**
1015

W
wusongqing 已提交
1016 1017 1018
| Type| Description|
| -------- | -------- |
| V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
W
wusongqing 已提交
1019

W
wusongqing 已提交
1020
**Example**
1021
  ```js
1022
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1023
  pro.put(2,10);
1024
  let result  = pro.get(2);
W
wusongqing 已提交
1025 1026 1027 1028 1029
  ```


### put<sup>8+</sup>

X
xdmal 已提交
1030
put(key: K,value: V): V
Z
zengyawen 已提交
1031 1032 1033

Adds a key-value pair to this buffer.

W
wusongqing 已提交
1034 1035 1036
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1037

W
wusongqing 已提交
1038 1039 1040 1041
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key of the key-value pair to add.|
| value | V | Yes| Value of the key-value pair to add.|
Z
zengyawen 已提交
1042

W
wusongqing 已提交
1043
**Return value**
1044

W
wusongqing 已提交
1045 1046 1047
| Type| Description|
| -------- | -------- |
| V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. |
Z
zengyawen 已提交
1048

W
wusongqing 已提交
1049
**Example**
1050
  ```js
1051 1052
  let pro = new util.LruBuffer();
  let result = pro.put(2,10);
W
wusongqing 已提交
1053
  ```
Z
zengyawen 已提交
1054

W
wusongqing 已提交
1055
### values<sup>8+</sup>
Z
zengyawen 已提交
1056

X
xdmal 已提交
1057
values(): V[]
W
wusongqing 已提交
1058 1059

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

W
wusongqing 已提交
1061 1062 1063
**System capability**: SystemCapability.Utils.Lang

**Return value**
1064

W
wusongqing 已提交
1065 1066 1067
| Type| Description|
| -------- | -------- |
| V [] | All values in the buffer, listed from the most to the least recently accessed.|
Z
zengyawen 已提交
1068

W
wusongqing 已提交
1069
**Example**
1070
  ```js
1071
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1072 1073 1074
  pro.put(2,10);
  pro.put(2,"anhu");
  pro.put("afaf","grfb");
1075
  let result = pro.values();
W
wusongqing 已提交
1076
  ```
Z
zengyawen 已提交
1077 1078


W
wusongqing 已提交
1079 1080
### keys<sup>8+</sup>

X
xdmal 已提交
1081
keys(): K[]
Z
zengyawen 已提交
1082 1083 1084

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

W
wusongqing 已提交
1085 1086 1087
**System capability**: SystemCapability.Utils.Lang

**Return value**
1088

W
wusongqing 已提交
1089 1090 1091
| Type| Description|
| -------- | -------- |
| K [] | All keys in the buffer, listed from the most to the least recently accessed.|
W
wusongqing 已提交
1092

W
wusongqing 已提交
1093
**Example**
1094
  ```js
1095
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1096
  pro.put(2,10);
1097
  let result = pro.keys();
W
wusongqing 已提交
1098 1099 1100 1101 1102
  ```


### remove<sup>8+</sup>

W
wusongqing 已提交
1103
remove(key: K): V | undefined
W
wusongqing 已提交
1104 1105 1106

Removes the specified key and its value from this buffer.

W
wusongqing 已提交
1107 1108 1109
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1110

W
wusongqing 已提交
1111 1112 1113
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to remove.|
W
wusongqing 已提交
1114

W
wusongqing 已提交
1115
**Return value**
1116

W
wusongqing 已提交
1117 1118 1119
| Type| Description|
| -------- | -------- |
| V \| undefind | 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 已提交
1120

W
wusongqing 已提交
1121
**Example**
1122
  ```js
1123
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1124
  pro.put(2,10);
1125
  let result = pro.remove(20);
W
wusongqing 已提交
1126 1127 1128 1129 1130
  ```


### afterRemoval<sup>8+</sup>

X
xdmal 已提交
1131
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
W
wusongqing 已提交
1132 1133 1134

Performs subsequent operations after a value is removed.

W
wusongqing 已提交
1135 1136 1137
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1138

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

W
wusongqing 已提交
1146
**Example**
1147
  ```js
1148 1149
  let arr = [];
  class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
W
wusongqing 已提交
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
  {
  	constructor()
  	{
  		super();
  	}
  	afterRemoval(isEvict, key, value, newValue)
  	{
  		if (isEvict === false)
  		{
  			arr = [key, value, newValue];
  		}
  	}
  }
1163
  let lru = new ChildLruBuffer();
S
shikai-123 已提交
1164
  lru.afterRemoval(false,10,30,null);
W
wusongqing 已提交
1165 1166 1167 1168 1169
  ```


### contains<sup>8+</sup>

X
xdmal 已提交
1170
contains(key: K): boolean
W
wusongqing 已提交
1171 1172

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

W
wusongqing 已提交
1174 1175 1176
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1177

W
wusongqing 已提交
1178 1179 1180
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key to check.|
Z
zengyawen 已提交
1181

W
wusongqing 已提交
1182
**Return value**
1183

W
wusongqing 已提交
1184 1185 1186
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
Z
zengyawen 已提交
1187

W
wusongqing 已提交
1188
**Example**
1189
  ```js
1190
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1191
  pro.put(2,10);
1192
  let result = pro.contains(20);
W
wusongqing 已提交
1193
  ```
Z
zengyawen 已提交
1194 1195


W
wusongqing 已提交
1196 1197
### createDefault<sup>8+</sup>

X
xdmal 已提交
1198
createDefault(key: K): V
Z
zengyawen 已提交
1199 1200 1201

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

W
wusongqing 已提交
1202 1203 1204
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1205

W
wusongqing 已提交
1206 1207 1208
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | K | Yes| Key of which the value is missing.|
Z
zengyawen 已提交
1209

W
wusongqing 已提交
1210
**Return value**
1211

W
wusongqing 已提交
1212 1213 1214
| Type| Description|
| -------- | -------- |
| V | Value of the key.|
Z
zengyawen 已提交
1215

W
wusongqing 已提交
1216
**Example**
1217
  ```js
1218 1219
  let pro = new util.LruBuffer();
  let result = pro.createDefault(50);
W
wusongqing 已提交
1220
  ```
Z
zengyawen 已提交
1221 1222


W
wusongqing 已提交
1223
### entries<sup>8+</sup>
Z
zengyawen 已提交
1224

X
xdmal 已提交
1225
entries(): IterableIterator&lt;[K,V]&gt;
Z
zengyawen 已提交
1226

W
wusongqing 已提交
1227
Obtains a new iterator object that contains all key-value pairs in this object.
Z
zengyawen 已提交
1228

W
wusongqing 已提交
1229 1230 1231
**System capability**: SystemCapability.Utils.Lang

**Return value**
1232

W
wusongqing 已提交
1233 1234 1235
| Type| Description|
| -------- | -------- |
| [K, V] | Iterable array.|
Z
zengyawen 已提交
1236

W
wusongqing 已提交
1237
**Example**
1238
  ```js
1239
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1240
  pro.put(2,10);
1241
  let result = pro.entries();
W
wusongqing 已提交
1242
  ```
Z
zengyawen 已提交
1243 1244


W
wusongqing 已提交
1245
### [Symbol.iterator]<sup>8+</sup>
Z
zengyawen 已提交
1246

W
wusongqing 已提交
1247
[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
Z
zengyawen 已提交
1248

W
wusongqing 已提交
1249
Obtains a two-dimensional array in key-value pairs.
Z
zengyawen 已提交
1250

W
wusongqing 已提交
1251 1252 1253
**System capability**: SystemCapability.Utils.Lang

**Return value**
1254

W
wusongqing 已提交
1255 1256 1257
| Type| Description|
| -------- | -------- |
| [K, V] | Two-dimensional array in key-value pairs.|
Z
zengyawen 已提交
1258

W
wusongqing 已提交
1259
**Example**
1260
  ```js
1261
  let pro = new util.LruBuffer();
W
wusongqing 已提交
1262
  pro.put(2,10);
1263
  let result = pro[Symbol.iterator]();
W
wusongqing 已提交
1264
  ```
Z
zengyawen 已提交
1265 1266


W
wusongqing 已提交
1267
## Scope<sup>8+</sup>
Z
zengyawen 已提交
1268 1269


W
wusongqing 已提交
1270
### ScopeType<sup>8+</sup>
Z
zengyawen 已提交
1271

W
wusongqing 已提交
1272
Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**.
Z
zengyawen 已提交
1273

W
wusongqing 已提交
1274
The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
1275
```js
Z
zengyawen 已提交
1276
interface ScopeComparable{
X
xdmal 已提交
1277
    compareTo(other: ScopeComparable): boolean;
Z
zengyawen 已提交
1278
}
W
wusongqing 已提交
1279
type ScopeType = ScopeComparable | number;
Z
zengyawen 已提交
1280 1281 1282
```


W
wusongqing 已提交
1283
Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#scopetype8) object.
Z
zengyawen 已提交
1284

W
wusongqing 已提交
1285 1286

Example
1287
```js
Z
zengyawen 已提交
1288 1289
class Temperature{
    constructor(value){
W
wusongqing 已提交
1290 1291
       // If TS is used for development, add the following code:
       // private readonly _temp: Temperature;
Z
zengyawen 已提交
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
       this._temp = value;
    }
    comapreTo(value){
       return this._temp >= value.getTemp();
    }
    getTemp(){
       return this._temp;
    }
    toString(){
       return this._temp.toString();
    }
}
```


W
wusongqing 已提交
1307 1308
### constructor<sup>8+</sup>

X
xdmal 已提交
1309
constructor(lowerObj: ScopeType, upperObj: ScopeType)
W
wusongqing 已提交
1310 1311 1312

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

W
wusongqing 已提交
1313 1314 1315
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1316

W
wusongqing 已提交
1317 1318 1319 1320
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
W
wusongqing 已提交
1321

W
wusongqing 已提交
1322
**Example**
1323
  ```js
1324 1325 1326
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
1327 1328 1329 1330 1331
  ```


### toString<sup>8+</sup>

X
xdmal 已提交
1332
toString(): string
W
wusongqing 已提交
1333 1334 1335

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

W
wusongqing 已提交
1336 1337 1338
**System capability**: SystemCapability.Utils.Lang

**Return value**
1339

W
wusongqing 已提交
1340 1341 1342
| Type| Description|
| -------- | -------- |
| string | String representation containing the **Scope**.|
W
wusongqing 已提交
1343

W
wusongqing 已提交
1344
**Example**
1345
  ```js
1346 1347 1348 1349
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.toString();
W
wusongqing 已提交
1350 1351 1352 1353 1354
  ```


### intersect<sup>8+</sup>

X
xdmal 已提交
1355
intersect(range: Scope): Scope
W
wusongqing 已提交
1356 1357 1358

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

W
wusongqing 已提交
1359 1360 1361
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1362

W
wusongqing 已提交
1363 1364 1365
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| range | [Scope](#scope8) | Yes| **Scope** specified.|
W
wusongqing 已提交
1366

W
wusongqing 已提交
1367
**Return value**
1368

W
wusongqing 已提交
1369 1370 1371
| Type| Description|
| -------- | -------- |
| [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
1372

W
wusongqing 已提交
1373
**Example**
1374
  ```js
1375 1376 1377 1378 1379 1380
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let tempMiDF = new Temperature(35);
  let tempMidS = new Temperature(39);
  let rangeFir = new util.Scope(tempMiDF, tempMidS);
W
wusongqing 已提交
1381 1382 1383 1384 1385 1386
  range.intersect(rangeFir );
  ```


### intersect<sup>8+</sup>

W
wusongqing 已提交
1387
intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
W
wusongqing 已提交
1388 1389 1390

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

W
wusongqing 已提交
1391 1392 1393
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1394

W
wusongqing 已提交
1395 1396 1397 1398
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
1399

W
wusongqing 已提交
1400
**Return value**
1401

W
wusongqing 已提交
1402 1403 1404
| Type| Description|
| -------- | -------- |
| [Scope](#scope8) | Intersection of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
1405

W
wusongqing 已提交
1406
**Example**
1407
  ```js
1408 1409 1410 1411 1412 1413
  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 已提交
1414 1415 1416 1417 1418
  ```


### getUpper<sup>8+</sup>

X
xdmal 已提交
1419
getUpper(): ScopeType
W
wusongqing 已提交
1420 1421 1422

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

W
wusongqing 已提交
1423 1424 1425 1426
**System capability**: SystemCapability.Utils.Lang

**Return value**

W
wusongqing 已提交
1427 1428 1429
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
W
wusongqing 已提交
1430

W
wusongqing 已提交
1431
**Example**
1432
  ```js
1433 1434 1435 1436
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getUpper();
W
wusongqing 已提交
1437 1438 1439 1440 1441
  ```


### getLower<sup>8+</sup>

X
xdmal 已提交
1442
getLower(): ScopeType
W
wusongqing 已提交
1443 1444 1445

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

W
wusongqing 已提交
1446 1447 1448
**System capability**: SystemCapability.Utils.Lang

**Return value**
1449

W
wusongqing 已提交
1450 1451 1452
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
W
wusongqing 已提交
1453

W
wusongqing 已提交
1454
**Example**
1455
  ```js
1456 1457 1458 1459
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let range = new util.Scope(tempLower, tempUpper);
  let result = range.getLower();
W
wusongqing 已提交
1460 1461 1462 1463 1464
  ```


### expand<sup>8+</sup>

X
xdmal 已提交
1465
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
W
wusongqing 已提交
1466 1467 1468

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

W
wusongqing 已提交
1469 1470 1471
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1472

W
wusongqing 已提交
1473 1474 1475 1476
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
W
wusongqing 已提交
1477

W
wusongqing 已提交
1478
**Return value**
1479

W
wusongqing 已提交
1480 1481 1482
| Type| Description|
| -------- | -------- |
| [Scope](#scope8) | Union set of this **Scope** and the given lower and upper limits.|
W
wusongqing 已提交
1483

W
wusongqing 已提交
1484
**Example**
W
wusongqing 已提交
1485

1486
  ```js
1487 1488 1489 1490 1491 1492
  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 已提交
1493 1494 1495 1496 1497
  ```


### expand<sup>8+</sup>

W
wusongqing 已提交
1498
expand(range: Scope): Scope
W
wusongqing 已提交
1499 1500 1501

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

W
wusongqing 已提交
1502 1503 1504
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1505

W
wusongqing 已提交
1506 1507 1508
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| range | [Scope](#scope8) | Yes| **Scope** specified.|
W
wusongqing 已提交
1509

W
wusongqing 已提交
1510
**Return value**
1511

W
wusongqing 已提交
1512 1513 1514
| Type| Description|
| -------- | -------- |
| [Scope](#scope8) | Union set of this **Scope** and the given **Scope**.|
W
wusongqing 已提交
1515

W
wusongqing 已提交
1516
**Example**
1517
  ```js
1518 1519 1520 1521 1522 1523 1524
  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 已提交
1525 1526 1527 1528 1529
  ```


### expand<sup>8+</sup>

X
xdmal 已提交
1530
expand(value: ScopeType): Scope
W
wusongqing 已提交
1531 1532 1533

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

W
wusongqing 已提交
1534 1535 1536
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1537

W
wusongqing 已提交
1538 1539 1540
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
1541

W
wusongqing 已提交
1542
**Return value**
1543

W
wusongqing 已提交
1544 1545 1546
| Type| Description|
| -------- | -------- |
| [Scope](#scope8) | Union set of this **Scope** and the given value.|
Z
zengyawen 已提交
1547

W
wusongqing 已提交
1548
**Example**
1549
  ```js
1550 1551 1552 1553 1554
  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 已提交
1555
  ```
Z
zengyawen 已提交
1556 1557


W
wusongqing 已提交
1558
### contains<sup>8+</sup>
Z
zengyawen 已提交
1559

X
xdmal 已提交
1560
contains(value: ScopeType): boolean
Z
zengyawen 已提交
1561

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

W
wusongqing 已提交
1564 1565 1566
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1567

W
wusongqing 已提交
1568 1569 1570
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
Z
zengyawen 已提交
1571

W
wusongqing 已提交
1572
**Return value**
1573

W
wusongqing 已提交
1574 1575 1576
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
1577

W
wusongqing 已提交
1578
**Example**
1579
  ```js
1580 1581 1582 1583
  let tempLower = new Temperature(30);
  let tempUpper = new Temperature(40);
  let tempMiDF = new Temperature(35);
  let range = new util.Scope(tempLower, tempUpper);
W
wusongqing 已提交
1584 1585 1586 1587 1588 1589
  range.contains(tempMiDF);
  ```


### contains<sup>8+</sup>

X
xdmal 已提交
1590
contains(range: Scope): boolean
W
wusongqing 已提交
1591 1592 1593

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

W
wusongqing 已提交
1594 1595 1596
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1597

W
wusongqing 已提交
1598 1599 1600
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| range | [Scope](#scope8) | Yes| **Scope** specified.|
W
wusongqing 已提交
1601

W
wusongqing 已提交
1602
**Return value**
1603

W
wusongqing 已提交
1604 1605 1606
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
W
wusongqing 已提交
1607

W
wusongqing 已提交
1608
**Example**
1609
  ```js
1610 1611 1612 1613 1614 1615 1616
  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 已提交
1617 1618 1619 1620 1621
  ```


### clamp<sup>8+</sup>

X
xdmal 已提交
1622
clamp(value: ScopeType): ScopeType
W
wusongqing 已提交
1623 1624 1625

Limits a value to this **Scope**.

W
wusongqing 已提交
1626 1627 1628
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1629

W
wusongqing 已提交
1630 1631 1632
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | [ScopeType](#scopetype8) | Yes| Value specified.|
W
wusongqing 已提交
1633

W
wusongqing 已提交
1634
**Return value**
1635

W
wusongqing 已提交
1636 1637 1638
| Type| Description|
| -------- | -------- |
| [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.|
W
wusongqing 已提交
1639

W
wusongqing 已提交
1640
**Example**
1641
  ```js
1642 1643 1644 1645 1646
  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 已提交
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
  ```


## Base64<sup>8+</sup>


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

constructor()

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

W
wusongqing 已提交
1659 1660 1661
**System capability**: SystemCapability.Utils.Lang

**Example**
1662
  ```js
1663
  let base64 = new  util.Base64();
W
wusongqing 已提交
1664 1665 1666 1667 1668
  ```


### encodeSync<sup>8+</sup>

X
xdmal 已提交
1669
encodeSync(src: Uint8Array): Uint8Array
Z
zengyawen 已提交
1670 1671 1672

Encodes the input content.

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

**Parameters**
1676

W
wusongqing 已提交
1677 1678 1679
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
1680

W
wusongqing 已提交
1681
**Return value**
1682

W
wusongqing 已提交
1683 1684 1685
| Type| Description|
| -------- | -------- |
| Uint8Array | Uint8Array encoded.|
W
wusongqing 已提交
1686

W
wusongqing 已提交
1687
**Example**
1688
  ```js
1689 1690 1691
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeSync(array);
W
wusongqing 已提交
1692 1693 1694 1695 1696
  ```


### encodeToStringSync<sup>8+</sup>

X
xdmal 已提交
1697
encodeToStringSync(src: Uint8Array): string
W
wusongqing 已提交
1698 1699 1700

Encodes the input content.

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

**Parameters**
1704

W
wusongqing 已提交
1705 1706 1707
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode.|
W
wusongqing 已提交
1708

W
wusongqing 已提交
1709
**Return value**
1710

W
wusongqing 已提交
1711 1712 1713
| Type| Description|
| -------- | -------- |
| string | String encoded from the Uint8Array.|
W
wusongqing 已提交
1714

W
wusongqing 已提交
1715
**Example**
1716
  ```js
1717 1718 1719
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let result = that.encodeToStringSync(array);
W
wusongqing 已提交
1720 1721 1722 1723 1724
  ```


### decodeSync<sup>8+</sup>

W
wusongqing 已提交
1725
decodeSync(src: Uint8Array | string): Uint8Array
Z
zengyawen 已提交
1726 1727 1728

Decodes the input content.

W
wusongqing 已提交
1729 1730 1731
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1732

W
wusongqing 已提交
1733 1734 1735
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array \| string | Yes| Uint8Array or string to decode.|
W
wusongqing 已提交
1736

W
wusongqing 已提交
1737
**Return value**
1738

W
wusongqing 已提交
1739 1740 1741
| Type| Description|
| -------- | -------- |
| Uint8Array | Uint8Array decoded.|
W
wusongqing 已提交
1742

W
wusongqing 已提交
1743
**Example**
1744
  ```js
1745 1746 1747
  let that = new util.Base64();
  let buff = 'czEz';
  let result = that.decodeSync(buff);
W
wusongqing 已提交
1748 1749 1750 1751 1752
  ```


### encode<sup>8+</sup>

X
xdmal 已提交
1753
encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
1754 1755 1756

Encodes the input content asynchronously.

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

**Parameters**
1760

W
wusongqing 已提交
1761 1762 1763
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
W
wusongqing 已提交
1764

W
wusongqing 已提交
1765
**Return value**
1766

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

W
wusongqing 已提交
1771
**Example**
1772
  ```js
1773 1774 1775
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
  let rarray = new Uint8Array([99,122,69,122]);
W
wusongqing 已提交
1776 1777
  that.encode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
S
shikai-123 已提交
1778
          console.log(val[i].toString())
W
wusongqing 已提交
1779 1780 1781 1782 1783 1784 1785
      }
  })
  ```


### encodeToString<sup>8+</sup>

X
xdmal 已提交
1786
encodeToString(src: Uint8Array): Promise&lt;string&gt;
W
wusongqing 已提交
1787 1788 1789

Encodes the input content asynchronously.

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

**Parameters**
1793

W
wusongqing 已提交
1794 1795 1796
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
W
wusongqing 已提交
1797

W
wusongqing 已提交
1798
**Return value**
1799

W
wusongqing 已提交
1800 1801 1802
| Type| Description|
| -------- | -------- |
| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
W
wusongqing 已提交
1803

W
wusongqing 已提交
1804
**Example**
1805
  ```js
1806 1807
  let that = new util.Base64();
  let array = new Uint8Array([115,49,51]);
W
wusongqing 已提交
1808 1809 1810 1811 1812 1813 1814 1815
  that.encodeToString(array).then(val=>{    
      console.log(val)
  })
  ```


### decode<sup>8+</sup>

W
wusongqing 已提交
1816
decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
1817 1818 1819

Decodes the input content asynchronously.

W
wusongqing 已提交
1820 1821 1822
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1823

W
wusongqing 已提交
1824 1825 1826
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.|
W
wusongqing 已提交
1827

W
wusongqing 已提交
1828
**Return value**
1829

W
wusongqing 已提交
1830 1831 1832
| Type| Description|
| -------- | -------- |
| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
W
wusongqing 已提交
1833

W
wusongqing 已提交
1834
**Example**
1835
  ```js
1836 1837 1838
  let that = new util.Base64();
  let array = new Uint8Array([99,122,69,122]);
  let rarray = new Uint8Array([115,49,51]);
W
wusongqing 已提交
1839 1840
  that.decode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
S
shikai-123 已提交
1841
          console.log(val[i].toString())
W
wusongqing 已提交
1842 1843 1844 1845 1846
      }
  })
  ```


1847
## types<sup>8+</sup>
W
wusongqing 已提交
1848 1849 1850 1851 1852 1853


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

constructor()

W
wusongqing 已提交
1854
A constructor used to create a **Types** object.
W
wusongqing 已提交
1855

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

**Example**
1859
  ```js
1860
  let type = new util.types();
W
wusongqing 已提交
1861 1862 1863 1864 1865
  ```


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

X
xdmal 已提交
1866
isAnyArrayBuffer(value: Object): boolean
W
wusongqing 已提交
1867 1868 1869

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

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

**Parameters**
1873

W
wusongqing 已提交
1874 1875 1876
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
1877

W
wusongqing 已提交
1878
**Return value**
1879

W
wusongqing 已提交
1880 1881 1882
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
1883

W
wusongqing 已提交
1884
**Example**
1885
  ```js
1886 1887
  let that = new util.types();
  let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
W
wusongqing 已提交
1888 1889 1890 1891 1892
  ```


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

X
xdmal 已提交
1893
isArrayBufferView(value: Object): boolean
W
wusongqing 已提交
1894 1895 1896 1897 1898

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

**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.

W
wusongqing 已提交
1899 1900 1901
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1902

W
wusongqing 已提交
1903 1904 1905
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
1906

W
wusongqing 已提交
1907
**Return value**
1908

W
wusongqing 已提交
1909 1910 1911
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
W
wusongqing 已提交
1912

W
wusongqing 已提交
1913
**Example**
1914
  ```js
1915 1916
  let that = new util.types();
  let result = that.isArrayBufferView(new Int8Array([]));
W
wusongqing 已提交
1917 1918 1919 1920 1921
  ```


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

X
xdmal 已提交
1922
isArgumentsObject(value: Object): boolean
W
wusongqing 已提交
1923 1924 1925

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

W
wusongqing 已提交
1926 1927 1928
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1929

W
wusongqing 已提交
1930 1931 1932
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
1933

W
wusongqing 已提交
1934
**Return value**
1935

W
wusongqing 已提交
1936 1937 1938
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
W
wusongqing 已提交
1939

W
wusongqing 已提交
1940
**Example**
1941
  ```js
1942
  let that = new util.types();
W
wusongqing 已提交
1943 1944 1945
  function foo() {
      var result = that.isArgumentsObject(arguments);
  }
1946
  let f = foo();
W
wusongqing 已提交
1947 1948 1949 1950 1951
  ```


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

X
xdmal 已提交
1952
isArrayBuffer(value: Object): boolean
W
wusongqing 已提交
1953 1954 1955

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

W
wusongqing 已提交
1956 1957 1958
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1959

W
wusongqing 已提交
1960 1961 1962
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
1963

W
wusongqing 已提交
1964
**Return value**
1965

W
wusongqing 已提交
1966 1967 1968
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
W
wusongqing 已提交
1969

W
wusongqing 已提交
1970
**Example**
1971
  ```js
1972 1973
  let that = new util.types();
  let result = that.isArrayBuffer(new ArrayBuffer(0));
W
wusongqing 已提交
1974 1975 1976 1977 1978
  ```


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

X
xdmal 已提交
1979
isAsyncFunction(value: Object): boolean
Z
zengyawen 已提交
1980 1981 1982

Checks whether the input value is an asynchronous function.

W
wusongqing 已提交
1983 1984 1985
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1986

W
wusongqing 已提交
1987 1988 1989
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
1990

W
wusongqing 已提交
1991
**Return value**
1992

W
wusongqing 已提交
1993 1994 1995
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
W
wusongqing 已提交
1996

W
wusongqing 已提交
1997
**Example**
1998
  ```js
1999 2000
  let that = new util.types();
  let result = that.isAsyncFunction(async function foo() {});
W
wusongqing 已提交
2001 2002 2003 2004 2005
  ```


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

X
xdmal 已提交
2006
isBooleanObject(value: Object): boolean
W
wusongqing 已提交
2007 2008 2009

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

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

**Parameters**
2013

W
wusongqing 已提交
2014 2015 2016
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2017

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

W
wusongqing 已提交
2020 2021 2022
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
W
wusongqing 已提交
2023

W
wusongqing 已提交
2024
**Example**
2025
  ```js
2026 2027
  let that = new util.types();
  let result = that.isBooleanObject(new Boolean(true));
W
wusongqing 已提交
2028 2029 2030 2031 2032
  ```


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

X
xdmal 已提交
2033
isBoxedPrimitive(value: Object): boolean
W
wusongqing 已提交
2034 2035 2036

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

W
wusongqing 已提交
2037 2038 2039
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2040

W
wusongqing 已提交
2041 2042 2043
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2044

W
wusongqing 已提交
2045
**Return value**
2046

W
wusongqing 已提交
2047 2048 2049
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
W
wusongqing 已提交
2050

W
wusongqing 已提交
2051
**Example**
2052
  ```js
2053 2054
  let that = new util.types();
  let result = that.isBoxedPrimitive(new Boolean(false));
W
wusongqing 已提交
2055 2056 2057 2058 2059
  ```


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

X
xdmal 已提交
2060
isDataView(value: Object): boolean
W
wusongqing 已提交
2061 2062 2063

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

W
wusongqing 已提交
2064 2065 2066
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2067

W
wusongqing 已提交
2068 2069 2070
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2071

W
wusongqing 已提交
2072
**Return value**
2073

W
wusongqing 已提交
2074 2075 2076
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
W
wusongqing 已提交
2077

W
wusongqing 已提交
2078
**Example**
2079
  ```js
2080
  let that = new util.types();
W
wusongqing 已提交
2081
  const ab = new ArrayBuffer(20);
2082
  let result = that.isDataView(new DataView(ab));
W
wusongqing 已提交
2083 2084 2085 2086 2087
  ```


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

X
xdmal 已提交
2088
isDate(value: Object): boolean
W
wusongqing 已提交
2089 2090 2091

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

W
wusongqing 已提交
2092 2093 2094
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2095

W
wusongqing 已提交
2096 2097 2098
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2099

W
wusongqing 已提交
2100
**Return value**
2101

W
wusongqing 已提交
2102 2103 2104
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
W
wusongqing 已提交
2105

W
wusongqing 已提交
2106
**Example**
2107
  ```js
2108 2109
  let that = new util.types();
  let result = that.isDate(new Date());
W
wusongqing 已提交
2110 2111 2112 2113 2114
  ```


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

X
xdmal 已提交
2115
isExternal(value: Object): boolean
W
wusongqing 已提交
2116 2117 2118

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

W
wusongqing 已提交
2119 2120 2121
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2122

W
wusongqing 已提交
2123 2124 2125
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2126

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

W
wusongqing 已提交
2129 2130 2131
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
W
wusongqing 已提交
2132

W
wusongqing 已提交
2133
**Example**
2134
  ```js
2135 2136
  let that = new util.types();
  let result = that.isExternal(true);
W
wusongqing 已提交
2137 2138 2139 2140 2141
  ```


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

X
xdmal 已提交
2142
isFloat32Array(value: Object): boolean
W
wusongqing 已提交
2143 2144 2145

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

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

**Parameters**
2149

W
wusongqing 已提交
2150 2151 2152
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2153

W
wusongqing 已提交
2154
**Return value**
2155

W
wusongqing 已提交
2156 2157 2158
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2159

W
wusongqing 已提交
2160
**Example**
2161
  ```js
2162 2163
  let that = new util.types();
  let result = that.isFloat32Array(new Float32Array());
W
wusongqing 已提交
2164 2165 2166 2167 2168
  ```


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

X
xdmal 已提交
2169
isFloat64Array(value: Object): boolean
W
wusongqing 已提交
2170 2171 2172

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

W
wusongqing 已提交
2173 2174 2175
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2176

W
wusongqing 已提交
2177 2178 2179
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2180

W
wusongqing 已提交
2181
**Return value**
2182

W
wusongqing 已提交
2183 2184 2185
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2186

W
wusongqing 已提交
2187
**Example**
2188
  ```js
2189 2190
  let that = new util.types();
  let result = that.isFloat64Array(new Float64Array());
W
wusongqing 已提交
2191 2192 2193 2194 2195
  ```


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

X
xdmal 已提交
2196
isGeneratorFunction(value: Object): boolean
Z
zengyawen 已提交
2197 2198 2199

Checks whether the input value is a generator function.

W
wusongqing 已提交
2200 2201 2202
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2203

W
wusongqing 已提交
2204 2205 2206
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2207

W
wusongqing 已提交
2208
**Return value**
2209

W
wusongqing 已提交
2210 2211 2212
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
W
wusongqing 已提交
2213

W
wusongqing 已提交
2214
**Example**
2215
  ```js
2216 2217
  let that = new util.types();
  let result = that.isGeneratorFunction(function* foo() {});
W
wusongqing 已提交
2218 2219 2220 2221 2222
  ```


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

X
xdmal 已提交
2223
isGeneratorObject(value: Object): boolean
Z
zengyawen 已提交
2224 2225 2226

Checks whether the input value is a generator object.

W
wusongqing 已提交
2227 2228 2229
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2230

W
wusongqing 已提交
2231 2232 2233
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2234

W
wusongqing 已提交
2235
**Return value**
2236

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

W
wusongqing 已提交
2241
**Example**
2242
  ```js
2243
  let that = new util.types();
W
wusongqing 已提交
2244 2245
  function* foo() {}
  const generator = foo();
2246
  let result = that.isGeneratorObject(generator);
W
wusongqing 已提交
2247 2248 2249 2250 2251
  ```


### isInt8Array<sup>8+</sup>

X
xdmal 已提交
2252
isInt8Array(value: Object): boolean
W
wusongqing 已提交
2253 2254 2255

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

W
wusongqing 已提交
2256 2257 2258
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2259

W
wusongqing 已提交
2260 2261 2262
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2263

W
wusongqing 已提交
2264
**Return value**
2265

W
wusongqing 已提交
2266 2267 2268
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2269

W
wusongqing 已提交
2270
**Example**
2271
  ```js
2272 2273
  let that = new util.types();
  let result = that.isInt8Array(new Int8Array([]));
W
wusongqing 已提交
2274 2275 2276 2277 2278
  ```


### isInt16Array<sup>8+</sup>

X
xdmal 已提交
2279
isInt16Array(value: Object): boolean
W
wusongqing 已提交
2280 2281 2282

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

W
wusongqing 已提交
2283 2284 2285
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2286

W
wusongqing 已提交
2287 2288 2289
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2290

W
wusongqing 已提交
2291
**Return value**
2292

W
wusongqing 已提交
2293 2294 2295
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2296

W
wusongqing 已提交
2297
**Example**
2298
  ```js
2299 2300
  let that = new util.types();
  let result = that.isInt16Array(new Int16Array([]));
W
wusongqing 已提交
2301 2302 2303 2304 2305
  ```


### isInt32Array<sup>8+</sup>

X
xdmal 已提交
2306
isInt32Array(value: Object): boolean
W
wusongqing 已提交
2307 2308 2309

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

W
wusongqing 已提交
2310 2311 2312
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2313

W
wusongqing 已提交
2314 2315 2316
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2317

W
wusongqing 已提交
2318
**Return value**
2319

W
wusongqing 已提交
2320 2321 2322
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2323

W
wusongqing 已提交
2324
**Example**
2325
  ```js
2326 2327
  let that = new util.types();
  let result = that.isInt32Array(new Int32Array([]));
W
wusongqing 已提交
2328 2329 2330 2331 2332
  ```


### isMap<sup>8+</sup>

X
xdmal 已提交
2333
isMap(value: Object): boolean
W
wusongqing 已提交
2334 2335 2336

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

W
wusongqing 已提交
2337 2338 2339
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2340

W
wusongqing 已提交
2341 2342 2343
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2344

W
wusongqing 已提交
2345
**Return value**
2346

W
wusongqing 已提交
2347 2348 2349
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
W
wusongqing 已提交
2350

W
wusongqing 已提交
2351
**Example**
2352
  ```js
2353 2354
  let that = new util.types();
  let result = that.isMap(new Map());
W
wusongqing 已提交
2355 2356 2357 2358 2359
  ```


### isMapIterator<sup>8+</sup>

X
xdmal 已提交
2360
isMapIterator(value: Object): boolean
W
wusongqing 已提交
2361 2362 2363

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

W
wusongqing 已提交
2364 2365 2366
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2367

W
wusongqing 已提交
2368 2369 2370
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2371

W
wusongqing 已提交
2372
**Return value**
2373

W
wusongqing 已提交
2374 2375 2376
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
W
wusongqing 已提交
2377

W
wusongqing 已提交
2378
**Example**
2379
  ```js
2380
  let that = new util.types();
W
wusongqing 已提交
2381
  const map = new Map();
2382
  let result = that.isMapIterator(map.keys());
W
wusongqing 已提交
2383 2384 2385 2386 2387
  ```


### isNativeError<sup>8+</sup>

X
xdmal 已提交
2388
isNativeError(value: Object): boolean
W
wusongqing 已提交
2389 2390 2391

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

W
wusongqing 已提交
2392 2393 2394
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2395

W
wusongqing 已提交
2396 2397 2398
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2399

W
wusongqing 已提交
2400
**Return value**
2401

W
wusongqing 已提交
2402 2403 2404
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
W
wusongqing 已提交
2405

W
wusongqing 已提交
2406
**Example**
2407
  ```js
2408 2409
  let that = new util.types();
  let result = that.isNativeError(new TypeError());
W
wusongqing 已提交
2410 2411 2412 2413 2414
  ```


### isNumberObject<sup>8+</sup>

X
xdmal 已提交
2415
isNumberObject(value: Object): boolean
Z
zengyawen 已提交
2416 2417 2418

Checks whether the input value is a number object.

W
wusongqing 已提交
2419 2420 2421
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2422

W
wusongqing 已提交
2423 2424 2425
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2426

W
wusongqing 已提交
2427
**Return value**
2428

W
wusongqing 已提交
2429 2430 2431
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
W
wusongqing 已提交
2432

W
wusongqing 已提交
2433
**Example**
2434
  ```js
2435 2436
  let that = new util.types();
  let result = that.isNumberObject(new Number(0));
W
wusongqing 已提交
2437 2438 2439 2440 2441
  ```


### isPromise<sup>8+</sup>

X
xdmal 已提交
2442
isPromise(value: Object): boolean
Z
zengyawen 已提交
2443 2444 2445

Checks whether the input value is a promise.

W
wusongqing 已提交
2446 2447 2448
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2449

W
wusongqing 已提交
2450 2451 2452
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2453

W
wusongqing 已提交
2454
**Return value**
2455

W
wusongqing 已提交
2456 2457 2458
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
W
wusongqing 已提交
2459

W
wusongqing 已提交
2460
**Example**
2461
  ```js
2462 2463
  let that = new util.types();
  let result = that.isPromise(Promise.resolve(1));
W
wusongqing 已提交
2464 2465 2466 2467 2468
  ```


### isProxy<sup>8+</sup>

X
xdmal 已提交
2469
isProxy(value: Object): boolean
Z
zengyawen 已提交
2470 2471 2472

Checks whether the input value is a proxy.

W
wusongqing 已提交
2473 2474 2475
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2476

W
wusongqing 已提交
2477 2478 2479
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2480

W
wusongqing 已提交
2481
**Return value**
2482

W
wusongqing 已提交
2483 2484 2485
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
W
wusongqing 已提交
2486

W
wusongqing 已提交
2487
**Example**
2488
  ```js
2489
  let that = new util.types();
W
wusongqing 已提交
2490 2491
  const target = {};
  const proxy = new Proxy(target, {});
2492
  let result = that.isProxy(proxy);
W
wusongqing 已提交
2493 2494 2495 2496 2497
  ```


### isRegExp<sup>8+</sup>

X
xdmal 已提交
2498
isRegExp(value: Object): boolean
W
wusongqing 已提交
2499 2500 2501

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

W
wusongqing 已提交
2502 2503 2504
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2505

W
wusongqing 已提交
2506 2507 2508
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2509

W
wusongqing 已提交
2510
**Return value**
2511

W
wusongqing 已提交
2512 2513 2514
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.|
W
wusongqing 已提交
2515

W
wusongqing 已提交
2516
**Example**
2517
  ```js
2518 2519
  let that = new util.types();
  let result = that.isRegExp(new RegExp('abc'));
W
wusongqing 已提交
2520 2521 2522 2523 2524
  ```


### isSet<sup>8+</sup>

X
xdmal 已提交
2525
isSet(value: Object): boolean
W
wusongqing 已提交
2526 2527 2528

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

W
wusongqing 已提交
2529 2530 2531
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2532

W
wusongqing 已提交
2533 2534 2535
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2536

W
wusongqing 已提交
2537
**Return value**
2538

W
wusongqing 已提交
2539 2540 2541
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
W
wusongqing 已提交
2542

W
wusongqing 已提交
2543
**Example**
2544
  ```js
2545 2546
  let that = new util.types();
  let result = that.isSet(new Set());
W
wusongqing 已提交
2547 2548 2549 2550 2551
  ```


### isSetIterator<sup>8+</sup>

X
xdmal 已提交
2552
isSetIterator(value: Object): boolean
W
wusongqing 已提交
2553 2554 2555

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

W
wusongqing 已提交
2556 2557 2558
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2559

W
wusongqing 已提交
2560 2561 2562
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2563

W
wusongqing 已提交
2564
**Return value**
2565

W
wusongqing 已提交
2566 2567 2568
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.|
W
wusongqing 已提交
2569

W
wusongqing 已提交
2570
**Example**
2571
  ```js
2572
  let that = new util.types();
W
wusongqing 已提交
2573
  const set = new Set();
2574
  let result = that.isSetIterator(set.keys());
W
wusongqing 已提交
2575 2576 2577 2578 2579
  ```


### isStringObject<sup>8+</sup>

X
xdmal 已提交
2580
isStringObject(value: Object): boolean
Z
zengyawen 已提交
2581 2582 2583

Checks whether the input value is a string object.

W
wusongqing 已提交
2584 2585 2586
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2587

W
wusongqing 已提交
2588 2589 2590
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2591

W
wusongqing 已提交
2592
**Return value**
2593

W
wusongqing 已提交
2594 2595 2596
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
W
wusongqing 已提交
2597

W
wusongqing 已提交
2598
**Example**
2599
  ```js
2600 2601
  let that = new util.types();
  let result = that.isStringObject(new String('foo'));
W
wusongqing 已提交
2602 2603 2604 2605 2606
  ```


### isSymbolObjec<sup>8+</sup>

X
xdmal 已提交
2607
isSymbolObject(value: Object): boolean
Z
zengyawen 已提交
2608 2609 2610

Checks whether the input value is a symbol object.

W
wusongqing 已提交
2611 2612 2613
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2614

W
wusongqing 已提交
2615 2616 2617
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2618

W
wusongqing 已提交
2619
**Return value**
2620

W
wusongqing 已提交
2621 2622 2623
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
W
wusongqing 已提交
2624

W
wusongqing 已提交
2625
**Example**
2626
  ```js
2627
  let that = new util.types();
W
wusongqing 已提交
2628
  const symbols = Symbol('foo');
2629
  let result = that.isSymbolObject(Object(symbols));
W
wusongqing 已提交
2630 2631 2632 2633 2634
  ```


### isTypedArray<sup>8+</sup>

X
xdmal 已提交
2635
isTypedArray(value: Object): boolean
W
wusongqing 已提交
2636 2637 2638 2639 2640

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

**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.

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

**Parameters**
2644

W
wusongqing 已提交
2645 2646 2647
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2648

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

W
wusongqing 已提交
2651 2652 2653
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
W
wusongqing 已提交
2654

W
wusongqing 已提交
2655
**Example**
2656
  ```js
2657 2658
  let that = new util.types();
  let result = that.isTypedArray(new Float64Array([]));
W
wusongqing 已提交
2659 2660 2661 2662 2663
  ```


### isUint8Array<sup>8+</sup>

X
xdmal 已提交
2664
isUint8Array(value: Object): boolean
W
wusongqing 已提交
2665 2666 2667

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

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

**Parameters**
2671

W
wusongqing 已提交
2672 2673 2674
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2675

W
wusongqing 已提交
2676
**Return value**
2677

W
wusongqing 已提交
2678 2679 2680
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2681

W
wusongqing 已提交
2682
**Example**
2683
  ```js
2684 2685
  let that = new util.types();
  let result = that.isUint8Array(new Uint8Array([]));
W
wusongqing 已提交
2686 2687 2688 2689 2690
  ```


### isUint8ClampedArray<sup>8+</sup>

X
xdmal 已提交
2691
isUint8ClampedArray(value: Object): boolean
W
wusongqing 已提交
2692 2693 2694

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

W
wusongqing 已提交
2695 2696 2697
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2698

W
wusongqing 已提交
2699 2700 2701
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2702

W
wusongqing 已提交
2703
**Return value**
2704

W
wusongqing 已提交
2705 2706 2707
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
W
wusongqing 已提交
2708

W
wusongqing 已提交
2709
**Example**
2710
  ```js
2711 2712
  let that = new util.types();
  let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
W
wusongqing 已提交
2713 2714 2715 2716 2717
  ```


### isUint16Array<sup>8+</sup>

X
xdmal 已提交
2718
isUint16Array(value: Object): boolean
W
wusongqing 已提交
2719 2720 2721

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

W
wusongqing 已提交
2722 2723 2724
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2725

W
wusongqing 已提交
2726 2727 2728
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2729

W
wusongqing 已提交
2730
**Return value**
2731

W
wusongqing 已提交
2732 2733 2734
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
W
wusongqing 已提交
2735

W
wusongqing 已提交
2736
**Example**
2737
  ```js
2738 2739
  let that = new util.types();
  let result = that.isUint16Array(new Uint16Array([]));
W
wusongqing 已提交
2740 2741 2742 2743 2744
  ```


### isUint32Array<sup>8+</sup>

X
xdmal 已提交
2745
isUint32Array(value: Object): boolean
W
wusongqing 已提交
2746 2747 2748

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

W
wusongqing 已提交
2749 2750 2751
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2752

W
wusongqing 已提交
2753 2754 2755
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2756

W
wusongqing 已提交
2757
**Return value**
2758

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

W
wusongqing 已提交
2763
**Example**
2764
  ```js
2765 2766
  let that = new util.types();
  let result = that.isUint32Array(new Uint32Array([]));
W
wusongqing 已提交
2767 2768 2769 2770 2771
  ```


### isWeakMap<sup>8+</sup>

X
xdmal 已提交
2772
isWeakMap(value: Object): boolean
W
wusongqing 已提交
2773 2774 2775

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

W
wusongqing 已提交
2776 2777 2778
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2779

W
wusongqing 已提交
2780 2781 2782
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2783

W
wusongqing 已提交
2784
**Return value**
2785

W
wusongqing 已提交
2786 2787 2788
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
W
wusongqing 已提交
2789

W
wusongqing 已提交
2790
**Example**
2791
  ```js
2792 2793
  let that = new util.types();
  let result = that.isWeakMap(new WeakMap());
W
wusongqing 已提交
2794 2795 2796 2797 2798
  ```


### isWeakSet<sup>8+</sup>

X
xdmal 已提交
2799
isWeakSet(value: Object): boolean
W
wusongqing 已提交
2800 2801 2802

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

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

**Parameters**
2806

W
wusongqing 已提交
2807 2808 2809
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | Object | Yes| Object to check.|
W
wusongqing 已提交
2810

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

W
wusongqing 已提交
2813 2814 2815
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
Z
zengyawen 已提交
2816

W
wusongqing 已提交
2817
**Example**
2818
  ```js
2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929
  let that = new util.types();
  let result = that.isWeakSet(new WeakSet());
  ```


### isBigInt64Array<sup>8+</sup>

isBigInt64Array(value: Object): boolean

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

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

**Parameters**

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

**Return value**

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

**Example**
  ```js
  let that = new util.types();
  let result = that.isBigInt64Array(new BigInt64Array([]));
  ```


### isBigUint64Array<sup>8+</sup>

isBigUint64Array(value: Object): boolean

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

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

**Parameters**

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

**Return value**

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

**Example**
  ```js
  let that = new util.types();
  let result = that.isBigUint64Array(new BigUint64Array([]));
  ```


### isModuleNamespaceObject<sup>8+</sup>

isModuleNamespaceObject(value: Object): boolean

Checks whether the input value is a module namespace object.

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

**Parameters**

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

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.|

**Example**
  ```js
  import url from '@ohos.url'
  let that = new util.types();
  let result = that.isModuleNamespaceObject(url);
  ```


### isSharedArrayBuffer<sup>8+</sup>

isSharedArrayBuffer(value: Object): boolean

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

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

**Parameters**

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

**Return value**

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

**Example**
  ```js
  let that = new util.types();
  let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
W
wusongqing 已提交
2930
  ```