• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16'use static';
17/**
18 * @file
19 * @kit ArkTS
20 * @arkts 1.2
21 */
22
23declare namespace util {
24  /**
25   * %s: String will be used to convert all values except BigInt, Object and -0. BigInt values will be represented
26   * with an n and Objects that have no user defined toString function are inspected using util.inspect() with
27   * options { depth: 0, colors: false, compact: 3 }.
28   * %d: Number will be used to convert all values except BigInt and Symbol.
29   * %i: parseInt(value, 10) is used for all values except BigInt and Symbol.
30   * %f: parseFloat(value) is used for all values except Bigint and Symbol.
31   * %j: JSON. Replaced with the string '[Circular]' if the argument contains circular references.
32   * %o: Object. A string representation of an object with generic JavaScript object formatting.Similar to
33   * util.inspect() with options { showHidden: true, showProxy: true}. This will show the full object including
34   * non-enumerable properties and proxies.
35   * %O: Object. A string representation of an object with generic JavaScript object formatting.
36   * %O: Object. A string representation of an object with generic JavaScript object formatting.Similar to
37   * util.inspect() without options. This will show the full object not including non-enumerable properties and
38   * proxies.
39   * %c: CSS. This specifier is ignored and will skip any CSS passed in.
40   * %%: single percent sign ('%'). This does not consume an argument.Returns: <string> The formatted string.
41   *
42   * @param { string } format - Styled string
43   * @param { Object[] } args - Data to be formatted
44   * @returns { string } a string formatted in a specific format.
45   * @throws { BusinessError } 401 - Parameter error. Possible causes:
46   * 1.Mandatory parameters are left unspecified;
47   * 2.Incorrect parameter types.
48   * @syscap SystemCapability.Utils.Lang
49   * @crossplatform
50   * @atomicservice
51   * @since 20
52   */
53  function format(format: string, ...args: Object[]): string;
54
55  /**
56   * Generate a random RFC 4122 version 4 UUID using a cryptographically secure random number generator.
57   *
58   * @param { boolean } [entropyCache] - Whether to generate the UUID with using the cache. Default: true.
59   * @returns { string } Return a string representing this UUID.
60   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
61   * @syscap SystemCapability.Utils.Lang
62   * @crossplatform
63   * @atomicservice
64   * @since 20
65   */
66  function generateRandomUUID(entropyCache?: boolean): string;
67
68  /**
69   * The Type represents four different encoding formats for base64
70   *
71   * @enum { number } Type
72   * @syscap SystemCapability.Utils.Lang
73   * @crossplatform
74   * @atomicservice
75   * @since 20
76   */
77  enum Type {
78    /**
79     * The value indicates that the encoding format of base64 is BASIC
80     * @syscap SystemCapability.Utils.Lang
81     * @crossplatform
82     * @atomicservice
83     * @since 20
84     */
85    BASIC,
86    /**
87     * The value indicates that the encoding format of base64 is MIME
88     * @syscap SystemCapability.Utils.Lang
89     * @crossplatform
90     * @atomicservice
91     * @since 20
92     */
93    MIME,
94    /**
95     * The value indicates that the encoding format of base64 is BASIC_URL_SAFE
96     * @syscap SystemCapability.Utils.Lang
97     * @crossplatform
98     * @atomicservice
99     * @since 20
100     */
101    BASIC_URL_SAFE,
102    /**
103     * The value indicates that the encoding format of base64 is MIME_URL_SAFE
104     * @syscap SystemCapability.Utils.Lang
105     * @crossplatform
106     * @atomicservice
107     * @since 20
108     */
109    MIME_URL_SAFE,
110  }
111
112  /**
113   * Decodes a Base64 encoded String or input u8 array into a newly-allocated
114   * u8 array using the Base64 encoding scheme.
115   *
116   * @syscap SystemCapability.Utils.Lang
117   * @crossplatform
118   * @atomicservice
119   * @since 20
120   */
121  class Base64Helper {
122    /**
123     * Constructor for creating base64 encoding and decoding
124     *
125     * @syscap SystemCapability.Utils.Lang
126     * @crossplatform
127     * @atomicservice
128     * @since 20
129     */
130    constructor();
131
132    /**
133     * Encodes all bytes from the specified u8 array into a newly-allocated u8 array using the Base64 encoding scheme.
134     *
135     * @param { Uint8Array } src - A Uint8Array value
136     * @param { Type } [options] - Enumerating input parameters includes two encoding formats: BASIC and BASIC_URL_SAFE
137     * @returns { Uint8Array } Return the encoded new Uint8Array.
138     * @throws { BusinessError } 401 - Parameter error. Possible causes:
139     * 1.Mandatory parameters are left unspecified;
140     * 2.Incorrect parameter types.
141     * @syscap SystemCapability.Utils.Lang
142     * @crossplatform
143     * @atomicservice
144     * @since 20
145     */
146    encodeSync(src: Uint8Array, options?: Type): Uint8Array;
147
148    /**
149     * Encodes the specified byte array into a String using the Base64 encoding scheme.
150     *
151     * @param { Uint8Array } src - A Uint8Array value
152     * @param { Type } options - one of the Type enumeration
153     * @returns { string } Return the encoded string.
154     * @throws { BusinessError } 401 - Parameter error. Possible causes:
155     * 1.Mandatory parameters are left unspecified;
156     * 2.Incorrect parameter types.
157     * @syscap SystemCapability.Utils.Lang
158     * @crossplatform
159     * @atomicservice
160     * @since 20
161     */
162    encodeToStringSync(src: Uint8Array, options?: Type): string;
163
164    /**
165     * Decodes a Base64 encoded String or input u8 array into a newly-allocated u8 array using the Base64 encoding scheme.
166     *
167     * @param { Uint8Array | string } src - A Uint8Array value or a string value
168     * @param { Type } [options] - one of the Type enumeration
169     * @returns { Uint8Array } Return the decoded Uint8Array.
170     * @throws { BusinessError } 401 - Parameter error. Possible causes:
171     * 1.Mandatory parameters are left unspecified;
172     * 2.Incorrect parameter types.
173     * @syscap SystemCapability.Utils.Lang
174     * @crossplatform
175     * @atomicservice
176     * @since 20
177     */
178    decodeSync(src: Uint8Array | string, options?: Type): Uint8Array;
179
180    /**
181     * Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme.
182     *
183     * @param { Uint8Array } src - A Uint8Array value
184     * @param { Type } [options] - Enumerating input parameters includes two encoding formats: BASIC and BASIC_URL_SAFE
185     * @returns { Promise<Uint8Array> } Return the encodes asynchronous new Uint8Array.
186     * @throws { BusinessError } 401 - Parameter error. Possible causes:
187     * 1.Mandatory parameters are left unspecified;
188     * 2.Incorrect parameter types.
189     * @syscap SystemCapability.Utils.Lang
190     * @crossplatform
191     * @atomicservice
192     * @since 20
193     */
194    encode(src: Uint8Array, options?: Type): Promise<Uint8Array>;
195
196    /**
197     * Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme.
198     *
199     * @param { Uint8Array } src - A Uint8Array value
200     * @param { Type } [options] - one of the Type enumeration
201     * @returns { Promise<string> } Returns the encoded asynchronous string.
202     * @throws { BusinessError } 401 - Parameter error. Possible causes:
203     * 1.Mandatory parameters are left unspecified;
204     * 2.Incorrect parameter types.
205     * @syscap SystemCapability.Utils.Lang
206     * @crossplatform
207     * @atomicservice
208     * @since 20
209     */
210    encodeToString(src: Uint8Array, options?: Type): Promise<string>;
211
212    /**
213     * Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or
214     * input u8 array into a newly allocated u8 array.
215     *
216     * @param { Uint8Array | string } src - A Uint8Array value or a string value
217     * @param { Type } [options] - one of the Type enumeration
218     * @returns { Promise<Uint8Array> } Return the decoded asynchronous Uint8Array.
219     * @throws { BusinessError } 401 - Parameter error. Possible causes:
220     * 1.Mandatory parameters are left unspecified;
221     * 2.Incorrect parameter types.
222     * @syscap SystemCapability.Utils.Lang
223     * @crossplatform
224     * @atomicservice
225     * @since 20
226     */
227    decode(src: Uint8Array | string, options?: Type): Promise<Uint8Array>;
228  }
229
230  /**
231   * The ScopeComparable contains comparison methods.
232   *
233   * @interface ScopeComparable
234   * @syscap SystemCapability.Utils.Lang
235   * @crossplatform
236   * @atomicservice
237   * @since 20
238   */
239  interface ScopeComparable<T> {
240    /**
241     * The comparison function is used by the scope.
242     *
243     * @param { ScopeComparable } other - Other
244     * @returns { boolean } Returns whether the current object is greater than or equal to the input object.
245     * @syscap SystemCapability.Utils.Lang
246     * @crossplatform
247     * @atomicservice
248     * @since 20
249     */
250    compareTo(other: T): boolean;
251  }
252
253  /**
254    * A type used to denote ScopeComparable or number.
255    *
256    * @typedef { ScopeComparable }
257    * @syscap SystemCapability.Utils.Lang
258    * @crossplatform
259    * @atomicservice
260    * @since 20
261    */
262  type ScopeType<T> = ScopeComparable<T>;
263
264  class ScopeHelper<T extends ScopeComparable<T>> {
265    /**
266     * A constructor used to create a Scope instance with the lower and upper bounds specified.
267     *
268     * @param { ScopeType } lowerObj - A ScopeType value
269     * @param { ScopeType } upperObj - A ScopeType value
270     * @since 20
271     */
272    constructor(lowerObj: T, upperObj: T);
273
274    /**
275     * Obtains a string representation of the current range.
276     *
277     * @returns { string } Returns a string representation of the current range object.
278     * @since 20
279     */
280    toString(): string;
281
282    /**
283     * Returns the intersection of a given range and the current range.
284     *
285     * @param { ScopeHelper } range - A Scope range object
286     * @returns { ScopeHelper } Returns the intersection of a given range and the current range.
287     * @since 20
288     */
289    intersect(range: ScopeHelper<T>): ScopeHelper<T>;
290
291    /**
292     * Returns the intersection of the current range and the range specified by the given lower and upper bounds.
293     *
294     * @param { ScopeType } lowerObj - A ScopeType value
295     * @param { ScopeType } upperObj - A ScopeType value
296     * @returns { ScopeHelper } Returns the intersection of the current range and the range specified by the given lower and upper bounds.
297     * @since 20
298     */
299    intersect(lowerObj: T, upperObj: T): ScopeHelper<T>;
300
301    /**
302     * Obtains the upper bound of the current range.
303     *
304     * @returns { ScopeType } Returns the upper bound of the current range.
305     * @since 20
306     */
307    getUpper(): T;
308
309    /**
310     * Obtains the lower bound of the current range.
311     *
312     * @returns { ScopeType } Returns the lower bound of the current range.
313     * @since 20
314     */
315    getLower(): T;
316
317    /**
318     * Creates the smallest range that includes the current range and the given lower and upper bounds.
319     *
320     * @param { ScopeType } lowerObj - A ScopeType value
321     * @param { ScopeType } upperObj - A ScopeType value
322     * @returns { ScopeHelper } Returns the smallest range that includes the current range and the given lower and upper bounds.
323     * @since 20
324     */
325    expand(lowerObj: T, upperObj: T): ScopeHelper<T>;
326
327    /**
328     * Creates the smallest range that includes the current range and a given range.
329     *
330     * @param { ScopeHelper } range - A Scope range object
331     * @returns { ScopeHelper } Returns the smallest range that includes the current range and a given range.
332     * @since 20
333     */
334    expand(range: ScopeHelper<T>): ScopeHelper<T>;
335
336    /**
337     * Creates the smallest range that includes the current range and a given value.
338     *
339     * @param { ScopeType } value - A ScopeType value
340     * @returns { ScopeHelper } Returns the smallest range that includes the current range and a given value.
341     * @since 20
342     */
343    expand(value: T): ScopeHelper<T>;
344
345    /**
346     * Checks whether a given value is within the current range.
347     *
348     * @param { ScopeType } value - A ScopeType value
349     * @returns { boolean } If the value is within the current range return true,otherwise return false.
350     * @since 20
351     */
352    contains(value: T): boolean;
353
354    /**
355     * Checks whether a given range is within the current range.
356     *
357     * @param { ScopeHelper } range - A Scope range
358     * @returns { boolean } If the current range is within the given range return true,otherwise return false.
359     * @since 20
360     */
361    contains(range: ScopeHelper<T>): boolean;
362
363    /**
364     * Clamps a given value to the current range.
365     *
366     * @param { ScopeType } value - A ScopeType value
367     * @returns { ScopeType } Returns a ScopeType object that a given value is clamped to the current range.
368     * @since 20
369     */
370    clamp(value: T): T;
371  }
372
373  class LRUCache<K, V> {
374    /**
375     * Default constructor used to create a new LruBuffer instance with the default capacity of 64.
376     *
377     * @param { number } [capacity] - Indicates the capacity to customize for the buffer.
378     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Incorrect parameter types.
379     * @syscap SystemCapability.Utils.Lang
380     * @crossplatform
381     * @atomicservice
382     * @since 20
383     */
384    constructor(capacity?: number);
385
386    /**
387     * Updates the buffer capacity to a specified capacity.
388     *
389     * @param { number } newCapacity - Indicates the new capacity to set.
390     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified.
391     * @syscap SystemCapability.Utils.Lang
392     * @crossplatform
393     * @atomicservice
394     * @since 20
395     */
396    updateCapacity(newCapacity: number): void;
397
398    /**
399     * Returns a string representation of the object.
400     *
401     * @returns { string } Returns the string representation of the object and outputs the string representation of the object.
402     * @syscap SystemCapability.Utils.Lang
403     * @crossplatform
404     * @atomicservice
405     * @since 20
406     */
407    toString(): string;
408
409    /**
410     * Obtains a list of all values in the current buffer.
411     *
412     * @type { number }
413     * @syscap SystemCapability.Utils.Lang
414     * @crossplatform
415     * @atomicservice
416     * @since 20
417     */
418    get length(): number;
419
420    /**
421     * Obtains the capacity of the current buffer.
422     *
423     * @returns { number } Returns the capacity of the current buffer.
424     * @syscap SystemCapability.Utils.Lang
425     * @crossplatform
426     * @atomicservice
427     * @since 20
428     */
429    getCapacity(): number;
430
431    /**
432     * Clears key-value pairs from the current buffer.
433     *
434     * @syscap SystemCapability.Utils.Lang
435     * @crossplatform
436     * @atomicservice
437     * @since 20
438     */
439    clear(): void;
440
441    /**
442     * Obtains the number of times createDefault(Object) returned a value.
443     *
444     * @returns { number } Returns the number of times createDefault(java.lang.Object) returned a value.
445     * @syscap SystemCapability.Utils.Lang
446     * @crossplatform
447     * @atomicservice
448     * @since 20
449     */
450    getCreateCount(): number;
451
452    /**
453     * Obtains the number of times that the queried values are not matched.
454     *
455     * @returns { number } Returns the number of times that the queried values are not matched.
456     * @syscap SystemCapability.Utils.Lang
457     * @crossplatform
458     * @atomicservice
459     * @since 20
460     */
461    getMissCount(): number;
462
463    /**
464     * Obtains the number of times that values are evicted from the buffer.
465     *
466     * @returns { number } Returns the number of times that values are evicted from the buffer.
467     * @syscap SystemCapability.Utils.Lang
468     * @crossplatform
469     * @atomicservice
470     * @since 20
471     */
472    getRemovalCount(): number;
473
474    /**
475     * Obtains the number of times that the queried values are successfully matched.
476     *
477     * @returns { number } Returns the number of times that the queried values are successfully matched.
478     * @syscap SystemCapability.Utils.Lang
479     * @crossplatform
480     * @atomicservice
481     * @since 20
482     */
483    getMatchCount(): number;
484
485    /**
486     * Obtains the number of times that values are added to the buffer.
487     *
488     * @returns { number } Returns the number of times that values are added to the buffer.
489     * @syscap SystemCapability.Utils.Lang
490     * @crossplatform
491     * @atomicservice
492     * @since 20
493     */
494    getPutCount(): number;
495
496    /**
497     * Checks whether the current buffer is empty.
498     *
499     * @returns { boolean } Returns true if the current buffer contains no value.
500     * @syscap SystemCapability.Utils.Lang
501     * @crossplatform
502     * @atomicservice
503     * @since 20
504     */
505    isEmpty(): boolean;
506
507    /**
508     * Obtains the value associated with a specified key.
509     *
510     * @param { K } key - Indicates the key to query.
511     * @returns { V | undefined } Returns the value associated with the key if the specified key is present in the buffer; returns null otherwise.
512     * @throws { BusinessError } 401 - Parameter error. Possible causes:
513     * 1.Mandatory parameters are left unspecified;
514     * 2.Incorrect parameter types.
515     * @syscap SystemCapability.Utils.Lang
516     * @crossplatform
517     * @atomicservice
518     * @since 20
519     */
520    get(key: K): V | undefined;
521
522    /**
523     * Adds a key-value pair to the buffer.
524     *
525     * @param { K } key - Indicates the key to add.
526     * @param { V } value - Indicates the value associated with the key to add.
527     * @returns { V | undefined } Returns the value associated with the added key; returns the original value if the key to add already exists, returns null otherwise.
528     * @throws { BusinessError } 401 - Parameter error. Possible causes:
529     * 1.Mandatory parameters are left unspecified;
530     * 2.Incorrect parameter types.
531     * @syscap SystemCapability.Utils.Lang
532     * @crossplatform
533     * @atomicservice
534     * @since 20
535     */
536    put(key: K, value: V): V | undefined;
537
538    /**
539     * Obtains a list of all values in the current buffer.
540     *
541     * @returns { Array<V> } Returns the list of all values in the current buffer, ordered from the most recently accessed to the least recently accessed.
542     * @syscap SystemCapability.Utils.Lang
543     * @crossplatform
544     * @atomicservice
545     * @since 20
546     */
547    values(): Array<V>;
548
549    /**
550     * Obtains a list of keys for the values in the current buffer.
551     * since 9
552     *
553     * @returns { Array<K> } Returns a list of keys ordered by access time, from the most recently accessed to the least recently accessed.
554     * @syscap SystemCapability.Utils.Lang
555     * @crossplatform
556     * @atomicservice
557     * @since 20
558     */
559    keys(): Array<K>;
560
561    /**
562     * Deletes a specified key and its associated value from the current buffer.
563     *
564     * @param { K } key - Indicates the key to delete.
565     * @returns { V | undefined } Returns an Optional object containing the deleted key-value pair; returns an empty Optional object if the key does not exist.
566     * @throws { BusinessError } 401 - Parameter error. Possible causes:
567     * 1.Mandatory parameters are left unspecified;
568     * 2.Incorrect parameter types.
569     * @syscap SystemCapability.Utils.Lang
570     * @crossplatform
571     * @atomicservice
572     * @since 20
573     */
574    remove(key: K): V | undefined;
575
576    /**
577     * Executes subsequent operations after a value is deleted.
578     *
579     * @param { boolean } isEvict - The parameter value is true if this method is called due to insufficient capacity,
580     * and the parameter value is false in other cases.
581     * @param { K } key - Indicates the deleted key.
582     * @param { V } value - Indicates the deleted value.
583     * @param { V } newValue - The parameter value is the new value associated if the put(java.lang.Object,java.lang.Object)
584     * method is called and the key to add already exists. The parameter value is null in other cases.
585     * @throws { BusinessError } 401 - Parameter error. Possible causes:
586     * 1.Mandatory parameters are left unspecified;
587     * 2.Incorrect parameter types.
588     * @syscap SystemCapability.Utils.Lang
589     * @crossplatform
590     * @atomicservice
591     * @since 20
592     */
593    afterRemoval(isEvict: boolean, key: K, value: V, newValue: V): void;
594
595    /**
596     * Checks whether the current buffer contains a specified key.
597     *
598     * @param { K } key - Indicates the key to check.
599     * @returns { boolean } Returns true if the buffer contains the specified key.
600     * @throws { BusinessError } 401 - Parameter error. Possible causes:
601     * 1.Mandatory parameters are left unspecified;
602     * 2.Incorrect parameter types.
603     * @syscap SystemCapability.Utils.Lang
604     * @crossplatform
605     * @atomicservice
606     * @since 20
607     */
608    contains(key: K): boolean;
609
610    /**
611     * Executes subsequent operations if miss to compute a value for the specific key.
612     *
613     * @param { K } key - Indicates the missed key.
614     * @returns { V | undefined } Returns the value associated with the key.
615     * @throws { BusinessError } 401 - Parameter error. Possible causes:
616     * 1.Mandatory parameters are left unspecified;
617     * 2.Incorrect parameter types.
618     * @syscap SystemCapability.Utils.Lang
619     * @crossplatform
620     * @atomicservice
621     * @since 20
622     */
623    createDefault(key: K): V | undefined;
624
625    /**
626     * Returns an array of key-value pairs of enumeratable properties of a given object.
627     *
628     * @returns { IterableIterator<[K, V]> } Returns an array of key-value pairs for the enumeratable properties of the given object itself.
629     * @syscap SystemCapability.Utils.Lang
630     * @crossplatform
631     * @atomicservice
632     * @since 20
633     */
634    entries(): IterableIterator<[K, V]>;
635
636    /**
637     * Specifies the default iterator for an object.
638     *
639     * @returns { IterableIterator<[K, V]> } Returns a two - dimensional array in the form of key - value pairs.
640     * @syscap SystemCapability.Utils.Lang
641     * @crossplatform
642     * @atomicservice
643     * @since 20
644     */
645    $_iterator(): IterableIterator<[K, V]>;
646  }
647
648  /**
649   * Defines the TextDecoder related options parameters.
650   *
651   * @interface TextDecoderOptions
652   * @syscap SystemCapability.Utils.Lang
653   * @crossplatform
654   * @atomicservice
655   * @since 20
656   */
657  interface TextDecoderOptions {
658    /**
659     * Is a fatal error displayed? The default value is false.
660     * @type { ?boolean }
661     * @syscap SystemCapability.Utils.Lang
662     * @crossplatform
663     * @atomicservice
664     * @since 20
665     */
666
667    fatal?: boolean;
668    /**
669    * Do you want to ignore BOM tags? The default value is false.
670    * @type { ?boolean }
671    * @syscap SystemCapability.Utils.Lang
672    * @crossplatform
673    * @atomicservice
674    * @since 20
675    */
676    ignoreBOM?: boolean;
677  }
678
679  /**
680   * Defines the decode with stream related options parameters.
681   *
682   * @interface DecodeToStringOptions
683   * @syscap SystemCapability.Utils.Lang
684   * @crossplatform
685   * @atomicservice
686   * @since 20
687   */
688  interface DecodeToStringOptions {
689    /**
690    * Stream option controls stream processing in decoding. The default value is false.
691    * @type { ?boolean }
692    * @syscap SystemCapability.Utils.Lang
693    * @crossplatform
694    * @atomicservice
695    * @since 20
696    */
697    stream?: boolean;
698  }
699
700  /**
701   * Provide the ability to decode binary streams into strings. The supported encoding types include: utf-8, iso-8859-2,
702   * koi8-r, macintosh, windows-1250, windows-1251, gbk, gb18030, big5, utf-16be, utf-16 le, etc.
703   *
704   * @syscap SystemCapability.Utils.Lang
705   * @crossplatform
706   * @atomicservice
707   * @since 20
708   */
709  class StringDecoder {
710    /**
711     * The StringDecoder constructor.
712     *
713     * @param { string } [encoding] - Encoding type of the input data.Default: utf8.
714     * @throws { BusinessError } 401 - Parameter error. Possible causes:
715     * 1.Mandatory parameters are left unspecified;
716     * @syscap SystemCapability.Utils.Lang
717     * @crossplatform
718     * @atomicservice
719     * @since 20
720     */
721    constructor(encoding?: string);
722
723    /**
724     * Returns a decoded string, ensuring that any incomplete multiple byte characters at the end of the Uint8Array are
725     * omitted from the returned string and stored in an internal buffer.
726     *
727     * @param { string | Uint8Array } chunk - The bytes to decode.
728     * @returns { string } Returns a decoded string.
729     * @throws { BusinessError } 401 - Parameter error. Possible causes:
730     * 1.Mandatory parameters are left unspecified;
731     * @syscap SystemCapability.Utils.Lang
732     * @crossplatform
733     * @atomicservice
734     * @since 20
735     */
736    write(chunk: string | Uint8Array): string;
737
738    /**
739     * Returns any remaining input stored in the internal buffer as a string. After end() is called,
740     * this object can be reused for new input.
741     *
742     * @param { string | Uint8Array } [chunk] - The bytes to decode.
743     * @returns { string } Returns any remaining input stored in the internal buffer as a string.
744     * @throws { BusinessError } 401 - Parameter error. Possible causes:
745     * 1.Mandatory parameters are left unspecified;
746     * @syscap SystemCapability.Utils.Lang
747     * @crossplatform
748     * @atomicservice
749     * @since 20
750     */
751    end(chunk?: string | Uint8Array): string;
752  }
753
754  /**
755   * The TextDecoder represents a text decoder that accepts a string as input,
756   * decodes it in UTF-8 format, and outputs UTF-8 byte stream.
757   *
758   * @syscap SystemCapability.Utils.Lang
759   * @crossplatform
760   * @atomicservice
761   * @since 20
762   */
763  class TextDecoder {
764    /**
765     * The textDecoder constructor.
766     *
767     * @syscap SystemCapability.Utils.Lang
768     * @crossplatform
769     * @atomicservice
770     * @since 20
771     */
772    constructor();
773
774    /**
775     * The source encoding's name, lowercased.
776     *
777     * @return { string } The string of the TextDecoder encoding.
778     * @syscap SystemCapability.Utils.Lang
779     * @crossplatform
780     * @atomicservice
781     * @since 20
782     */
783    get encoding(): string;
784
785    /**
786     * Returns `true` if error mode is "fatal", and `false` otherwise.
787     *
788     * @return { boolean } Whether to display fatal errors.
789     * @syscap SystemCapability.Utils.Lang
790     * @crossplatform
791     * @atomicservice
792     * @since 20
793     */
794    get fatal(): boolean;
795
796    /**
797     * Returns `true` if ignore BOM flag is set, and `false` otherwise.
798     *
799     * @return { boolean } Returns `true` if ignore BOM flag is set, and `false` otherwise.
800     * @syscap SystemCapability.Utils.Lang
801     * @crossplatform
802     * @atomicservice
803     * @since 20
804     */
805    get ignoreBOM(): boolean;
806
807    /**
808     * Replaces the original constructor to process arguments and return a textDecoder object.
809     *
810     * @param { string } [encoding] - Decoding format
811     * @param { TextDecoderOptions } [options] - Options
812     * @returns { TextDecoder }
813     * @syscap SystemCapability.Utils.Lang
814     * @crossplatform
815     * @atomicservice
816     * @since 20
817     */
818    static create(encoding?: string, options?: TextDecoderOptions): TextDecoder;
819
820    /**
821     * The input is decoded and a string is returned.
822     * If options.stream is set to true, any incomplete byte sequences found at the end of the input are internally
823     * buffered and will be emitted after the next call to textDecoder.decodeToString().
824     * If textDecoder.fatal is set to true, any decoding errors that occur will result in a TypeError being thrown.
825     *
826     * @param { Uint8Array } input - Decoded numbers in accordance with the format.
827     * @param { DecodeToStringOptions } [options] - The default option is set to false.
828     * @returns { string } Return decoded text
829     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Parameter verification failed;
830     * @syscap SystemCapability.Utils.Lang
831     * @crossplatform
832     * @atomicservice
833     * @since 20
834     */
835    decodeToString(input: Uint8Array, options?: DecodeToStringOptions): string;
836  }
837
838  /**
839   * Return encoded text.
840   *
841   * @interface EncodeIntoUint8ArrayInfo
842   * @syscap SystemCapability.Utils.Lang
843   * @crossplatform
844   * @atomicservice
845   * @since 20
846   */
847  interface EncodeIntoUint8ArrayInfo {
848    /**
849    * The read represents the number of characters that have been encoded.
850    * @type { int }
851    * @syscap SystemCapability.Utils.Lang
852    * @crossplatform
853    * @atomicservice
854    * @since 20
855    */
856
857    read: int;
858    /**
859    * The written represents the number of bytes occupied by the encoded characters.
860    * @type { int }
861    * @syscap SystemCapability.Utils.Lang
862    * @crossplatform
863    * @atomicservice
864    * @since 20
865    */
866    written: int;
867  }
868
869  /**
870   * The rational number is mainly to compare rational numbers and obtain the numerator and denominator.
871   *
872   * @syscap SystemCapability.Utils.Lang
873   * @crossplatform
874   * @atomicservice
875   * @since 20
876   */
877  class RationalNumber {
878    /**
879     * A constructor used to create a RationalNumber instance with a given numerator and denominator.
880     *
881     * @syscap SystemCapability.Utils.Lang
882     * @crossplatform
883     * @atomicservice
884     * @since 20
885     */
886    constructor();
887
888    /**
889     * Used to create a RationalNumber instance with a given numerator and denominator.
890     *
891     * @param { number } numerator - An integer number
892     * @param { number } denominator - An integer number
893     * @returns { RationalNumber }
894     * @throws { BusinessError } 401 - Parameter error. Possible causes:
895     * 1.Mandatory parameters are left unspecified;
896     * 2.Incorrect parameter types.
897     * @syscap SystemCapability.Utils.Lang
898     * @crossplatform
899     * @atomicservice
900     * @since 20
901     */
902    static parseRationalNumber(numerator: number, denominator: number): RationalNumber;
903
904    /**
905     * Creates a RationalNumber object based on a given string.
906     *
907     * @param { string } rationalString - String Expression of Rational Numbers
908     * @returns { RationalNumber } Returns a RationalNumber object generated based on the given string.
909     * @throws { BusinessError } 401 - The type of rationalString must be string.
910     * @syscap SystemCapability.Utils.Lang
911     * @crossplatform
912     * @atomicservice
913     * @since 20
914     */
915    static createRationalFromString(rationalString: string): RationalNumber;
916
917    /**
918     * Compares the current RationalNumber object to the given object.
919     *
920     * @param { RationalNumber } another - An object of other rational numbers
921     * @returns { number } Returns 0 or 1, or -1, depending on the comparison.
922     * @throws { BusinessError } 401 - Parameter error. Possible causes:
923     * 1.Mandatory parameters are left unspecified;
924     * 2.Incorrect parameter types.
925     * @syscap SystemCapability.Utils.Lang
926     * @crossplatform
927     * @atomicservice
928     * @since 20
929     */
930    compare(another: RationalNumber): number;
931
932    /**
933     * Compares two objects for equality.
934     *
935     * @param { Object } obj - An object
936     * @returns { boolean } Returns true if the given object is the same as the current object;
937     * Otherwise, false is returned.
938     * @syscap SystemCapability.Utils.Lang
939     * @crossplatform
940     * @atomicservice
941     * @since 20
942     */
943    equals(obj: Object): boolean;
944
945    /**
946     * Gets integer and floating-point values of a rational number object.
947     *
948     * @returns { number } Returns the integer and floating-point values of a rational number object.
949     * @syscap SystemCapability.Utils.Lang
950     * @crossplatform
951     * @atomicservice
952     * @since 12
953     */
954    valueOf(): number;
955
956    /**
957     * Get the greatest common factor of two integers.
958     *
959     * @param { number } number1 - Is an integer.
960     * @param { number } number2 - Is an integer.
961     * @returns { number } Returns the greatest common factor of two integers, integer type.
962     * @throws { BusinessError } 401 - Parameter error. Possible causes:
963     * 1.Mandatory parameters are left unspecified;
964     * 2.Incorrect parameter types.
965     * @syscap SystemCapability.Utils.Lang
966     * @crossplatform
967     * @atomicservice
968     * @since 20
969     */
970    static getCommonFactor(number1: number, number2: number): number;
971
972    /**
973     * Gets the denominator of the current object.
974     *
975     * @returns { number } Returns the denominator of the current object.
976     * @syscap SystemCapability.Utils.Lang
977     * @crossplatform
978     * @atomicservice
979     * @since 20
980     */
981    getDenominator(): number;
982
983    /**
984     * Gets the numerator of the current object.
985     *
986     * @returns { number } Returns the numerator of the current object.
987     * @syscap SystemCapability.Utils.Lang
988     * @crossplatform
989     * @atomicservice
990     * @since 20
991     */
992    getNumerator(): number;
993
994    /**
995     * Checks whether the current RationalNumber object represents an infinite value.
996     *
997     * @returns { boolean } If the denominator is not 0, true is returned. Otherwise, false is returned.
998     * @syscap SystemCapability.Utils.Lang
999     * @crossplatform
1000     * @atomicservice
1001     * @since 20
1002     */
1003    isFinite(): boolean;
1004
1005    /**
1006     * Checks whether the current RationalNumber object represents a Not-a-Number (NaN) value.
1007     *
1008     * @returns { boolean } If both the denominator and numerator are 0, true is returned. Otherwise, false is returned.
1009     * @syscap SystemCapability.Utils.Lang
1010     * @crossplatform
1011     * @atomicservice
1012     * @since 20
1013     */
1014    isNaN(): boolean;
1015
1016    /**
1017     * Checks whether the current RationalNumber object represents the value 0.
1018     *
1019     * @returns { boolean } If the value represented by the current object is 0, true is returned.
1020     * Otherwise, false is returned.
1021     * @syscap SystemCapability.Utils.Lang
1022     * @crossplatform
1023     * @atomicservice
1024     * @since 20
1025     */
1026    isZero(): boolean;
1027
1028    /**
1029     * Obtains a string representation of the current RationalNumber object.
1030     *
1031     * @returns { string } Returns a string representation of the current RationalNumber object.
1032     * @syscap SystemCapability.Utils.Lang
1033     * @crossplatform
1034     * @atomicservice
1035     * @since 20
1036     */
1037    toString(): string;
1038  }
1039
1040  /**
1041   * The TextEncoder interface represents a text encoder.
1042   * The encoder takes the byte stream as the input and outputs the String string.
1043   *
1044   * @syscap SystemCapability.Utils.Lang
1045   * @crossplatform
1046   * @atomicservice
1047   * @since 20
1048   */
1049  class TextEncoder {
1050    /**
1051     * Encoding format.
1052     *
1053     * @return { string } The string of the TextEncoder encoding.
1054     * @syscap SystemCapability.Utils.Lang
1055     * @crossplatform
1056     * @atomicservice
1057     * @since 20
1058     */
1059    get encoding(): string;
1060
1061    /**
1062     * The textEncoder constructor.
1063     *
1064     * @param { string } [encoding] - The string for encoding format.
1065     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Parameter verification failed.
1066     * @syscap SystemCapability.Utils.Lang
1067     * @crossplatform
1068     * @atomicservice
1069     * @since 20
1070     */
1071    constructor(encoding?: string);
1072
1073    /**
1074     * Create a TextEncoder object.
1075     *
1076     * @param { string } [encoding] - The string for encoding format.
1077     * @returns { TextEncoder }
1078     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Parameter verification failed.
1079     * @syscap SystemCapability.Utils.Lang
1080     * @crossplatform
1081     * @atomicservice
1082     * @since 20
1083     */
1084    static create(encoding?: string): TextEncoder;
1085
1086    /**
1087     * UTF-8 encodes the input string and returns a Uint8Array containing the encoded bytes.
1088     *
1089     * @param { string } [input] - The string to be encoded.
1090     * @returns { Uint8Array } Returns the encoded text.
1091     * @syscap SystemCapability.Utils.Lang
1092     * @crossplatform
1093     * @atomicservice
1094     * @since 20
1095     */
1096    encodeInto(input?: string): Uint8Array;
1097
1098    /**
1099     * Encode string, write the result to dest array.
1100     *
1101     * @param { string } input - The string to be encoded.
1102     * @param { Uint8Array } dest - Encoded numbers in accordance with the format
1103     * @returns { EncodeIntoUint8ArrayInfo } Return the object, where read represents
1104     * the number of characters that have been encoded, and written
1105     * represents the number of bytes occupied by the encoded characters.
1106     * @syscap SystemCapability.Utils.Lang
1107     * @crossplatform
1108     * @atomicservice
1109     * @since 20
1110     */
1111    encodeIntoUint8Array(input: string, dest: Uint8Array): EncodeIntoUint8ArrayInfo;
1112  }
1113  /**
1114   * Check the type of parameter.
1115   *
1116   * @syscap SystemCapability.Utils.Lang
1117   * @crossplatform
1118   * @atomicservice
1119   * @since 20
1120   */
1121  class types {
1122
1123    /**
1124     * Check whether the entered value is of arraybuffer or sharedarraybuffer type.
1125     *
1126     * @param { Object } value - A ArrayBuffer or SharedArrayBuffer value
1127     * @returns { boolean } Returns true if the value is a built-in ArrayBuffer or SharedArrayBuffer instance.
1128     * @syscap SystemCapability.Utils.Lang
1129     * @crossplatform
1130     * @atomicservice
1131     * @since 20
1132     */
1133    isAnyArrayBuffer(value: Object): boolean;
1134    /**
1135     * Check whether the type is included in the isAnyArrayBuffer.
1136     *
1137     * @param { Object } value - A included in the isAnyArrayBuffer value
1138     * @returns { boolean } Returns true if the value is an instance of one of the ArrayBuffer views,
1139     * such as typed array objects or DataView.
1140     * @syscap SystemCapability.Utils.Lang
1141     * @crossplatform
1142     * @atomicservice
1143     * @since 20
1144     */
1145    isArrayBufferView(value: Object): boolean;
1146    /**
1147     * Check whether the entered value is of arraybuffer type.
1148     *
1149     * @param { Object } value - A arraybuffer value
1150     * @returns { boolean } Returns true if the value is a built-in ArrayBuffer instance.
1151     * This does not include SharedArrayBuffer instances.
1152     * Usually, it is desirable to test for both; See isAnyArrayBuffer() for that.
1153     * @syscap SystemCapability.Utils.Lang
1154     * @crossplatform
1155     * @atomicservice
1156     * @since 20
1157     */
1158    isArrayBuffer(value: Object): boolean;
1159    /**
1160     * Check whether the entered value is of bigint64array array type.
1161     *
1162     * @param { Object } value - A BigInt64Array value
1163     * @returns { boolean } Returns true if the value is a BigInt64Array instance.
1164     * @syscap SystemCapability.Utils.Lang
1165     * @crossplatform
1166     * @atomicservice
1167     * @since 20
1168     */
1169    isBigInt64Array(value: Object): boolean;
1170    /**
1171     * Check whether the entered value is of biguint64array array array type.
1172     *
1173     * @param { Object } value - A BigUint64Array value
1174     * @returns { boolean } Returns true if the value is a BigUint64Array instance.
1175     * @syscap SystemCapability.Utils.Lang
1176     * @crossplatform
1177     * @atomicservice
1178     * @since 20
1179     */
1180    isBigUint64Array(value: Object): boolean;
1181    /**
1182     * Check whether the entered value is of DataView type.
1183     *
1184     * @param { Object } value - A DataView value
1185     * @returns { boolean } Returns true if the value is a built-in DataView instance.
1186     * @syscap SystemCapability.Utils.Lang
1187     * @crossplatform
1188     * @atomicservice
1189     * @since 20
1190     */
1191    isDataView(value: Object): boolean;
1192    /**
1193     * Check whether the entered value is of type date.
1194     *
1195     * @param { Object } value - A Date value
1196     * @returns { boolean } Returns true if the value is a built-in Date instance.
1197     * @syscap SystemCapability.Utils.Lang
1198     * @crossplatform
1199     * @atomicservice
1200     * @since 20
1201     */
1202    isDate(value: Object): boolean;
1203    /**
1204     * Check whether the entered value is of float32array array type.
1205     *
1206     * @param { Object } value - A Float32Array value
1207     * @returns { boolean } Returns true if the value is a built-in Float32Array instance.
1208     * @syscap SystemCapability.Utils.Lang
1209     * @crossplatform
1210     * @atomicservice
1211     * @since 20
1212     */
1213    isFloat32Array(value: Object): boolean;
1214    /**
1215     * Check whether the entered value is of float64array array type.
1216     *
1217     * @param { Object } value - A Float64Array value
1218     * @returns { boolean } Returns true if the value is a built-in Float64Array instance.
1219     * @syscap SystemCapability.Utils.Lang
1220     * @crossplatform
1221     * @atomicservice
1222     * @since 20
1223     */
1224    isFloat64Array(value: Object): boolean;
1225    /**
1226     * Check whether the entered value is of int8array array type.
1227     *
1228     * @param { Object } value - A Int8Array value
1229     * @returns { boolean } Returns true if the value is a built-in Int8Array instance.
1230     * @syscap SystemCapability.Utils.Lang
1231     * @crossplatform
1232     * @atomicservice
1233     * @since 20
1234     */
1235    isInt8Array(value: Object): boolean;
1236    /**
1237     * Check whether the entered value is the int16array type.
1238     *
1239     * @param { Object } value - A Int16Array value
1240     * @returns { boolean } Returns true if the value is a built-in Int16Array instance.
1241     * @syscap SystemCapability.Utils.Lang
1242     * @crossplatform
1243     * @atomicservice
1244     * @since 20
1245     */
1246    isInt16Array(value: Object): boolean;
1247    /**
1248     * Check whether the entered value is the int32array array type.
1249     *
1250     * @param { Object } value - A Int32Array value
1251     * @returns { boolean } Returns true if the value is a built-in Int32Array instance.
1252     * @syscap SystemCapability.Utils.Lang
1253     * @crossplatform
1254     * @atomicservice
1255     * @since 20
1256     */
1257    isInt32Array(value: Object): boolean;
1258    /**
1259     * Check whether the entered value is of map type.
1260     *
1261     * @param { Object } value - A Map value
1262     * @returns { boolean } Returns true if the value is a built-in Map instance.
1263     * @syscap SystemCapability.Utils.Lang
1264     * @crossplatform
1265     * @atomicservice
1266     * @since 20
1267     */
1268    isMap(value: Object): boolean;
1269    /**
1270     * Check whether the entered value is the iterator type of map.
1271     *
1272     * @param { Object } value - A Map iterator value
1273     * @returns { boolean } Returns true if the value is an iterator returned for a built-in Map instance.
1274     * @syscap SystemCapability.Utils.Lang
1275     * @crossplatform
1276     * @atomicservice
1277     * @since 20
1278     */
1279    isMapIterator(value: Object): boolean;
1280    /**
1281     * Check whether the value entered is of type error.
1282     *
1283     * @param { Object } value - A Error value
1284     * @returns { boolean } Returns true if the value is an instance of a built-in Error type.
1285     * @syscap SystemCapability.Utils.Lang
1286     * @crossplatform
1287     * @atomicservice
1288     * @since 20
1289     */
1290    isNativeError(value: Object): boolean;
1291    /**
1292     * Check whether the entered value is of promise type.
1293     *
1294     * @param { Object } value - A Promise value
1295     * @returns { boolean } Returns true if the value is a built-in Promise.
1296     * @syscap SystemCapability.Utils.Lang
1297     * @crossplatform
1298     * @atomicservice
1299     * @since 20
1300     */
1301    isPromise(value: Object): boolean;
1302    /**
1303     * Check whether the entered value is of type regexp.
1304     *
1305     * @param { Object } value - A regular expression object value
1306     * @returns { boolean } Returns true if the value is a regular expression object.
1307     * @syscap SystemCapability.Utils.Lang
1308     * @crossplatform
1309     * @atomicservice
1310     * @since 20
1311     */
1312    isRegExp(value: Object): boolean;
1313    /**
1314     * Check whether the entered value is of type set.
1315     *
1316     * @param { Object } value - A Set instance value
1317     * @returns { boolean } Returns true if the value is a built-in Set instance.
1318     * @syscap SystemCapability.Utils.Lang
1319     * @crossplatform
1320     * @atomicservice
1321     * @since 20
1322     */
1323    isSet(value: Object): boolean;
1324    /**
1325     * Check whether the entered value is the iterator type of set.
1326     *
1327     * @param { Object } value - A Set iterator value
1328     * @returns { boolean } Returns true if the value is an iterator returned for a built-in Set instance.
1329     * @syscap SystemCapability.Utils.Lang
1330     * @crossplatform
1331     * @atomicservice
1332     * @since 20
1333     */
1334    isSetIterator(value: Object): boolean;
1335    /**
1336     * Check whether the entered value is a type contained in typedarray.
1337     *
1338     * @param { Object } value - A TypedArray instance value
1339     * @returns { boolean } Returns true if the value is a built-in TypedArray instance.
1340     * @syscap SystemCapability.Utils.Lang
1341     * @crossplatform
1342     * @atomicservice
1343     * @since 20
1344     */
1345    isTypedArray(value: Object): boolean;
1346    /**
1347     * Check whether the entered value is the uint8array array type.
1348     *
1349     * @param { Object } value - A Uint8Array value
1350     * @returns { boolean } Returns true if the value is a built-in Uint8Array instance.
1351     * @syscap SystemCapability.Utils.Lang
1352     * @crossplatform
1353     * @atomicservice
1354     * @since 20
1355     */
1356    isUint8Array(value: Object): boolean;
1357    /**
1358     * Check whether the entered value is the uint8clapedarray array type.
1359     *
1360     * @param { Object } value - A Uint8ClampedArray value
1361     * @returns { boolean } Returns true if the value is a built-in Uint8ClampedArray instance.
1362     * @syscap SystemCapability.Utils.Lang
1363     * @crossplatform
1364     * @atomicservice
1365     * @since 20
1366     */
1367    isUint8ClampedArray(value: Object): boolean;
1368    /**
1369     * Check whether the entered value is the uint16array array array type.
1370     *
1371     * @param { Object } value - A Uint16Array value
1372     * @returns { boolean } Returns true if the value is a built-in Uint16Array instance.
1373     * @syscap SystemCapability.Utils.Lang
1374     * @crossplatform
1375     * @atomicservice
1376     * @since 20
1377     */
1378    isUint16Array(value: Object): boolean;
1379    /**
1380     * Check whether the entered value is the uint32array array type.
1381     *
1382     * @param { Object } value - A Uint32Array value
1383     * @returns { boolean } Returns true if the value is a built-in Uint32Array instance.
1384     * @syscap SystemCapability.Utils.Lang
1385     * @crossplatform
1386     * @atomicservice
1387     * @since 20
1388     */
1389    isUint32Array(value: Object): boolean;
1390    /**
1391     * Check whether the entered value is of type weakmap.
1392     *
1393     * @param { Object } value - A WeakMap value
1394     * @returns { boolean } Returns true if the value is a built-in WeakMap instance.
1395     * @syscap SystemCapability.Utils.Lang
1396     * @crossplatform
1397     * @atomicservice
1398     * @since 20
1399     */
1400    isWeakMap(value: Object): boolean;
1401    /**
1402     * Check whether the entered value is of type weakset.
1403     *
1404     * @param { Object } value - A WeakSet value
1405     * @returns { boolean } Returns true if the value is a built-in WeakSet instance.
1406     * @syscap SystemCapability.Utils.Lang
1407     * @crossplatform
1408     * @atomicservice
1409     * @since 20
1410     */
1411    isWeakSet(value: Object): boolean;
1412  }
1413
1414  /**
1415   * Get the hash code of an object.
1416   *
1417   * @param { object } [obj] - The object that need to get hash code.
1418   * @returns { number } Return a hash code of an object.
1419   * @syscap SystemCapability.Utils.Lang
1420   * @crossplatform
1421   * @atomicservice
1422   * @since 20
1423   */
1424  function getHash(obj: object): number;
1425}
1426export default util;
1427