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