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