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