• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.util (util)
2
3The **util** 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.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9
10## Modules to Import
11
12```js
13import util from '@ohos.util';
14```
15
16## util.format<sup>9+</sup>
17
18format(format: string,  ...args: Object[]): string
19
20Formats the specified values and inserts them into the string by replacing the wildcard in the string.
21
22**System capability**: SystemCapability.Utils.Lang
23
24**Parameters**
25
26| Name | Type    | Mandatory| Description          |
27| ------- | -------- | ---- | -------------- |
28| format  | string   | Yes  | String.|
29| ...args | Object[] | No  | Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
30
31**Return value**
32
33| Type  | Description                        |
34| ------ | ---------------------------- |
35| string | String containing the formatted values.|
36
37**Example**
38
39  ```js
40let res = util.format("%s", "hello world!");
41console.log(res);
42  ```
43
44## util.errnoToString<sup>9+</sup>
45
46errnoToString(errno: number): string
47
48Obtains detailed information about a system error code.
49
50**System capability**: SystemCapability.Utils.Lang
51
52**Parameters**
53
54| Name| Type  | Mandatory| Description                      |
55| ------ | ------ | ---- | -------------------------- |
56| errno  | number | Yes  | Error code generated.|
57
58**Return value**
59
60| Type  | Description                  |
61| ------ | ---------------------- |
62| string | Detailed information about the error code.|
63
64**Example**
65
66```js
67let errnum = -1; // -1 is a system error code.
68let result = util.errnoToString(errnum);
69console.log("result = " + result);
70```
71
72**Some error code and message examples**
73
74| Error Code| Message                             |
75| ------ | -------------------------------- |
76| -1     | operation not permitted          |
77| -2     | no such file or directory        |
78| -3     | no such process                  |
79| -4     | interrupted system call          |
80| -5     | i/o error                        |
81| -11    | resource temporarily unavailable |
82| -12    | not enough memory                |
83| -13    | permission denied                |
84| -100   | network is down                  |
85
86## util.callbackWrapper
87
88callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void
89
90Calls 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.
91
92**System capability**: SystemCapability.Utils.Lang
93
94**Parameters**
95
96| Name| Type| Mandatory| Description|
97| -------- | -------- | -------- | -------- |
98| original | Function | Yes| Asynchronous function.|
99
100**Return value**
101
102| Type| Description|
103| -------- | -------- |
104| 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.|
105
106**Example**
107
108  ```js
109async function fn() {
110   return 'hello world';
111}
112let cb = util.callbackWrapper(fn);
113cb(1, (err, ret) => {
114   if (err) throw err;
115   console.log(ret);
116});
117  ```
118
119## util.promisify<sup>9+</sup>
120
121promisify(original: (err: Object, value: Object) =&gt; void): Function
122
123Processes an asynchronous function and returns a promise.
124
125**System capability**: SystemCapability.Utils.Lang
126
127**Parameters**
128
129| Name| Type| Mandatory| Description|
130| -------- | -------- | -------- | -------- |
131| original | Function | Yes| Asynchronous function.|
132
133**Return value**
134
135| Type| Description|
136| -------- | -------- |
137| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
138
139**Example**
140
141  ```js
142function fun(num, callback) {
143   if (typeof num === 'number') {
144      callback(null, num + 3);
145   } else {
146      callback("type err");
147   }
148}
149
150const addCall = util.promisify(fun);
151(async () => {
152   try {
153      let res = await addCall(2);
154      console.log(res);
155   } catch (err) {
156      console.log(err);
157   }
158})();
159  ```
160
161## util.generateRandomUUID<sup>9+</sup>
162
163generateRandomUUID(entropyCache?: boolean): string
164
165Uses a secure random number generator to generate a random universally unique identifier (UUID) of the string type in RFC 4122 version 4.
166
167**System capability**: SystemCapability.Utils.Lang
168
169**Parameters**
170
171| Name| Type| Mandatory| Description|
172| -------- | -------- | -------- | -------- |
173| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.|
174
175**Return value**
176
177| Type| Description|
178| -------- | -------- |
179| string | A string representing the UUID generated.|
180
181**Example**
182
183  ```js
184  let uuid = util.generateRandomUUID(true);
185  console.log("RFC 4122 Version 4 UUID:" + uuid);
186  // Output:
187  // RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
188  ```
189
190## util.generateRandomBinaryUUID<sup>9+</sup>
191
192generateRandomBinaryUUID(entropyCache?: boolean): Uint8Array
193
194Uses a secure random number generator to generate a random UUID of the Uint8Array type in RFC 4122 version 4.
195
196**System capability**: SystemCapability.Utils.Lang
197
198**Parameters**
199
200| Name| Type| Mandatory| Description|
201| -------- | -------- | -------- | -------- |
202| entropyCache | boolean | No| Whether a cached UUID can be used. The default value is **true**.|
203
204**Return value**
205
206| Type| Description|
207| -------- | -------- |
208| Uint8Array | A Uint8Array value representing the UUID generated.|
209
210**Example**
211
212  ```js
213  let uuid = util.generateRandomBinaryUUID(true);
214  console.log(JSON.stringify(uuid));
215  // Output:
216  // 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150
217  ```
218
219## util.parseUUID<sup>9+</sup>
220
221parseUUID(uuid: string): Uint8Array
222
223Converts the UUID of the string type generated by **generateRandomUUID** to the UUID of the **Uint8Array** type generated by **generateRandomBinaryUUID**, as described in RFC 4122 version 4.
224
225**System capability**: SystemCapability.Utils.Lang
226
227**Parameters**
228
229| Name| Type| Mandatory| Description|
230| -------- | -------- | -------- | -------- |
231| uuid | string | Yes| A string representing the UUID.|
232
233**Return value**
234
235| Type| Description|
236| -------- | -------- |
237| Uint8Array | A Uint8Array value representing the UUID parsed. If the parsing fails, **SyntaxError** is thrown.|
238
239**Example**
240
241  ```js
242  let uuid = util.parseUUID("84bdf796-66cc-4655-9b89-d6218d100f9c");
243  console.log(JSON.stringify(uuid));
244  // Output:
245  // 132,189,247,150,102,204,70,85,155,137,214,33,141,16,15,156
246  ```
247
248## util.printf<sup>(deprecated)</sup>
249
250printf(format: string,  ...args: Object[]): string
251
252Formats the specified values and inserts them into the string by replacing the wildcard in the string.
253
254> **NOTE**
255>
256> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.format<sup>9+</sup>](#utilformat9) instead.
257
258**System capability**: SystemCapability.Utils.Lang
259
260**Parameters**
261
262| Name| Type| Mandatory| Description|
263| -------- | -------- | -------- | -------- |
264| format | string | Yes| String.|
265| ...args | Object[] | No| Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
266
267**Return value**
268
269| Type| Description|
270| -------- | -------- |
271| string | String containing the formatted values.|
272
273**Example**
274
275  ```js
276  let res = util.printf("%s", "hello world!");
277  console.log(res);
278  ```
279
280
281## util.getErrorString<sup>(deprecated)</sup>
282
283getErrorString(errno: number): string
284
285Obtains detailed information about a system error code.
286
287> **NOTE**
288>
289> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [util.errnoToString<sup>9+</sup>](#utilerrnotostring9) instead.
290
291**System capability**: SystemCapability.Utils.Lang
292
293**Parameters**
294
295| Name| Type| Mandatory| Description|
296| -------- | -------- | -------- | -------- |
297| errno | number | Yes| Error code generated.|
298
299**Return value**
300
301| Type| Description|
302| -------- | -------- |
303| string | Detailed information about the error code.|
304
305**Example**
306
307  ```js
308  let errnum = -1; // -1 is a system error code.
309  let result = util.getErrorString(errnum);
310  console.log("result = " + result);
311  ```
312
313## util.promiseWrapper<sup>(deprecated)</sup>
314
315promiseWrapper(original: (err: Object, value: Object) =&gt; void): Object
316
317Processes an asynchronous function and returns a promise.
318
319> **NOTE**
320>
321> This API is unavailable. You are advised to use [util.promisify<sup>9+</sup>](#utilpromisify9) instead.
322
323**System capability**: SystemCapability.Utils.Lang
324
325**Parameters**
326
327| Name| Type| Mandatory| Description|
328| -------- | -------- | -------- | -------- |
329| original | Function | Yes| Asynchronous function.|
330
331**Return value**
332
333| Type| Description|
334| -------- | -------- |
335| Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise.|
336
337
338## TextDecoder
339
340### Attributes
341
342**System capability**: SystemCapability.Utils.Lang
343
344| Name| Type| Readable| Writable| Description|
345| -------- | -------- | -------- | -------- | -------- |
346| encoding | string | Yes| No| Encoding format.<br>- Supported formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u, macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, x-mac-cyrilli, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, euc-kr, utf-16be, utf-16le|
347| fatal | boolean | Yes| No| Whether to display fatal errors.|
348| 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.|
349
350### constructor<sup>9+</sup>
351
352constructor()
353
354A constructor used to create a **TextDecoder** object.
355
356**System capability**: SystemCapability.Utils.Lang
357
358### create<sup>9+</sup>
359
360create(encoding?: string,options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoder;
361
362Creates a **TextDecoder** object. It provides the same function as the deprecated argument constructor.
363
364**System capability**: SystemCapability.Utils.Lang
365
366**Parameters**
367
368| Name  | Type  | Mandatory| Description                                            |
369| -------- | ------ | ---- | ------------------------------------------------ |
370| encoding | string | No  | Encoding format.                                      |
371| options  | Object | No  | Encoding-related options, which include **fatal** and **ignoreBOM**.|
372
373**Table 1.1** options
374
375| Name     | Type| Mandatory| Description              |
376| --------- | -------- | ---- | ------------------ |
377| fatal     | boolean  | No  | Whether to display fatal errors.|
378| ignoreBOM | boolean  | No  | Whether to ignore the BOM. |
379
380**Example**
381
382```js
383let result = util.TextDecoder.create('utf-8', { ignoreBOM : true })
384let retStr = result.encoding
385```
386
387### decodeWithStream<sup>9+</sup>
388
389decodeWithStream(input: Uint8Array, options?: { stream?: boolean }): string
390
391Decodes the input content.
392
393**System capability**: SystemCapability.Utils.Lang
394
395**Parameters**
396
397| Name| Type| Mandatory| Description|
398| -------- | -------- | -------- | -------- |
399| input | Uint8Array | Yes| Uint8Array to decode.|
400| options | Object | No| Options related to decoding.|
401
402**Table 2** options
403
404| Name| Type| Mandatory| Description|
405| -------- | -------- | -------- | -------- |
406| stream | boolean | No| Whether to allow data blocks in subsequent **decodeWithStream()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.|
407
408**Return value**
409
410| Type| Description|
411| -------- | -------- |
412| string | Data decoded.|
413
414**Example**
415
416  ```js
417  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
418  let result = new Uint8Array(6);
419  result[0] = 0xEF;
420  result[1] = 0xBB;
421  result[2] = 0xBF;
422  result[3] = 0x61;
423  result[4] = 0x62;
424  result[5] = 0x63;
425  console.log("input num:");
426  let retStr = textDecoder.decodeWithStream( result , {stream: false});
427  console.log("retStr = " + retStr);
428  ```
429
430### constructor<sup>(deprecated)</sup>
431
432constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean })
433
434A constructor used to create a **TextDecoder** object.
435
436> **NOTE**
437>
438> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [create<sup>9+</sup>](#create9) instead.
439
440**System capability**: SystemCapability.Utils.Lang
441
442**Parameters**
443
444| Name| Type| Mandatory| Description|
445| -------- | -------- | -------- | -------- |
446| encoding | string | No| Encoding format.|
447| options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.|
448
449  **Table 1** options
450
451| Name| Type| Mandatory| Description|
452| -------- | -------- | -------- | -------- |
453| fatal | boolean | No| Whether to display fatal errors.|
454| ignoreBOM | boolean | No| Whether to ignore the BOM.|
455
456**Example**
457
458  ```js
459  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
460  ```
461
462### decode<sup>(deprecated)</sup>
463
464decode(input: Uint8Array, options?: { stream?: false }): string
465
466Decodes the input content.
467
468> **NOTE**
469>
470> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [decodeWithStream<sup>9+</sup>](#decodewithstream9) instead.
471
472**System capability**: SystemCapability.Utils.Lang
473
474**Parameters**
475
476| Name| Type| Mandatory| Description|
477| -------- | -------- | -------- | -------- |
478| input | Uint8Array | Yes| Uint8Array to decode.|
479| options | Object | No| Options related to decoding.|
480
481**Table 2** options
482
483| Name| Type| Mandatory| Description|
484| -------- | -------- | -------- | -------- |
485| 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**.|
486
487**Return value**
488
489| Type| Description|
490| -------- | -------- |
491| string | Data decoded.|
492
493**Example**
494
495  ```js
496  let textDecoder = new util.TextDecoder("utf-8",{ignoreBOM: true});
497  let result = new Uint8Array(6);
498  result[0] = 0xEF;
499  result[1] = 0xBB;
500  result[2] = 0xBF;
501  result[3] = 0x61;
502  result[4] = 0x62;
503  result[5] = 0x63;
504  console.log("input num:");
505  let retStr = textDecoder.decode( result , {stream: false});
506  console.log("retStr = " + retStr);
507  ```
508
509## TextEncoder
510
511### Attributes
512
513**System capability**: SystemCapability.Utils.Lang
514
515| Name| Type| Readable| Writable| Description|
516| -------- | -------- | -------- | -------- | -------- |
517| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
518
519
520### constructor
521
522constructor()
523
524A constructor used to create a **TextEncoder** object.
525
526**System capability**: SystemCapability.Utils.Lang
527
528**Example**
529
530  ```js
531  let textEncoder = new util.TextEncoder();
532  ```
533
534### constructor<sup>9+</sup>
535
536constructor(encoding?: string)
537
538A constructor used to create a **TextEncoder** object.
539
540**System capability**: SystemCapability.Utils.Lang
541
542**Parameters**
543
544| Name| Type| Mandatory| Description|
545| ----- | ---- | ---- | ---- |
546| encoding | string | No| Encoding format.|
547
548**Example**
549
550  ```js
551  let textEncoder = new util.TextEncoder("utf-8");
552  ```
553
554### encodeInto<sup>9+</sup>
555
556encodeInto(input?: string): Uint8Array
557
558Encodes the input content.
559
560**System capability**: SystemCapability.Utils.Lang
561
562**Parameters**
563
564| Name| Type  | Mandatory| Description              |
565| ------ | ------ | ---- | ------------------ |
566| input  | string | No  | String to encode.|
567
568**Return value**
569
570| Type      | Description              |
571| ---------- | ------------------ |
572| Uint8Array | Encoded text.|
573
574**Example**
575
576  ```js
577let textEncoder = new util.TextEncoder();
578let buffer = new ArrayBuffer(20);
579let result = new Uint8Array(buffer);
580result = textEncoder.encodeInto("\uD800¥¥");
581  ```
582
583### encodeIntoUint8Array<sup>9+</sup>
584
585encodeIntoUint8Array(input: string, dest: Uint8Array, ): { read: number; written: number }
586
587Stores the UTF-8 encoded text.
588
589**System capability**: SystemCapability.Utils.Lang
590
591**Parameters**
592
593| Name| Type      | Mandatory| Description                                                   |
594| ------ | ---------- | ---- | ------------------------------------------------------- |
595| input  | string     | Yes  | String to encode.                                     |
596| dest   | Uint8Array | Yes  | **Uint8Array** instance used to store the UTF-8 encoded text.|
597
598**Return value**
599
600| Type      | Description              |
601| ---------- | ------------------ |
602| Uint8Array | Encoded text.|
603
604**Example**
605
606  ```js
607let that = new util.TextEncoder()
608let buffer = new ArrayBuffer(4)
609let dest = new Uint8Array(buffer)
610let result = new Object()
611result = that.encodeIntoUint8Array('abcd', dest)
612  ```
613
614### encodeInto<sup>(deprecated)</sup>
615
616encodeInto(input: string, dest: Uint8Array, ): { read: number; written: number }
617
618Stores the UTF-8 encoded text.
619
620> **NOTE**
621>
622> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeIntoUint8Array<sup>9+</sup>](#encodeintouint8array9) instead.
623
624**System capability**: SystemCapability.Utils.Lang
625
626**Parameters**
627
628| Name| Type| Mandatory| Description|
629| -------- | -------- | -------- | -------- |
630| input | string | Yes| String to encode.|
631| dest | Uint8Array | Yes| **Uint8Array** instance used to store the UTF-8 encoded text.|
632
633**Return value**
634
635| Type| Description|
636| -------- | -------- |
637| Uint8Array | Encoded text.|
638
639**Example**
640  ```js
641  let that = new util.TextEncoder()
642  let buffer = new ArrayBuffer(4)
643  let dest = new Uint8Array(buffer)
644  let result = new Object()
645  result = that.encodeInto('abcd', dest)
646  ```
647
648### encode<sup>(deprecated)</sup>
649
650encode(input?: string): Uint8Array
651
652Encodes the input content.
653
654> **NOTE**
655>
656> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [encodeInto<sup>9+</sup>](#encodeinto9) instead.
657
658**System capability**: SystemCapability.Utils.Lang
659
660**Parameters**
661
662| Name| Type| Mandatory| Description|
663| -------- | -------- | -------- | -------- |
664| input | string | No| String to encode.|
665
666**Return value**
667
668| Type| Description|
669| -------- | -------- |
670| Uint8Array | Encoded text.|
671
672**Example**
673  ```js
674  let textEncoder = new util.TextEncoder();
675  let buffer = new ArrayBuffer(20);
676  let result = new Uint8Array(buffer);
677  result = textEncoder.encode("\uD800¥¥");
678  ```
679
680## RationalNumber<sup>8+</sup>
681
682### constructor<sup>9+</sup>
683
684constructor()
685
686A constructor used to create a **RationalNumber** object.
687
688**System capability**: SystemCapability.Utils.Lang
689
690**Example**
691
692```js
693let rationalNumber = new util.RationalNumber();
694```
695
696### parseRationalNumber<sup>9+</sup>
697
698parseRationalNumber(numerator: number,denominator: number): RationalNumber
699
700Parses a rational number. Previously, this processing is an internal action of the deprecated constructor.
701
702**System capability**: SystemCapability.Utils.Lang
703
704**Parameters**
705
706| Name     | Type  | Mandatory| Description            |
707| ----------- | ------ | ---- | ---------------- |
708| numerator   | number | Yes  | Numerator, which is an integer.|
709| denominator | number | Yes  | Denominator, which is an integer.|
710
711**Example**
712
713```js
714let rationalNumber = util.RationalNumber.parseRationalNumber(1,2)
715```
716
717### createRationalFromString<sup>8+</sup>
718
719static createRationalFromString​(rationalString: string): RationalNumber​
720
721Creates a **RationalNumber** object based on the given string.
722
723**System capability**: SystemCapability.Utils.Lang
724
725**Parameters**
726
727| Name| Type| Mandatory| Description|
728| -------- | -------- | -------- | -------- |
729| rationalString | string | Yes| String used to create the **RationalNumber** object.|
730
731**Return value**
732
733| Type| Description|
734| -------- | -------- |
735| object | **RationalNumber** object created.|
736
737**Example**
738
739```js
740let rationalNumber = new util.RationalNumber(1,2);
741let rational = util.RationalNumber.createRationalFromString("3/4");
742```
743
744### compare<sup>9+</sup>
745
746compare​(another: RationalNumber): number​
747
748Compares this **RationalNumber** object with a given object.
749
750**System capability**: SystemCapability.Utils.Lang
751
752**Parameters**
753
754| Name | Type          | Mandatory| Description              |
755| ------- | -------------- | ---- | ------------------ |
756| another | RationalNumber | Yes  | Object used to compare with this **RationalNumber** object.|
757
758**Return value**
759
760| Type  | Description                                                        |
761| ------ | ------------------------------------------------------------ |
762| 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.|
763
764**Example**
765
766  ```js
767let rationalNumber = new util.RationalNumber(1,2);
768let rational = util.RationalNumber.createRationalFromString("3/4");
769let result = rationalNumber.compare(rational);
770  ```
771
772### valueOf<sup>8+</sup>
773
774valueOf(): number
775
776Obtains the value of this **RationalNumber** object as an integer or a floating-point number.
777
778**System capability**: SystemCapability.Utils.Lang
779
780**Return value**
781
782| Type| Description|
783| -------- | -------- |
784| number | An integer or a floating-point number.|
785
786**Example**
787
788```js
789let rationalNumber = new util.RationalNumber(1,2);
790let result = rationalNumber.valueOf();
791```
792
793### equals<sup>8+</sup>
794
795equals​(obj: Object): boolean
796
797Checks whether this **RationalNumber** object equals the given object.
798
799**System capability**: SystemCapability.Utils.Lang
800
801**Parameters**
802
803| Name| Type| Mandatory| Description|
804| -------- | -------- | -------- | -------- |
805| object | Object | Yes| Object used to compare with this **RationalNumber** object.|
806
807**Return value**
808
809| Type| Description|
810| -------- | -------- |
811| boolean | Returns **true** if the two objects are equal; returns **false** otherwise.|
812
813**Example**
814
815```js
816let rationalNumber = new util.RationalNumber(1,2);
817let rational = util.RationalNumber.createRationalFromString("3/4");
818let result = rationalNumber.equals(rational);
819```
820
821### getCommonFactor<sup>9+</sup>
822
823getCommonFactor(number1: number,number2: number): number
824
825Obtains the greatest common divisor of two specified integers.
826
827**System capability**: SystemCapability.Utils.Lang
828
829**Parameters**
830
831| Name | Type  | Mandatory| Description      |
832| ------- | ------ | ---- | ---------- |
833| number1 | number | Yes  | The first integer used to get the greatest common divisor.|
834| number2 | number | Yes  | The second integer used to get the greatest common divisor.|
835
836**Return value**
837
838| Type  | Description                          |
839| ------ | ------------------------------ |
840| number | Greatest common divisor obtained.|
841
842**Example**
843
844```js
845let rationalNumber = new util.RationalNumber(1,2);
846let result = util.RationalNumber.getCommonFactor(4,6);
847```
848
849### getNumerator<sup>8+</sup>
850
851getNumerator​(): number
852
853Obtains the numerator of this **RationalNumber** object.
854
855**System capability**: SystemCapability.Utils.Lang
856
857**Return value**
858
859| Type| Description|
860| -------- | -------- |
861| number | Numerator of this **RationalNumber** object.|
862
863**Example**
864
865```js
866let rationalNumber = new util.RationalNumber(1,2);
867let result = rationalNumber.getNumerator();
868```
869
870### getDenominator<sup>8+</sup>
871
872getDenominator​(): number
873
874Obtains the denominator of this **RationalNumber** object.
875
876**System capability**: SystemCapability.Utils.Lang
877
878**Return value**
879
880| Type| Description|
881| -------- | -------- |
882| number | Denominator of this **RationalNumber** object.|
883
884**Example**
885
886```js
887let rationalNumber = new util.RationalNumber(1,2);
888let result = rationalNumber.getDenominator();
889```
890
891### isZero<sup>8+</sup>
892
893isZero​():boolean
894
895Checks whether this **RationalNumber** object is **0**.
896
897**System capability**: SystemCapability.Utils.Lang
898
899**Return value**
900
901| Type| Description|
902| -------- | -------- |
903| boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.|
904
905**Example**
906
907```js
908let rationalNumber = new util.RationalNumber(1,2);
909let result = rationalNumber.isZero();
910```
911
912### isNaN<sup>8+</sup>
913
914isNaN​(): boolean
915
916Checks whether this **RationalNumber** object is a Not a Number (NaN).
917
918**System capability**: SystemCapability.Utils.Lang
919
920**Return value**
921
922| Type| Description|
923| -------- | -------- |
924| boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.|
925
926**Example**
927
928```js
929let rationalNumber = new util.RationalNumber(1,2);
930let result = rationalNumber.isNaN();
931```
932
933### isFinite<sup>8+</sup>
934
935isFinite​():boolean
936
937Checks whether this **RationalNumber** object represents a finite value.
938
939**System capability**: SystemCapability.Utils.Lang
940
941**Return value**
942
943| Type| Description|
944| -------- | -------- |
945| boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.|
946
947**Example**
948
949```js
950let rationalNumber = new util.RationalNumber(1,2);
951let result = rationalNumber.isFinite();
952```
953
954### toString<sup>8+</sup>
955
956toString​(): string
957
958Obtains the string representation of this **RationalNumber** object.
959
960**System capability**: SystemCapability.Utils.Lang
961
962**Return value**
963
964| Type| Description|
965| -------- | -------- |
966| 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**.|
967
968**Example**
969
970```js
971let rationalNumber = new util.RationalNumber(1,2);
972let result = rationalNumber.toString();
973```
974
975### constructor<sup>(deprecated)</sup>
976
977constructor(numerator: number,denominator: number)
978
979A constructor used to create a **RationalNumber** object.
980
981> **NOTE**
982>
983> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [constructor<sup>9+</sup>](#constructor9) instead.
984
985**System capability**: SystemCapability.Utils.Lang
986
987**Parameters**
988
989| Name| Type| Mandatory| Description|
990| -------- | -------- | -------- | -------- |
991| numerator | number | Yes| Numerator, which is an integer.|
992| denominator | number | Yes| Denominator, which is an integer.|
993
994**Example**
995
996```js
997let rationalNumber = new util.RationalNumber(1,2);
998```
999
1000### compareTo<sup>(deprecated)</sup>
1001
1002compareTo​(another: RationalNumber): number​
1003
1004Compares this **RationalNumber** object with a given object.
1005
1006> **NOTE**
1007>
1008> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [compare<sup>9+</sup>](#compare9) instead.
1009
1010**System capability**: SystemCapability.Utils.Lang
1011
1012**Parameters**
1013
1014| Name| Type| Mandatory| Description|
1015| -------- | -------- | -------- | -------- |
1016| another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.|
1017
1018**Return value**
1019
1020| Type| Description|
1021| -------- | -------- |
1022| 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.|
1023
1024**Example**
1025
1026```js
1027let rationalNumber = new util.RationalNumber(1,2);
1028let rational = util.RationalNumber.createRationalFromString("3/4");
1029let result = rationalNumber.compareTo(rational);
1030```
1031
1032### getCommonDivisor<sup>(deprecated)</sup>
1033
1034static getCommonDivisor​(number1: number,number2: number): number
1035
1036Obtains the greatest common divisor of two specified integers.
1037
1038> **NOTE**
1039>
1040> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getCommonFactor<sup>9+</sup>](#getcommonfactor9) instead.
1041
1042**System capability**: SystemCapability.Utils.Lang
1043
1044**Parameters**
1045
1046| Name| Type| Mandatory| Description|
1047| -------- | -------- | -------- | -------- |
1048| number1 | number | Yes| The first integer used to get the greatest common divisor.|
1049| number2 | number | Yes| The second integer used to get the greatest common divisor.|
1050
1051**Return value**
1052
1053| Type| Description|
1054| -------- | -------- |
1055| number | Greatest common divisor obtained.|
1056
1057**Example**
1058
1059```js
1060let rationalNumber = new util.RationalNumber(1,2);
1061let result = util.RationalNumber.getCommonDivisor(4,6);
1062```
1063
1064## LRUCache<sup>9+</sup>
1065
1066### Attributes
1067
1068**System capability**: SystemCapability.Utils.Lang
1069
1070| Name  | Type  | Readable| Writable| Description                  |
1071| ------ | ------ | ---- | ---- | ---------------------- |
1072| length | number | Yes  | No  | Total number of values in this cache.|
1073
1074**Example**
1075
1076```js
1077let pro = new util.LRUCache();
1078pro.put(2,10);
1079pro.put(1,8);
1080let result = pro.length;
1081```
1082
1083### constructor<sup>9+</sup>
1084
1085constructor(capacity?: number)
1086
1087A constructor used to create a **LruCache** instance. The default capacity of the cache is 64.
1088
1089**System capability**: SystemCapability.Utils.Lang
1090
1091**Parameters**
1092
1093| Name  | Type  | Mandatory| Description                        |
1094| -------- | ------ | ---- | ---------------------------- |
1095| capacity | number | No  | Capacity of the **LruCache** to create.|
1096
1097**Example**
1098
1099```js
1100let lrubuffer= new util.LRUCache();
1101```
1102
1103
1104### updateCapacity<sup>9+</sup>
1105
1106updateCapacity(newCapacity: number): void
1107
1108Changes the **LruCache** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
1109
1110**System capability**: SystemCapability.Utils.Lang
1111
1112**Parameters**
1113
1114| Name     | Type  | Mandatory| Description                        |
1115| ----------- | ------ | ---- | ---------------------------- |
1116| newCapacity | number | Yes  | New capacity of the **LruCache**.|
1117
1118**Example**
1119
1120```js
1121let pro = new util.LRUCache();
1122let result = pro.updateCapacity(100);
1123```
1124
1125
1126### toString<sup>9+</sup>
1127
1128toString(): string
1129
1130Obtains the string representation of this **LruCache** object.
1131
1132**System capability**: SystemCapability.Utils.Lang
1133
1134**Return value**
1135
1136| Type  | Description                      |
1137| ------ | -------------------------- |
1138| string | String representation of this **LruCache** object.|
1139
1140**Example**
1141
1142```js
1143let pro = new util.LRUCache();
1144pro.put(2,10);
1145pro.get(2);
1146pro.remove(20);
1147let result = pro.toString();
1148```
1149
1150
1151### getCapacity<sup>9+</sup>
1152
1153getCapacity(): number
1154
1155Obtains the capacity of this cache.
1156
1157**System capability**: SystemCapability.Utils.Lang
1158
1159**Return value**
1160
1161| Type  | Description                  |
1162| ------ | ---------------------- |
1163| number | Capacity of this cache.|
1164
1165**Example**
1166
1167  ```js
1168let pro = new util.LRUCache();
1169let result = pro.getCapacity();
1170  ```
1171
1172
1173### clear<sup>9+</sup>
1174
1175clear(): void
1176
1177Clears key-value pairs from this cache. The **afterRemoval()** method will be called to perform subsequent operations.
1178
1179**System capability**: SystemCapability.Utils.Lang
1180
1181**Example**
1182
1183  ```js
1184let pro = new util.LRUCache();
1185pro.put(2,10);
1186let result = pro.length;
1187pro.clear();
1188  ```
1189
1190
1191### getCreateCount<sup>9+</sup>
1192
1193getCreateCount(): number
1194
1195Obtains the number of return values for **createDefault()**.
1196
1197**System capability**: SystemCapability.Utils.Lang
1198
1199**Return value**
1200
1201| Type  | Description                             |
1202| ------ | --------------------------------- |
1203| number | Number of return values for **createDefault()**.|
1204
1205**Example**
1206
1207  ```js
1208let pro = new util.LRUCache();
1209pro.put(1,8);
1210let result = pro.getCreateCount();
1211  ```
1212
1213
1214### getMissCount<sup>9+</sup>
1215
1216getMissCount(): number
1217
1218Obtains the number of times that the queried values are mismatched.
1219
1220**System capability**: SystemCapability.Utils.Lang
1221
1222**Return value**
1223
1224| Type  | Description                    |
1225| ------ | ------------------------ |
1226| number | Number of times that the queried values are mismatched.|
1227
1228**Example**
1229
1230  ```js
1231let pro = new util.LRUCache();
1232pro.put(2,10);
1233pro.get(2);
1234let result = pro.getMissCount();
1235  ```
1236
1237
1238### getRemovalCount<sup>9+</sup>
1239
1240getRemovalCount(): number
1241
1242Obtains the number of removals from this cache.
1243
1244**System capability**: SystemCapability.Utils.Lang
1245
1246**Return value**
1247
1248| Type  | Description                      |
1249| ------ | -------------------------- |
1250| number | Number of removals from the cache.|
1251
1252**Example**
1253
1254  ```js
1255let pro = new util.LRUCache();
1256pro.put(2,10);
1257pro.updateCapacity(2);
1258pro.put(50,22);
1259let result = pro.getRemovalCount();
1260  ```
1261
1262
1263### getMatchCount<sup>9+</sup>
1264
1265getMatchCount(): number
1266
1267Obtains the number of times that the queried values are matched.
1268
1269**System capability**: SystemCapability.Utils.Lang
1270
1271**Return value**
1272
1273| Type  | Description                      |
1274| ------ | -------------------------- |
1275| number | Number of times that the queried values are matched.|
1276
1277**Example**
1278
1279  ```js
1280let pro = new util.LRUCache();
1281pro.put(2,10);
1282pro.get(2);
1283let result = pro.getMatchCount();
1284  ```
1285
1286
1287### getPutCount<sup>9+</sup>
1288
1289getPutCount(): number
1290
1291Obtains the number of additions to this cache.
1292
1293**System capability**: SystemCapability.Utils.Lang
1294
1295**Return value**
1296
1297| Type  | Description                        |
1298| ------ | ---------------------------- |
1299| number | Number of additions to the cache.|
1300
1301**Example**
1302
1303  ```js
1304let pro = new util.LRUCache();
1305pro.put(2,10);
1306let result = pro.getPutCount();
1307  ```
1308
1309
1310### isEmpty<sup>9+</sup>
1311
1312isEmpty(): boolean
1313
1314Checks whether this cache is empty.
1315
1316**System capability**: SystemCapability.Utils.Lang
1317
1318**Return value**
1319
1320| Type   | Description                                    |
1321| ------- | ---------------------------------------- |
1322| boolean | Returns **true** if the cache does not contain any value.|
1323
1324**Example**
1325
1326  ```js
1327let pro = new util.LRUCache();
1328pro.put(2,10);
1329let result = pro.isEmpty();
1330  ```
1331
1332
1333### get<sup>9+</sup>
1334
1335get(key: K): V | undefined
1336
1337Obtains the value of the specified key.
1338
1339**System capability**: SystemCapability.Utils.Lang
1340
1341**Parameters**
1342
1343| Name| Type| Mandatory| Description        |
1344| ------ | ---- | ---- | ------------ |
1345| key    | K    | Yes  | Key based on which the value is queried.|
1346
1347**Return value**
1348
1349| Type                    | Description                                                        |
1350| ------------------------ | ------------------------------------------------------------ |
1351| V \| undefined | Returns the value of the key if a match is found in the cache; returns **undefined** otherwise.|
1352
1353**Example**
1354
1355  ```js
1356let pro = new util.LRUCache();
1357pro.put(2,10);
1358let result  = pro.get(2);
1359  ```
1360
1361
1362### put<sup>9+</sup>
1363
1364put(key: K,value: V): V
1365
1366Adds a key-value pair to this cache.
1367
1368**System capability**: SystemCapability.Utils.Lang
1369
1370**Parameters**
1371
1372| Name| Type| Mandatory| Description                      |
1373| ------ | ---- | ---- | -------------------------- |
1374| key    | K    | Yes  | Key of the key-value pair to add.            |
1375| value  | V    | Yes  | Value of the key-value pair to add.|
1376
1377**Return value**
1378
1379| Type| Description                                                        |
1380| ---- | ------------------------------------------------------------ |
1381| 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. |
1382
1383**Example**
1384
1385  ```js
1386let pro = new util.LRUCache();
1387let result = pro.put(2,10);
1388  ```
1389
1390### values<sup>9+</sup>
1391
1392values(): V[]
1393
1394Obtains all values in this cache, listed from the most to the least recently accessed.
1395
1396**System capability**: SystemCapability.Utils.Lang
1397
1398**Return value**
1399
1400| Type     | Description                                                        |
1401| --------- | ------------------------------------------------------------ |
1402| V&nbsp;[] | All values in the cache, listed from the most to the least recently accessed.|
1403
1404**Example**
1405
1406  ```js
1407let pro = new util.LRUCache();
1408pro.put(2,10);
1409pro.put(2,"anhu");
1410pro.put("afaf","grfb");
1411let result = pro.values();
1412  ```
1413
1414
1415### keys<sup>9+</sup>
1416
1417keys(): K[]
1418
1419Obtains all keys in this cache, listed from the most to the least recently accessed.
1420
1421**System capability**: SystemCapability.Utils.Lang
1422
1423**Return value**
1424
1425| Type     | Description                                                        |
1426| --------- | ------------------------------------------------------------ |
1427| K&nbsp;[] | All keys in the cache, listed from the most to the least recently accessed.|
1428
1429**Example**
1430
1431  ```js
1432let pro = new util.LRUCache();
1433pro.put(2,10);
1434let result = pro.keys();
1435  ```
1436
1437
1438### remove<sup>9+</sup>
1439
1440remove(key: K): V | undefined
1441
1442Removes the specified key and its value from this cache.
1443
1444**System capability**: SystemCapability.Utils.Lang
1445
1446**Parameters**
1447
1448| Name| Type| Mandatory| Description          |
1449| ------ | ---- | ---- | -------------- |
1450| key    | K    | Yes  | Key to remove.|
1451
1452**Return value**
1453
1454| Type                    | Description                                                        |
1455| ------------------------ | ------------------------------------------------------------ |
1456| V&nbsp;\|&nbsp;undefined | Returns an **Optional** object containing the removed key-value pair if the key exists in the cache; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.|
1457
1458**Example**
1459
1460  ```js
1461let pro = new util.LRUCache();
1462pro.put(2,10);
1463let result = pro.remove(20);
1464  ```
1465
1466
1467### afterRemoval<sup>9+</sup>
1468
1469afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
1470
1471Performs subsequent operations after a value is removed.
1472
1473**System capability**: SystemCapability.Utils.Lang
1474
1475**Parameters**
1476
1477| Name  | Type   | Mandatory| Description                                                        |
1478| -------- | ------- | ---- | ------------------------------------------------------------ |
1479| isEvict  | boolean | Yes  | Whether the cache capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity.   |
1480| key      | K       | Yes  | Key removed.                                              |
1481| value    | V       | Yes  | Value removed.                                              |
1482| newValue | V       | Yes  | New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
1483
1484**Example**
1485
1486  ```js
1487let arr = [];
1488class ChildLruBuffer<K, V> extends util.LRUCache<K, V>
1489{
1490	constructor()
1491	{
1492		super();
1493	}
1494	afterRemoval(isEvict, key, value, newValue)
1495	{
1496		if (isEvict === false)
1497		{
1498			arr = [key, value, newValue];
1499		}
1500	}
1501}
1502let lru = new ChildLruBuffer();
1503lru.afterRemoval(false,10,30,null);
1504  ```
1505
1506
1507### contains<sup>9+</sup>
1508
1509contains(key: K): boolean
1510
1511Checks whether this cache contains the specified key.
1512
1513**System capability**: SystemCapability.Utils.Lang
1514
1515**Parameters**
1516
1517| Name| Type  | Mandatory| Description            |
1518| ------ | ------ | ---- | ---------------- |
1519| key    | K | Yes  | Key to check.|
1520
1521**Return value**
1522
1523| Type   | Description                                      |
1524| ------- | ------------------------------------------ |
1525| boolean | Returns **true** if the cache contains the specified key; returns **false** otherwise.|
1526
1527**Example**
1528
1529  ```js
1530let pro = new util.LRUCache();
1531pro.put(2,10);
1532let obj = {1:"key"};
1533let result = pro.contains(obj);
1534  ```
1535
1536
1537### createDefault<sup>9+</sup>
1538
1539createDefault(key: K): V
1540
1541Creates a value if the value of the specified key is not available.
1542
1543**System capability**: SystemCapability.Utils.Lang
1544
1545**Parameters**
1546
1547| Name| Type| Mandatory| Description          |
1548| ------ | ---- | ---- | -------------- |
1549| key    | K    | Yes  | Key of which the value is missing.|
1550
1551**Return value**
1552
1553| Type| Description              |
1554| ---- | ------------------ |
1555| V    | Value of the key.|
1556
1557**Example**
1558
1559  ```js
1560let pro = new util.LRUCache();
1561let result = pro.createDefault(50);
1562  ```
1563
1564
1565### entries<sup>9+</sup>
1566
1567entries(): IterableIterator&lt;[K,V]&gt;
1568
1569Obtains a new iterator object that contains all key-value pairs in this object.
1570
1571**System capability**: SystemCapability.Utils.Lang
1572
1573**Return value**
1574
1575| Type       | Description                |
1576| ----------- | -------------------- |
1577| [K,&nbsp;V] | Iterable array.|
1578
1579**Example**
1580
1581  ```js
1582let pro = new util.LRUCache();
1583pro.put(2,10);
1584let result = pro.entries();
1585  ```
1586
1587### [Symbol.iterator]<sup>9+</sup>
1588
1589[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
1590
1591Obtains a two-dimensional array in key-value pairs.
1592
1593**System capability**: SystemCapability.Utils.Lang
1594
1595**Return value**
1596
1597| Type       | Description                          |
1598| ----------- | ------------------------------ |
1599| [K,&nbsp;V] | Two-dimensional array in key-value pairs.|
1600
1601**Example**
1602
1603  ```js
1604let pro = new util.LRUCache();
1605pro.put(2,10);
1606let result = pro[Symbol.iterator]();
1607  ```
1608
1609## ScopeComparable<sup>8+</sup>
1610
1611The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable.
1612
1613**System capability**: SystemCapability.Utils.Lang
1614
1615### compareTo<sup>8+</sup>
1616
1617compareTo(other: ScopeComparable): boolean;
1618
1619Compares two values and returns a Boolean value.
1620
1621**System capability**: SystemCapability.Utils.Lang
1622
1623**Parameters**
1624
1625| Name| Type| Mandatory| Description          |
1626| ------ | ---- | ---- | -------------- |
1627| other  | [ScopeComparable](#scopecomparable8) | Yes | The other value to be compared with the current value.|
1628
1629**Return value**
1630
1631| Type| Description              |
1632| ---- | ------------------ |
1633| boolean | If the current value is greater than or equal to the input value, **true** is returned. Otherwise, **false** is returned.|
1634
1635**Example**
1636
1637Create a class to implement the **compareTo** method. The **Temperature** class is used as an example in the following sample code.
1638
1639```js
1640class Temperature{
1641    constructor(value){
1642       // If TS is used for development, add the following code:
1643       // private readonly _temp: Temperature;
1644       this._temp = value;
1645    }
1646    compareTo(value){
1647       return this._temp >= value.getTemp();
1648    }
1649    getTemp(){
1650       return this._temp;
1651    }
1652    toString(){
1653       return this._temp.toString();
1654    }
1655}
1656```
1657
1658## ScopeType<sup>8+</sup>
1659
1660Defines the type of values in a **Scope** object.
1661
1662**System capability**: SystemCapability.Utils.Lang
1663
1664| Type| Description|
1665| -------- | -------- |
1666| number | The value type is a number.|
1667| [ScopeComparable](#scopecomparable8) | The value type is ScopeComparable.|
1668
1669## ScopeHelper<sup>9+</sup>
1670
1671### constructor<sup>9+</sup>
1672
1673constructor(lowerObj: ScopeType, upperObj: ScopeType)
1674
1675A constructor used to create a **ScopeHelper** object with the specified upper and lower limits.
1676
1677**System capability**: SystemCapability.Utils.Lang
1678
1679**Parameters**
1680
1681| Name  | Type                    | Mandatory| Description                  |
1682| -------- | ------------------------ | ---- | ---------------------- |
1683| lowerObj | [ScopeType](#scopetype8) | Yes  | Lower limit of the **Scope** object.|
1684| upperObj | [ScopeType](#scopetype8) | Yes  | Upper limit of the **Scope** object.|
1685
1686**Example**
1687
1688  ```js
1689let tempLower = new Temperature(30);
1690let tempUpper = new Temperature(40);
1691let range = new util.ScopeHelper(tempLower, tempUpper);
1692  ```
1693
1694
1695### toString<sup>9+</sup>
1696
1697toString(): string
1698
1699Obtains a string representation that contains this **Scope**.
1700
1701**System capability**: SystemCapability.Utils.Lang
1702
1703**Return value**
1704
1705| Type  | Description                                  |
1706| ------ | -------------------------------------- |
1707| string | String representation containing the **Scope**.|
1708
1709**Example**
1710
1711  ```js
1712let tempLower = new Temperature(30);
1713let tempUpper = new Temperature(40);
1714let range = new util.ScopeHelper(tempLower, tempUpper);
1715let result = range.toString();
1716  ```
1717
1718
1719### intersect<sup>9+</sup>
1720
1721intersect(range: ScopeHelper): ScopeHelper
1722
1723Obtains the intersection of this **Scope** and the given **Scope**.
1724
1725**System capability**: SystemCapability.Utils.Lang
1726
1727**Parameters**
1728
1729| Name| Type                        | Mandatory| Description              |
1730| ------ | ---------------------------- | ---- | ------------------ |
1731| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
1732
1733**Return value**
1734
1735| Type                          | Description                          |
1736| ------------------------------ | ------------------------------ |
1737| [ScopeHelper9+](#scopehelper9) | Intersection of this **Scope** and the given **Scope**.|
1738
1739**Example**
1740
1741  ```js
1742let tempLower = new Temperature(30);
1743let tempUpper = new Temperature(40);
1744let range = new util.ScopeHelper(tempLower, tempUpper);
1745let tempMiDF = new Temperature(35);
1746let tempMidS = new Temperature(39);
1747let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
1748range.intersect(rangeFir);
1749  ```
1750
1751
1752### intersect<sup>9+</sup>
1753
1754intersect(lowerObj:ScopeType,upperObj:ScopeType):ScopeHelper
1755
1756Obtains the intersection of this **Scope** and the given lower and upper limits.
1757
1758**System capability**: SystemCapability.Utils.Lang
1759
1760**Parameters**
1761
1762| Name  | Type                    | Mandatory| Description            |
1763| -------- | ------------------------ | ---- | ---------------- |
1764| lowerObj | [ScopeType](#scopetype8) | Yes  | Lower limit.|
1765| upperObj | [ScopeType](#scopetype8) | Yes  | Upper limit.|
1766
1767**Return value**
1768
1769| Type                        | Description                                    |
1770| ---------------------------- | ---------------------------------------- |
1771| [ScopeHelper](#scopehelper9) | Intersection of this **Scope** and the given lower and upper limits.|
1772
1773**Example**
1774
1775  ```js
1776let tempLower = new Temperature(30);
1777let tempUpper = new Temperature(40);
1778let tempMiDF = new Temperature(35);
1779let tempMidS = new Temperature(39);
1780let range = new util.ScopeHelper(tempLower, tempUpper);
1781let result = range.intersect(tempMiDF, tempMidS);
1782  ```
1783
1784
1785### getUpper<sup>9+</sup>
1786
1787getUpper(): ScopeType
1788
1789Obtains the upper limit of this **Scope**.
1790
1791**System capability**: SystemCapability.Utils.Lang
1792
1793**Return value**
1794
1795| Type                    | Description                  |
1796| ------------------------ | ---------------------- |
1797| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
1798
1799**Example**
1800
1801  ```js
1802let tempLower = new Temperature(30);
1803let tempUpper = new Temperature(40);
1804let range = new util.ScopeHelper(tempLower, tempUpper);
1805let result = range.getUpper();
1806  ```
1807
1808
1809### getLower<sup>9+</sup>
1810
1811getLower(): ScopeType
1812
1813Obtains the lower limit of this **Scope**.
1814
1815**System capability**: SystemCapability.Utils.Lang
1816
1817**Return value**
1818
1819| Type                    | Description                  |
1820| ------------------------ | ---------------------- |
1821| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
1822
1823**Example**
1824
1825  ```js
1826let tempLower = new Temperature(30);
1827let tempUpper = new Temperature(40);
1828let range = new util.ScopeHelper(tempLower, tempUpper);
1829let result = range.getLower();
1830  ```
1831
1832
1833### expand<sup>9+</sup>
1834
1835expand(lowerObj: ScopeType,upperObj: ScopeType): ScopeHelper
1836
1837Obtains the union set of this **Scope** and the given lower and upper limits.
1838
1839**System capability**: SystemCapability.Utils.Lang
1840
1841**Parameters**
1842
1843| Name  | Type                    | Mandatory| Description            |
1844| -------- | ------------------------ | ---- | ---------------- |
1845| lowerObj | [ScopeType](#scopetype8) | Yes  | Lower limit.|
1846| upperObj | [ScopeType](#scopetype8) | Yes  | Upper limit.|
1847
1848**Return value**
1849
1850| Type                        | Description                                |
1851| ---------------------------- | ------------------------------------ |
1852| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given lower and upper limits.|
1853
1854**Example**
1855
1856  ```js
1857let tempLower = new Temperature(30);
1858let tempUpper = new Temperature(40);
1859let tempMiDF = new Temperature(35);
1860let tempMidS = new Temperature(39);
1861let range = new util.ScopeHelper(tempLower, tempUpper);
1862let result = range.expand(tempMiDF, tempMidS);
1863  ```
1864
1865
1866### expand<sup>9+</sup>
1867
1868expand(range: ScopeHelper): ScopeHelper
1869
1870Obtains the union set of this **Scope** and the given **Scope**.
1871
1872**System capability**: SystemCapability.Utils.Lang
1873
1874**Parameters**
1875
1876| Name| Type                        | Mandatory| Description              |
1877| ------ | ---------------------------- | ---- | ------------------ |
1878| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
1879
1880**Return value**
1881
1882| Type                        | Description                              |
1883| ---------------------------- | ---------------------------------- |
1884| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given **Scope**.|
1885
1886**Example**
1887
1888  ```js
1889let tempLower = new Temperature(30);
1890let tempUpper = new Temperature(40);
1891let tempMiDF = new Temperature(35);
1892let tempMidS = new Temperature(39);
1893let range = new util.ScopeHelper(tempLower, tempUpper);
1894let rangeFir = new util.ScopeHelper(tempMiDF, tempMidS);
1895let result = range.expand(rangeFir);
1896  ```
1897
1898
1899### expand<sup>9+</sup>
1900
1901expand(value: ScopeType): ScopeHelper
1902
1903Obtains the union set of this **Scope** and the given value.
1904
1905**System capability**: SystemCapability.Utils.Lang
1906
1907**Parameters**
1908
1909| Name| Type                    | Mandatory| Description            |
1910| ------ | ------------------------ | ---- | ---------------- |
1911| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|
1912
1913**Return value**
1914
1915| Type                        | Description                            |
1916| ---------------------------- | -------------------------------- |
1917| [ScopeHelper](#scopehelper9) | Union set of this **Scope** and the given value.|
1918
1919**Example**
1920
1921  ```js
1922let tempLower = new Temperature(30);
1923let tempUpper = new Temperature(40);
1924let tempMiDF = new Temperature(35);
1925let range = new util.ScopeHelper(tempLower, tempUpper);
1926let result = range.expand(tempMiDF);
1927  ```
1928
1929
1930### contains<sup>9+</sup>
1931
1932contains(value: ScopeType): boolean
1933
1934Checks whether a value is within this **Scope**.
1935
1936**System capability**: SystemCapability.Utils.Lang
1937
1938**Parameters**
1939
1940| Name| Type                    | Mandatory| Description            |
1941| ------ | ------------------------ | ---- | ---------------- |
1942| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|
1943
1944**Return value**
1945
1946| Type   | Description                                               |
1947| ------- | --------------------------------------------------- |
1948| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
1949
1950**Example**
1951
1952  ```js
1953let tempLower = new Temperature(30);
1954let tempUpper = new Temperature(40);
1955let tempMiDF = new Temperature(35);
1956let range = new util.ScopeHelper(tempLower, tempUpper);
1957range.contains(tempMiDF);
1958  ```
1959
1960
1961### contains<sup>9+</sup>
1962
1963contains(range: ScopeHelper): boolean
1964
1965Checks whether a range is within this **Scope**.
1966
1967**System capability**: SystemCapability.Utils.Lang
1968
1969**Parameters**
1970
1971| Name| Type                        | Mandatory| Description              |
1972| ------ | ---------------------------- | ---- | ------------------ |
1973| range  | [ScopeHelper](#scopehelper9) | Yes  | **Scope** specified.|
1974
1975**Return value**
1976
1977| Type   | Description                                                 |
1978| ------- | ----------------------------------------------------- |
1979| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
1980
1981**Example**
1982
1983  ```js
1984let tempLower = new Temperature(30);
1985let tempUpper = new Temperature(40);
1986let range = new util.ScopeHelper(tempLower, tempUpper);
1987let tempLess = new Temperature(20);
1988let tempMore = new Temperature(45);
1989let rangeSec = new util.ScopeHelper(tempLess, tempMore);
1990let result = range.contains(rangeSec);
1991  ```
1992
1993
1994### clamp<sup>9+</sup>
1995
1996clamp(value: ScopeType): ScopeType
1997
1998Limits a value to this **Scope**.
1999
2000**System capability**: SystemCapability.Utils.Lang
2001
2002**Parameters**
2003
2004| Name| Type                    | Mandatory| Description          |
2005| ------ | ------------------------ | ---- | -------------- |
2006| value  | [ScopeType](#scopetype8) | Yes  | Value specified.|
2007
2008**Return value**
2009
2010| Type                    | Description                                                        |
2011| ------------------------ | ------------------------------------------------------------ |
2012| [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**.|
2013
2014**Example**
2015
2016  ```js
2017let tempLower = new Temperature(30);
2018let tempUpper = new Temperature(40);
2019let tempMiDF = new Temperature(35);
2020let range = new util.ScopeHelper(tempLower, tempUpper);
2021let result = range.clamp(tempMiDF);
2022  ```
2023
2024## Base64Helper<sup>9+</sup>
2025
2026### constructor<sup>9+</sup>
2027
2028constructor()
2029
2030A constructor used to create a **Base64Helper** instance.
2031
2032**System capability**: SystemCapability.Utils.Lang
2033
2034**Example**
2035
2036  ```js
2037let base64 = new  util.Base64Helper();
2038  ```
2039
2040### encodeSync<sup>9+</sup>
2041
2042encodeSync(src: Uint8Array): Uint8Array
2043
2044Encodes the input content.
2045
2046**System capability**: SystemCapability.Utils.Lang
2047
2048**Parameters**
2049
2050| Name| Type      | Mandatory| Description               |
2051| ------ | ---------- | ---- | ------------------- |
2052| src    | Uint8Array | Yes  | Uint8Array to encode.|
2053
2054**Return value**
2055
2056| Type      | Description                         |
2057| ---------- | ----------------------------- |
2058| Uint8Array | Uint8Array encoded.|
2059
2060**Example**
2061
2062  ```js
2063let that = new util.Base64Helper();
2064let array = new Uint8Array([115,49,51]);
2065let result = that.encodeSync(array);
2066  ```
2067
2068
2069### encodeToStringSync<sup>9+</sup>
2070
2071encodeToStringSync(src: Uint8Array): string
2072
2073Encodes the input content.
2074
2075**System capability**: SystemCapability.Utils.Lang
2076
2077**Parameters**
2078
2079| Name| Type      | Mandatory| Description               |
2080| ------ | ---------- | ---- | ------------------- |
2081| src    | Uint8Array | Yes  | Uint8Array to encode.|
2082
2083**Return value**
2084
2085| Type  | Description                |
2086| ------ | -------------------- |
2087| string | String encoded from the Uint8Array.|
2088
2089**Example**
2090
2091  ```js
2092let that = new util.Base64Helper();
2093let array = new Uint8Array([115,49,51]);
2094let result = that.encodeToStringSync(array);
2095  ```
2096
2097
2098### decodeSync<sup>9+</sup>
2099
2100decodeSync(src: Uint8Array | string): Uint8Array
2101
2102Decodes the input content.
2103
2104**System capability**: SystemCapability.Utils.Lang
2105
2106**Parameters**
2107
2108| Name| Type                          | Mandatory| Description                         |
2109| ------ | ------------------------------ | ---- | ----------------------------- |
2110| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode.|
2111
2112**Return value**
2113
2114| Type      | Description                         |
2115| ---------- | ----------------------------- |
2116| Uint8Array | Uint8Array decoded.|
2117
2118**Example**
2119
2120  ```js
2121let that = new util.Base64Helper();
2122let buff = 'czEz';
2123let result = that.decodeSync(buff);
2124  ```
2125
2126
2127### encode<sup>9+</sup>
2128
2129encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
2130
2131Encodes the input content asynchronously.
2132
2133**System capability**: SystemCapability.Utils.Lang
2134
2135**Parameters**
2136
2137| Name| Type      | Mandatory| Description                   |
2138| ------ | ---------- | ---- | ----------------------- |
2139| src    | Uint8Array | Yes  | Uint8Array to encode asynchronously.|
2140
2141**Return value**
2142
2143| Type                     | Description                             |
2144| ------------------------- | --------------------------------- |
2145| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
2146
2147**Example**
2148
2149  ```js
2150let that = new util.Base64Helper();
2151let array = new Uint8Array([115,49,51]);
2152let rarray = new Uint8Array([99,122,69,122]);
2153that.encode(array).then(val=>{
2154    for (var i = 0; i < rarray.length; i++) {
2155        console.log(val[i].toString())
2156    }
2157})
2158  ```
2159
2160
2161### encodeToString<sup>9+</sup>
2162
2163encodeToString(src: Uint8Array): Promise&lt;string&gt;
2164
2165Encodes the input content asynchronously.
2166
2167**System capability**: SystemCapability.Utils.Lang
2168
2169**Parameters**
2170
2171| Name| Type      | Mandatory| Description                   |
2172| ------ | ---------- | ---- | ----------------------- |
2173| src    | Uint8Array | Yes  | Uint8Array to encode asynchronously.|
2174
2175**Return value**
2176
2177| Type                 | Description                    |
2178| --------------------- | ------------------------ |
2179| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
2180
2181**Example**
2182
2183  ```js
2184let that = new util.Base64Helper();
2185let array = new Uint8Array([115,49,51]);
2186that.encodeToString(array).then(val=>{
2187    console.log(val)
2188})
2189  ```
2190
2191
2192### decode<sup>9+</sup>
2193
2194decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
2195
2196Decodes the input content asynchronously.
2197
2198**System capability**: SystemCapability.Utils.Lang
2199
2200**Parameters**
2201
2202| Name| Type                          | Mandatory| Description                             |
2203| ------ | ------------------------------ | ---- | --------------------------------- |
2204| src    | Uint8Array&nbsp;\|&nbsp;string | Yes  | Uint8Array or string to decode asynchronously.|
2205
2206**Return value**
2207
2208| Type                     | Description                             |
2209| ------------------------- | --------------------------------- |
2210| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
2211
2212**Example**
2213
2214  ```js
2215let that = new util.Base64Helper();
2216let array = new Uint8Array([99,122,69,122]);
2217let rarray = new Uint8Array([115,49,51]);
2218that.decode(array).then(val=>{
2219    for (var i = 0; i < rarray.length; i++) {
2220        console.log(val[i].toString())
2221    }
2222})
2223  ```
2224
2225## types<sup>8+</sup>
2226
2227### constructor<sup>8+</sup>
2228
2229constructor()
2230
2231A constructor used to create a **Types** object.
2232
2233**System capability**: SystemCapability.Utils.Lang
2234
2235**Example**
2236
2237  ```js
2238  let type = new util.types();
2239  ```
2240
2241
2242### isAnyArrayBuffer<sup>8+</sup>
2243
2244isAnyArrayBuffer(value: Object): boolean
2245
2246Checks whether the input value is of the **ArrayBuffer** type.
2247
2248**System capability**: SystemCapability.Utils.Lang
2249
2250**Parameters**
2251
2252| Name| Type| Mandatory| Description|
2253| -------- | -------- | -------- | -------- |
2254| value | Object | Yes| Object to check.|
2255
2256**Return value**
2257
2258| Type| Description|
2259| -------- | -------- |
2260| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
2261
2262**Example**
2263
2264  ```js
2265  let that = new util.types();
2266  let result = that.isAnyArrayBuffer(new ArrayBuffer(0));
2267  ```
2268
2269
2270### isArrayBufferView<sup>8+</sup>
2271
2272isArrayBufferView(value: Object): boolean
2273
2274Checks whether the input value is of the **ArrayBufferView** type.
2275
2276**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
2277
2278**System capability**: SystemCapability.Utils.Lang
2279
2280**Parameters**
2281
2282| Name| Type| Mandatory| Description|
2283| -------- | -------- | -------- | -------- |
2284| value | Object | Yes| Object to check.|
2285
2286**Return value**
2287
2288| Type| Description|
2289| -------- | -------- |
2290| boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.|
2291
2292**Example**
2293
2294  ```js
2295  let that = new util.types();
2296  let result = that.isArrayBufferView(new Int8Array([]));
2297  ```
2298
2299
2300### isArgumentsObject<sup>8+</sup>
2301
2302isArgumentsObject(value: Object): boolean
2303
2304Checks whether the input value is of the **arguments** type.
2305
2306**System capability**: SystemCapability.Utils.Lang
2307
2308**Parameters**
2309
2310| Name| Type| Mandatory| Description|
2311| -------- | -------- | -------- | -------- |
2312| value | Object | Yes| Object to check.|
2313
2314**Return value**
2315
2316| Type| Description|
2317| -------- | -------- |
2318| boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.|
2319
2320**Example**
2321
2322  ```js
2323  let that = new util.types();
2324  function foo() {
2325      var result = that.isArgumentsObject(arguments);
2326  }
2327  let f = foo();
2328  ```
2329
2330
2331### isArrayBuffer<sup>8+</sup>
2332
2333isArrayBuffer(value: Object): boolean
2334
2335Checks whether the input value is of the **ArrayBuffer** type.
2336
2337**System capability**: SystemCapability.Utils.Lang
2338
2339**Parameters**
2340
2341| Name| Type| Mandatory| Description|
2342| -------- | -------- | -------- | -------- |
2343| value | Object | Yes| Object to check.|
2344
2345**Return value**
2346
2347| Type| Description|
2348| -------- | -------- |
2349| boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.|
2350
2351**Example**
2352
2353  ```js
2354  let that = new util.types();
2355  let result = that.isArrayBuffer(new ArrayBuffer(0));
2356  ```
2357
2358
2359### isAsyncFunction<sup>8+</sup>
2360
2361isAsyncFunction(value: Object): boolean
2362
2363Checks whether the input value is an asynchronous function.
2364
2365**System capability**: SystemCapability.Utils.Lang
2366
2367**Parameters**
2368
2369| Name| Type| Mandatory| Description|
2370| -------- | -------- | -------- | -------- |
2371| value | Object | Yes| Object to check.|
2372
2373**Return value**
2374
2375| Type| Description|
2376| -------- | -------- |
2377| boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.|
2378
2379**Example**
2380
2381  ```js
2382  let that = new util.types();
2383  let result = that.isAsyncFunction(async function foo() {});
2384  ```
2385
2386
2387### isBooleanObject<sup>8+</sup>
2388
2389isBooleanObject(value: Object): boolean
2390
2391Checks whether the input value is of the **Boolean** type.
2392
2393**System capability**: SystemCapability.Utils.Lang
2394
2395**Parameters**
2396
2397| Name| Type| Mandatory| Description|
2398| -------- | -------- | -------- | -------- |
2399| value | Object | Yes| Object to check.|
2400
2401**Return value**
2402
2403| Type| Description|
2404| -------- | -------- |
2405| boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.|
2406
2407**Example**
2408
2409  ```js
2410  let that = new util.types();
2411  let result = that.isBooleanObject(new Boolean(true));
2412  ```
2413
2414
2415### isBoxedPrimitive<sup>8+</sup>
2416
2417isBoxedPrimitive(value: Object): boolean
2418
2419Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type.
2420
2421**System capability**: SystemCapability.Utils.Lang
2422
2423**Parameters**
2424
2425| Name| Type| Mandatory| Description|
2426| -------- | -------- | -------- | -------- |
2427| value | Object | Yes| Object to check.|
2428
2429**Return value**
2430
2431| Type| Description|
2432| -------- | -------- |
2433| boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.|
2434
2435**Example**
2436
2437  ```js
2438  let that = new util.types();
2439  let result = that.isBoxedPrimitive(new Boolean(false));
2440  ```
2441
2442
2443### isDataView<sup>8+</sup>
2444
2445isDataView(value: Object): boolean
2446
2447Checks whether the input value is of the **DataView** type.
2448
2449**System capability**: SystemCapability.Utils.Lang
2450
2451**Parameters**
2452
2453| Name| Type| Mandatory| Description|
2454| -------- | -------- | -------- | -------- |
2455| value | Object | Yes| Object to check.|
2456
2457**Return value**
2458
2459| Type| Description|
2460| -------- | -------- |
2461| boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.|
2462
2463**Example**
2464
2465  ```js
2466  let that = new util.types();
2467  const ab = new ArrayBuffer(20);
2468  let result = that.isDataView(new DataView(ab));
2469  ```
2470
2471
2472### isDate<sup>8+</sup>
2473
2474isDate(value: Object): boolean
2475
2476Checks whether the input value is of the **Date** type.
2477
2478**System capability**: SystemCapability.Utils.Lang
2479
2480**Parameters**
2481
2482| Name| Type| Mandatory| Description|
2483| -------- | -------- | -------- | -------- |
2484| value | Object | Yes| Object to check.|
2485
2486**Return value**
2487
2488| Type| Description|
2489| -------- | -------- |
2490| boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.|
2491
2492**Example**
2493
2494  ```js
2495  let that = new util.types();
2496  let result = that.isDate(new Date());
2497  ```
2498
2499
2500### isExternal<sup>8+</sup>
2501
2502isExternal(value: Object): boolean
2503
2504Checks whether the input value is of the **native external** type.
2505
2506**System capability**: SystemCapability.Utils.Lang
2507
2508**Parameters**
2509
2510| Name| Type| Mandatory| Description|
2511| -------- | -------- | -------- | -------- |
2512| value | Object | Yes| Object to check.|
2513
2514**Return value**
2515
2516| Type| Description|
2517| -------- | -------- |
2518| boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.|
2519
2520**Example**
2521
2522  ```js
2523  let that = new util.types();
2524  let result = that.isExternal(true);
2525  ```
2526
2527
2528### isFloat32Array<sup>8+</sup>
2529
2530isFloat32Array(value: Object): boolean
2531
2532Checks whether the input value is of the **Float32Array** type.
2533
2534**System capability**: SystemCapability.Utils.Lang
2535
2536**Parameters**
2537
2538| Name| Type| Mandatory| Description|
2539| -------- | -------- | -------- | -------- |
2540| value | Object | Yes| Object to check.|
2541
2542**Return value**
2543
2544| Type| Description|
2545| -------- | -------- |
2546| boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.|
2547
2548**Example**
2549
2550  ```js
2551  let that = new util.types();
2552  let result = that.isFloat32Array(new Float32Array());
2553  ```
2554
2555
2556### isFloat64Array<sup>8+</sup>
2557
2558isFloat64Array(value: Object): boolean
2559
2560Checks whether the input value is of the **Float64Array** type.
2561
2562**System capability**: SystemCapability.Utils.Lang
2563
2564**Parameters**
2565
2566| Name| Type| Mandatory| Description|
2567| -------- | -------- | -------- | -------- |
2568| value | Object | Yes| Object to check.|
2569
2570**Return value**
2571
2572| Type| Description|
2573| -------- | -------- |
2574| boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.|
2575
2576**Example**
2577
2578  ```js
2579  let that = new util.types();
2580  let result = that.isFloat64Array(new Float64Array());
2581  ```
2582
2583
2584### isGeneratorFunction<sup>8+</sup>
2585
2586isGeneratorFunction(value: Object): boolean
2587
2588Checks whether the input value is a generator function.
2589
2590**System capability**: SystemCapability.Utils.Lang
2591
2592**Parameters**
2593
2594| Name| Type| Mandatory| Description|
2595| -------- | -------- | -------- | -------- |
2596| value | Object | Yes| Object to check.|
2597
2598**Return value**
2599
2600| Type| Description|
2601| -------- | -------- |
2602| boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.|
2603
2604**Example**
2605
2606  ```js
2607  let that = new util.types();
2608  let result = that.isGeneratorFunction(function* foo() {});
2609  ```
2610
2611
2612### isGeneratorObject<sup>8+</sup>
2613
2614isGeneratorObject(value: Object): boolean
2615
2616Checks whether the input value is a generator object.
2617
2618**System capability**: SystemCapability.Utils.Lang
2619
2620**Parameters**
2621
2622| Name| Type| Mandatory| Description|
2623| -------- | -------- | -------- | -------- |
2624| value | Object | Yes| Object to check.|
2625
2626**Return value**
2627
2628| Type| Description|
2629| -------- | -------- |
2630| boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.|
2631
2632**Example**
2633
2634  ```js
2635  let that = new util.types();
2636  function* foo() {}
2637  const generator = foo();
2638  let result = that.isGeneratorObject(generator);
2639  ```
2640
2641
2642### isInt8Array<sup>8+</sup>
2643
2644isInt8Array(value: Object): boolean
2645
2646Checks whether the input value is of the **Int8Array** type.
2647
2648**System capability**: SystemCapability.Utils.Lang
2649
2650**Parameters**
2651
2652| Name| Type| Mandatory| Description|
2653| -------- | -------- | -------- | -------- |
2654| value | Object | Yes| Object to check.|
2655
2656**Return value**
2657
2658| Type| Description|
2659| -------- | -------- |
2660| boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.|
2661
2662**Example**
2663
2664  ```js
2665  let that = new util.types();
2666  let result = that.isInt8Array(new Int8Array([]));
2667  ```
2668
2669
2670### isInt16Array<sup>8+</sup>
2671
2672isInt16Array(value: Object): boolean
2673
2674Checks whether the input value is of the **Int16Array** type.
2675
2676**System capability**: SystemCapability.Utils.Lang
2677
2678**Parameters**
2679
2680| Name| Type| Mandatory| Description|
2681| -------- | -------- | -------- | -------- |
2682| value | Object | Yes| Object to check.|
2683
2684**Return value**
2685
2686| Type| Description|
2687| -------- | -------- |
2688| boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.|
2689
2690**Example**
2691
2692  ```js
2693  let that = new util.types();
2694  let result = that.isInt16Array(new Int16Array([]));
2695  ```
2696
2697
2698### isInt32Array<sup>8+</sup>
2699
2700isInt32Array(value: Object): boolean
2701
2702Checks whether the input value is of the **Int32Array** type.
2703
2704**System capability**: SystemCapability.Utils.Lang
2705
2706**Parameters**
2707
2708| Name| Type| Mandatory| Description|
2709| -------- | -------- | -------- | -------- |
2710| value | Object | Yes| Object to check.|
2711
2712**Return value**
2713
2714| Type| Description|
2715| -------- | -------- |
2716| boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.|
2717
2718**Example**
2719
2720  ```js
2721  let that = new util.types();
2722  let result = that.isInt32Array(new Int32Array([]));
2723  ```
2724
2725
2726### isMap<sup>8+</sup>
2727
2728isMap(value: Object): boolean
2729
2730Checks whether the input value is of the **Map** type.
2731
2732**System capability**: SystemCapability.Utils.Lang
2733
2734**Parameters**
2735
2736| Name| Type| Mandatory| Description|
2737| -------- | -------- | -------- | -------- |
2738| value | Object | Yes| Object to check.|
2739
2740**Return value**
2741
2742| Type| Description|
2743| -------- | -------- |
2744| boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.|
2745
2746**Example**
2747
2748  ```js
2749  let that = new util.types();
2750  let result = that.isMap(new Map());
2751  ```
2752
2753
2754### isMapIterator<sup>8+</sup>
2755
2756isMapIterator(value: Object): boolean
2757
2758Checks whether the input value is of the **MapIterator** type.
2759
2760**System capability**: SystemCapability.Utils.Lang
2761
2762**Parameters**
2763
2764
2765| Name| Type| Mandatory| Description|
2766| -------- | -------- | -------- | -------- |
2767| value | Object | Yes| Object to check.|
2768
2769**Return value**
2770
2771| Type| Description|
2772| -------- | -------- |
2773| boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.|
2774
2775**Example**
2776
2777  ```js
2778  let that = new util.types();
2779  const map = new Map();
2780  let result = that.isMapIterator(map.keys());
2781  ```
2782
2783
2784### isNativeError<sup>8+</sup>
2785
2786isNativeError(value: Object): boolean
2787
2788Checks whether the input value is of the **Error** type.
2789
2790**System capability**: SystemCapability.Utils.Lang
2791
2792**Parameters**
2793
2794| Name| Type| Mandatory| Description|
2795| -------- | -------- | -------- | -------- |
2796| value | Object | Yes| Object to check.|
2797
2798**Return value**
2799
2800| Type| Description|
2801| -------- | -------- |
2802| boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.|
2803
2804**Example**
2805
2806  ```js
2807  let that = new util.types();
2808  let result = that.isNativeError(new TypeError());
2809  ```
2810
2811
2812### isNumberObject<sup>8+</sup>
2813
2814isNumberObject(value: Object): boolean
2815
2816Checks whether the input value is a number object.
2817
2818**System capability**: SystemCapability.Utils.Lang
2819
2820**Parameters**
2821
2822| Name| Type| Mandatory| Description|
2823| -------- | -------- | -------- | -------- |
2824| value | Object | Yes| Object to check.|
2825
2826**Return value**
2827
2828| Type| Description|
2829| -------- | -------- |
2830| boolean | Returns **true** if the input value is a number object; returns **false** otherwise.|
2831
2832**Example**
2833
2834  ```js
2835  let that = new util.types();
2836  let result = that.isNumberObject(new Number(0));
2837  ```
2838
2839
2840### isPromise<sup>8+</sup>
2841
2842isPromise(value: Object): boolean
2843
2844Checks whether the input value is a promise.
2845
2846**System capability**: SystemCapability.Utils.Lang
2847
2848**Parameters**
2849
2850| Name| Type| Mandatory| Description|
2851| -------- | -------- | -------- | -------- |
2852| value | Object | Yes| Object to check.|
2853
2854**Return value**
2855
2856| Type| Description|
2857| -------- | -------- |
2858| boolean | Returns **true** if the input value is a promise; returns **false** otherwise.|
2859
2860**Example**
2861
2862  ```js
2863  let that = new util.types();
2864  let result = that.isPromise(Promise.resolve(1));
2865  ```
2866
2867
2868### isProxy<sup>8+</sup>
2869
2870isProxy(value: Object): boolean
2871
2872Checks whether the input value is a proxy.
2873
2874**System capability**: SystemCapability.Utils.Lang
2875
2876**Parameters**
2877
2878| Name| Type| Mandatory| Description|
2879| -------- | -------- | -------- | -------- |
2880| value | Object | Yes| Object to check.|
2881
2882**Return value**
2883
2884| Type| Description|
2885| -------- | -------- |
2886| boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.|
2887
2888**Example**
2889
2890  ```js
2891  let that = new util.types();
2892  const target = {};
2893  const proxy = new Proxy(target, {});
2894  let result = that.isProxy(proxy);
2895  ```
2896
2897
2898### isRegExp<sup>8+</sup>
2899
2900isRegExp(value: Object): boolean
2901
2902Checks whether the input value is of the **RegExp** type.
2903
2904**System capability**: SystemCapability.Utils.Lang
2905
2906**Parameters**
2907
2908| Name| Type| Mandatory| Description|
2909| -------- | -------- | -------- | -------- |
2910| value | Object | Yes| Object to check.|
2911
2912**Return value**
2913
2914| Type| Description|
2915| -------- | -------- |
2916| boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.|
2917
2918**Example**
2919
2920  ```js
2921  let that = new util.types();
2922  let result = that.isRegExp(new RegExp('abc'));
2923  ```
2924
2925
2926### isSet<sup>8+</sup>
2927
2928isSet(value: Object): boolean
2929
2930Checks whether the input value is of the **Set** type.
2931
2932**System capability**: SystemCapability.Utils.Lang
2933
2934**Parameters**
2935
2936| Name| Type| Mandatory| Description|
2937| -------- | -------- | -------- | -------- |
2938| value | Object | Yes| Object to check.|
2939
2940**Return value**
2941
2942| Type| Description|
2943| -------- | -------- |
2944| boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.|
2945
2946**Example**
2947
2948  ```js
2949  let that = new util.types();
2950  let result = that.isSet(new Set());
2951  ```
2952
2953
2954### isSetIterator<sup>8+</sup>
2955
2956isSetIterator(value: Object): boolean
2957
2958Checks whether the input value is of the **SetIterator** type.
2959
2960**System capability**: SystemCapability.Utils.Lang
2961
2962**Parameters**
2963
2964| Name| Type| Mandatory| Description|
2965| -------- | -------- | -------- | -------- |
2966| value | Object | Yes| Object to check.|
2967
2968**Return value**
2969
2970| Type| Description|
2971| -------- | -------- |
2972| boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.|
2973
2974**Example**
2975
2976  ```js
2977  let that = new util.types();
2978  const set = new Set();
2979  let result = that.isSetIterator(set.keys());
2980  ```
2981
2982
2983### isStringObject<sup>8+</sup>
2984
2985isStringObject(value: Object): boolean
2986
2987Checks whether the input value is a string object.
2988
2989**System capability**: SystemCapability.Utils.Lang
2990
2991**Parameters**
2992
2993| Name| Type| Mandatory| Description|
2994| -------- | -------- | -------- | -------- |
2995| value | Object | Yes| Object to check.|
2996
2997**Return value**
2998
2999| Type| Description|
3000| -------- | -------- |
3001| boolean | Returns **true** if the input value is a string object; returns **false** otherwise.|
3002
3003**Example**
3004
3005  ```js
3006  let that = new util.types();
3007  let result = that.isStringObject(new String('foo'));
3008  ```
3009
3010
3011### isSymbolObjec<sup>8+</sup>
3012
3013isSymbolObject(value: Object): boolean
3014
3015Checks whether the input value is a symbol object.
3016
3017**System capability**: SystemCapability.Utils.Lang
3018
3019**Parameters**
3020
3021| Name| Type| Mandatory| Description|
3022| -------- | -------- | -------- | -------- |
3023| value | Object | Yes| Object to check.|
3024
3025**Return value**
3026
3027| Type| Description|
3028| -------- | -------- |
3029| boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.|
3030
3031**Example**
3032
3033  ```js
3034  let that = new util.types();
3035  const symbols = Symbol('foo');
3036  let result = that.isSymbolObject(Object(symbols));
3037  ```
3038
3039
3040### isTypedArray<sup>8+</sup>
3041
3042isTypedArray(value: Object): boolean
3043
3044Checks whether the input value is of the **TypedArray** type.
3045
3046**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**.
3047
3048**System capability**: SystemCapability.Utils.Lang
3049
3050**Parameters**
3051
3052| Name| Type| Mandatory| Description|
3053| -------- | -------- | -------- | -------- |
3054| value | Object | Yes| Object to check.|
3055
3056**Return value**
3057
3058| Type| Description|
3059| -------- | -------- |
3060| boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.|
3061
3062**Example**
3063
3064  ```js
3065  let that = new util.types();
3066  let result = that.isTypedArray(new Float64Array([]));
3067  ```
3068
3069
3070### isUint8Array<sup>8+</sup>
3071
3072isUint8Array(value: Object): boolean
3073
3074Checks whether the input value is of the **Uint8Array** type.
3075
3076**System capability**: SystemCapability.Utils.Lang
3077
3078**Parameters**
3079
3080| Name| Type| Mandatory| Description|
3081| -------- | -------- | -------- | -------- |
3082| value | Object | Yes| Object to check.|
3083
3084**Return value**
3085
3086| Type| Description|
3087| -------- | -------- |
3088| boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.|
3089
3090**Example**
3091
3092  ```js
3093  let that = new util.types();
3094  let result = that.isUint8Array(new Uint8Array([]));
3095  ```
3096
3097
3098### isUint8ClampedArray<sup>8+</sup>
3099
3100isUint8ClampedArray(value: Object): boolean
3101
3102Checks whether the input value is of the **Uint8ClampedArray** type.
3103
3104**System capability**: SystemCapability.Utils.Lang
3105
3106**Parameters**
3107
3108| Name| Type| Mandatory| Description|
3109| -------- | -------- | -------- | -------- |
3110| value | Object | Yes| Object to check.|
3111
3112**Return value**
3113
3114| Type| Description|
3115| -------- | -------- |
3116| boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.|
3117
3118**Example**
3119
3120  ```js
3121  let that = new util.types();
3122  let result = that.isUint8ClampedArray(new Uint8ClampedArray([]));
3123  ```
3124
3125
3126### isUint16Array<sup>8+</sup>
3127
3128isUint16Array(value: Object): boolean
3129
3130Checks whether the input value is of the **Uint16Array** type.
3131
3132**System capability**: SystemCapability.Utils.Lang
3133
3134**Parameters**
3135
3136| Name| Type| Mandatory| Description|
3137| -------- | -------- | -------- | -------- |
3138| value | Object | Yes| Object to check.|
3139
3140**Return value**
3141
3142| Type| Description|
3143| -------- | -------- |
3144| boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.|
3145
3146**Example**
3147
3148  ```js
3149  let that = new util.types();
3150  let result = that.isUint16Array(new Uint16Array([]));
3151  ```
3152
3153
3154### isUint32Array<sup>8+</sup>
3155
3156isUint32Array(value: Object): boolean
3157
3158Checks whether the input value is of the **Uint32Array** type.
3159
3160**System capability**: SystemCapability.Utils.Lang
3161
3162**Parameters**
3163
3164| Name| Type| Mandatory| Description|
3165| -------- | -------- | -------- | -------- |
3166| value | Object | Yes| Object to check.|
3167
3168**Return value**
3169
3170| Type| Description|
3171| -------- | -------- |
3172| boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.|
3173
3174**Example**
3175
3176  ```js
3177  let that = new util.types();
3178  let result = that.isUint32Array(new Uint32Array([]));
3179  ```
3180
3181
3182### isWeakMap<sup>8+</sup>
3183
3184isWeakMap(value: Object): boolean
3185
3186Checks whether the input value is of the **WeakMap** type.
3187
3188**System capability**: SystemCapability.Utils.Lang
3189
3190**Parameters**
3191
3192| Name| Type| Mandatory| Description|
3193| -------- | -------- | -------- | -------- |
3194| value | Object | Yes| Object to check.|
3195
3196**Return value**
3197
3198| Type| Description|
3199| -------- | -------- |
3200| boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.|
3201
3202**Example**
3203
3204  ```js
3205  let that = new util.types();
3206  let result = that.isWeakMap(new WeakMap());
3207  ```
3208
3209
3210### isWeakSet<sup>8+</sup>
3211
3212isWeakSet(value: Object): boolean
3213
3214Checks whether the input value is of the **WeakSet** type.
3215
3216**System capability**: SystemCapability.Utils.Lang
3217
3218**Parameters**
3219
3220| Name| Type| Mandatory| Description|
3221| -------- | -------- | -------- | -------- |
3222| value | Object | Yes| Object to check.|
3223
3224**Return value**
3225
3226| Type| Description|
3227| -------- | -------- |
3228| boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.|
3229
3230**Example**
3231
3232  ```js
3233  let that = new util.types();
3234  let result = that.isWeakSet(new WeakSet());
3235  ```
3236
3237
3238### isBigInt64Array<sup>8+</sup>
3239
3240isBigInt64Array(value: Object): boolean
3241
3242Checks whether the input value is of the **BigInt64Array** type.
3243
3244**System capability**: SystemCapability.Utils.Lang
3245
3246**Parameters**
3247
3248| Name| Type| Mandatory| Description|
3249| -------- | -------- | -------- | -------- |
3250| value | Object | Yes| Object to check.|
3251
3252**Return value**
3253
3254| Type| Description|
3255| -------- | -------- |
3256| boolean | Returns **true** if the input value is of the **BigInt64Array** type; returns **false** otherwise.|
3257
3258**Example**
3259
3260  ```js
3261  let that = new util.types();
3262  let result = that.isBigInt64Array(new BigInt64Array([]));
3263  ```
3264
3265
3266### isBigUint64Array<sup>8+</sup>
3267
3268isBigUint64Array(value: Object): boolean
3269
3270Checks whether the input value is of the **BigUint64Array** type.
3271
3272**System capability**: SystemCapability.Utils.Lang
3273
3274**Parameters**
3275
3276| Name| Type| Mandatory| Description|
3277| -------- | -------- | -------- | -------- |
3278| value | Object | Yes| Object to check.|
3279
3280**Return value**
3281
3282| Type| Description|
3283| -------- | -------- |
3284| boolean | Returns **true** if the input value is of the **BigUint64Array** type; returns **false** otherwise.|
3285
3286**Example**
3287
3288  ```js
3289  let that = new util.types();
3290  let result = that.isBigUint64Array(new BigUint64Array([]));
3291  ```
3292
3293
3294### isModuleNamespaceObject<sup>8+</sup>
3295
3296isModuleNamespaceObject(value: Object): boolean
3297
3298Checks whether the input value is a module namespace object.
3299
3300**System capability**: SystemCapability.Utils.Lang
3301
3302**Parameters**
3303
3304| Name| Type| Mandatory| Description|
3305| -------- | -------- | -------- | -------- |
3306| value | Object | Yes| Object to check.|
3307
3308**Return value**
3309
3310| Type| Description|
3311| -------- | -------- |
3312| boolean | Returns **true** if the input value is a module namespace object; returns **false** otherwise.|
3313
3314**Example**
3315
3316  ```js
3317  import url from '@ohos.url'
3318  let that = new util.types();
3319  let result = that.isModuleNamespaceObject(url);
3320  ```
3321
3322
3323### isSharedArrayBuffer<sup>8+</sup>
3324
3325isSharedArrayBuffer(value: Object): boolean
3326
3327Checks whether the input value is of the **SharedArrayBuffer** type.
3328
3329**System capability**: SystemCapability.Utils.Lang
3330
3331**Parameters**
3332
3333| Name| Type| Mandatory| Description|
3334| -------- | -------- | -------- | -------- |
3335| value | Object | Yes| Object to check.|
3336
3337**Return value**
3338
3339| Type| Description|
3340| -------- | -------- |
3341| boolean | Returns **true** if the input value is of the **SharedArrayBuffer** type; returns **false** otherwise.|
3342
3343**Example**
3344
3345  ```js
3346  let that = new util.types();
3347  let result = that.isSharedArrayBuffer(new SharedArrayBuffer(0));
3348  ```
3349
3350## LruBuffer<sup>(deprecated)</sup>
3351
3352> **NOTE**
3353>
3354> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache<sup>9+</sup>](#lrucache9) instead.
3355
3356### Attributes
3357
3358**System capability**: SystemCapability.Utils.Lang
3359
3360| Name| Type| Readable| Writable| Description|
3361| -------- | -------- | -------- | -------- | -------- |
3362| length | number | Yes| No| Total number of values in this buffer.|
3363
3364**Example**
3365
3366  ```js
3367  let pro = new util.LruBuffer();
3368  pro.put(2,10);
3369  pro.put(1,8);
3370  let result = pro.length;
3371  ```
3372
3373### constructor<sup>(deprecated)</sup>
3374
3375constructor(capacity?: number)
3376
3377A constructor used to create a **LruBuffer** instance. The default capacity of the buffer is 64.
3378
3379> **NOTE**
3380>
3381> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.constructor<sup>9+</sup>](#constructor9-3) instead.
3382
3383**System capability**: SystemCapability.Utils.Lang
3384
3385**Parameters**
3386
3387| Name| Type| Mandatory| Description|
3388| -------- | -------- | -------- | -------- |
3389| capacity | number | No| Capacity of the **LruBuffer** to create.|
3390
3391**Example**
3392
3393  ```js
3394  let lrubuffer= new util.LruBuffer();
3395  ```
3396
3397### updateCapacity<sup>(deprecated)</sup>
3398
3399updateCapacity(newCapacity: number): void
3400
3401Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown.
3402
3403> **NOTE**
3404>
3405> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.updateCapacity<sup>9+</sup>](#updatecapacity9) instead.
3406
3407**System capability**: SystemCapability.Utils.Lang
3408
3409**Parameters**
3410
3411| Name| Type| Mandatory| Description|
3412| -------- | -------- | -------- | -------- |
3413| newCapacity | number | Yes| New capacity of the **LruBuffer**.|
3414
3415**Example**
3416
3417  ```js
3418  let pro = new util.LruBuffer();
3419  let result = pro.updateCapacity(100);
3420  ```
3421
3422### toString<sup>(deprecated)</sup>
3423
3424toString(): string
3425
3426Obtains the string representation of this **LruBuffer** object.
3427
3428> **NOTE**
3429>
3430> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.toString<sup>9+</sup>](#tostring9) instead.
3431
3432**System capability**: SystemCapability.Utils.Lang
3433
3434**Return value**
3435
3436| Type| Description|
3437| -------- | -------- |
3438| string | String representation of this **LruBuffer** object.|
3439
3440**Example**
3441
3442  ```js
3443  let pro = new util.LruBuffer();
3444  pro.put(2,10);
3445  pro.get(2);
3446  pro.remove(20);
3447  let result = pro.toString();
3448  ```
3449
3450### getCapacity<sup>(deprecated)</sup>
3451
3452getCapacity(): number
3453
3454Obtains the capacity of this buffer.
3455
3456> **NOTE**
3457>
3458> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCapacity<sup>9+</sup>](#getcapacity9) instead.
3459
3460**System capability**: SystemCapability.Utils.Lang
3461
3462**Return value**
3463
3464| Type| Description|
3465| -------- | -------- |
3466| number | Capacity of this buffer.|
3467
3468**Example**
3469  ```js
3470  let pro = new util.LruBuffer();
3471  let result = pro.getCapacity();
3472  ```
3473
3474### clear<sup>(deprecated)</sup>
3475
3476clear(): void
3477
3478Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations.
3479
3480> **NOTE**
3481>
3482> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.clear<sup>9+</sup>](#clear9) instead.
3483
3484**System capability**: SystemCapability.Utils.Lang
3485
3486**Example**
3487
3488  ```js
3489  let pro = new util.LruBuffer();
3490  pro.put(2,10);
3491  let result = pro.length;
3492  pro.clear();
3493  ```
3494
3495### getCreateCount<sup>(deprecated)</sup>
3496
3497getCreateCount(): number
3498
3499Obtains the number of return values for **createDefault()**.
3500
3501> **NOTE**
3502>
3503> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getCreateCount<sup>9+</sup>](#getcreatecount9) instead.
3504
3505**System capability**: SystemCapability.Utils.Lang
3506
3507**Return value**
3508
3509| Type| Description|
3510| -------- | -------- |
3511| number | Number of return values for **createDefault()**.|
3512
3513**Example**
3514
3515  ```js
3516  let pro = new util.LruBuffer();
3517  pro.put(1,8);
3518  let result = pro.getCreateCount();
3519  ```
3520
3521### getMissCount<sup>(deprecated)</sup>
3522
3523getMissCount(): number
3524
3525Obtains the number of times that the queried values are mismatched.
3526
3527> **NOTE**
3528>
3529> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMissCount<sup>9+</sup>](#getmisscount9) instead.
3530
3531**System capability**: SystemCapability.Utils.Lang
3532
3533**Return value**
3534
3535| Type| Description|
3536| -------- | -------- |
3537| number | Number of times that the queried values are mismatched.|
3538
3539**Example**
3540
3541  ```js
3542  let pro = new util.LruBuffer();
3543  pro.put(2,10);
3544  pro.get(2);
3545  let result = pro.getMissCount();
3546  ```
3547
3548### getRemovalCount<sup>(deprecated)</sup>
3549
3550getRemovalCount(): number
3551
3552Obtains the number of removals from this buffer.
3553
3554> **NOTE**
3555>
3556> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getRemovalCount<sup>9+</sup>](#getremovalcount9) instead.
3557
3558**System capability**: SystemCapability.Utils.Lang
3559
3560**Return value**
3561
3562| Type| Description|
3563| -------- | -------- |
3564| number | Number of removals from the buffer.|
3565
3566**Example**
3567
3568  ```js
3569  let pro = new util.LruBuffer();
3570  pro.put(2,10);
3571  pro.updateCapacity(2);
3572  pro.put(50,22);
3573  let result = pro.getRemovalCount();
3574  ```
3575
3576### getMatchCount<sup>(deprecated)</sup>
3577
3578getMatchCount(): number
3579
3580Obtains the number of times that the queried values are matched.
3581
3582> **NOTE**
3583>
3584> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getMatchCount<sup>9+</sup>](#getmatchcount9) instead.
3585
3586**System capability**: SystemCapability.Utils.Lang
3587
3588**Return value**
3589
3590| Type| Description|
3591| -------- | -------- |
3592| number | Number of times that the queried values are matched.|
3593
3594**Example**
3595
3596  ```js
3597  let pro = new util.LruBuffer();
3598  pro.put(2,10);
3599  pro.get(2);
3600  let result = pro.getMatchCount();
3601  ```
3602
3603### getPutCount<sup>(deprecated)</sup>
3604
3605getPutCount(): number
3606
3607Obtains the number of additions to this buffer.
3608
3609> **NOTE**
3610>
3611> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.getPutCount<sup>9+</sup>](#getputcount9) instead.
3612
3613**System capability**: SystemCapability.Utils.Lang
3614
3615**Return value**
3616
3617| Type| Description|
3618| -------- | -------- |
3619| number | Number of additions to the buffer.|
3620
3621**Example**
3622
3623  ```js
3624  let pro = new util.LruBuffer();
3625  pro.put(2,10);
3626  let result = pro.getPutCount();
3627  ```
3628
3629### isEmpty<sup>(deprecated)</sup>
3630
3631isEmpty(): boolean
3632
3633Checks whether this buffer is empty.
3634
3635> **NOTE**
3636>
3637> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.isEmpty<sup>9+</sup>](#isempty9) instead.
3638
3639**System capability**: SystemCapability.Utils.Lang
3640
3641**Return value**
3642
3643| Type| Description|
3644| -------- | -------- |
3645| boolean | Returns **true** if the buffer does not contain any value.|
3646
3647**Example**
3648
3649  ```js
3650  let pro = new util.LruBuffer();
3651  pro.put(2,10);
3652  let result = pro.isEmpty();
3653  ```
3654
3655### get<sup>(deprecated)</sup>
3656
3657get(key: K): V | undefined
3658
3659Obtains the value of the specified key.
3660
3661> **NOTE**
3662>
3663> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.get<sup>9+</sup>](#get9) instead.
3664
3665**System capability**: SystemCapability.Utils.Lang
3666
3667**Parameters**
3668
3669| Name| Type| Mandatory| Description|
3670| -------- | -------- | -------- | -------- |
3671| key | K | Yes| Key based on which the value is queried.|
3672
3673**Return value**
3674
3675| Type| Description|
3676| -------- | -------- |
3677| V&nbsp;\|&nbsp;undefined | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.|
3678
3679**Example**
3680
3681  ```js
3682  let pro = new util.LruBuffer();
3683  pro.put(2,10);
3684  let result  = pro.get(2);
3685  ```
3686
3687### put<sup>(deprecated)</sup>
3688
3689put(key: K,value: V): V
3690
3691Adds a key-value pair to this buffer.
3692
3693> **NOTE**
3694>
3695> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.put<sup>9+</sup>](#put9) instead.
3696
3697**System capability**: SystemCapability.Utils.Lang
3698
3699**Parameters**
3700
3701| Name| Type| Mandatory| Description|
3702| -------- | -------- | -------- | -------- |
3703| key | K | Yes| Key of the key-value pair to add.|
3704| value | V | Yes| Value of the key-value pair to add.|
3705
3706**Return value**
3707
3708| Type| Description|
3709| -------- | -------- |
3710| 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. |
3711
3712**Example**
3713
3714  ```js
3715  let pro = new util.LruBuffer();
3716  let result = pro.put(2,10);
3717  ```
3718
3719### values<sup>(deprecated)</sup>
3720
3721values(): V[]
3722
3723Obtains all values in this buffer, listed from the most to the least recently accessed.
3724
3725> **NOTE**
3726>
3727> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.values<sup>9+</sup>](#values9) instead.
3728
3729**System capability**: SystemCapability.Utils.Lang
3730
3731**Return value**
3732
3733| Type| Description|
3734| -------- | -------- |
3735| V&nbsp;[] | All values in the buffer, listed from the most to the least recently accessed.|
3736
3737**Example**
3738
3739  ```js
3740  let pro = new util.LruBuffer();
3741  pro.put(2,10);
3742  pro.put(2,"anhu");
3743  pro.put("afaf","grfb");
3744  let result = pro.values();
3745  ```
3746
3747### keys<sup>(deprecated)</sup>
3748
3749keys(): K[]
3750
3751Obtains all keys in this buffer, listed from the most to the least recently accessed.
3752
3753> **NOTE**
3754>
3755> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.keys<sup>9+</sup>](#keys9) instead.
3756
3757**System capability**: SystemCapability.Utils.Lang
3758
3759**Return value**
3760
3761| Type| Description|
3762| -------- | -------- |
3763| K&nbsp;[] | All keys in the buffer, listed from the most to the least recently accessed.|
3764
3765**Example**
3766
3767  ```js
3768  let pro = new util.LruBuffer();
3769  pro.put(2,10);
3770  let result = pro.keys();
3771  ```
3772
3773### remove<sup>(deprecated)</sup>
3774
3775remove(key: K): V | undefined
3776
3777Removes the specified key and its value from this buffer.
3778
3779> **NOTE**
3780>
3781> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.remove<sup>9+</sup>](#remove9) instead.
3782
3783**System capability**: SystemCapability.Utils.Lang
3784
3785**Parameters**
3786
3787| Name| Type| Mandatory| Description|
3788| -------- | -------- | -------- | -------- |
3789| key | K | Yes| Key to remove.|
3790
3791**Return value**
3792
3793| Type| Description|
3794| -------- | -------- |
3795| V&nbsp;\|&nbsp;undefined | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.|
3796
3797**Example**
3798  ```js
3799  let pro = new util.LruBuffer();
3800  pro.put(2,10);
3801  let result = pro.remove(20);
3802  ```
3803
3804### afterRemoval<sup>(deprecated)</sup>
3805
3806afterRemoval(isEvict: boolean,key: K,value: V,newValue: V): void
3807
3808Performs subsequent operations after a value is removed.
3809
3810> **NOTE**
3811>
3812> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.afterRemoval<sup>9+</sup>](#afterremoval9) instead.
3813
3814**System capability**: SystemCapability.Utils.Lang
3815
3816**Parameters**
3817
3818| Name| Type| Mandatory| Description|
3819| -------- | -------- | -------- | -------- |
3820| isEvict | boolean | Yes| Whether the buffer capacity is insufficient. If the value is **true**, this API is called due to insufficient capacity.|
3821| key | K | Yes| Key removed.|
3822| value | V | Yes| Value removed.|
3823| newValue | V | Yes| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.|
3824
3825**Example**
3826
3827  ```js
3828  let arr = [];
3829  class ChildLruBuffer<K, V> extends util.LruBuffer<K, V>
3830  {
3831  	constructor()
3832  	{
3833  		super();
3834  	}
3835  	afterRemoval(isEvict, key, value, newValue)
3836  	{
3837  		if (isEvict === false)
3838  		{
3839  			arr = [key, value, newValue];
3840  		}
3841  	}
3842  }
3843  let lru = new ChildLruBuffer();
3844  lru.afterRemoval(false,10,30,null);
3845  ```
3846
3847### contains<sup>(deprecated)</sup>
3848
3849contains(key: K): boolean
3850
3851Checks whether this buffer contains the specified key.
3852
3853
3854> **NOTE**
3855>
3856> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.contains<sup>9+</sup>](#contains9) instead.
3857
3858**System capability**: SystemCapability.Utils.Lang
3859
3860**Parameters**
3861
3862| Name| Type| Mandatory| Description|
3863| -------- | -------- | -------- | -------- |
3864| key | K | Yes| Key to check.|
3865
3866**Return value**
3867
3868| Type| Description|
3869| -------- | -------- |
3870| boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.|
3871
3872**Example**
3873
3874  ```js
3875  let pro = new util.LruBuffer();
3876  pro.put(2,10);
3877  let result = pro.contains(20);
3878  ```
3879
3880### createDefault<sup>(deprecated)</sup>
3881
3882createDefault(key: K): V
3883
3884Creates a value if the value of the specified key is not available.
3885
3886> **NOTE**
3887>
3888> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.createDefault<sup>9+</sup>](#createdefault9) instead.
3889
3890**System capability**: SystemCapability.Utils.Lang
3891
3892**Parameters**
3893
3894| Name| Type| Mandatory| Description|
3895| -------- | -------- | -------- | -------- |
3896| key | K | Yes| Key of which the value is missing.|
3897
3898**Return value**
3899
3900| Type| Description|
3901| -------- | -------- |
3902| V | Value of the key.|
3903
3904**Example**
3905
3906  ```js
3907  let pro = new util.LruBuffer();
3908  let result = pro.createDefault(50);
3909  ```
3910
3911### entries<sup>(deprecated)</sup>
3912
3913entries(): IterableIterator&lt;[K,V]&gt;
3914
3915Obtains a new iterator object that contains all key-value pairs in this object.
3916
3917> **NOTE**
3918>
3919> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.entries<sup>9+</sup>](#entries9) instead.
3920
3921**System capability**: SystemCapability.Utils.Lang
3922
3923**Return value**
3924
3925| Type| Description|
3926| -------- | -------- |
3927| [K,&nbsp;V] | Iterable array.|
3928
3929**Example**
3930
3931  ```js
3932  let pro = new util.LruBuffer();
3933  pro.put(2,10);
3934  let result = pro.entries();
3935  ```
3936
3937### [Symbol.iterator]<sup>(deprecated)</sup>
3938
3939[Symbol.iterator]\(): IterableIterator&lt;[K, V]&gt;
3940
3941Obtains a two-dimensional array in key-value pairs.
3942
3943> **NOTE**
3944>
3945> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [LRUCache.Symbol.iterator<sup>9+</sup>](#symboliterator9) instead.
3946
3947**System capability**: SystemCapability.Utils.Lang
3948
3949**Return value**
3950
3951| Type| Description|
3952| -------- | -------- |
3953| [K,&nbsp;V] | Two-dimensional array in key-value pairs.|
3954
3955**Example**
3956
3957  ```js
3958  let pro = new util.LruBuffer();
3959  pro.put(2,10);
3960  let result = pro[Symbol.iterator]();
3961  ```
3962
3963## Scope<sup>(deprecated)</sup>
3964
3965> **NOTE**
3966>
3967> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper<sup>9+</sup>](#scopehelper9) instead.
3968
3969### constructor<sup>(deprecated)</sup>
3970
3971constructor(lowerObj: ScopeType, upperObj: ScopeType)
3972
3973A constructor used to create a **Scope** object with the specified upper and lower limits.
3974
3975> **NOTE**
3976>
3977> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.constructor<sup>9+</sup>](#constructor9-4) instead.
3978
3979
3980**System capability**: SystemCapability.Utils.Lang
3981
3982**Parameters**
3983
3984| Name| Type| Mandatory| Description|
3985| -------- | -------- | -------- | -------- |
3986| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.|
3987| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.|
3988
3989**Example**
3990  ```js
3991  let tempLower = new Temperature(30);
3992  let tempUpper = new Temperature(40);
3993  let range = new util.Scope(tempLower, tempUpper);
3994  ```
3995
3996### toString<sup>(deprecated)</sup>
3997
3998toString(): string
3999
4000Obtains a string representation that contains this **Scope**.
4001
4002> **NOTE**
4003>
4004> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.toString<sup>9+</sup>](#tostring9-1) instead.
4005
4006**System capability**: SystemCapability.Utils.Lang
4007
4008**Return value**
4009
4010| Type| Description|
4011| -------- | -------- |
4012| string | String representation containing the **Scope**.|
4013
4014**Example**
4015
4016  ```js
4017  let tempLower = new Temperature(30);
4018  let tempUpper = new Temperature(40);
4019  let range = new util.Scope(tempLower, tempUpper);
4020  let result = range.toString();
4021  ```
4022
4023### intersect<sup>(deprecated)</sup>
4024
4025intersect(range: Scope): Scope
4026
4027Obtains the intersection of this **Scope** and the given **Scope**.
4028
4029> **NOTE**
4030>
4031> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9) instead.
4032
4033**System capability**: SystemCapability.Utils.Lang
4034
4035**Parameters**
4036
4037| Name| Type| Mandatory| Description|
4038| -------- | -------- | -------- | -------- |
4039| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
4040
4041**Return value**
4042
4043| Type| Description|
4044| -------- | -------- |
4045| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given **Scope**.|
4046
4047**Example**
4048
4049  ```js
4050  let tempLower = new Temperature(30);
4051  let tempUpper = new Temperature(40);
4052  let range = new util.Scope(tempLower, tempUpper);
4053  let tempMiDF = new Temperature(35);
4054  let tempMidS = new Temperature(39);
4055  let rangeFir = new util.Scope(tempMiDF, tempMidS);
4056  range.intersect(rangeFir );
4057  ```
4058
4059### intersect<sup>(deprecated)</sup>
4060
4061intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope
4062
4063Obtains the intersection of this **Scope** and the given lower and upper limits.
4064
4065> **NOTE**
4066>
4067> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.intersect<sup>9+</sup>](#intersect9-1) instead.
4068
4069**System capability**: SystemCapability.Utils.Lang
4070
4071**Parameters**
4072
4073| Name| Type| Mandatory| Description|
4074| -------- | -------- | -------- | -------- |
4075| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
4076| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
4077
4078**Return value**
4079
4080| Type| Description|
4081| -------- | -------- |
4082| [Scope](#scopedeprecated) | Intersection of this **Scope** and the given lower and upper limits.|
4083
4084**Example**
4085
4086  ```js
4087  let tempLower = new Temperature(30);
4088  let tempUpper = new Temperature(40);
4089  let tempMiDF = new Temperature(35);
4090  let tempMidS = new Temperature(39);
4091  let range = new util.Scope(tempLower, tempUpper);
4092  let result = range.intersect(tempMiDF, tempMidS);
4093  ```
4094
4095### getUpper<sup>(deprecated)</sup>
4096
4097getUpper(): ScopeType
4098
4099Obtains the upper limit of this **Scope**.
4100
4101> **NOTE**
4102>
4103> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getUpper<sup>9+</sup>](#getupper9) instead.
4104
4105**System capability**: SystemCapability.Utils.Lang
4106
4107**Return value**
4108
4109| Type| Description|
4110| -------- | -------- |
4111| [ScopeType](#scopetype8) | Upper limit of this **Scope**.|
4112
4113**Example**
4114
4115  ```js
4116  let tempLower = new Temperature(30);
4117  let tempUpper = new Temperature(40);
4118  let range = new util.Scope(tempLower, tempUpper);
4119  let result = range.getUpper();
4120  ```
4121
4122### getLower<sup>(deprecated)</sup>
4123
4124getLower(): ScopeType
4125
4126Obtains the lower limit of this **Scope**.
4127
4128> **NOTE**
4129>
4130> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.getLower<sup>9+</sup>](#getlower9) instead.
4131
4132**System capability**: SystemCapability.Utils.Lang
4133
4134**Return value**
4135
4136| Type| Description|
4137| -------- | -------- |
4138| [ScopeType](#scopetype8) | Lower limit of this **Scope**.|
4139
4140**Example**
4141
4142  ```js
4143  let tempLower = new Temperature(30);
4144  let tempUpper = new Temperature(40);
4145  let range = new util.Scope(tempLower, tempUpper);
4146  let result = range.getLower();
4147  ```
4148
4149### expand<sup>(deprecated)</sup>
4150
4151expand(lowerObj: ScopeType,upperObj: ScopeType): Scope
4152
4153Obtains the union set of this **Scope** and the given lower and upper limits.
4154
4155> **NOTE**
4156>
4157> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9) instead.
4158
4159**System capability**: SystemCapability.Utils.Lang
4160
4161**Parameters**
4162
4163| Name| Type| Mandatory| Description|
4164| -------- | -------- | -------- | -------- |
4165| lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.|
4166| upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.|
4167
4168**Return value**
4169
4170| Type| Description|
4171| -------- | -------- |
4172| [Scope](#scopedeprecated) | Union set of this **Scope** and the given lower and upper limits.|
4173
4174**Example**
4175
4176  ```js
4177  let tempLower = new Temperature(30);
4178  let tempUpper = new Temperature(40);
4179  let tempMiDF = new Temperature(35);
4180  let tempMidS = new Temperature(39);
4181  let range = new util.Scope(tempLower, tempUpper);
4182  let result = range.expand(tempMiDF, tempMidS);
4183  ```
4184
4185### expand<sup>(deprecated)</sup>
4186
4187expand(range: Scope): Scope
4188
4189Obtains the union set of this **Scope** and the given **Scope**.
4190
4191> **NOTE**
4192>
4193> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-1) instead.
4194
4195**System capability**: SystemCapability.Utils.Lang
4196
4197**Parameters**
4198
4199| Name| Type| Mandatory| Description|
4200| -------- | -------- | -------- | -------- |
4201| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
4202
4203**Return value**
4204
4205| Type| Description|
4206| -------- | -------- |
4207| [Scope](#scopedeprecated) | Union set of this **Scope** and the given **Scope**.|
4208
4209**Example**
4210
4211  ```js
4212  let tempLower = new Temperature(30);
4213  let tempUpper = new Temperature(40);
4214  let tempMiDF = new Temperature(35);
4215  let tempMidS = new Temperature(39);
4216  let range = new util.Scope(tempLower, tempUpper);
4217  let rangeFir = new util.Scope(tempMiDF, tempMidS);
4218  let result = range.expand(rangeFir);
4219  ```
4220
4221### expand<sup>(deprecated)</sup>
4222
4223expand(value: ScopeType): Scope
4224
4225Obtains the union set of this **Scope** and the given value.
4226
4227> **NOTE**
4228>
4229> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.expand<sup>9+</sup>](#expand9-2) instead.
4230
4231**System capability**: SystemCapability.Utils.Lang
4232
4233**Parameters**
4234
4235| Name| Type| Mandatory| Description|
4236| -------- | -------- | -------- | -------- |
4237| value | [ScopeType](#scopetype8) | Yes| Value specified.|
4238
4239**Return value**
4240
4241| Type| Description|
4242| -------- | -------- |
4243| [Scope](#scopedeprecated) | Union set of this **Scope** and the given value.|
4244
4245**Example**
4246
4247  ```js
4248  let tempLower = new Temperature(30);
4249  let tempUpper = new Temperature(40);
4250  let tempMiDF = new Temperature(35);
4251  let range = new util.Scope(tempLower, tempUpper);
4252  let result = range.expand(tempMiDF);
4253  ```
4254
4255### contains<sup>(deprecated)</sup>
4256
4257contains(value: ScopeType): boolean
4258
4259Checks whether a value is within this **Scope**.
4260
4261> **NOTE**
4262>
4263> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-1) instead.
4264
4265**System capability**: SystemCapability.Utils.Lang
4266
4267**Parameters**
4268
4269| Name| Type| Mandatory| Description|
4270| -------- | -------- | -------- | -------- |
4271| value | [ScopeType](#scopetype8) | Yes| Value specified.|
4272
4273**Return value**
4274
4275| Type| Description|
4276| -------- | -------- |
4277| boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.|
4278
4279**Example**
4280
4281  ```js
4282  let tempLower = new Temperature(30);
4283  let tempUpper = new Temperature(40);
4284  let tempMiDF = new Temperature(35);
4285  let range = new util.Scope(tempLower, tempUpper);
4286  range.contains(tempMiDF);
4287  ```
4288
4289### contains<sup>(deprecated)</sup>
4290
4291contains(range: Scope): boolean
4292
4293Checks whether a range is within this **Scope**.
4294
4295> **NOTE**
4296>
4297> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.contains<sup>9+</sup>](#contains9-2) instead.
4298
4299**System capability**: SystemCapability.Utils.Lang
4300
4301**Parameters**
4302
4303| Name| Type| Mandatory| Description|
4304| -------- | -------- | -------- | -------- |
4305| range | [Scope](#scopedeprecated) | Yes| **Scope** specified.|
4306
4307**Return value**
4308
4309| Type| Description|
4310| -------- | -------- |
4311| boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.|
4312
4313**Example**
4314
4315  ```js
4316  let tempLower = new Temperature(30);
4317  let tempUpper = new Temperature(40);
4318  let range = new util.Scope(tempLower, tempUpper);
4319  let tempLess = new Temperature(20);
4320  let tempMore = new Temperature(45);
4321  let rangeSec = new util.Scope(tempLess, tempMore);
4322  let result = range.contains(rangeSec);
4323  ```
4324
4325### clamp<sup>(deprecated)</sup>
4326
4327
4328clamp(value: ScopeType): ScopeType
4329
4330Limits a value to this **Scope**.
4331
4332> **NOTE**
4333>
4334> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [ScopeHelper.clamp<sup>9+</sup>](#clamp9) instead.
4335
4336**System capability**: SystemCapability.Utils.Lang
4337
4338**Parameters**
4339
4340| Name| Type| Mandatory| Description|
4341| -------- | -------- | -------- | -------- |
4342| value | [ScopeType](#scopetype8) | Yes| Value specified.|
4343
4344**Return value**
4345
4346| Type| Description|
4347| -------- | -------- |
4348| [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**.|
4349
4350**Example**
4351
4352  ```js
4353  let tempLower = new Temperature(30);
4354  let tempUpper = new Temperature(40);
4355  let tempMiDF = new Temperature(35);
4356  let range = new util.Scope(tempLower, tempUpper);
4357  let result = range.clamp(tempMiDF);
4358  ```
4359
4360
4361## Base64<sup>(deprecated)</sup>
4362
4363> **NOTE**
4364>
4365> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper<sup>9+</sup>](#base64helper9) instead.
4366
4367### constructor<sup>(deprecated)</sup>
4368
4369constructor()
4370
4371A constructor used to create a **Base64** object.
4372
4373> **NOTE**
4374>
4375> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.constructor<sup>9+</sup>](#constructor9-5) instead.
4376
4377**System capability**: SystemCapability.Utils.Lang
4378
4379**Example**
4380
4381  ```js
4382  let base64 = new  util.Base64();
4383  ```
4384
4385### encodeSync<sup>(deprecated)</sup>
4386
4387encodeSync(src: Uint8Array): Uint8Array
4388
4389Encodes the input content.
4390
4391> **NOTE**
4392>
4393> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeSync<sup>9+</sup>](#encodesync9) instead.
4394
4395**System capability**: SystemCapability.Utils.Lang
4396
4397**Parameters**
4398
4399| Name| Type| Mandatory| Description|
4400| -------- | -------- | -------- | -------- |
4401| src | Uint8Array | Yes| Uint8Array to encode.|
4402
4403**Return value**
4404
4405| Type| Description|
4406| -------- | -------- |
4407| Uint8Array | Uint8Array encoded.|
4408
4409**Example**
4410
4411  ```js
4412  let that = new util.Base64();
4413  let array = new Uint8Array([115,49,51]);
4414  let result = that.encodeSync(array);
4415  ```
4416
4417### encodeToStringSync<sup>(deprecated)</sup>
4418
4419encodeToStringSync(src: Uint8Array): string
4420
4421Encodes the input content.
4422
4423> **NOTE**
4424>
4425> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToStringSync<sup>9+</sup>](#encodetostringsync9) instead.
4426
4427**System capability**: SystemCapability.Utils.Lang
4428
4429**Parameters**
4430
4431| Name| Type| Mandatory| Description|
4432| -------- | -------- | -------- | -------- |
4433| src | Uint8Array | Yes| Uint8Array to encode.|
4434
4435**Return value**
4436
4437| Type| Description|
4438| -------- | -------- |
4439| string | String encoded from the Uint8Array.|
4440
4441**Example**
4442
4443  ```js
4444  let that = new util.Base64();
4445  let array = new Uint8Array([115,49,51]);
4446  let result = that.encodeToStringSync(array);
4447  ```
4448
4449### decodeSync<sup>(deprecated)</sup>
4450
4451decodeSync(src: Uint8Array | string): Uint8Array
4452
4453Decodes the input content.
4454
4455> **NOTE**
4456>
4457> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decodeSync<sup>9+</sup>](#decodesync9) instead.
4458
4459**System capability**: SystemCapability.Utils.Lang
4460
4461**Parameters**
4462
4463| Name| Type| Mandatory| Description|
4464| -------- | -------- | -------- | -------- |
4465| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode.|
4466
4467**Return value**
4468
4469| Type| Description|
4470| -------- | -------- |
4471| Uint8Array | Uint8Array decoded.|
4472
4473**Example**
4474
4475  ```js
4476  let that = new util.Base64();
4477  let buff = 'czEz';
4478  let result = that.decodeSync(buff);
4479  ```
4480
4481### encode<sup>(deprecated)</sup>
4482
4483encode(src: Uint8Array): Promise&lt;Uint8Array&gt;
4484
4485Encodes the input content asynchronously.
4486
4487> **NOTE**
4488>
4489> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encode<sup>9+</sup>](#encode9) instead.
4490
4491**System capability**: SystemCapability.Utils.Lang
4492
4493**Parameters**
4494
4495| Name| Type| Mandatory| Description|
4496| -------- | -------- | -------- | -------- |
4497| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
4498
4499**Return value**
4500
4501| Type| Description|
4502| -------- | -------- |
4503| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous encoding.|
4504
4505**Example**
4506
4507  ```js
4508  let that = new util.Base64();
4509  let array = new Uint8Array([115,49,51]);
4510  let rarray = new Uint8Array([99,122,69,122]);
4511  that.encode(array).then(val=>{
4512      for (var i = 0; i < rarray.length; i++) {
4513          console.log(val[i].toString())
4514      }
4515  })
4516  ```
4517
4518### encodeToString<sup>(deprecated)</sup>
4519
4520encodeToString(src: Uint8Array): Promise&lt;string&gt;
4521
4522Encodes the input content asynchronously.
4523
4524> **NOTE**
4525>
4526> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.encodeToString<sup>9+</sup>](#encodetostring9) instead.
4527
4528**System capability**: SystemCapability.Utils.Lang
4529
4530**Parameters**
4531
4532| Name| Type| Mandatory| Description|
4533| -------- | -------- | -------- | -------- |
4534| src | Uint8Array | Yes| Uint8Array to encode asynchronously.|
4535
4536**Return value**
4537
4538| Type| Description|
4539| -------- | -------- |
4540| Promise&lt;string&gt; | String obtained after asynchronous encoding.|
4541
4542**Example**
4543
4544  ```js
4545  let that = new util.Base64();
4546  let array = new Uint8Array([115,49,51]);
4547  that.encodeToString(array).then(val=>{
4548      console.log(val)
4549  })
4550  ```
4551
4552### decode<sup>(deprecated)</sup>
4553
4554
4555decode(src: Uint8Array | string): Promise&lt;Uint8Array&gt;
4556
4557Decodes the input content asynchronously.
4558
4559> **NOTE**
4560>
4561> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [Base64Helper.decode<sup>9+</sup>](#decode9) instead.
4562
4563**System capability**: SystemCapability.Utils.Lang
4564
4565**Parameters**
4566
4567| Name| Type| Mandatory| Description|
4568| -------- | -------- | -------- | -------- |
4569| src | Uint8Array&nbsp;\|&nbsp;string | Yes| Uint8Array or string to decode asynchronously.|
4570
4571**Return value**
4572
4573| Type| Description|
4574| -------- | -------- |
4575| Promise&lt;Uint8Array&gt; | Uint8Array obtained after asynchronous decoding.|
4576
4577**Example**
4578
4579  ```js
4580  let that = new util.Base64();
4581  let array = new Uint8Array([99,122,69,122]);
4582  let rarray = new Uint8Array([115,49,51]);
4583  that.decode(array).then(val=>{
4584      for (var i = 0; i < rarray.length; i++) {
4585          console.log(val[i].toString())
4586      }
4587  })
4588  ```
4589