• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# util
2
3
4> **NOTE**
5>
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.
7
8
9This 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.
10
11
12## Modules to Import
13
14```
15import util from '@ohos.util';
16```
17
18## util.printf
19
20printf(format: string,  ...args: Object[]): string
21
22Prints the input content in a formatted string.
23
24**System capability**: SystemCapability.Utils.Lang
25
26**Parameters**
27| Name| Type| Mandatory| Description|
28| -------- | -------- | -------- | -------- |
29| format | string | Yes| Format of the string to print.|
30| ...args | Object[] | No| Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
31
32**Return value**
33| Type| Description|
34| -------- | -------- |
35| string | String in the specified format.|
36
37**Example**
38  ```js
39  var res = util.printf("%s", "hello world!");
40  console.log(res);
41  ```
42
43
44## util.getErrorString
45
46getErrorString(errno: number): string
47
48Obtains detailed information about a system error code.
49
50**System capability**: SystemCapability.Utils.Lang
51
52**Parameters**
53| Name| Type| Mandatory| Description|
54| -------- | -------- | -------- | -------- |
55| errno | number | Yes| Error code generated.|
56
57**Return value**
58| Type| Description|
59| -------- | -------- |
60| string | Detailed information about the error code.|
61
62**Example**
63  ```js
64  var errnum = 10; // 10 is the system error code.
65  var result = util.getErrorString(errnum);
66  console.log("result = " + result);
67  ```
68
69
70## util.callbackWrapper
71
72callbackWrapper(original: Function): (err: Object, value: Object )=>void
73
74Calls 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.
75
76**System capability**: SystemCapability.Utils.Lang
77
78**Parameters**
79
80| Name| Type| Mandatory| Description|
81| -------- | -------- | -------- | -------- |
82| original | Function | Yes| Asynchronous function.|
83
84**Return value**
85| Type| Description|
86| -------- | -------- |
87| 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.|
88
89**Example**
90  ```js
91async function fn() {
92   return 'hello world';
93}
94let cb = util.callbackWrapper(fn);
95cb(1, (err, ret) => {
96   if (err) throw err;
97   console.log(ret);
98});
99  ```
100
101
102## util.promiseWrapper
103
104promiseWrapper(original: (err: Object, value: Object) => void): Object
105
106Processes an asynchronous function and returns a promise version.
107
108**System capability**: SystemCapability.Utils.Lang
109
110**Parameters**
111| Name| Type| Mandatory| Description|
112| -------- | -------- | -------- | -------- |
113| original | Function | Yes| Asynchronous function.|
114
115**Return value**
116| Type| Description|
117| -------- | -------- |
118| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise version.|
119
120**Example**
121  ```js
122  function aysnFun(str1, str2, callback) {
123      if (typeof str1 === 'string' && typeof str2 === 'string') {
124          callback(null, str1 + str2);
125      } else {
126          callback('type err');
127      }
128  }
129  let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World');
130  newPromiseObj.then(res => {
131      console.log(res);
132  })
133  ```
134
135
136## TextDecoder
137
138### Attributes
139
140**System capability**: SystemCapability.Utils.Lang
141
142| Name| Type| Readable| Writable| Description|
143| -------- | -------- | -------- | -------- | -------- |
144| encoding | string | Yes| No| Encoding format.<br>- Supported formats: utf-8.|
145| fatal | boolean | Yes| No| Whether to display fatal errors.|
146| 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.|
147
148
149### constructor
150
151constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean },)
152
153A constructor used to create a **TextDecoder** object.
154
155**System capability**: SystemCapability.Utils.Lang
156
157**Parameters**
158| Name| Type| Mandatory| Description|
159| -------- | -------- | -------- | -------- |
160| encoding | string | No| Encoding format.|
161| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
162
163  **Table 1** options
164
165| Name| Type| Mandatory| Description|
166| -------- | -------- | -------- | -------- |
167| fatal | boolean | No| Whether to display fatal errors.|
168| ignoreBOM | boolean | No| Whether to ignore the BOM.|
169
170**Example**
171  ```js
172  var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
173  ```
174
175
176### decode
177
178decode(input: Uint8Array, options?: { stream?: false }): string
179
180Decodes the input content.
181
182**System capability**: SystemCapability.Utils.Lang
183
184**Parameters**
185| Name| Type| Mandatory| Description|
186| -------- | -------- | -------- | -------- |
187| input | Unit8Array | Yes| Uint8Array to decode.|
188| options | Object | No| Options related to decoding.|
189
190  **Table 2** options
191
192| Name| Type| Mandatory| Description|
193| -------- | -------- | -------- | -------- |
194| 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**.|
195
196**Return value**
197| Type| Description|
198| -------- | -------- |
199| string | Data decoded.|
200
201**Example**
202  ```js
203  var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
204  var result = new Uint8Array(6);
205  result[0] = 0xEF;
206  result[1] = 0xBB;
207  result[2] = 0xBF;
208  result[3] = 0x61;
209  result[4] = 0x62;
210  result[5] = 0x63;
211  console.log("input num:");
212  var retStr = textDecoder.decode( result , {stream: false});
213  console.log("retStr = " + retStr);
214  ```
215
216
217## TextEncoder
218
219### Attributes
220
221**System capability**: SystemCapability.Utils.Lang
222
223| Name| Type| Readable| Writable| Description|
224| -------- | -------- | -------- | -------- | -------- |
225| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
226
227
228### constructor
229
230constructor()
231
232A constructor used to create a **TextEncoder** object.
233
234**System capability**: SystemCapability.Utils.Lang
235
236**Example**
237  ```js
238  var textEncoder = new util.TextEncoder();
239  ```
240
241
242### encode
243
244encode(input?: string): Uint8Array
245
246Encodes the input content.
247
248**System capability**: SystemCapability.Utils.Lang
249
250**Parameters**
251| Name| Type| Mandatory| Description|
252| -------- | -------- | -------- | -------- |
253| input | string | Yes| String to encode.|
254
255**Return value**
256| Type| Description|
257| -------- | -------- |
258| Uint8Array | Encoded text.|
259
260**Example**
261  ```js
262  var textEncoder = new util.TextEncoder();
263  var buffer = new ArrayBuffer(20);
264  var result = new Uint8Array(buffer);
265  result = textEncoder.encode("\uD800¥¥");
266  ```
267
268
269### encodeInto
270
271encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
272
273Stores the UTF-8 encoded text.
274
275**System capability**: SystemCapability.Utils.Lang
276
277**Parameters**
278| Name| Type| Mandatory| Description|
279| -------- | -------- | -------- | -------- |
280| input | string | Yes| String to encode.|
281| dest | Uint8Array | Yes| **Uint8Array** instance used to store the UTF-8 encoded text.|
282
283**Return value**
284| Type| Description|
285| -------- | -------- |
286| Uint8Array | Encoded text.|
287
288**Example**
289  ```js
290  var that = new util.TextEncoder();
291  var buffer = new ArrayBuffer(4);
292  this.dest = new Uint8Array(buffer);
293  var result = that.encodeInto("abcd", this.dest);
294  ```
295
296## RationalNumber<sup>8+</sup>
297
298
299### constructor<sup>8+</sup>
300
301constructor(numerator: number,denominator: number)
302
303A constructor used to create a **RationalNumber** object.
304
305**System capability**: SystemCapability.Utils.Lang
306
307**Parameters**
308| Name| Type| Mandatory| Description|
309| -------- | -------- | -------- | -------- |
310| numerator | number | Yes| Numerator, which is an integer.|
311| denominator | number | Yes| Denominator, which is an integer.|
312
313**Example**
314  ```js
315  var rationalNumber = new util.RationalNumber(1,2);
316  ```
317
318
319### createRationalFromString<sup>8+</sup>
320
321static createRationalFromString​(rationalString: string): RationalNumber​
322
323Creates a **RationalNumber** object based on the given string.
324
325**System capability**: SystemCapability.Utils.Lang
326
327**Parameters**
328| Name| Type| Mandatory| Description|
329| -------- | -------- | -------- | -------- |
330| rationalString | string | Yes| String used to create the **RationalNumber** object.|
331
332**Return value**
333| Type| Description|
334| -------- | -------- |
335| object | **RationalNumber** object created.|
336
337**Example**
338  ```js
339  var rationalNumber = new util.RationalNumber(1,2);
340  var rational = rationalNumer.creatRationalFromString("3/4");
341  ```
342
343
344### compareTo<sup>8+</sup>
345
346compareTo​(another: RationalNumber): number​
347
348Compares this **RationalNumber** object with a given object.
349
350**System capability**: SystemCapability.Utils.Lang
351
352**Parameters**
353| Name| Type| Mandatory| Description|
354| -------- | -------- | -------- | -------- |
355| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
356
357**Return value**
358| Type| Description|
359| -------- | -------- |
360| 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.|
361
362**Example**
363  ```js
364  var rationalNumber = new util.RationalNumber(1,2);
365  var rational = rationalNumer.creatRationalFromString("3/4");
366  var result = rationalNumber.compareTo(rational);
367  ```
368
369
370### valueOf<sup>8+</sup>
371
372valueOf(): number
373
374Obtains the value of this **RationalNumber** object as an integer or a floating-point number.
375
376**System capability**: SystemCapability.Utils.Lang
377
378**Return value**
379| Type| Description|
380| -------- | -------- |
381| number | An integer or a floating-point number.|
382
383**Example**
384  ```js
385  var rationalNumber = new util.RationalNumber(1,2);
386  var result = rationalNumber.valueOf();
387  ```
388
389
390### equals<sup>8+</sup>
391
392equals​(obj: Object): boolean
393
394Checks whether this **RationalNumber** object equals the given object.
395
396**System capability**: SystemCapability.Utils.Lang
397
398**Parameters**
399| Name| Type| Mandatory| Description|
400| -------- | -------- | -------- | -------- |
401| object | Object | Yes| Object used to compare with this **RationalNumber** object.|
402
403**Return value**
404| Type| Description|
405| -------- | -------- |
406| boolean | Returns **true** if the two objects are equal; returns **false** otherwise.|
407
408**Example**
409  ```js
410  var rationalNumber = new util.RationalNumber(1,2);
411  var rational = rationalNumer.creatRationalFromString("3/4");
412  var result = rationalNumber.equals(rational);
413  ```
414
415
416### getCommonDivisor<sup>8+</sup>
417
418static getCommonDivisor​(number1: number,number2: number): number
419
420Obtains the greatest common divisor of two specified integers.
421
422**System capability**: SystemCapability.Utils.Lang
423
424**Parameters**
425| Name| Type| Mandatory| Description|
426| -------- | -------- | -------- | -------- |
427| number1 | number | Yes| The first integer used to get the greatest common divisor.|
428| number2 | number | Yes| The second integer used to get the greatest common divisor.|
429
430**Return value**
431| Type| Description|
432| -------- | -------- |
433| number | Greatest common divisor obtained.|
434
435**Example**
436  ```js
437  var rationalNumber = new util.RationalNumber(1,2);
438  var result = rationalNumber.getCommonDivisor(4,6);
439  ```
440
441
442### getNumerator<sup>8+</sup>
443
444getNumerator​(): number
445
446Obtains the numerator of this **RationalNumber** object.
447
448**System capability**: SystemCapability.Utils.Lang
449
450**Return value**
451
452| Type| Description|
453| -------- | -------- |
454| number | Numerator of this **RationalNumber** object.|
455
456**Example**
457  ```js
458  var rationalNumber = new util.RationalNumber(1,2);
459  var result = rationalNumber.getNumerator();
460  ```
461
462
463### getDenominator<sup>8+</sup>
464
465getDenominator​(): number
466
467Obtains the denominator of this **RationalNumber** object.
468
469**System capability**: SystemCapability.Utils.Lang
470
471**Return value**
472| Type| Description|
473| -------- | -------- |
474| number | Denominator of this **RationalNumber** object.|
475
476**Example**
477  ```js
478  var rationalNumber = new util.RationalNumber(1,2);
479  var result = rationalNumber.getDenominator();
480  ```
481
482
483### isZero<sup>8+</sup>
484
485isZero​():boolean
486
487Checks whether this **RationalNumber** object is **0**.
488
489**System capability**: SystemCapability.Utils.Lang
490
491**Return value**
492| Type| Description|
493| -------- | -------- |
494| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
495
496**Example**
497  ```js
498  var rationalNumber = new util.RationalNumber(1,2);
499  var result = rationalNumber.isZero();
500  ```
501
502
503### isNaN<sup>8+</sup>
504
505isNaN​(): boolean
506
507Checks whether this **RationalNumber** object is a Not a Number (NaN).
508
509**System capability**: SystemCapability.Utils.Lang
510
511**Return value**
512| Type| Description|
513| -------- | -------- |
514| boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.|
515
516**Example**
517  ```js
518  var rationalNumber = new util.RationalNumber(1,2);
519  var result = rationalNumber.isNaN();
520  ```
521
522
523### isFinite<sup>8+</sup>
524
525isFinite​():boolean
526
527Checks whether this **RationalNumber** object represents a finite value.
528
529**System capability**: SystemCapability.Utils.Lang
530
531**Return value**
532| Type| Description|
533| -------- | -------- |
534| boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.|
535
536**Example**
537  ```js
538  var rationalNumber = new util.RationalNumber(1,2);
539  var result = rationalNumber.isFinite();
540  ```
541
542
543### toString<sup>8+</sup>
544
545toString​(): string
546
547Obtains the string representation of this **RationalNumber** object.
548
549**System capability**: SystemCapability.Utils.Lang
550
551**Return value**
552| Type| Description|
553| -------- | -------- |
554| 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**.|
555
556**Example**
557  ```js
558  var rationalNumber = new util.RationalNumber(1,2);
559  var result = rationalNumber.toString();
560  ```
561
562## LruBuffer<sup>8+</sup>
563
564### Attributes
565
566**System capability**: SystemCapability.Utils.Lang
567
568| Name| Type| Readable| Writable| Description|
569| -------- | -------- | -------- | -------- | -------- |
570| length | number | Yes| No| Total number of values in this buffer.|
571
572**Example**
573  ```js
574  var pro = new util.LruBuffer();
575  pro.put(2,10);
576  pro.put(1,8);
577  var result = pro.length;
578  ```
579
580
581### constructor<sup>8+</sup>
582
583constructor(capacity?: number)
584
585A constructor used to create an **LruBuffer** instance. The default capacity of the buffer is 64.
586
587**System capability**: SystemCapability.Utils.Lang
588
589**Parameters**
590| Name| Type| Mandatory| Description|
591| -------- | -------- | -------- | -------- |
592| capacity | number | No| Capacity of the **LruBuffer** to create.|
593
594**Example**
595  ```js
596  var lrubuffer= new util.LruBuffer();
597  ```
598
599
600### updateCapacity<sup>8+</sup>
601
602updateCapacity(newCapacity: number): void
603
604Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
605
606**System capability**: SystemCapability.Utils.Lang
607
608**Parameters**
609| Name| Type| Mandatory| Description|
610| -------- | -------- | -------- | -------- |
611| newCapacity | number | Yes| New capacity of the **LruBuffer**.|
612
613**Example**
614  ```js
615  var pro = new util.LruBuffer();
616  var result = pro.updateCapacity(100);
617  ```
618
619
620### toString<sup>8+</sup>
621
622toString(): string
623
624Obtains the string representation of this **LruBuffer** object.
625
626**System capability**: SystemCapability.Utils.Lang
627
628**Return value**
629| Type| Description|
630| -------- | -------- |
631| string | String representation of this **LruBuffer** object.|
632
633**Example**
634  ```js
635  var pro = new util.LruBuffer();
636  pro.put(2,10);
637  pro.get(2);
638  pro.remove(20);
639  var result = pro.toString();
640  ```
641
642
643### getCapacity<sup>8+</sup>
644
645getCapacity(): number
646
647Obtains the capacity of this buffer.
648
649**System capability**: SystemCapability.Utils.Lang
650
651**Return value**
652| Type| Description|
653| -------- | -------- |
654| number | Capacity of this buffer.|
655
656**Example**
657  ```js
658  var pro = new util.LruBuffer();
659  var result = pro.getCapacity();
660  ```
661
662
663### clear<sup>8+</sup>
664
665clear(): void
666
667Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations.
668
669**System capability**: SystemCapability.Utils.Lang
670
671**Example**
672  ```js
673  var pro = new util.LruBuffer();
674  pro.put(2,10);
675  var result = pro.size();
676  pro.clear();
677  ```
678
679
680### getCreateCount<sup>8+</sup>
681
682getCreateCount(): number
683
684Obtains the number of return values for **createDefault()**.
685
686**System capability**: SystemCapability.Utils.Lang
687
688**Return value**
689| Type| Description|
690| -------- | -------- |
691| number | Number of return values for **createDefault()**.|
692
693**Example**
694  ```js
695  var pro = new util.LruBuffer();
696  pro.put(1,8);
697  var result = pro.getCreateCount();
698  ```
699
700
701### getMissCount<sup>8+</sup>
702
703getMissCount(): number
704
705Obtains the number of times that the queried values are mismatched.
706
707**System capability**: SystemCapability.Utils.Lang
708
709**Return value**
710| Type| Description|
711| -------- | -------- |
712| number | Number of times that the queried values are mismatched.|
713
714**Example**
715  ```js
716  var pro = new util.LruBuffer();
717  pro.put(2,10);
718  pro.get(2);
719  var result = pro.getMissCount();
720  ```
721
722
723### getRemovalCount<sup>8+</sup>
724
725getRemovalCount(): number
726
727Obtains the number of removals from this buffer.
728
729**System capability**: SystemCapability.Utils.Lang
730
731**Return value**
732| Type| Description|
733| -------- | -------- |
734| number | Number of removals from the buffer.|
735
736**Example**
737  ```js
738  var pro = new util.LruBuffer();
739  pro.put(2,10);
740  pro.updateCapacity(2);
741  pro.put(50,22);
742  var result = pro.getRemovalCount();
743  ```
744
745
746### getMatchCount<sup>8+</sup>
747
748getMatchCount(): number
749
750Obtains the number of times that the queried values are matched.
751
752**System capability**: SystemCapability.Utils.Lang
753
754**Return value**
755| Type| Description|
756| -------- | -------- |
757| number | Number of times that the queried values are matched.|
758
759**Example**
760  ```js
761  var pro = new util.LruBuffer();
762  pro.put(2,10);
763  pro.get(2);
764  var result = pro.getMatchCount();
765  ```
766
767
768### getPutCount<sup>8+</sup>
769
770getPutCount(): number
771
772Obtains the number of additions to this buffer.
773
774**System capability**: SystemCapability.Utils.Lang
775
776**Return value**
777| Type| Description|
778| -------- | -------- |
779| number | Number of additions to the buffer.|
780
781**Example**
782  ```js
783  var pro = new util.LruBuffer();
784  pro.put(2,10);
785  var result = pro.getPutCount();
786  ```
787
788
789### isEmpty<sup>8+</sup>
790
791isEmpty(): boolean
792
793Checks whether this buffer is empty.
794
795**System capability**: SystemCapability.Utils.Lang
796
797**Return value**
798| Type| Description|
799| -------- | -------- |
800| boolean | Returns **true** if the buffer does not contain any value.|
801
802**Example**
803  ```js
804  var pro = new util.LruBuffer();
805  pro.put(2,10);
806  var result = pro.isEmpty();
807  ```
808
809
810### get<sup>8+</sup>
811
812get(key: K): V | undefined
813
814Obtains the value of the specified key.
815
816**System capability**: SystemCapability.Utils.Lang
817
818**Parameters**
819| Name| Type| Mandatory| Description|
820| -------- | -------- | -------- | -------- |
821| key | K | Yes| Key based on which the value is queried.|
822
823**Return value**
824| Type| Description|
825| -------- | -------- |
826| V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
827
828**Example**
829  ```js
830  var pro = new util.LruBuffer();
831  pro.put(2,10);
832  var result  = pro.get(2);
833  ```
834
835
836### put<sup>8+</sup>
837
838put(key: K,value: V): V
839
840Adds a key-value pair to this buffer.
841
842**System capability**: SystemCapability.Utils.Lang
843
844**Parameters**
845| Name| Type| Mandatory| Description|
846| -------- | -------- | -------- | -------- |
847| key | K | Yes| Key of the key-value pair to add.|
848| value | V | Yes| Value of the key-value pair to add.|
849
850**Return value**
851| Type| Description|
852| -------- | -------- |
853| 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. |
854
855**Example**
856  ```js
857  var pro = new util.LruBuffer();
858  var result = pro.put(2,10);
859  ```
860
861
862### values<sup>8+</sup>
863
864values(): V[]
865
866Obtains all values in this buffer, listed from the most to the least recently accessed.
867
868**System capability**: SystemCapability.Utils.Lang
869
870**Return value**
871| Type| Description|
872| -------- | -------- |
873| V [] | All values in the buffer, listed from the most to the least recently accessed.|
874
875**Example**
876  ```js
877  var pro = new util.LruBuffer();
878  pro.put(2,10);
879  pro.put(2,"anhu");
880  pro.put("afaf","grfb");
881  var result = pro.values();
882  ```
883
884
885### keys<sup>8+</sup>
886
887keys(): K[]
888
889Obtains all keys in this buffer, listed from the most to the least recently accessed.
890
891**System capability**: SystemCapability.Utils.Lang
892
893**Return value**
894| Type| Description|
895| -------- | -------- |
896| K [] | All keys in the buffer, listed from the most to the least recently accessed.|
897
898**Example**
899  ```js
900  var pro = new util.LruBuffer();
901  pro.put(2,10);
902  var result = pro.keys();
903  ```
904
905
906### remove<sup>8+</sup>
907
908remove(key: K): V | undefined
909
910Removes the specified key and its value from this buffer.
911
912**System capability**: SystemCapability.Utils.Lang
913
914**Parameters**
915| Name| Type| Mandatory| Description|
916| -------- | -------- | -------- | -------- |
917| key | K | Yes| Key to remove.|
918
919**Return value**
920| Type| Description|
921| -------- | -------- |
922| 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.|
923
924**Example**
925  ```js
926  var pro = new util.LruBuffer();
927  pro.put(2,10);
928  var result = pro.remove(20);
929  ```
930
931
932### afterRemoval<sup>8+</sup>
933
934afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
935
936Performs subsequent operations after a value is removed.
937
938**System capability**: SystemCapability.Utils.Lang
939
940**Parameters**
941| Name| Type| Mandatory| Description|
942| -------- | -------- | -------- | -------- |
943| isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.|
944| key | K | Yes| Key removed.|
945| value | V | Yes| Value removed.|
946| 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.|
947
948**Example**
949  ```js
950  var arr = [];
951  class ChildLruBuffer extends util.LruBuffer
952  {
953  	constructor()
954  	{
955  		super();
956  	}
957  	static getInstance()
958  	{
959  		if(this.instance ==  null)
960  		{
961  			this.instance = new ChildLruBuffer();
962  		}
963  		return this.instance;
964  	}
965  	afterRemoval(isEvict, key, value, newValue)
966  	{
967  		if (isEvict === false)
968  		{
969  			arr = [key, value, newValue];
970  		}
971  	}
972  }
973  ChildLruBuffer.getInstance().afterRemoval(false,10,30,null);
974  ```
975
976
977### contains<sup>8+</sup>
978
979contains(key: K): boolean
980
981Checks whether this buffer contains the specified key.
982
983**System capability**: SystemCapability.Utils.Lang
984
985**Parameters**
986| Name| Type| Mandatory| Description|
987| -------- | -------- | -------- | -------- |
988| key | K | Yes| Key to check.|
989
990**Return value**
991| Type| Description|
992| -------- | -------- |
993| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
994
995**Example**
996  ```js
997  var pro = new util.LruBuffer();
998  pro.put(2,10);
999  var result = pro.contains(20);
1000  ```
1001
1002
1003### createDefault<sup>8+</sup>
1004
1005createDefault(key: K): V
1006
1007Creates a value if the value of the specified key is not available.
1008
1009**System capability**: SystemCapability.Utils.Lang
1010
1011**Parameters**
1012| Name| Type| Mandatory| Description|
1013| -------- | -------- | -------- | -------- |
1014| key | K | Yes| Key of which the value is missing.|
1015
1016**Return value**
1017| Type| Description|
1018| -------- | -------- |
1019| V | Value of the key.|
1020
1021**Example**
1022  ```js
1023  var pro = new util.LruBuffer();
1024  var result = pro.createDefault(50);
1025  ```
1026
1027
1028### entries<sup>8+</sup>
1029
1030entries(): IterableIterator&lt;[K,V]&gt;
1031
1032Obtains a new iterator object that contains all key-value pairs in this object.
1033
1034**System capability**: SystemCapability.Utils.Lang
1035
1036**Return value**
1037| Type| Description|
1038| -------- | -------- |
1039| [K, V] | Iterable array.|
1040
1041**Example**
1042  ```js
1043  var pro = new util.LruBuffer();
1044  pro.put(2,10);
1045  var result = pro.entries();
1046  ```
1047
1048
1049### [Symbol.iterator]<sup>8+</sup>
1050
1051[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
1052
1053Obtains a two-dimensional array in key-value pairs.
1054
1055**System capability**: SystemCapability.Utils.Lang
1056
1057**Return value**
1058| Type| Description|
1059| -------- | -------- |
1060| [K, V] | Two-dimensional array in key-value pairs.|
1061
1062**Example**
1063  ```js
1064  var pro = new util.LruBuffer();
1065  pro.put(2,10);
1066  var result = pro[symbol.iterator]();
1067  ```
1068
1069
1070## Scope<sup>8+</sup>
1071
1072
1073### ScopeType<sup>8+</sup>
1074
1075Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**.
1076
1077The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
1078```js
1079interface ScopeComparable{
1080    compareTo(other: ScopeComparable): boolean;
1081}
1082type ScopeType = ScopeComparable | number;
1083```
1084
1085
1086Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#scopetype8) object.
1087
1088
1089Example
1090```js
1091class Temperature{
1092    constructor(value){
1093       // If TS is used for development, add the following code:
1094       // private readonly _temp: Temperature;
1095       this._temp = value;
1096    }
1097    comapreTo(value){
1098       return this._temp >= value.getTemp();
1099    }
1100    getTemp(){
1101       return this._temp;
1102    }
1103    toString(){
1104       return this._temp.toString();
1105    }
1106}
1107```
1108
1109
1110### constructor<sup>8+</sup>
1111
1112constructor(lowerObj: ScopeType, upperObj: ScopeType)
1113
1114A constructor used to create a **Scope** object with the specified upper and lower limits.
1115
1116**System capability**: SystemCapability.Utils.Lang
1117
1118**Parameters**
1119| Name| Type| Mandatory| Description|
1120| -------- | -------- | -------- | -------- |
1121| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
1122| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
1123
1124**Example**
1125  ```js
1126  var tempLower = new Temperature(30);
1127  var tempUpper = new Temperature(40);
1128  var range = new util.Scope(tempLower, tempUpper);
1129  ```
1130
1131
1132### toString<sup>8+</sup>
1133
1134toString(): string
1135
1136Obtains a string representation that contains this **Scope**.
1137
1138**System capability**: SystemCapability.Utils.Lang
1139
1140**Return value**
1141| Type| Description|
1142| -------- | -------- |
1143| string | String representation containing the **Scope**.|
1144
1145**Example**
1146  ```js
1147  var tempLower = new Temperature(30);
1148  var tempUpper = new Temperature(40);
1149  var range = new util.Scope(tempLower, tempUpper);
1150  var result = range.toString();
1151  ```
1152
1153
1154### intersect<sup>8+</sup>
1155
1156intersect(range: Scope): Scope
1157
1158Obtains the intersection of this **Scope** and the given **Scope**.
1159
1160**System capability**: SystemCapability.Utils.Lang
1161
1162**Parameters**
1163| Name| Type| Mandatory| Description|
1164| -------- | -------- | -------- | -------- |
1165| range | [Scope](#scope8) | Yes| **Scope** specified.|
1166
1167**Return value**
1168| Type| Description|
1169| -------- | -------- |
1170| [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.|
1171
1172**Example**
1173  ```js
1174  var tempLower = new Temperature(30);
1175  var tempUpper = new Temperature(40);
1176  var range = new util.Scope(tempLower, tempUpper);
1177  var tempMiDF = new Temperature(35);
1178  var tempMidS = new Temperature(39);
1179  var rangeFir = new util.Scope(tempMiDF, tempMidS);
1180  range.intersect(rangeFir );
1181  ```
1182
1183
1184### intersect<sup>8+</sup>
1185
1186intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
1187
1188Obtains the intersection of this **Scope** and the given lower and upper limits.
1189
1190**System capability**: SystemCapability.Utils.Lang
1191
1192**Parameters**
1193| Name| Type| Mandatory| Description|
1194| -------- | -------- | -------- | -------- |
1195| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
1196| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
1197
1198**Return value**
1199| Type| Description|
1200| -------- | -------- |
1201| [Scope](#scope8) | Intersection of this **Scope** and the given lower and upper limits.|
1202
1203**Example**
1204  ```js
1205  var tempLower = new Temperature(30);
1206  var tempUpper = new Temperature(40);
1207  var tempMiDF = new Temperature(35);
1208  var tempMidS = new Temperature(39);
1209  var range = new util.Scope(tempLower, tempUpper);
1210  var result = range.intersect(tempMiDF, tempMidS);
1211  ```
1212
1213
1214### getUpper<sup>8+</sup>
1215
1216getUpper(): ScopeType
1217
1218Obtains the upper limit of this **Scope**.
1219
1220**System capability**: SystemCapability.Utils.Lang
1221
1222**Return value**
1223
1224| Type| Description|
1225| -------- | -------- |
1226| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
1227
1228**Example**
1229  ```js
1230  var tempLower = new Temperature(30);
1231  var tempUpper = new Temperature(40);
1232  var range = new util.Scope(tempLower, tempUpper);
1233  var result = range.getUpper();
1234  ```
1235
1236
1237### getLower<sup>8+</sup>
1238
1239getLower(): ScopeType
1240
1241Obtains the lower limit of this **Scope**.
1242
1243**System capability**: SystemCapability.Utils.Lang
1244
1245**Return value**
1246| Type| Description|
1247| -------- | -------- |
1248| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
1249
1250**Example**
1251  ```js
1252  var tempLower = new Temperature(30);
1253  var tempUpper = new Temperature(40);
1254  var range = new util.Scope(tempLower, tempUpper);
1255  var result = range.getLower();
1256  ```
1257
1258
1259### expand<sup>8+</sup>
1260
1261expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
1262
1263Obtains the union set of this **Scope** and the given lower and upper limits.
1264
1265**System capability**: SystemCapability.Utils.Lang
1266
1267**Parameters**
1268| Name| Type| Mandatory| Description|
1269| -------- | -------- | -------- | -------- |
1270| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
1271| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
1272
1273**Return value**
1274| Type| Description|
1275| -------- | -------- |
1276| [Scope](#scope8) | Union set of this **Scope** and the given lower and upper limits.|
1277
1278**Example**
1279
1280  ```js
1281  var tempLower = new Temperature(30);
1282  var tempUpper = new Temperature(40);
1283  var tempMiDF = new Temperature(35);
1284  var tempMidS = new Temperature(39);
1285  var range = new util.Scope(tempLower, tempUpper);
1286  var result = range.expand(tempMiDF, tempMidS);
1287  ```
1288
1289
1290### expand<sup>8+</sup>
1291
1292expand(range: Scope): Scope
1293
1294Obtains the union set of this **Scope** and the given **Scope**.
1295
1296**System capability**: SystemCapability.Utils.Lang
1297
1298**Parameters**
1299| Name| Type| Mandatory| Description|
1300| -------- | -------- | -------- | -------- |
1301| range | [Scope](#scope8) | Yes| **Scope** specified.|
1302
1303**Return value**
1304| Type| Description|
1305| -------- | -------- |
1306| [Scope](#scope8) | Union set of this **Scope** and the given **Scope**.|
1307
1308**Example**
1309  ```js
1310  var tempLower = new Temperature(30);
1311  var tempUpper = new Temperature(40);
1312  var tempMiDF = new Temperature(35);
1313  var tempMidS = new Temperature(39);
1314  var range = new util.Scope(tempLower, tempUpper);
1315  var rangeFir = new util.Scope(tempMiDF, tempMidS);
1316  var result = range.expand(rangeFir);
1317  ```
1318
1319
1320### expand<sup>8+</sup>
1321
1322expand(value: ScopeType): Scope
1323
1324Obtains the union set of this **Scope** and the given value.
1325
1326**System capability**: SystemCapability.Utils.Lang
1327
1328**Parameters**
1329| Name| Type| Mandatory| Description|
1330| -------- | -------- | -------- | -------- |
1331| value | [ScopeType](#scopetype8) | Yes| Value specified.|
1332
1333**Return value**
1334| Type| Description|
1335| -------- | -------- |
1336| [Scope](#scope8) | Union set of this **Scope** and the given value.|
1337
1338**Example**
1339  ```js
1340  var tempLower = new Temperature(30);
1341  var tempUpper = new Temperature(40);
1342  var tempMiDF = new Temperature(35);
1343  var range = new util.Scope(tempLower, tempUpper);
1344  var result = range.expand(tempMiDF);
1345  ```
1346
1347
1348### contains<sup>8+</sup>
1349
1350contains(value: ScopeType): boolean
1351
1352Checks whether a value is within this **Scope**.
1353
1354**System capability**: SystemCapability.Utils.Lang
1355
1356**Parameters**
1357| Name| Type| Mandatory| Description|
1358| -------- | -------- | -------- | -------- |
1359| value | [ScopeType](#scopetype8) | Yes| Value specified.|
1360
1361**Return value**
1362| Type| Description|
1363| -------- | -------- |
1364| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
1365
1366**Example**
1367  ```js
1368  var tempLower = new Temperature(30);
1369  var tempUpper = new Temperature(40);
1370  var tempMiDF = new Temperature(35);
1371  var range = new util.Scope(tempLower, tempUpper);
1372  range.contains(tempMiDF);
1373  ```
1374
1375
1376### contains<sup>8+</sup>
1377
1378contains(range: Scope): boolean
1379
1380Checks whether a range is within this **Scope**.
1381
1382**System capability**: SystemCapability.Utils.Lang
1383
1384**Parameters**
1385| Name| Type| Mandatory| Description|
1386| -------- | -------- | -------- | -------- |
1387| range | [Scope](#scope8) | Yes| **Scope** specified.|
1388
1389**Return value**
1390| Type| Description|
1391| -------- | -------- |
1392| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
1393
1394**Example**
1395  ```js
1396  var tempLower = new Temperature(30);
1397  var tempUpper = new Temperature(40);
1398  var range = new util.Scope(tempLower, tempUpper);
1399  var tempLess = new Temperature(20);
1400  var tempMore = new Temperature(45);
1401  var rangeSec = new util.Scope(tempLess, tempMore);
1402  var result = range.contains(rangeSec);
1403  ```
1404
1405
1406### clamp<sup>8+</sup>
1407
1408clamp(value: ScopeType): ScopeType
1409
1410Limits a value to this **Scope**.
1411
1412**System capability**: SystemCapability.Utils.Lang
1413
1414**Parameters**
1415| Name| Type| Mandatory| Description|
1416| -------- | -------- | -------- | -------- |
1417| value | [ScopeType](#scopetype8) | Yes| Value specified.|
1418
1419**Return value**
1420| Type| Description|
1421| -------- | -------- |
1422| [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**.|
1423
1424**Example**
1425  ```js
1426  var tempLower = new Temperature(30);
1427  var tempUpper = new Temperature(40);
1428  var tempMiDF = new Temperature(35);
1429  var range = new util.Scope(tempLower, tempUpper);
1430  var result = range.clamp(tempMiDF);
1431  ```
1432
1433
1434## Base64<sup>8+</sup>
1435
1436
1437### constructor<sup>8+</sup>
1438
1439constructor()
1440
1441A constructor used to create a **Base64** object.
1442
1443**System capability**: SystemCapability.Utils.Lang
1444
1445**Example**
1446  ```js
1447  var base64 = new  util.Base64();
1448  ```
1449
1450
1451### encodeSync<sup>8+</sup>
1452
1453encodeSync(src: Uint8Array): Uint8Array
1454
1455Encodes the input content.
1456
1457**System capability**: SystemCapability.Utils.Lang
1458
1459**Parameters**
1460| Name| Type| Mandatory| Description|
1461| -------- | -------- | -------- | -------- |
1462| src | Uint8Array | Yes| Uint8Array to encode.|
1463
1464**Return value**
1465| Type| Description|
1466| -------- | -------- |
1467| Uint8Array | Uint8Array encoded.|
1468
1469**Example**
1470  ```js
1471  var that = new util.Base64();
1472  var array = new Uint8Array([115,49,51]);
1473  var result = that.encodeSync(array);
1474  ```
1475
1476
1477### encodeToStringSync<sup>8+</sup>
1478
1479encodeToStringSync(src: Uint8Array): string
1480
1481Encodes the input content.
1482
1483**System capability**: SystemCapability.Utils.Lang
1484
1485**Parameters**
1486| Name| Type| Mandatory| Description|
1487| -------- | -------- | -------- | -------- |
1488| src | Uint8Array | Yes| Uint8Array to encode.|
1489
1490**Return value**
1491| Type| Description|
1492| -------- | -------- |
1493| string | String encoded from the Uint8Array.|
1494
1495**Example**
1496  ```js
1497  var that = new util.Base64();
1498  var array = new Uint8Array([115,49,51]);
1499  var result = that.encodeToStringSync(array);
1500  ```
1501
1502
1503### decodeSync<sup>8+</sup>
1504
1505decodeSync(src: Uint8Array | string): Uint8Array
1506
1507Decodes the input content.
1508
1509**System capability**: SystemCapability.Utils.Lang
1510
1511**Parameters**
1512| Name| Type| Mandatory| Description|
1513| -------- | -------- | -------- | -------- |
1514| src | Uint8Array \| string | Yes| Uint8Array or string to decode.|
1515
1516**Return value**
1517| Type| Description|
1518| -------- | -------- |
1519| Uint8Array | Uint8Array decoded.|
1520
1521**Example**
1522  ```js
1523  var that = new util.Base64();
1524  var buff = 'czEz';
1525  var result = that.decodeSync(buff);
1526  ```
1527
1528
1529### encode<sup>8+</sup>
1530
1531encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
1532
1533Encodes the input content asynchronously.
1534
1535**System capability**: SystemCapability.Utils.Lang
1536
1537**Parameters**
1538| Name| Type| Mandatory| Description|
1539| -------- | -------- | -------- | -------- |
1540| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
1541
1542**Return value**
1543| Type| Description|
1544| -------- | -------- |
1545| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
1546
1547**Example**
1548  ```js
1549  var that = new util.Base64();
1550  var array = new Uint8Array([115,49,51]);
1551  var rarray = new Uint8Array([99,122,69,122]);
1552  that.encode(array).then(val=>{
1553      for (var i = 0; i < rarray.length; i++) {
1554          console.log(val[i])
1555      }
1556  })
1557  ```
1558
1559
1560### encodeToString<sup>8+</sup>
1561
1562encodeToString(src: Uint8Array): Promise&lt;string&gt;
1563
1564Encodes the input content asynchronously.
1565
1566**System capability**: SystemCapability.Utils.Lang
1567
1568**Parameters**
1569| Name| Type| Mandatory| Description|
1570| -------- | -------- | -------- | -------- |
1571| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
1572
1573**Return value**
1574| Type| Description|
1575| -------- | -------- |
1576| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
1577
1578**Example**
1579  ```js
1580  var that = new util.Base64();
1581  var array = new Uint8Array([115,49,51]);
1582  that.encodeToString(array).then(val=>{
1583      console.log(val)
1584  })
1585  ```
1586
1587
1588### decode<sup>8+</sup>
1589
1590decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
1591
1592Decodes the input content asynchronously.
1593
1594**System capability**: SystemCapability.Utils.Lang
1595
1596**Parameters**
1597| Name| Type| Mandatory| Description|
1598| -------- | -------- | -------- | -------- |
1599| src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.|
1600
1601**Return value**
1602| Type| Description|
1603| -------- | -------- |
1604| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
1605
1606**Example**
1607  ```js
1608  var that = new util.Base64();
1609  var array = new Uint8Array([99,122,69,122]);
1610  var rarray = new Uint8Array([115,49,51]);
1611  that.decode(array).then(val=>{
1612      for (var i = 0; i < rarray.length; i++) {
1613          console.log(val[i])
1614      }
1615  })
1616  ```
1617
1618
1619## types<sup>8+</sup>
1620
1621
1622### constructor<sup>8+</sup>
1623
1624constructor()
1625
1626A constructor used to create a **Types** object.
1627
1628**System capability**: SystemCapability.Utils.Lang
1629
1630**Example**
1631  ```js
1632  var type = new util.types();
1633  ```
1634
1635
1636### isAnyArrayBuffer<sup>8+</sup>
1637
1638isAnyArrayBuffer(value: Object): boolean
1639
1640Checks whether the input value is of the **ArrayBuffer** type.
1641
1642**System capability**: SystemCapability.Utils.Lang
1643
1644**Parameters**
1645| Name| Type| Mandatory| Description|
1646| -------- | -------- | -------- | -------- |
1647| value | Object | Yes| Object to check.|
1648
1649**Return value**
1650| Type| Description|
1651| -------- | -------- |
1652| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
1653
1654**Example**
1655  ```js
1656  var that = new util.types();
1657  var result = that.isAnyArrayBuffer(new ArrayBuffer([]));
1658  ```
1659
1660
1661### isArrayBufferView<sup>8+</sup>
1662
1663isArrayBufferView(value: Object): boolean
1664
1665Checks whether the input value is of the **ArrayBufferView** type.
1666
1667**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
1668
1669**System capability**: SystemCapability.Utils.Lang
1670
1671**Parameters**
1672| Name| Type| Mandatory| Description|
1673| -------- | -------- | -------- | -------- |
1674| value | Object | Yes| Object to check.|
1675
1676**Return value**
1677| Type| Description|
1678| -------- | -------- |
1679| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
1680
1681**Example**
1682  ```js
1683  var that = new util.types();
1684  var result = that.isArrayBufferView(new Int8Array([]));
1685  ```
1686
1687
1688### isArgumentsObject<sup>8+</sup>
1689
1690isArgumentsObject(value: Object): boolean
1691
1692Checks whether the input value is of the **arguments** type.
1693
1694**System capability**: SystemCapability.Utils.Lang
1695
1696**Parameters**
1697| Name| Type| Mandatory| Description|
1698| -------- | -------- | -------- | -------- |
1699| value | Object | Yes| Object to check.|
1700
1701**Return value**
1702| Type| Description|
1703| -------- | -------- |
1704| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
1705
1706**Example**
1707  ```js
1708  var that = new util.types();
1709  function foo() {
1710      var result = that.isArgumentsObject(arguments);
1711  }
1712  var f = foo();
1713  ```
1714
1715
1716### isArrayBuffer<sup>8+</sup>
1717
1718isArrayBuffer(value: Object): boolean
1719
1720Checks whether the input value is of the **ArrayBuffer** type.
1721
1722**System capability**: SystemCapability.Utils.Lang
1723
1724**Parameters**
1725| Name| Type| Mandatory| Description|
1726| -------- | -------- | -------- | -------- |
1727| value | Object | Yes| Object to check.|
1728
1729**Return value**
1730| Type| Description|
1731| -------- | -------- |
1732| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
1733
1734**Example**
1735  ```js
1736  var that = new util.types();
1737  var result = that.isArrayBuffer(new ArrayBuffer([]));
1738  ```
1739
1740
1741### isAsyncFunction<sup>8+</sup>
1742
1743isAsyncFunction(value: Object): boolean
1744
1745Checks whether the input value is an asynchronous function.
1746
1747**System capability**: SystemCapability.Utils.Lang
1748
1749**Parameters**
1750| Name| Type| Mandatory| Description|
1751| -------- | -------- | -------- | -------- |
1752| value | Object | Yes| Object to check.|
1753
1754**Return value**
1755| Type| Description|
1756| -------- | -------- |
1757| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
1758
1759**Example**
1760  ```js
1761  var that = new util.types();
1762  var result = that.isAsyncFunction(async function foo() {});
1763  ```
1764
1765
1766### isBooleanObject<sup>8+</sup>
1767
1768isBooleanObject(value: Object): boolean
1769
1770Checks whether the input value is of the **Boolean** type.
1771
1772**System capability**: SystemCapability.Utils.Lang
1773
1774**Parameters**
1775| Name| Type| Mandatory| Description|
1776| -------- | -------- | -------- | -------- |
1777| value | Object | Yes| Object to check.|
1778
1779**Return value**
1780| Type| Description|
1781| -------- | -------- |
1782| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
1783
1784**Example**
1785  ```js
1786  var that = new util.types();
1787  var result = that.isBooleanObject(new Boolean(true));
1788  ```
1789
1790
1791### isBoxedPrimitive<sup>8+</sup>
1792
1793isBoxedPrimitive(value: Object): boolean
1794
1795Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.
1796
1797**System capability**: SystemCapability.Utils.Lang
1798
1799**Parameters**
1800| Name| Type| Mandatory| Description|
1801| -------- | -------- | -------- | -------- |
1802| value | Object | Yes| Object to check.|
1803
1804**Return value**
1805| Type| Description|
1806| -------- | -------- |
1807| boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
1808
1809**Example**
1810  ```js
1811  var that = new util.types();
1812  var result = that.isBoxedPrimitive(new Boolean(false));
1813  ```
1814
1815
1816### isDataView<sup>8+</sup>
1817
1818isDataView(value: Object): boolean
1819
1820Checks whether the input value is of the **DataView** type.
1821
1822**System capability**: SystemCapability.Utils.Lang
1823
1824**Parameters**
1825| Name| Type| Mandatory| Description|
1826| -------- | -------- | -------- | -------- |
1827| value | Object | Yes| Object to check.|
1828
1829**Return value**
1830| Type| Description|
1831| -------- | -------- |
1832| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
1833
1834**Example**
1835  ```js
1836  var that = new util.types();
1837  const ab = new ArrayBuffer(20);
1838  var result = that.isDataView(new DataView(ab));
1839  ```
1840
1841
1842### isDate<sup>8+</sup>
1843
1844isDate(value: Object): boolean
1845
1846Checks whether the input value is of the **Date** type.
1847
1848**System capability**: SystemCapability.Utils.Lang
1849
1850**Parameters**
1851| Name| Type| Mandatory| Description|
1852| -------- | -------- | -------- | -------- |
1853| value | Object | Yes| Object to check.|
1854
1855**Return value**
1856| Type| Description|
1857| -------- | -------- |
1858| boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
1859
1860**Example**
1861  ```js
1862  var that = new util.types();
1863  var result = that.isDate(new Date());
1864  ```
1865
1866
1867### isExternal<sup>8+</sup>
1868
1869isExternal(value: Object): boolean
1870
1871Checks whether the input value is of the **native external** type.
1872
1873**System capability**: SystemCapability.Utils.Lang
1874
1875**Parameters**
1876| Name| Type| Mandatory| Description|
1877| -------- | -------- | -------- | -------- |
1878| value | Object | Yes| Object to check.|
1879
1880**Return value**
1881| Type| Description|
1882| -------- | -------- |
1883| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
1884
1885**Example**
1886  ```js
1887  var that = new util.types();
1888  const data = util.createExternalType();
1889  var result = that.isExternal(data);
1890  ```
1891
1892
1893### isFloat32Array<sup>8+</sup>
1894
1895isFloat32Array(value: Object): boolean
1896
1897Checks whether the input value is of the **Float32Array** type.
1898
1899**System capability**: SystemCapability.Utils.Lang
1900
1901**Parameters**
1902| Name| Type| Mandatory| Description|
1903| -------- | -------- | -------- | -------- |
1904| value | Object | Yes| Object to check.|
1905
1906**Return value**
1907| Type| Description|
1908| -------- | -------- |
1909| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.|
1910
1911**Example**
1912  ```js
1913  var that = new util.types();
1914  var result = that.isFloat32Array(new Float32Array());
1915  ```
1916
1917
1918### isFloat64Array<sup>8+</sup>
1919
1920isFloat64Array(value: Object): boolean
1921
1922Checks whether the input value is of the **Float64Array** type.
1923
1924**System capability**: SystemCapability.Utils.Lang
1925
1926**Parameters**
1927| Name| Type| Mandatory| Description|
1928| -------- | -------- | -------- | -------- |
1929| value | Object | Yes| Object to check.|
1930
1931**Return value**
1932| Type| Description|
1933| -------- | -------- |
1934| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
1935
1936**Example**
1937  ```js
1938  var that = new util.types();
1939  var result = that.isFloat64Array(new Float64Array());
1940  ```
1941
1942
1943### isGeneratorFunction<sup>8+</sup>
1944
1945isGeneratorFunction(value: Object): boolean
1946
1947Checks whether the input value is a generator function.
1948
1949**System capability**: SystemCapability.Utils.Lang
1950
1951**Parameters**
1952| Name| Type| Mandatory| Description|
1953| -------- | -------- | -------- | -------- |
1954| value | Object | Yes| Object to check.|
1955
1956**Return value**
1957| Type| Description|
1958| -------- | -------- |
1959| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
1960
1961**Example**
1962  ```js
1963  var that = new util.types();
1964  var result = that.isGeneratorFunction(function* foo() {});
1965  ```
1966
1967
1968### isGeneratorObject<sup>8+</sup>
1969
1970isGeneratorObject(value: Object): boolean
1971
1972Checks whether the input value is a generator object.
1973
1974**System capability**: SystemCapability.Utils.Lang
1975
1976**Parameters**
1977| Name| Type| Mandatory| Description|
1978| -------- | -------- | -------- | -------- |
1979| value | Object | Yes| Object to check.|
1980
1981**Return value**
1982| Type| Description|
1983| -------- | -------- |
1984| boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.|
1985
1986**Example**
1987  ```js
1988  var that = new util.types();
1989  function* foo() {}
1990  const generator = foo();
1991  var result = that.isGeneratorObject(generator);
1992  ```
1993
1994
1995### isInt8Array<sup>8+</sup>
1996
1997isInt8Array(value: Object): boolean
1998
1999Checks whether the input value is of the **Int8Array** type.
2000
2001**System capability**: SystemCapability.Utils.Lang
2002
2003**Parameters**
2004| Name| Type| Mandatory| Description|
2005| -------- | -------- | -------- | -------- |
2006| value | Object | Yes| Object to check.|
2007
2008**Return value**
2009| Type| Description|
2010| -------- | -------- |
2011| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
2012
2013**Example**
2014  ```js
2015  var that = new util.types();
2016  var result = that.isInt8Array(new Int8Array([]));
2017  ```
2018
2019
2020### isInt16Array<sup>8+</sup>
2021
2022isInt16Array(value: Object): boolean
2023
2024Checks whether the input value is of the **Int16Array** type.
2025
2026**System capability**: SystemCapability.Utils.Lang
2027
2028**Parameters**
2029| Name| Type| Mandatory| Description|
2030| -------- | -------- | -------- | -------- |
2031| value | Object | Yes| Object to check.|
2032
2033**Return value**
2034| Type| Description|
2035| -------- | -------- |
2036| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
2037
2038**Example**
2039  ```js
2040  var that = new util.types();
2041  var result = that.isInt16Array(new Int16Array([]));
2042  ```
2043
2044
2045### isInt32Array<sup>8+</sup>
2046
2047isInt32Array(value: Object): boolean
2048
2049Checks whether the input value is of the **Int32Array** type.
2050
2051**System capability**: SystemCapability.Utils.Lang
2052
2053**Parameters**
2054| Name| Type| Mandatory| Description|
2055| -------- | -------- | -------- | -------- |
2056| value | Object | Yes| Object to check.|
2057
2058**Return value**
2059| Type| Description|
2060| -------- | -------- |
2061| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
2062
2063**Example**
2064  ```js
2065  var that = new util.types();
2066  var result = that.isInt32Array(new Int32Array([]));
2067  ```
2068
2069
2070### isMap<sup>8+</sup>
2071
2072isMap(value: Object): boolean
2073
2074Checks whether the input value is of the **Map** type.
2075
2076**System capability**: SystemCapability.Utils.Lang
2077
2078**Parameters**
2079| Name| Type| Mandatory| Description|
2080| -------- | -------- | -------- | -------- |
2081| value | Object | Yes| Object to check.|
2082
2083**Return value**
2084| Type| Description|
2085| -------- | -------- |
2086| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
2087
2088**Example**
2089  ```js
2090  var that = new util.types();
2091  var result = that.isMap(new Map());
2092  ```
2093
2094
2095### isMapIterator<sup>8+</sup>
2096
2097isMapIterator(value: Object): boolean
2098
2099Checks whether the input value is of the **MapIterator** type.
2100
2101**System capability**: SystemCapability.Utils.Lang
2102
2103**Parameters**
2104| Name| Type| Mandatory| Description|
2105| -------- | -------- | -------- | -------- |
2106| value | Object | Yes| Object to check.|
2107
2108**Return value**
2109| Type| Description|
2110| -------- | -------- |
2111| boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
2112
2113**Example**
2114  ```js
2115  var that = new util.types();
2116  const map = new Map();
2117  var result = that.isMapIterator(map.keys());
2118  ```
2119
2120
2121### isNativeError<sup>8+</sup>
2122
2123isNativeError(value: Object): boolean
2124
2125Checks whether the input value is of the **Error** type.
2126
2127**System capability**: SystemCapability.Utils.Lang
2128
2129**Parameters**
2130| Name| Type| Mandatory| Description|
2131| -------- | -------- | -------- | -------- |
2132| value | Object | Yes| Object to check.|
2133
2134**Return value**
2135| Type| Description|
2136| -------- | -------- |
2137| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
2138
2139**Example**
2140  ```js
2141  var that = new util.types();
2142  var result = that.isNativeError(new TypeError());
2143  ```
2144
2145
2146### isNumberObject<sup>8+</sup>
2147
2148isNumberObject(value: Object): boolean
2149
2150Checks whether the input value is a number object.
2151
2152**System capability**: SystemCapability.Utils.Lang
2153
2154**Parameters**
2155| Name| Type| Mandatory| Description|
2156| -------- | -------- | -------- | -------- |
2157| value | Object | Yes| Object to check.|
2158
2159**Return value**
2160| Type| Description|
2161| -------- | -------- |
2162| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
2163
2164**Example**
2165  ```js
2166  var that = new util.types();
2167  var result = that.isNumberObject(new Number(0));
2168  ```
2169
2170
2171### isPromise<sup>8+</sup>
2172
2173isPromise(value: Object): boolean
2174
2175Checks whether the input value is a promise.
2176
2177**System capability**: SystemCapability.Utils.Lang
2178
2179**Parameters**
2180| Name| Type| Mandatory| Description|
2181| -------- | -------- | -------- | -------- |
2182| value | Object | Yes| Object to check.|
2183
2184**Return value**
2185| Type| Description|
2186| -------- | -------- |
2187| boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
2188
2189**Example**
2190  ```js
2191  var that = new util.types();
2192  var result = that.isPromise(Promise.resolve(1));
2193  ```
2194
2195
2196### isProxy<sup>8+</sup>
2197
2198isProxy(value: Object): boolean
2199
2200Checks whether the input value is a proxy.
2201
2202**System capability**: SystemCapability.Utils.Lang
2203
2204**Parameters**
2205| Name| Type| Mandatory| Description|
2206| -------- | -------- | -------- | -------- |
2207| value | Object | Yes| Object to check.|
2208
2209**Return value**
2210| Type| Description|
2211| -------- | -------- |
2212| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
2213
2214**Example**
2215  ```js
2216  var that = new util.types();
2217  const target = {};
2218  const proxy = new Proxy(target, {});
2219  var result = that.isProxy(proxy);
2220  ```
2221
2222
2223### isRegExp<sup>8+</sup>
2224
2225isRegExp(value: Object): boolean
2226
2227Checks whether the input value is of the **RegExp** type.
2228
2229**System capability**: SystemCapability.Utils.Lang
2230
2231**Parameters**
2232| Name| Type| Mandatory| Description|
2233| -------- | -------- | -------- | -------- |
2234| value | Object | Yes| Object to check.|
2235
2236**Return value**
2237| Type| Description|
2238| -------- | -------- |
2239| boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.|
2240
2241**Example**
2242  ```js
2243  var that = new util.types();
2244  var result = that.isRegExp(new RegExp('abc'));
2245  ```
2246
2247
2248### isSet<sup>8+</sup>
2249
2250isSet(value: Object): boolean
2251
2252Checks whether the input value is of the **Set** type.
2253
2254**System capability**: SystemCapability.Utils.Lang
2255
2256**Parameters**
2257| Name| Type| Mandatory| Description|
2258| -------- | -------- | -------- | -------- |
2259| value | Object | Yes| Object to check.|
2260
2261**Return value**
2262| Type| Description|
2263| -------- | -------- |
2264| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
2265
2266**Example**
2267  ```js
2268  var that = new util.types();
2269  var result = that.isSet(new Set());
2270  ```
2271
2272
2273### isSetIterator<sup>8+</sup>
2274
2275isSetIterator(value: Object): boolean
2276
2277Checks whether the input value is of the **SetIterator** type.
2278
2279**System capability**: SystemCapability.Utils.Lang
2280
2281**Parameters**
2282| Name| Type| Mandatory| Description|
2283| -------- | -------- | -------- | -------- |
2284| value | Object | Yes| Object to check.|
2285
2286**Return value**
2287| Type| Description|
2288| -------- | -------- |
2289| boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.|
2290
2291**Example**
2292  ```js
2293  var that = new util.types();
2294  const set = new Set();
2295  var result = that.isSetIterator(set.keys());
2296  ```
2297
2298
2299### isStringObject<sup>8+</sup>
2300
2301isStringObject(value: Object): boolean
2302
2303Checks whether the input value is a string object.
2304
2305**System capability**: SystemCapability.Utils.Lang
2306
2307**Parameters**
2308| Name| Type| Mandatory| Description|
2309| -------- | -------- | -------- | -------- |
2310| value | Object | Yes| Object to check.|
2311
2312**Return value**
2313| Type| Description|
2314| -------- | -------- |
2315| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
2316
2317**Example**
2318  ```js
2319  var that = new util.types();
2320  var result = that.isStringObject(new String('foo'));
2321  ```
2322
2323
2324### isSymbolObjec<sup>8+</sup>
2325
2326isSymbolObject(value: Object): boolean
2327
2328Checks whether the input value is a symbol object.
2329
2330**System capability**: SystemCapability.Utils.Lang
2331
2332**Parameters**
2333| Name| Type| Mandatory| Description|
2334| -------- | -------- | -------- | -------- |
2335| value | Object | Yes| Object to check.|
2336
2337**Return value**
2338| Type| Description|
2339| -------- | -------- |
2340| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
2341
2342**Example**
2343  ```js
2344  var that = new util.types();
2345  const symbols = Symbol('foo');
2346  var result = that.isSymbolObject(Object(symbols));
2347  ```
2348
2349
2350### isTypedArray<sup>8+</sup>
2351
2352isTypedArray(value: Object): boolean
2353
2354Checks whether the input value is of the **TypedArray** type.
2355
2356**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
2357
2358**System capability**: SystemCapability.Utils.Lang
2359
2360**Parameters**
2361| Name| Type| Mandatory| Description|
2362| -------- | -------- | -------- | -------- |
2363| value | Object | Yes| Object to check.|
2364
2365**Return value**
2366| Type| Description|
2367| -------- | -------- |
2368| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
2369
2370**Example**
2371  ```js
2372  var that = new util.types();
2373  var result = that.isTypedArray(new Float64Array([]));
2374  ```
2375
2376
2377### isUint8Array<sup>8+</sup>
2378
2379isUint8Array(value: Object): boolean
2380
2381Checks whether the input value is of the **Uint8Array** type.
2382
2383**System capability**: SystemCapability.Utils.Lang
2384
2385**Parameters**
2386| Name| Type| Mandatory| Description|
2387| -------- | -------- | -------- | -------- |
2388| value | Object | Yes| Object to check.|
2389
2390**Return value**
2391| Type| Description|
2392| -------- | -------- |
2393| boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
2394
2395**Example**
2396  ```js
2397  var that = new util.types();
2398  var result = that.isUint8Array(new Uint8Array([]));
2399  ```
2400
2401
2402### isUint8ClampedArray<sup>8+</sup>
2403
2404isUint8ClampedArray(value: Object): boolean
2405
2406Checks whether the input value is of the **Uint8ClampedArray** type.
2407
2408**System capability**: SystemCapability.Utils.Lang
2409
2410**Parameters**
2411| Name| Type| Mandatory| Description|
2412| -------- | -------- | -------- | -------- |
2413| value | Object | Yes| Object to check.|
2414
2415**Return value**
2416| Type| Description|
2417| -------- | -------- |
2418| boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
2419
2420**Example**
2421  ```js
2422  var that = new util.types();
2423  var result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
2424  ```
2425
2426
2427### isUint16Array<sup>8+</sup>
2428
2429isUint16Array(value: Object): boolean
2430
2431Checks whether the input value is of the **Uint16Array** type.
2432
2433**System capability**: SystemCapability.Utils.Lang
2434
2435**Parameters**
2436| Name| Type| Mandatory| Description|
2437| -------- | -------- | -------- | -------- |
2438| value | Object | Yes| Object to check.|
2439
2440**Return value**
2441| Type| Description|
2442| -------- | -------- |
2443| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
2444
2445**Example**
2446  ```js
2447  var that = new util.types();
2448  var result = that.isUint16Array(new Uint16Array([]));
2449  ```
2450
2451
2452### isUint32Array<sup>8+</sup>
2453
2454isUint32Array(value: Object): boolean
2455
2456Checks whether the input value is of the **Uint32Array** type.
2457
2458**System capability**: SystemCapability.Utils.Lang
2459
2460**Parameters**
2461| Name| Type| Mandatory| Description|
2462| -------- | -------- | -------- | -------- |
2463| value | Object | Yes| Object to check.|
2464
2465**Return value**
2466| Type| Description|
2467| -------- | -------- |
2468| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
2469
2470**Example**
2471  ```js
2472  var that = new util.types();
2473  var result = that.isUint32Array(new Uint32Array([]));
2474  ```
2475
2476
2477### isWeakMap<sup>8+</sup>
2478
2479isWeakMap(value: Object): boolean
2480
2481Checks whether the input value is of the **WeakMap** type.
2482
2483**System capability**: SystemCapability.Utils.Lang
2484
2485**Parameters**
2486| Name| Type| Mandatory| Description|
2487| -------- | -------- | -------- | -------- |
2488| value | Object | Yes| Object to check.|
2489
2490**Return value**
2491| Type| Description|
2492| -------- | -------- |
2493| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
2494
2495**Example**
2496  ```js
2497  var that = new util.types();
2498  var result = that.isWeakMap(new WeakMap());
2499  ```
2500
2501
2502### isWeakSet<sup>8+</sup>
2503
2504isWeakSet(value: Object): boolean
2505
2506Checks whether the input value is of the **WeakSet** type.
2507
2508**System capability**: SystemCapability.Utils.Lang
2509
2510**Parameters**
2511| Name| Type| Mandatory| Description|
2512| -------- | -------- | -------- | -------- |
2513| value | Object | Yes| Object to check.|
2514
2515**Return value**
2516| Type| Description|
2517| -------- | -------- |
2518| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
2519
2520**Example**
2521  ```js
2522  var that = new util.types();
2523  var result = that.isWeakSet(new WeakSet());
2524  ```
2525