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


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

W
wusongqing 已提交
7

8
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 已提交
9 10 11


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

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

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

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

Prints the input content in a formatted string.

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

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

W
wusongqing 已提交
31
**Return value**
32 33 34
 | Type | Description |
 | --------  | --------  |
 | string  | String in the specified format. |
W
wusongqing 已提交
35

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


## util.getErrorString

getErrorString(errno: number): string
Z
zengyawen 已提交
46 47 48

Obtains detailed information about a system error code.

W
wusongqing 已提交
49 50 51
**System capability**: SystemCapability.Utils.Lang

**Parameters**
52 53 54
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | errno  | number  | Yes | Error code generated. |
W
wusongqing 已提交
55

W
wusongqing 已提交
56
**Return value**
57 58 59
 | Type | Description |
 | --------  | --------  |
 | string  | Detailed information about the error code. |
W
wusongqing 已提交
60

W
wusongqing 已提交
61
**Example**
62
  ```js
W
wusongqing 已提交
63 64 65 66 67 68 69 70 71 72 73
  var errnum = 10; // 10 is the system error code.
  var result = util.getErrorString(errnum);
  console.log("result = " + result);
  ```


## util.callbackWrapper

callbackWrapper(original: Function): (err: Object, value: Object )=&gt;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 已提交
74

W
wusongqing 已提交
75 76 77 78
**System capability**: SystemCapability.Utils.Lang

**Parameters**

79 80 81
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | original  | Function  | Yes | Asynchronous function. |
Z
zengyawen 已提交
82

W
wusongqing 已提交
83
**Return value**
84 85 86
 | 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 已提交
87

W
wusongqing 已提交
88
**Example**
89
  ```js
W
wusongqing 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103
  async function promiseFn() {
      return Promise.reject('value');
  }
  var cb = util.callbackWrapper(promiseFn);
  cb((err, ret) => {
      console.log(err);
      console.log(ret);
  })
  ```


## util.promiseWrapper

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

Processes an asynchronous function and returns a promise version.

W
wusongqing 已提交
107 108 109
**System capability**: SystemCapability.Utils.Lang

**Parameters**
110 111 112
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | original  | Function  | Yes | Asynchronous function. |
W
wusongqing 已提交
113

W
wusongqing 已提交
114
**Return value**
115 116 117
 | Type | Description |
 | --------  | --------  |
 | Function  | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise version. |
W
wusongqing 已提交
118

W
wusongqing 已提交
119
**Example**
120
  ```js
W
wusongqing 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
  function aysnFun(str1, str2, callback) {
      if (typeof str1 === 'string' && typeof str2 === 'string') {
          callback(null, str1 + str2);
      } else {
          callback('type err');
      }
  }
  let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World');
  newPromiseObj.then(res => {
      console.log(res);
  })
  ```


## TextDecoder

### Attributes

W
wusongqing 已提交
139 140
**System capability**: SystemCapability.Utils.Lang

141 142 143 144 145
 | Name | Type | Readable | Writable | Description |
 | --------  | --------  | --------  | --------  | --------  |
 | encoding  | string  | Yes | No | Encoding format.<br>-&nbsp;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 已提交
146 147 148 149


### constructor

S
shikai-123 已提交
150
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
W
wusongqing 已提交
151 152 153

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

W
wusongqing 已提交
154 155 156
**System capability**: SystemCapability.Utils.Lang

**Parameters**
157 158 159 160
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | encoding  | string  | No | Encoding format. |
 | options  | Object  | No | Encoding-related options, which include **fatal** and **ignoreBOM**. |
W
wusongqing 已提交
161 162

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

164 165 166 167
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | fatal  | boolean  | No | Whether to display fatal errors. |
 | ignoreBOM  | boolean  | No | Whether to ignore the BOM. |
W
wusongqing 已提交
168

W
wusongqing 已提交
169
**Example**
170
  ```js
X
xdmal 已提交
171
  var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
W
wusongqing 已提交
172 173 174 175 176
  ```


### decode

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

Z
zengyawen 已提交
179
Decodes the input content.
Z
zengyawen 已提交
180

W
wusongqing 已提交
181 182 183
**System capability**: SystemCapability.Utils.Lang

**Parameters**
184 185 186 187
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | input  | Unit8Array  | Yes | Uint8Array to decode. |
 | options  | Object  | No | Options related to decoding. |
W
wusongqing 已提交
188 189

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

191 192 193
 | 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 已提交
194

W
wusongqing 已提交
195
**Return value**
196 197 198
 | Type | Description |
 | --------  | --------  |
 | string  | Data decoded. |
Z
zengyawen 已提交
199

W
wusongqing 已提交
200
**Example**
201
  ```js
X
xdmal 已提交
202
  var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
W
wusongqing 已提交
203 204 205 206 207 208 209 210 211 212 213
  var 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:");
  for(var j= 0; j < 6; j++) {
      console.log(result[j]);
  }
X
xdmal 已提交
214
  var retStr = textDecoder.decode( result , {stream: false});
W
wusongqing 已提交
215 216
  console.log("retStr = " + retStr);
  ```
Z
zengyawen 已提交
217 218


W
wusongqing 已提交
219
## TextEncoder
Z
zengyawen 已提交
220

W
wusongqing 已提交
221
### Attributes
Z
zengyawen 已提交
222

W
wusongqing 已提交
223 224
**System capability**: SystemCapability.Utils.Lang

225 226 227
 | Name | Type | Readable | Writable | Description |
 | --------  | --------  | --------  | --------  | --------  |
 | encoding  | string  | Yes | No | Encoding format. The default format is **utf-8**. |
Z
zengyawen 已提交
228 229


W
wusongqing 已提交
230
### constructor
Z
zengyawen 已提交
231

W
wusongqing 已提交
232
constructor()
Z
zengyawen 已提交
233

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

W
wusongqing 已提交
236 237 238
**System capability**: SystemCapability.Utils.Lang

**Example**
239
  ```js
W
wusongqing 已提交
240 241 242 243 244 245
  var textEncoder = new util.TextEncoder();
  ```


### encode

X
xdmal 已提交
246
encode(input?: string): Uint8Array
Z
zengyawen 已提交
247

Z
zengyawen 已提交
248
Encodes the input content.
Z
zengyawen 已提交
249

W
wusongqing 已提交
250 251 252
**System capability**: SystemCapability.Utils.Lang

**Parameters**
253 254 255
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | input  | string  | Yes | String to encode. |
W
wusongqing 已提交
256

W
wusongqing 已提交
257
**Return value**
258 259 260
 | Type | Description |
 | --------  | --------  |
 | Uint8Array  | Encoded text. |
W
wusongqing 已提交
261

W
wusongqing 已提交
262
**Example**
263
  ```js
W
wusongqing 已提交
264 265 266 267 268 269 270 271
  var textEncoder = new util.TextEncoder();
  var result = new Uint8Array(buffer);
  result = textEncoder.encode("\uD800¥¥");
  ```


### encodeInto

X
xdmal 已提交
272
encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
Z
zengyawen 已提交
273 274 275

Stores the UTF-8 encoded text.

W
wusongqing 已提交
276 277 278
**System capability**: SystemCapability.Utils.Lang

**Parameters**
279 280 281 282
 | 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 已提交
283

W
wusongqing 已提交
284
**Return value**
285 286 287
 | Type | Description |
 | --------  | --------  |
 | Uint8Array  | Encoded text. |
Z
zengyawen 已提交
288

W
wusongqing 已提交
289
**Example**
290
  ```js
W
wusongqing 已提交
291 292 293 294 295
  var that = new util.TextEncoder();
  var buffer = new ArrayBuffer(4);
  this.dest = new Uint8Array(buffer);
  var result = that.encodeInto("abcd", this.dest);
  ```
Z
zengyawen 已提交
296

W
wusongqing 已提交
297
## RationalNumber<sup>8+</sup>
Z
zengyawen 已提交
298 299


W
wusongqing 已提交
300
### constructor<sup>8+</sup>
Z
zengyawen 已提交
301

X
xdmal 已提交
302
constructor(numerator: number,denominator: number)
Z
zengyawen 已提交
303

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

W
wusongqing 已提交
306 307 308
**System capability**: SystemCapability.Utils.Lang

**Parameters**
309 310 311 312
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | numerator  | number  | Yes | Numerator, which is an integer. |
 | denominator  | number  | Yes | Denominator, which is an integer. |
Z
zengyawen 已提交
313

W
wusongqing 已提交
314
**Example**
315
  ```js
W
wusongqing 已提交
316 317
  var rationalNumber = new util.RationalNumber(1,2);
  ```
Z
zengyawen 已提交
318 319


W
wusongqing 已提交
320
### createRationalFromString<sup>8+</sup>
Z
zengyawen 已提交
321

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

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

W
wusongqing 已提交
326 327 328
**System capability**: SystemCapability.Utils.Lang

**Parameters**
329 330 331
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | rationalString  | string  | Yes | String used to create the **RationalNumber** object. |
Z
zengyawen 已提交
332

W
wusongqing 已提交
333
**Return value**
334 335 336
 | Type | Description |
 | --------  | --------  |
 | object  | **RationalNumber** object created. |
Z
zengyawen 已提交
337

W
wusongqing 已提交
338
**Example**
339
  ```js
W
wusongqing 已提交
340 341 342
  var rationalNumber = new util.RationalNumber(1,2);
  var rational = rationalNumer.creatRationalFromString("3/4");
  ```
Z
zengyawen 已提交
343 344


W
wusongqing 已提交
345
### compareTo<sup>8+</sup>
Z
zengyawen 已提交
346

X
xdmal 已提交
347
compareTo​(another: RationalNumber): number​
Z
zengyawen 已提交
348

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

W
wusongqing 已提交
351 352 353
**System capability**: SystemCapability.Utils.Lang

**Parameters**
354 355 356
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | another  | RationalNumber  | Yes | Object used to compare with this **RationalNumber** object. |
Z
zengyawen 已提交
357

W
wusongqing 已提交
358
**Return value**
359 360 361
 | 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 已提交
362

W
wusongqing 已提交
363
**Example**
364 365

  ```js
W
wusongqing 已提交
366 367 368 369
  var rationalNumber = new util.RationalNumber(1,2);
  var rational = rationalNumer.creatRationalFromString("3/4");
  var result = rationalNumber.compareTo(rational);
  ```
Z
zengyawen 已提交
370 371


W
wusongqing 已提交
372
### valueOf<sup>8+</sup>
Z
zengyawen 已提交
373

X
xdmal 已提交
374
valueOf(): number
Z
zengyawen 已提交
375

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

W
wusongqing 已提交
378 379 380
**System capability**: SystemCapability.Utils.Lang

**Return value**
381 382 383
 | Type | Description |
 | --------  | --------  |
 | number  | An integer or a floating-point number. |
Z
zengyawen 已提交
384

W
wusongqing 已提交
385
**Example**
386
  ```js
W
wusongqing 已提交
387 388 389
  var rationalNumber = new util.RationalNumber(1,2);
  var result = rationalNumber.valueOf();
  ```
Z
zengyawen 已提交
390 391


W
wusongqing 已提交
392
### equals<sup>8+</sup>
Z
zengyawen 已提交
393

X
xdmal 已提交
394
equals​(obj: Object): boolean
Z
zengyawen 已提交
395

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

W
wusongqing 已提交
398 399 400
**System capability**: SystemCapability.Utils.Lang

**Parameters**
401 402 403
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | object  | Object  | Yes | Object used to compare with this **RationalNumber** object. |
Z
zengyawen 已提交
404

W
wusongqing 已提交
405
**Return value**
406 407 408
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the two objects are equal; returns **false** otherwise. |
Z
zengyawen 已提交
409

W
wusongqing 已提交
410
**Example**
411
  ```js
W
wusongqing 已提交
412 413 414 415
  var rationalNumber = new util.RationalNumber(1,2);
  var rational = rationalNumer.creatRationalFromString("3/4");
  var result = rationalNumber.equals(rational);
  ```
Z
zengyawen 已提交
416 417


W
wusongqing 已提交
418
### getCommonDivisor<sup>8+</sup>
Z
zengyawen 已提交
419

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

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

W
wusongqing 已提交
424 425 426
**System capability**: SystemCapability.Utils.Lang

**Parameters**
427 428 429 430
 | 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 已提交
431

W
wusongqing 已提交
432
**Return value**
433 434 435
 | Type | Description |
 | --------  | --------  |
 | number  | Greatest common divisor obtained. |
Z
zengyawen 已提交
436

W
wusongqing 已提交
437
**Example**
438
  ```js
W
wusongqing 已提交
439 440 441
  var rationalNumber = new util.RationalNumber(1,2);
  var result = rationalNumber.getCommonDivisor(4,6);
  ```
Z
zengyawen 已提交
442 443


W
wusongqing 已提交
444
### getNumerator<sup>8+</sup>
Z
zengyawen 已提交
445

X
xdmal 已提交
446
getNumerator​(): number
Z
zengyawen 已提交
447

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

W
wusongqing 已提交
450 451 452 453
**System capability**: SystemCapability.Utils.Lang

**Return value**

454 455 456
 | Type | Description |
 | --------  | --------  |
 | number  | Numerator of this **RationalNumber** object. |
Z
zengyawen 已提交
457

W
wusongqing 已提交
458
**Example**
459
  ```js
W
wusongqing 已提交
460 461 462
  var rationalNumber = new util.RationalNumber(1,2);
  var result = rationalNumber.getNumerator();
  ```
Z
zengyawen 已提交
463 464


W
wusongqing 已提交
465
### getDenominator<sup>8+</sup>
Z
zengyawen 已提交
466

X
xdmal 已提交
467
getDenominator​(): number
Z
zengyawen 已提交
468

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

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

**Return value**
474 475 476
 | Type | Description |
 | --------  | --------  |
 | number  | Denominator of this **RationalNumber** object. |
Z
zengyawen 已提交
477

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


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

X
xdmal 已提交
487
isZero​(): boolean
Z
zengyawen 已提交
488

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

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

**Return value**
494 495 496
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise. |
Z
zengyawen 已提交
497

W
wusongqing 已提交
498
**Example**
499
  ```js
W
wusongqing 已提交
500 501 502
  var rationalNumber = new util.RationalNumber(1,2);
  var result = rationalNumber.isZero();
  ```
Z
zengyawen 已提交
503 504


W
wusongqing 已提交
505
### isNaN<sup>8+</sup>
Z
zengyawen 已提交
506

X
xdmal 已提交
507
isNaN​(): boolean
Z
zengyawen 已提交
508

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

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

**Return value**
514 515 516
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise. |
Z
zengyawen 已提交
517

W
wusongqing 已提交
518
**Example**
519
  ```js
W
wusongqing 已提交
520 521 522
  var rationalNumber = new util.RationalNumber(1,2);
  var result = rationalNumber.isNaN();
  ```
Z
zengyawen 已提交
523 524


W
wusongqing 已提交
525
### isFinite<sup>8+</sup>
Z
zengyawen 已提交
526

X
xdmal 已提交
527
isFinite​(): boolean
Z
zengyawen 已提交
528

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

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

**Return value**
534 535 536
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise. |
Z
zengyawen 已提交
537

W
wusongqing 已提交
538
**Example**
539
  ```js
W
wusongqing 已提交
540 541 542
  var rationalNumber = new util.RationalNumber(1,2);
  var result = rationalNumber.isFinite();
  ```
Z
zengyawen 已提交
543 544


W
wusongqing 已提交
545
### toString<sup>8+</sup>
Z
zengyawen 已提交
546

X
xdmal 已提交
547
toString​(): string
Z
zengyawen 已提交
548

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

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

**Return value**
554 555 556
 | 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 已提交
557

W
wusongqing 已提交
558
**Example**
559
  ```js
W
wusongqing 已提交
560 561 562
  var rationalNumber = new util.RationalNumber(1,2);
  var result = rationalNumber.toString();
  ```
Z
zengyawen 已提交
563

W
wusongqing 已提交
564
## LruBuffer<sup>8+</sup>
Z
zengyawen 已提交
565

W
wusongqing 已提交
566
### Attributes
Z
zengyawen 已提交
567

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

570 571 572
 | Name | Type | Readable | Writable | Description |
 | --------  | --------  | --------  | --------  | --------  |
 | length  | number  | Yes | No | Total number of values in this buffer. |
Z
zengyawen 已提交
573

W
wusongqing 已提交
574
**Example**
575
  ```js
W
wusongqing 已提交
576 577 578 579 580
  var pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(1,8);
  var result = pro.length;
  ```
Z
zengyawen 已提交
581 582


W
wusongqing 已提交
583
### constructor<sup>8+</sup>
Z
zengyawen 已提交
584

X
xdmal 已提交
585
constructor(capacity?: number)
Z
zengyawen 已提交
586

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

W
wusongqing 已提交
589 590 591
**System capability**: SystemCapability.Utils.Lang

**Parameters**
592 593 594
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | capacity  | number  | No | Capacity of the **LruBuffer** to create. |
Z
zengyawen 已提交
595

W
wusongqing 已提交
596
**Example**
597
  ```js
W
wusongqing 已提交
598 599
  var lrubuffer= new util.LruBuffer();
  ```
Z
zengyawen 已提交
600 601


W
wusongqing 已提交
602
### updateCapacity<sup>8+</sup>
Z
zengyawen 已提交
603

X
xdmal 已提交
604
updateCapacity(newCapacity: number): void
Z
zengyawen 已提交
605

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

W
wusongqing 已提交
608 609 610
**System capability**: SystemCapability.Utils.Lang

**Parameters**
611 612 613
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | newCapacity  | number  | Yes | New capacity of the **LruBuffer**. |
Z
zengyawen 已提交
614

W
wusongqing 已提交
615
**Example**
616
  ```js
W
wusongqing 已提交
617 618 619
  var pro = new util.LruBuffer();
  var result = pro.updateCapacity(100);
  ```
Z
zengyawen 已提交
620 621


W
wusongqing 已提交
622
### toString<sup>8+</sup>
Z
zengyawen 已提交
623

X
xdmal 已提交
624
toString(): string
Z
zengyawen 已提交
625

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

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

**Return value**
631 632 633
 | Type | Description |
 | --------  | --------  |
 | string  | String representation of this **LruBuffer** object. |
W
wusongqing 已提交
634

W
wusongqing 已提交
635
**Example**
636
  ```js
W
wusongqing 已提交
637 638 639 640 641 642 643 644 645 646
  var pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  pro.remove(20);
  var result = pro.toString();
  ```


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

X
xdmal 已提交
647
getCapacity(): number
W
wusongqing 已提交
648 649 650

Obtains the capacity of this buffer.

W
wusongqing 已提交
651 652 653
**System capability**: SystemCapability.Utils.Lang

**Return value**
654 655 656
 | Type | Description |
 | --------  | --------  |
 | number  | Capacity of this buffer. |
W
wusongqing 已提交
657

W
wusongqing 已提交
658
**Example**
659
  ```js
W
wusongqing 已提交
660 661 662
  var pro = new util.LruBuffer();
  var result = pro.getCapacity();
  ```
Z
zengyawen 已提交
663 664


W
wusongqing 已提交
665
### clear<sup>8+</sup>
Z
zengyawen 已提交
666

X
xdmal 已提交
667
clear(): void
Z
zengyawen 已提交
668

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

W
wusongqing 已提交
671 672 673
**System capability**: SystemCapability.Utils.Lang

**Example**
674
  ```js
W
wusongqing 已提交
675 676 677 678 679
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result = pro.size();
  pro.clear();
  ```
Z
zengyawen 已提交
680 681


W
wusongqing 已提交
682
### getCreateCount<sup>8+</sup>
Z
zengyawen 已提交
683

X
xdmal 已提交
684
getCreateCount(): number
W
wusongqing 已提交
685 686 687

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

W
wusongqing 已提交
688 689 690
**System capability**: SystemCapability.Utils.Lang

**Return value**
691 692 693
 | Type | Description |
 | --------  | --------  |
 | number  | Number of return values for **createDefault()**. |
W
wusongqing 已提交
694

W
wusongqing 已提交
695
**Example**
696
  ```js
W
wusongqing 已提交
697 698 699 700 701 702 703 704
  var pro = new util.LruBuffer();
  pro.put(1,8);
  var result = pro.getCreateCount();
  ```


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

X
xdmal 已提交
705
getMissCount(): number
W
wusongqing 已提交
706 707 708

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

W
wusongqing 已提交
709 710 711
**System capability**: SystemCapability.Utils.Lang

**Return value**
712 713 714
 | Type | Description |
 | --------  | --------  |
 | number  | Number of times that the queried values are mismatched. |
W
wusongqing 已提交
715

W
wusongqing 已提交
716
**Example**
717
  ```js
W
wusongqing 已提交
718 719 720 721 722 723 724 725 726
  var pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  var result = pro.getMissCount();
  ```


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

X
xdmal 已提交
727
getRemovalCount(): number
W
wusongqing 已提交
728 729 730

Obtains the number of removals from this buffer.

W
wusongqing 已提交
731 732 733
**System capability**: SystemCapability.Utils.Lang

**Return value**
734 735 736
 | Type | Description |
 | --------  | --------  |
 | number  | Number of removals from the buffer. |
W
wusongqing 已提交
737

W
wusongqing 已提交
738
**Example**
739
  ```js
W
wusongqing 已提交
740 741 742 743 744 745 746 747 748 749
  var pro = new util.LruBuffer();
  pro.put(2,10);
  pro.updateCapacity(2);
  pro.put(50,22);
  var result = pro.getRemovalCount();
  ```


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

X
xdmal 已提交
750
getMatchCount(): number
W
wusongqing 已提交
751 752 753

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

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

**Return value**
757 758 759
 | Type | Description |
 | --------  | --------  |
 | number  | Number of times that the queried values are matched. |
W
wusongqing 已提交
760

W
wusongqing 已提交
761
**Example**
762
  ```js
W
wusongqing 已提交
763 764 765 766 767 768 769 770 771
  var pro = new util.LruBuffer();
  pro.put(2,10);
  pro.get(2);
  var result = pro.getMatchCount();
  ```


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

X
xdmal 已提交
772
getPutCount(): number
W
wusongqing 已提交
773 774 775

Obtains the number of additions to this buffer.

W
wusongqing 已提交
776 777 778
**System capability**: SystemCapability.Utils.Lang

**Return value**
779 780 781
 | Type | Description |
 | --------  | --------  |
 | number  | Number of additions to the buffer. |
W
wusongqing 已提交
782

W
wusongqing 已提交
783
**Example**
784
  ```js
W
wusongqing 已提交
785 786 787 788 789 790 791 792
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result = pro.getPutCount();
  ```


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

X
xdmal 已提交
793
isEmpty(): boolean
W
wusongqing 已提交
794 795 796

Checks whether this buffer is empty.

W
wusongqing 已提交
797 798 799
**System capability**: SystemCapability.Utils.Lang

**Return value**
800 801 802
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the buffer does not contain any value. |
W
wusongqing 已提交
803

W
wusongqing 已提交
804
**Example**
805
  ```js
W
wusongqing 已提交
806 807 808 809 810 811 812 813
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result = pro.isEmpty();
  ```


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

814
get(key: K): V  | undefined
Z
zengyawen 已提交
815 816 817

Obtains the value of the specified key.

W
wusongqing 已提交
818 819 820
**System capability**: SystemCapability.Utils.Lang

**Parameters**
821 822 823
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | key  | K  | Yes | Key based on which the value is queried. |
W
wusongqing 已提交
824

W
wusongqing 已提交
825
**Return value**
826 827 828
 | Type | Description |
 | --------  | --------  |
 | V&nbsp;\ |&nbsp;undefind  | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise. |
W
wusongqing 已提交
829

W
wusongqing 已提交
830
**Example**
831
  ```js
W
wusongqing 已提交
832 833 834 835 836 837 838 839
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result  = pro.get(2);
  ```


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

X
xdmal 已提交
840
put(key: K,value: V): V
Z
zengyawen 已提交
841 842 843

Adds a key-value pair to this buffer.

W
wusongqing 已提交
844 845 846
**System capability**: SystemCapability.Utils.Lang

**Parameters**
847 848 849 850
 | 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 已提交
851

W
wusongqing 已提交
852
**Return value**
853 854 855
 | 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 已提交
856

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


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

X
xdmal 已提交
866
values(): V[]
W
wusongqing 已提交
867 868

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

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

**Return value**
873 874 875
 | Type | Description |
 | --------  | --------  |
 | V&nbsp;[]  | All values in the buffer, listed from the most to the least recently accessed. |
Z
zengyawen 已提交
876

W
wusongqing 已提交
877
**Example**
878
  ```js
W
wusongqing 已提交
879 880 881 882 883 884
  var pro = new util.LruBuffer();
  pro.put(2,10);
  pro.put(2,"anhu");
  pro.put("afaf","grfb");
  var result = pro.values();
  ```
Z
zengyawen 已提交
885 886


W
wusongqing 已提交
887 888
### keys<sup>8+</sup>

X
xdmal 已提交
889
keys(): K[]
Z
zengyawen 已提交
890 891 892

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

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

**Return value**
896 897 898
 | Type | Description |
 | --------  | --------  |
 | K&nbsp;[]  | All keys in the buffer, listed from the most to the least recently accessed. |
W
wusongqing 已提交
899

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


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

910
remove(key: K): V  | undefined
W
wusongqing 已提交
911 912 913

Removes the specified key and its value from this buffer.

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

**Parameters**
917 918 919
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | key  | K  | Yes | Key to remove. |
W
wusongqing 已提交
920

W
wusongqing 已提交
921
**Return value**
922 923 924
 | Type | Description |
 | --------  | --------  |
 | V&nbsp;\ |&nbsp;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 已提交
925

W
wusongqing 已提交
926
**Example**
927
  ```js
W
wusongqing 已提交
928 929 930 931 932 933 934 935
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result = pro.remove(20);
  ```


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

X
xdmal 已提交
936
afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
W
wusongqing 已提交
937 938 939

Performs subsequent operations after a value is removed.

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

**Parameters**
943 944 945 946 947 948
 | 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 已提交
949

W
wusongqing 已提交
950
**Example**
951
  ```js
W
wusongqing 已提交
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
  var arr = [];
  class ChildLruBuffer extends util.LruBuffer
  {
  	constructor()
  	{
  		super();
  	}
  	static getInstance()
  	{
  		if(this.instance ==  null)
  		{
  			this.instance = new ChildLruBuffer();
  		}
  		return this.instance;  
  	}
  	afterRemoval(isEvict, key, value, newValue)
  	{
  		if (isEvict === false)
  		{
  			arr = [key, value, newValue];
  		}
  	}
  }
  ChildLruBuffer.getInstance().afterRemoval(false,10,30,null);
  ```


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

X
xdmal 已提交
981
contains(key: K): boolean
W
wusongqing 已提交
982 983

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

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

**Parameters**
988 989 990
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | key  | K  | Yes | Key to check. |
Z
zengyawen 已提交
991

W
wusongqing 已提交
992
**Return value**
993 994 995
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the buffer contains the specified key; returns **false** otherwise. |
Z
zengyawen 已提交
996

W
wusongqing 已提交
997
**Example**
998
  ```js
W
wusongqing 已提交
999 1000 1001 1002
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result = pro.contains(20);
  ```
Z
zengyawen 已提交
1003 1004


W
wusongqing 已提交
1005 1006
### createDefault<sup>8+</sup>

X
xdmal 已提交
1007
createDefault(key: K): V
Z
zengyawen 已提交
1008 1009 1010

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

W
wusongqing 已提交
1011 1012 1013
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1014 1015 1016
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | key  | K  | Yes | Key of which the value is missing. |
Z
zengyawen 已提交
1017

W
wusongqing 已提交
1018
**Return value**
1019 1020 1021
 | Type | Description |
 | --------  | --------  |
 | V  | Value of the key. |
Z
zengyawen 已提交
1022

W
wusongqing 已提交
1023
**Example**
1024
  ```js
W
wusongqing 已提交
1025 1026 1027
  var pro = new util.LruBuffer();
  var result = pro.createDefault(50);
  ```
Z
zengyawen 已提交
1028 1029


W
wusongqing 已提交
1030
### entries<sup>8+</sup>
Z
zengyawen 已提交
1031

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

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

W
wusongqing 已提交
1036 1037 1038
**System capability**: SystemCapability.Utils.Lang

**Return value**
1039 1040 1041
 | Type | Description |
 | --------  | --------  |
 | [K,&nbsp;V]  | Iterable array. |
Z
zengyawen 已提交
1042

W
wusongqing 已提交
1043
**Example**
1044
  ```js
W
wusongqing 已提交
1045 1046 1047 1048
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result = pro.entries();
  ```
Z
zengyawen 已提交
1049 1050


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

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

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

W
wusongqing 已提交
1057 1058 1059
**System capability**: SystemCapability.Utils.Lang

**Return value**
1060 1061 1062
 | Type | Description |
 | --------  | --------  |
 | [K,&nbsp;V]  | Two-dimensional array in key-value pairs. |
Z
zengyawen 已提交
1063

W
wusongqing 已提交
1064
**Example**
1065
  ```js
W
wusongqing 已提交
1066 1067 1068 1069
  var pro = new util.LruBuffer();
  pro.put(2,10);
  var result = pro[symbol.iterator]();
  ```
Z
zengyawen 已提交
1070 1071


W
wusongqing 已提交
1072
## Scope<sup>8+</sup>
Z
zengyawen 已提交
1073 1074


W
wusongqing 已提交
1075
### ScopeType<sup>8+</sup>
Z
zengyawen 已提交
1076

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

W
wusongqing 已提交
1079
The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
1080
```js
Z
zengyawen 已提交
1081
interface ScopeComparable{
X
xdmal 已提交
1082
    compareTo(other: ScopeComparable): boolean;
Z
zengyawen 已提交
1083
}
1084
type ScopeType = ScopeComparable  | number;
Z
zengyawen 已提交
1085 1086 1087
```


W
wusongqing 已提交
1088
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 已提交
1089

W
wusongqing 已提交
1090 1091

Example
1092
```js
Z
zengyawen 已提交
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
class Temperature{
    constructor(value){
       this._temp = value;
    }
    comapreTo(value){
       return this._temp >= value.getTemp();
    }
    getTemp(){
       return this._temp;
    }
    toString(){
       return this._temp.toString();
    }
}
```


W
wusongqing 已提交
1110 1111
### constructor<sup>8+</sup>

X
xdmal 已提交
1112
constructor(lowerObj: ScopeType, upperObj: ScopeType)
W
wusongqing 已提交
1113 1114 1115

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

W
wusongqing 已提交
1116 1117 1118
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1119 1120 1121 1122
 | 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 已提交
1123

W
wusongqing 已提交
1124
**Example**
1125
  ```js
W
wusongqing 已提交
1126 1127 1128 1129 1130 1131 1132 1133
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var range = new util.Scope(tempLower, tempUpper);
  ```


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

X
xdmal 已提交
1134
toString(): string
W
wusongqing 已提交
1135 1136 1137

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

W
wusongqing 已提交
1138 1139 1140
**System capability**: SystemCapability.Utils.Lang

**Return value**
1141 1142 1143
 | Type | Description |
 | --------  | --------  |
 | string  | String representation containing the **Scope**. |
W
wusongqing 已提交
1144

W
wusongqing 已提交
1145
**Example**
1146
  ```js
W
wusongqing 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var range = new util.Scope(tempLower, tempUpper);
  var result = range.toString();
  ```


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

X
xdmal 已提交
1156
intersect(range: Scope): Scope
W
wusongqing 已提交
1157 1158 1159

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

W
wusongqing 已提交
1160 1161 1162
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1163 1164 1165
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | range  | [Scope](#scope8)  | Yes | **Scope** specified. |
W
wusongqing 已提交
1166

W
wusongqing 已提交
1167
**Return value**
1168 1169 1170
 | Type | Description |
 | --------  | --------  |
 | [Scope](#scope8)  | Intersection of this **Scope** and the given **Scope**. |
W
wusongqing 已提交
1171

W
wusongqing 已提交
1172
**Example**
1173
  ```js
W
wusongqing 已提交
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var range = new util.Scope(tempLower, tempUpper);
  var tempMiDF = new Temperature(35);
  var tempMidS = new Temperature(39);
  var rangeFir = new util.Scope(tempMiDF, tempMidS);
  range.intersect(rangeFir );
  ```


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

X
xdmal 已提交
1186
intersect(lowerObj: ScopeType,upperObj: ScopeType): Scope
W
wusongqing 已提交
1187 1188 1189

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

W
wusongqing 已提交
1190 1191 1192
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1193 1194 1195 1196
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | lowerObj  | [ScopeType](#scopetype8)  | Yes | Lower limit. |
 | upperObj  | [ScopeType](#scopetype8)  | Yes | Upper limit. |
W
wusongqing 已提交
1197

W
wusongqing 已提交
1198
**Return value**
1199 1200 1201
 | Type | Description |
 | --------  | --------  |
 | [Scope](#scope8)  | Intersection of this **Scope** and the given lower and upper limits. |
W
wusongqing 已提交
1202

W
wusongqing 已提交
1203
**Example**
1204
  ```js
W
wusongqing 已提交
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var tempMiDF = new Temperature(35);
  var tempMidS = new Temperature(39);
  var range = new util.Scope(tempLower, tempUpper);
  var result = range.intersect(tempMiDF, tempMidS);
  ```


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

X
xdmal 已提交
1216
getUpper(): ScopeType
W
wusongqing 已提交
1217 1218 1219

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

W
wusongqing 已提交
1220 1221 1222 1223
**System capability**: SystemCapability.Utils.Lang

**Return value**

1224 1225 1226
 | Type | Description |
 | --------  | --------  |
 | [ScopeType](#scopetype8)  | Upper limit of this **Scope**. |
W
wusongqing 已提交
1227

W
wusongqing 已提交
1228
**Example**
1229
  ```js
W
wusongqing 已提交
1230 1231 1232 1233 1234 1235 1236 1237 1238
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var range = new util.Scope(tempLower, tempUpper);
  var result = range.getUpper();
  ```


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

X
xdmal 已提交
1239
getLower(): ScopeType
W
wusongqing 已提交
1240 1241 1242

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

W
wusongqing 已提交
1243 1244 1245
**System capability**: SystemCapability.Utils.Lang

**Return value**
1246 1247 1248
 | Type | Description |
 | --------  | --------  |
 | [ScopeType](#scopetype8)  | Lower limit of this **Scope**. |
W
wusongqing 已提交
1249

W
wusongqing 已提交
1250
**Example**
1251
  ```js
W
wusongqing 已提交
1252 1253 1254 1255 1256 1257 1258 1259 1260
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var range = new util.Scope(tempLower, tempUpper);
  var result = range.getLower();
  ```


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

X
xdmal 已提交
1261
expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
W
wusongqing 已提交
1262 1263 1264

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

W
wusongqing 已提交
1265 1266 1267
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1268 1269 1270 1271
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | lowerObj  | [ScopeType](#scopetype8)  | Yes | Lower limit. |
 | upperObj  | [ScopeType](#scopetype8)  | Yes | Upper limit. |
W
wusongqing 已提交
1272

W
wusongqing 已提交
1273
**Return value**
1274 1275 1276
 | Type | Description |
 | --------  | --------  |
 | [Scope](#scope8)  | Union set of this **Scope** and the given lower and upper limits. |
W
wusongqing 已提交
1277

W
wusongqing 已提交
1278
**Example**
1279
  ```js
W
wusongqing 已提交
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var tempMiDF = new Temperature(35);
  var tempMidS = new Temperature(39);
  var range = new util.Scope(tempLower, tempUpper);
  var result = range.expand(tempMiDF, tempMidS);
  ```


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

expand(range:Scope):Scope

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

W
wusongqing 已提交
1295 1296 1297
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1298 1299 1300
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | range  | [Scope](#scope8)  | Yes | **Scope** specified. |
W
wusongqing 已提交
1301

W
wusongqing 已提交
1302
**Return value**
1303 1304 1305
 | Type | Description |
 | --------  | --------  |
 | [Scope](#scope8)  | Union set of this **Scope** and the given **Scope**. |
W
wusongqing 已提交
1306

W
wusongqing 已提交
1307
**Example**
1308
  ```js
W
wusongqing 已提交
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var tempMiDF = new Temperature(35);
  var tempMidS = new Temperature(39);
  var range = new util.Scope(tempLower, tempUpper);
  var rangeFir = new util.Scope(tempMiDF, tempMidS);
  var result = range.expand(rangeFir);
  ```


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

X
xdmal 已提交
1321
expand(value: ScopeType): Scope
W
wusongqing 已提交
1322 1323 1324

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

W
wusongqing 已提交
1325 1326 1327
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1328 1329 1330
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | [ScopeType](#scopetype8)  | Yes | Value specified. |
W
wusongqing 已提交
1331

W
wusongqing 已提交
1332
**Return value**
1333 1334 1335
 | Type | Description |
 | --------  | --------  |
 | [Scope](#scope8)  | Union set of this **Scope** and the given value. |
Z
zengyawen 已提交
1336

W
wusongqing 已提交
1337
**Example**
1338
  ```js
W
wusongqing 已提交
1339 1340 1341 1342 1343 1344
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var tempMiDF = new Temperature(35);
  var range = new util.Scope(tempLower, tempUpper);
  var result = range.expand(tempMiDF);
  ```
Z
zengyawen 已提交
1345 1346


W
wusongqing 已提交
1347
### contains<sup>8+</sup>
Z
zengyawen 已提交
1348

X
xdmal 已提交
1349
contains(value: ScopeType): boolean
Z
zengyawen 已提交
1350

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

W
wusongqing 已提交
1353 1354 1355
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1356 1357 1358
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | [ScopeType](#scopetype8)  | Yes | Value specified. |
Z
zengyawen 已提交
1359

W
wusongqing 已提交
1360
**Return value**
1361 1362 1363
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the value is within this **Scope**; returns **false** otherwise. |
W
wusongqing 已提交
1364

W
wusongqing 已提交
1365
**Example**
1366
  ```js
W
wusongqing 已提交
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var tempMiDF = new Temperature(35);
  var range = new util.Scope(tempLower, tempUpper);
  range.contains(tempMiDF);
  ```


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

X
xdmal 已提交
1377
contains(range: Scope): boolean
W
wusongqing 已提交
1378 1379 1380

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

W
wusongqing 已提交
1381 1382 1383
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1384 1385 1386
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | range  | [Scope](#scope8)  | Yes | **Scope** specified. |
W
wusongqing 已提交
1387

W
wusongqing 已提交
1388
**Return value**
1389 1390 1391
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the range is within this **Scope**; returns **false** otherwise. |
W
wusongqing 已提交
1392

W
wusongqing 已提交
1393
**Example**
1394
  ```js
W
wusongqing 已提交
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var range = new util.Scope(tempLower, tempUpper);
  var tempLess = new Temperature(20);
  var tempMore = new Temperature(45);
  var rangeSec = new util.Scope(tempLess, tempMore);
  var result = range.contains(rangeSec);
  ```


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

X
xdmal 已提交
1407
clamp(value: ScopeType): ScopeType
W
wusongqing 已提交
1408 1409 1410

Limits a value to this **Scope**.

W
wusongqing 已提交
1411 1412 1413
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1414 1415 1416
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | [ScopeType](#scopetype8)  | Yes | Value specified. |
W
wusongqing 已提交
1417

W
wusongqing 已提交
1418
**Return value**
1419 1420 1421
 | 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 已提交
1422

W
wusongqing 已提交
1423
**Example**
1424
  ```js
W
wusongqing 已提交
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
  var tempLower = new Temperature(30);
  var tempUpper = new Temperature(40);
  var tempMiDF = new Temperature(35);
  var range = new util.Scope(tempLower, tempUpper);
  var result = range.clamp(tempMiDF);
  ```


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


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

constructor()

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

W
wusongqing 已提交
1442 1443 1444
**System capability**: SystemCapability.Utils.Lang

**Example**
1445
  ```js
W
wusongqing 已提交
1446 1447 1448 1449 1450 1451
  var base64 = new  util.Base64();
  ```


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

X
xdmal 已提交
1452
encodeSync(src: Uint8Array): Uint8Array
Z
zengyawen 已提交
1453 1454 1455

Encodes the input content.

W
wusongqing 已提交
1456 1457 1458
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1459 1460 1461
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | src  | Uint8Array  | Yes | Uint8Array to encode. |
W
wusongqing 已提交
1462

W
wusongqing 已提交
1463
**Return value**
1464 1465 1466
 | Type | Description |
 | --------  | --------  |
 | Uint8Array  | Uint8Array encoded. |
W
wusongqing 已提交
1467

W
wusongqing 已提交
1468
**Example**
1469
  ```js
W
wusongqing 已提交
1470 1471 1472 1473 1474 1475 1476 1477
  var that = new util.Base64();
  var array = new Uint8Array([115,49,51]);
  var result = that.encodeSync(array);
  ```


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

X
xdmal 已提交
1478
encodeToStringSync(src: Uint8Array): string
W
wusongqing 已提交
1479 1480 1481

Encodes the input content.

W
wusongqing 已提交
1482 1483 1484
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1485 1486 1487
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | src  | Uint8Array  | Yes | Uint8Array to encode. |
W
wusongqing 已提交
1488

W
wusongqing 已提交
1489
**Return value**
1490 1491 1492
 | Type | Description |
 | --------  | --------  |
 | string  | String encoded from the Uint8Array. |
W
wusongqing 已提交
1493

W
wusongqing 已提交
1494
**Example**
1495
  ```js
W
wusongqing 已提交
1496 1497 1498 1499 1500 1501 1502 1503
  var that = new util.Base64();
  var array = new Uint8Array([115,49,51]);
  var result = that.encodeToStringSync(array);
  ```


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

1504
decodeSync(src: Uint8Array  | string): Uint8Array
Z
zengyawen 已提交
1505 1506 1507

Decodes the input content.

W
wusongqing 已提交
1508 1509 1510
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1511 1512 1513
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | src  | Uint8Array&nbsp;\ |&nbsp;string  | Yes | Uint8Array or string to decode. |
W
wusongqing 已提交
1514

W
wusongqing 已提交
1515
**Return value**
1516 1517 1518
 | Type | Description |
 | --------  | --------  |
 | Uint8Array  | Uint8Array decoded. |
W
wusongqing 已提交
1519

W
wusongqing 已提交
1520
**Example**
1521
  ```js
W
wusongqing 已提交
1522 1523 1524 1525 1526 1527 1528 1529
  var that = new util.Base64();
  var buff = 'czEz';
  var result = that.decodeSync(buff);
  ```


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

X
xdmal 已提交
1530
encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
1531 1532 1533

Encodes the input content asynchronously.

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

**Parameters**
1537 1538 1539
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | src  | Uint8Array  | Yes | Uint8Array to encode asynchronously. |
W
wusongqing 已提交
1540

W
wusongqing 已提交
1541
**Return value**
1542 1543 1544
 | Type | Description |
 | --------  | --------  |
 | Promise&lt;Uint8Array&gt;  | Uint8Array obtained after asynchronous encoding. |
W
wusongqing 已提交
1545

W
wusongqing 已提交
1546
**Example**
1547
  ```js
W
wusongqing 已提交
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
  var that = new util.Base64();
  var array = new Uint8Array([115,49,51]);
  var rarray = new Uint8Array([99,122,69,122]);
  that.encode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
          console.log(val[i])
      }
  })
  ```


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

X
xdmal 已提交
1561
encodeToString(src: Uint8Array): Promise&lt;string&gt;
W
wusongqing 已提交
1562 1563 1564

Encodes the input content asynchronously.

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

**Parameters**
1568 1569 1570
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | src  | Uint8Array  | Yes | Uint8Array to encode asynchronously. |
W
wusongqing 已提交
1571

W
wusongqing 已提交
1572
**Return value**
1573 1574 1575
 | Type | Description |
 | --------  | --------  |
 | Promise&lt;string&gt;  | String obtained after asynchronous encoding. |
W
wusongqing 已提交
1576

W
wusongqing 已提交
1577
**Example**
1578
  ```js
W
wusongqing 已提交
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
  var that = new util.Base64();
  var array = new Uint8Array([115,49,51]);
  that.encodeToString(array).then(val=>{    
      console.log(val)
  })
  ```


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

1589
decode(src: Uint8Array  | string): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
1590 1591 1592

Decodes the input content asynchronously.

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

**Parameters**
1596 1597 1598
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | src  | Uint8Array&nbsp;\ |&nbsp;string  | Yes | Uint8Array or string to decode asynchronously. |
W
wusongqing 已提交
1599

W
wusongqing 已提交
1600
**Return value**
1601 1602 1603
 | Type | Description |
 | --------  | --------  |
 | Promise&lt;Uint8Array&gt;  | Uint8Array obtained after asynchronous decoding. |
W
wusongqing 已提交
1604

W
wusongqing 已提交
1605
**Example**
1606
  ```js
W
wusongqing 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617
  var that = new util.Base64();
  var array = new Uint8Array([99,122,69,122]);
  var rarray = new Uint8Array([115,49,51]);
  that.decode(array).then(val=>{    
      for (var i = 0; i < rarray.length; i++) {        
          console.log(val[i])
      }
  })
  ```


1618
## types<sup>8+</sup>
W
wusongqing 已提交
1619 1620 1621 1622 1623 1624


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

constructor()

1625
A constructor used to create a **types** object.
W
wusongqing 已提交
1626

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

**Example**
1630
  ```js
1631
  var type = new util.types();
W
wusongqing 已提交
1632 1633 1634 1635 1636
  ```


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

X
xdmal 已提交
1637
isAnyArrayBuffer(value: Object): boolean
W
wusongqing 已提交
1638 1639 1640

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

W
wusongqing 已提交
1641 1642 1643
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1644 1645 1646
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1647

W
wusongqing 已提交
1648
**Return value**
1649 1650 1651
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise. |
W
wusongqing 已提交
1652

W
wusongqing 已提交
1653
**Example**
1654
  ```js
1655
  var that = new util.types();
W
wusongqing 已提交
1656 1657 1658 1659 1660 1661
  var result = that.isAnyArrayBuffer(new ArrayBuffer([]));
  ```


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

X
xdmal 已提交
1662
isArrayBufferView(value: Object): boolean
W
wusongqing 已提交
1663 1664 1665 1666 1667

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 已提交
1668 1669 1670
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1671 1672 1673
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1674

W
wusongqing 已提交
1675
**Return value**
1676 1677 1678
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise. |
W
wusongqing 已提交
1679

W
wusongqing 已提交
1680
**Example**
1681
  ```js
1682
  var that = new util.types();
W
wusongqing 已提交
1683 1684 1685 1686 1687 1688
  var result = that.isArrayBufferView(new Int8Array([]));
  ```


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

X
xdmal 已提交
1689
isArgumentsObject(value: Object): boolean
W
wusongqing 已提交
1690 1691 1692

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

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

**Parameters**
1696 1697 1698
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1699

W
wusongqing 已提交
1700
**Return value**
1701 1702 1703
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise. |
W
wusongqing 已提交
1704

W
wusongqing 已提交
1705
**Example**
1706
  ```js
1707
  var that = new util.types();
W
wusongqing 已提交
1708 1709 1710 1711 1712 1713 1714 1715 1716
  function foo() {
      var result = that.isArgumentsObject(arguments);
  }
  var f = foo();
  ```


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

X
xdmal 已提交
1717
isArrayBuffer(value: Object): boolean
W
wusongqing 已提交
1718 1719 1720

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

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

**Parameters**
1724 1725 1726
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1727

W
wusongqing 已提交
1728
**Return value**
1729 1730 1731
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise. |
W
wusongqing 已提交
1732

W
wusongqing 已提交
1733
**Example**
1734
  ```js
1735
  var that = new util.types();
W
wusongqing 已提交
1736 1737 1738 1739 1740 1741
  var result = that.isArrayBuffer(new ArrayBuffer([]));
  ```


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

X
xdmal 已提交
1742
isAsyncFunction(value: Object): boolean
Z
zengyawen 已提交
1743 1744 1745

Checks whether the input value is an asynchronous function.

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

**Parameters**
1749 1750 1751
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1752

W
wusongqing 已提交
1753
**Return value**
1754 1755 1756
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is an asynchronous function; returns **false** otherwise. |
W
wusongqing 已提交
1757

W
wusongqing 已提交
1758
**Example**
1759
  ```js
1760
  var that = new util.types();
W
wusongqing 已提交
1761 1762 1763 1764 1765 1766
  var result = that.isAsyncFunction(async function foo() {});
  ```


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

X
xdmal 已提交
1767
isBooleanObject(value: Object): boolean
W
wusongqing 已提交
1768 1769 1770

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

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

**Parameters**
1774 1775 1776
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1777

W
wusongqing 已提交
1778
**Return value**
1779 1780 1781
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise. |
W
wusongqing 已提交
1782

W
wusongqing 已提交
1783
**Example**
1784
  ```js
1785
  var that = new util.types();
W
wusongqing 已提交
1786 1787 1788 1789 1790 1791
  var result = that.isBooleanObject(new Boolean(true));
  ```


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

X
xdmal 已提交
1792
isBoxedPrimitive(value: Object): boolean
W
wusongqing 已提交
1793 1794 1795

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

W
wusongqing 已提交
1796 1797 1798
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1799 1800 1801
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1802

W
wusongqing 已提交
1803
**Return value**
1804 1805 1806
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise. |
W
wusongqing 已提交
1807

W
wusongqing 已提交
1808
**Example**
1809
  ```js
1810
  var that = new util.types();
W
wusongqing 已提交
1811 1812 1813 1814 1815 1816
  var result = that.isBoxedPrimitive(new Boolean(false));
  ```


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

X
xdmal 已提交
1817
isDataView(value: Object): boolean
W
wusongqing 已提交
1818 1819 1820

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

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

**Parameters**
1824 1825 1826
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1827

W
wusongqing 已提交
1828
**Return value**
1829 1830 1831
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise. |
W
wusongqing 已提交
1832

W
wusongqing 已提交
1833
**Example**
1834
  ```js
1835
  var that = new util.types();
W
wusongqing 已提交
1836 1837 1838 1839 1840 1841 1842
  const ab = new ArrayBuffer(20);
  var result = that.isDataView(new DataView(ab));
  ```


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

X
xdmal 已提交
1843
isDate(value: Object): boolean
W
wusongqing 已提交
1844 1845 1846

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

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

**Parameters**
1850 1851 1852
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1853

W
wusongqing 已提交
1854
**Return value**
1855 1856 1857
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Date** type; returns **false** otherwise. |
W
wusongqing 已提交
1858

W
wusongqing 已提交
1859
**Example**
1860
  ```js
1861
  var that = new util.types();
W
wusongqing 已提交
1862 1863 1864 1865 1866 1867
  var result = that.isDate(new Date());
  ```


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

X
xdmal 已提交
1868
isExternal(value: Object): boolean
W
wusongqing 已提交
1869 1870 1871

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

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

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

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

W
wusongqing 已提交
1884
**Example**
1885
  ```js
1886
  var that = new util.types();
W
wusongqing 已提交
1887 1888 1889 1890 1891 1892 1893
  const data = util.createExternalType();
  var result = that.isExternal(data);
  ```


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

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

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

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

**Parameters**
1901 1902 1903
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1904

W
wusongqing 已提交
1905
**Return value**
1906 1907 1908
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise. |
W
wusongqing 已提交
1909

W
wusongqing 已提交
1910
**Example**
1911
  ```js
1912
  var that = new util.types();
W
wusongqing 已提交
1913 1914 1915 1916 1917 1918
  var result = that.isFloat32Array(new Float32Array());
  ```


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

X
xdmal 已提交
1919
isFloat64Array(value: Object): boolean
W
wusongqing 已提交
1920 1921 1922

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

W
wusongqing 已提交
1923 1924 1925
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1926 1927 1928
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1929

W
wusongqing 已提交
1930
**Return value**
1931 1932 1933
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise. |
W
wusongqing 已提交
1934

W
wusongqing 已提交
1935
**Example**
1936
  ```js
1937
  var that = new util.types();
W
wusongqing 已提交
1938 1939 1940 1941 1942 1943
  var result = that.isFloat64Array(new Float64Array());
  ```


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

X
xdmal 已提交
1944
isGeneratorFunction(value: Object): boolean
Z
zengyawen 已提交
1945 1946 1947

Checks whether the input value is a generator function.

W
wusongqing 已提交
1948 1949 1950
**System capability**: SystemCapability.Utils.Lang

**Parameters**
1951 1952 1953
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1954

W
wusongqing 已提交
1955
**Return value**
1956 1957 1958
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is a generator function; returns **false** otherwise. |
W
wusongqing 已提交
1959

W
wusongqing 已提交
1960
**Example**
1961
  ```js
1962
  var that = new util.types();
W
wusongqing 已提交
1963 1964 1965 1966 1967 1968
  var result = that.isGeneratorFunction(function* foo() {});
  ```


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

X
xdmal 已提交
1969
isGeneratorObject(value: Object): boolean
Z
zengyawen 已提交
1970 1971 1972

Checks whether the input value is a generator object.

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

**Parameters**
1976 1977 1978
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
1979

W
wusongqing 已提交
1980
**Return value**
1981 1982 1983
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is a generator object; returns **false** otherwise. |
W
wusongqing 已提交
1984

W
wusongqing 已提交
1985
**Example**
1986
  ```js
1987
  var that = new util.types();
W
wusongqing 已提交
1988 1989 1990 1991 1992 1993 1994 1995
  function* foo() {}
  const generator = foo();
  var result = that.isGeneratorObject(generator);
  ```


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

X
xdmal 已提交
1996
isInt8Array(value: Object): boolean
W
wusongqing 已提交
1997 1998 1999

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

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

**Parameters**
2003 2004 2005
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2006

W
wusongqing 已提交
2007
**Return value**
2008 2009 2010
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise. |
W
wusongqing 已提交
2011

W
wusongqing 已提交
2012
**Example**
2013
  ```js
2014
  var that = new util.types();
W
wusongqing 已提交
2015 2016 2017 2018 2019 2020
  var result = that.isInt8Array(new Int8Array([]));
  ```


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

X
xdmal 已提交
2021
isInt16Array(value: Object): boolean
W
wusongqing 已提交
2022 2023 2024

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

W
wusongqing 已提交
2025 2026 2027
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2028 2029 2030
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2031

W
wusongqing 已提交
2032
**Return value**
2033 2034 2035
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise. |
W
wusongqing 已提交
2036

W
wusongqing 已提交
2037
**Example**
2038
  ```js
2039
  var that = new util.types();
W
wusongqing 已提交
2040 2041 2042 2043 2044 2045
  var result = that.isInt16Array(new Int16Array([]));
  ```


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

X
xdmal 已提交
2046
isInt32Array(value: Object): boolean
W
wusongqing 已提交
2047 2048 2049

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

W
wusongqing 已提交
2050 2051 2052
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2053 2054 2055
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2056

W
wusongqing 已提交
2057
**Return value**
2058 2059 2060
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise. |
W
wusongqing 已提交
2061

W
wusongqing 已提交
2062
**Example**
2063
  ```js
2064
  var that = new util.types();
W
wusongqing 已提交
2065 2066 2067 2068 2069 2070
  var result = that.isInt32Array(new Int32Array([]));
  ```


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

X
xdmal 已提交
2071
isMap(value: Object): boolean
W
wusongqing 已提交
2072 2073 2074

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

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

**Parameters**
2078 2079 2080
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2081

W
wusongqing 已提交
2082
**Return value**
2083 2084 2085
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Map** type; returns **false** otherwise. |
W
wusongqing 已提交
2086

W
wusongqing 已提交
2087
**Example**
2088
  ```js
2089
  var that = new util.types();
W
wusongqing 已提交
2090 2091 2092 2093 2094 2095
  var result = that.isMap(new Map());
  ```


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

X
xdmal 已提交
2096
isMapIterator(value: Object): boolean
W
wusongqing 已提交
2097 2098 2099

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

W
wusongqing 已提交
2100 2101 2102
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2103 2104 2105
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2106

W
wusongqing 已提交
2107
**Return value**
2108 2109 2110
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise. |
W
wusongqing 已提交
2111

W
wusongqing 已提交
2112
**Example**
2113
  ```js
2114
  var that = new util.types();
W
wusongqing 已提交
2115 2116 2117 2118 2119 2120 2121
  const map = new Map();
  var result = that.isMapIterator(map.keys());
  ```


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

X
xdmal 已提交
2122
isNativeError(value: Object): boolean
W
wusongqing 已提交
2123 2124 2125

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

W
wusongqing 已提交
2126 2127 2128
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2129 2130 2131
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2132

W
wusongqing 已提交
2133
**Return value**
2134 2135 2136
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Error** type; returns **false** otherwise. |
W
wusongqing 已提交
2137

W
wusongqing 已提交
2138
**Example**
2139
  ```js
2140
  var that = new util.types();
W
wusongqing 已提交
2141 2142 2143 2144 2145 2146
  var result = that.isNativeError(new TypeError());
  ```


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

X
xdmal 已提交
2147
isNumberObject(value: Object): boolean
Z
zengyawen 已提交
2148 2149 2150

Checks whether the input value is a number object.

W
wusongqing 已提交
2151 2152 2153
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2154 2155 2156
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2157

W
wusongqing 已提交
2158
**Return value**
2159 2160 2161
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is a number object; returns **false** otherwise. |
W
wusongqing 已提交
2162

W
wusongqing 已提交
2163
**Example**
2164
  ```js
2165
  var that = new util.types();
W
wusongqing 已提交
2166 2167 2168 2169 2170 2171
  var result = that.isNumberObject(new Number(0));
  ```


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

X
xdmal 已提交
2172
isPromise(value: Object): boolean
Z
zengyawen 已提交
2173 2174 2175

Checks whether the input value is a promise.

W
wusongqing 已提交
2176 2177 2178
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2179 2180 2181
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2182

W
wusongqing 已提交
2183
**Return value**
2184 2185 2186
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is a promise; returns **false** otherwise. |
W
wusongqing 已提交
2187

W
wusongqing 已提交
2188
**Example**
2189
  ```js
2190
  var that = new util.types();
W
wusongqing 已提交
2191 2192 2193 2194 2195 2196
  var result = that.isPromise(Promise.resolve(1));
  ```


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

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

Checks whether the input value is a proxy.

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

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

W
wusongqing 已提交
2208
**Return value**
2209 2210 2211
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is a proxy; returns **false** otherwise. |
W
wusongqing 已提交
2212

W
wusongqing 已提交
2213
**Example**
2214
  ```js
2215
  var that = new util.types();
W
wusongqing 已提交
2216 2217 2218 2219 2220 2221 2222 2223
  const target = {};
  const proxy = new Proxy(target, {});
  var result = that.isProxy(proxy);
  ```


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

X
xdmal 已提交
2224
isRegExp(value: Object): boolean
W
wusongqing 已提交
2225 2226 2227

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

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

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

W
wusongqing 已提交
2235
**Return value**
2236 2237 2238
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise. |
W
wusongqing 已提交
2239

W
wusongqing 已提交
2240
**Example**
2241
  ```js
2242
  var that = new util.types();
W
wusongqing 已提交
2243 2244 2245 2246 2247 2248
  var result = that.isRegExp(new RegExp('abc'));
  ```


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

X
xdmal 已提交
2249
isSet(value: Object): boolean
W
wusongqing 已提交
2250 2251 2252

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

W
wusongqing 已提交
2253 2254 2255
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2256 2257 2258
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2259

W
wusongqing 已提交
2260
**Return value**
2261 2262 2263
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Set** type; returns **false** otherwise. |
W
wusongqing 已提交
2264

W
wusongqing 已提交
2265
**Example**
2266
  ```js
2267
  var that = new util.types();
W
wusongqing 已提交
2268 2269 2270 2271 2272 2273
  var result = that.isSet(new Set());
  ```


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

X
xdmal 已提交
2274
isSetIterator(value: Object): boolean
W
wusongqing 已提交
2275 2276 2277

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

W
wusongqing 已提交
2278 2279 2280
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2281 2282 2283
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2284

W
wusongqing 已提交
2285
**Return value**
2286 2287 2288
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise. |
W
wusongqing 已提交
2289

W
wusongqing 已提交
2290
**Example**
2291
  ```js
2292
  var that = new util.types();
W
wusongqing 已提交
2293 2294 2295 2296 2297 2298 2299
  const set = new Set();
  var result = that.isSetIterator(set.keys());
  ```


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

X
xdmal 已提交
2300
isStringObject(value: Object): boolean
Z
zengyawen 已提交
2301 2302 2303

Checks whether the input value is a string object.

W
wusongqing 已提交
2304 2305 2306
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2307 2308 2309
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2310

W
wusongqing 已提交
2311
**Return value**
2312 2313 2314
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is a string object; returns **false** otherwise. |
W
wusongqing 已提交
2315

W
wusongqing 已提交
2316
**Example**
2317
  ```js
2318
  var that = new util.types();
W
wusongqing 已提交
2319 2320 2321 2322 2323 2324
  var result = that.isStringObject(new String('foo'));
  ```


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

X
xdmal 已提交
2325
isSymbolObject(value: Object): boolean
Z
zengyawen 已提交
2326 2327 2328

Checks whether the input value is a symbol object.

W
wusongqing 已提交
2329 2330 2331
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2332 2333 2334
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2335

W
wusongqing 已提交
2336
**Return value**
2337 2338 2339
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is a symbol object; returns **false** otherwise. |
W
wusongqing 已提交
2340

W
wusongqing 已提交
2341
**Example**
2342
  ```js
2343
  var that = new util.types();
W
wusongqing 已提交
2344 2345 2346 2347 2348 2349 2350
  const symbols = Symbol('foo');
  var result = that.isSymbolObject(Object(symbols));
  ```


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

X
xdmal 已提交
2351
isTypedArray(value: Object): boolean
W
wusongqing 已提交
2352 2353 2354 2355 2356

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 已提交
2357 2358 2359
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2360 2361 2362
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2363

W
wusongqing 已提交
2364
**Return value**
2365 2366 2367
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise. |
W
wusongqing 已提交
2368

W
wusongqing 已提交
2369
**Example**
2370
  ```js
2371
  var that = new util.types();
W
wusongqing 已提交
2372 2373 2374 2375 2376 2377
  var result = that.isTypedArray(new Float64Array([]));
  ```


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

X
xdmal 已提交
2378
isUint8Array(value: Object): boolean
W
wusongqing 已提交
2379 2380 2381

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

W
wusongqing 已提交
2382 2383 2384
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2385 2386 2387
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2388

W
wusongqing 已提交
2389
**Return value**
2390 2391 2392
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise. |
W
wusongqing 已提交
2393

W
wusongqing 已提交
2394
**Example**
2395
  ```js
2396
  var that = new util.types();
W
wusongqing 已提交
2397 2398 2399 2400 2401 2402
  var result = that.isUint8Array(new Uint8Array([]));
  ```


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

X
xdmal 已提交
2403
isUint8ClampedArray(value: Object): boolean
W
wusongqing 已提交
2404 2405 2406

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

W
wusongqing 已提交
2407 2408 2409
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2410 2411 2412
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2413

W
wusongqing 已提交
2414
**Return value**
2415 2416 2417
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise. |
W
wusongqing 已提交
2418

W
wusongqing 已提交
2419
**Example**
2420
  ```js
2421
  var that = new util.types();
W
wusongqing 已提交
2422 2423 2424 2425 2426 2427
  var result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
  ```


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

X
xdmal 已提交
2428
isUint16Array(value: Object): boolean
W
wusongqing 已提交
2429 2430 2431

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

W
wusongqing 已提交
2432 2433 2434
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2435 2436 2437
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2438

W
wusongqing 已提交
2439
**Return value**
2440 2441 2442
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise. |
W
wusongqing 已提交
2443

W
wusongqing 已提交
2444
**Example**
2445
  ```js
2446
  var that = new util.types();
W
wusongqing 已提交
2447 2448 2449 2450 2451 2452
  var result = that.isUint16Array(new Uint16Array([]));
  ```


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

X
xdmal 已提交
2453
isUint32Array(value: Object): boolean
W
wusongqing 已提交
2454 2455 2456

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

W
wusongqing 已提交
2457 2458 2459
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2460 2461 2462
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2463

W
wusongqing 已提交
2464
**Return value**
2465 2466 2467
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise. |
W
wusongqing 已提交
2468

W
wusongqing 已提交
2469
**Example**
2470
  ```js
2471
  var that = new util.types();
W
wusongqing 已提交
2472 2473 2474 2475 2476 2477
  var result = that.isUint32Array(new Uint32Array([]));
  ```


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

X
xdmal 已提交
2478
isWeakMap(value: Object): boolean
W
wusongqing 已提交
2479 2480 2481

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

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

**Parameters**
2485 2486 2487
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2488

W
wusongqing 已提交
2489
**Return value**
2490 2491 2492
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise. |
W
wusongqing 已提交
2493

W
wusongqing 已提交
2494
**Example**
2495
  ```js
2496
  var that = new util.types();
W
wusongqing 已提交
2497 2498 2499 2500 2501 2502
  var result = that.isWeakMap(new WeakMap());
  ```


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

X
xdmal 已提交
2503
isWeakSet(value: Object): boolean
W
wusongqing 已提交
2504 2505 2506

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

W
wusongqing 已提交
2507 2508 2509
**System capability**: SystemCapability.Utils.Lang

**Parameters**
2510 2511 2512
 | Name | Type | Mandatory | Description |
 | --------  | --------  | --------  | --------  |
 | value  | Object  | Yes | Object to check. |
W
wusongqing 已提交
2513

W
wusongqing 已提交
2514
**Return value**
2515 2516 2517
 | Type | Description |
 | --------  | --------  |
 | boolean  | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise. |
Z
zengyawen 已提交
2518

W
wusongqing 已提交
2519
**Example**
2520
  ```js
2521
  var that = new util.types();
W
wusongqing 已提交
2522
  var result = that.isWeakSet(new WeakSet());
2523
  ```