• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 * TextDecoder support full encoding in ICU data utf-8 utf-16 iso8859 must support in all device, TextEncoder takes a
17 * stream of code points as input and emits a stream of UTF-8 bytes, and system help function.
18 * @since 7
19 * @sysCap SystemCapability.CCRuntime
20 * @devices phone, tablet
21 * @import import util from '@ohos.util';
22 * @permission N/A
23 */
24 declare namespace util {
25    /**
26     * %s: String will be used to convert all values except BigInt, Object and -0. BigInt values will be represented
27     * with an n and Objects that have no user defined toString function are inspected using util.inspect() with
28     * options { depth: 0, colors: false, compact: 3 }.
29     * %d: Number will be used to convert all values except BigInt and Symbol.
30     * %i: parseInt(value, 10) is used for all values except BigInt and Symbol.
31     * %f: parseFloat(value) is used for all values except Bigint and Symbol.
32     * %j: JSON. Replaced with the string '[Circular]' if the argument contains circular references.
33     * %o: Object. A string representation of an object with generic JavaScript object formatting.Similar to
34     * util.inspect() with options { showHidden: true, showProxy: true}. This will show the full object including
35     * non-enumerable properties and proxies.
36     * %O: Object. A string representation of an object with generic JavaScript object formatting.
37     * %O: Object. A string representation of an object with generic JavaScript object formatting.Similar to
38     * util.inspect() without options. This will show the full object not including non-enumerable properties and
39     * proxies.
40     * %c: CSS. This specifier is ignored and will skip any CSS passed in.
41     * %%: single percent sign ('%'). This does not consume an argument.Returns: <string> The formatted string.
42     * @since 7
43     * @sysCap SystemCapability.CCRuntime
44     * @param format styled string
45     * @param args data to be formatted
46     * @return Return the character string formatted in a specific format
47     */
48    function printf(format: string, ...args: Object[]): string;
49
50    /**
51     * Get the string name of the system errno.
52     * @since 7
53     * @sysCap SystemCapability.CCRuntime
54     * @param errno the error code generated by an error in the system
55     * @return return the string name of a system errno
56     */
57    function getErrorString(errno: number): string;
58
59    /**
60     * Takes an async function (or a function that returns a Promise) and returns a function following the
61     * error-first callback style.
62     * @since 7
63     * @sysCap SystemCapability.CCRuntime
64     * @param original asynchronous function
65     */
66    function callbackWrapper(original: Function): (err: Object, value: Object) => void;
67
68    /**
69     * Takes a function following the common error-first callback style, i.e taking an (err, value) =>
70     * callback as the last argument, and return a version that returns promises.
71     * @since 7
72     * @sysCap SystemCapability.CCRuntime
73     * @param original asynchronous function
74     * @return return a version that returns promises
75     */
76    function promiseWrapper(original: (err: Object, value: Object) => void): Object;
77
78    class TextDecoder {
79        /**
80         * the source encoding's name, lowercased.
81         * @since 7
82         * @sysCap SystemCapability.CCRuntime
83         */
84        readonly encoding: string;
85
86        /**
87         * Returns `true` if error mode is "fatal", and `false` otherwise.
88         * @since 7
89         * @sysCap SystemCapability.CCRuntime
90         */
91        readonly fatal: boolean;
92
93        /**
94         * Returns `true` if ignore BOM flag is set, and `false` otherwise.
95         * @since 7
96         * @sysCap SystemCapability.CCRuntime
97         */
98        readonly ignoreBOM = false;
99
100		/**
101         * the textEncoder constructor.
102         * @param 7
103         * @sysCap SystemCapability.CCRuntime
104         * @param encoding decoding format
105         */
106        constructor(
107            encoding?: string,
108            options?: { fatal?: boolean; ignoreBOM?: boolean },
109        );
110
111        /**
112         * Returns the result of running encoding's decoder.
113         * @since 7
114         * @sysCap SystemCapability.CCRuntime
115         * @param input decoded numbers in accordance with the format
116         * @return return decoded text
117         */
118        decode(input: Uint8Array, options?: { stream?: false }): string;
119    }
120
121    class TextEncoder {
122        /**
123         * Encoding format.
124         * @since 7
125         * @sysCap SystemCapability.CCRuntime
126         */
127        readonly encoding = "utf-8";
128
129		/**
130         * the textEncoder constructor.
131         * @since 7
132         * @sysCap SystemCapability.CCRuntime
133         */
134        constructor();
135
136        /**
137         * Returns the result of encoder.
138         * @since 7
139         * @sysCap SystemCapability.CCRuntime
140         * @param The string to be encoded.
141         * @return returns the encoded text.
142         */
143        encode(input?: string): Uint8Array;
144
145        /**
146         * encode string, write the result to dest array.
147         * @since 7
148         * @sysCap SystemCapability.CCRuntime
149         * @param input The string to be encoded.
150		 * @param dest decoded numbers in accordance with the format
151         * @return returns Returns the object, where read represents
152		 * the number of characters that have been encoded, and written
153		 * represents the number of bytes occupied by the encoded characters.
154         */
155        encodeInto(
156            input: string,
157            dest: Uint8Array,
158        ): { read: number; written: number };
159    }
160
161	class RationalNumber​ {
162		/**
163         * A constructor used to create a RationalNumber instance with a given numerator and denominator.
164         * @since 8
165         * @sysCap SystemCapability.CCRuntime
166         * @param numerator An integer number
167         * @param denominator An integer number
168         */
169        constructor(numerator: number, denominator: number);
170        /**
171         * Creates a RationalNumber object based on a given string.
172         * @since 8
173         * @sysCap SystemCapability.CCRuntime
174         * @param String Expression of Rational Numbers
175         * @return Returns a RationalNumber object generated based on the given string.
176         */
177		static createRationalFromString​(rationalString: string): RationalNumber​;
178        /**
179         * Compares the current RationalNumber object to the given object.
180         * @since 8
181         * @sysCap SystemCapability.CCRuntime
182         * @param An object of other rational numbers
183         * @return Returns 0 or 1, or -1, depending on the comparison.
184         */
185        compareTo​(another :RationalNumber): number;
186        /**
187         * Compares two objects for equality.
188         * @since 8
189         * @sysCap SystemCapability.CCRuntime
190         * @param An object
191         * @return Returns true if the given object is the same as the current object; Otherwise, false is returned.
192         */
193		equals​(obj: Object): boolean;
194		/**
195         * Gets integer and floating-point values of a rational number object.
196         * @since 8
197         * @sysCap SystemCapability.CCRuntime
198         * @return Returns the integer and floating-point values of a rational number object.
199         */
200        value(): number;
201        /**
202         * Get the greatest common divisor of two integers.
203         * @since 8
204         * @sysCap SystemCapability.CCRuntime
205         * @param number1 is an integer.
206         * @param number2 is an integer.
207         * @return Returns the greatest common divisor of two integers, integer type.
208         */
209		static getCommonDivisor​(number1: number, number2: number): number;
210        /**
211         * Gets the denominator of the current object.
212         * @since 8
213         * @sysCap SystemCapability.CCRuntime
214         * @return Returns the denominator of the current object.
215         */
216        getDenominator​(): number;
217        /**
218         * Gets the numerator​ of the current object.
219         * @since 8
220         * @sysCap SystemCapability.CCRuntime
221         * @return Returns the numerator​ of the current object.
222         */
223		getNumerator​(): number;
224        /**
225         * Checks whether the current RationalNumber object represents an infinite value.
226         * @since 8
227         * @sysCap SystemCapability.CCRuntime
228         * @return If the denominator is not 0, true is returned. Otherwise, false is returned.
229         */
230        isFinite​() : boolean;
231        /**
232         * Checks whether the current RationalNumber object represents a Not-a-Number (NaN) value.
233         * @since 8
234         * @sysCap SystemCapability.CCRuntime
235         * @return If both the denominator and numerator are 0, true is returned. Otherwise, false is returned.
236         */
237		isNaN​(): boolean;
238        /**
239         * Checks whether the current RationalNumber object represents the value 0.
240         * @since 8
241         * @sysCap SystemCapability.CCRuntime
242         * @return If the value represented by the current object is 0, true is returned. Otherwise, false is returned.
243         */
244        isZero​(): boolean;
245        /**
246         * Obtains a string representation of the current RationalNumber object.
247         * @since 8
248         * @sysCap SystemCapability.CCRuntime
249         * @return Returns a string representation of the current RationalNumber object.
250         */
251        toString​(): string;
252    }
253
254	class LruBuffer {
255		/**
256         * Default constructor used to create a new LruBuffer instance with the default capacity of 64.
257         * @since 8
258         * @sysCap SystemCapability.CCRuntime
259         * @param capacity 	Indicates the capacity to customize for the buffer.
260         */
261        constructor(capacity?:number);
262        /**
263         * Updates the buffer capacity to a specified capacity.
264         * @since 8
265         * @sysCap SystemCapability.CCRuntime
266         * @param newCapacity Indicates the new capacity to set.
267         */
268		updateCapacity(newCapacity: number):void
269        /**
270         *Returns a string representation of the object.
271         * @since 8
272         * @sysCap SystemCapability.CCRuntime
273         * @return Returns the string representation of the object and outputs the string representation of the object.
274         */
275        toString():string
276        /**
277         * Obtains a list of all values in the current buffer.
278         * @since 8
279         * @sysCap SystemCapability.CCRuntime
280         * @return Returns the total number of values in the current buffer.
281         */
282		size():number
283        /**
284         * Obtains the capacity of the current buffer.
285         * @since 8
286         * @sysCap SystemCapability.CCRuntime
287         * @return Returns the capacity of the current buffer.
288         */
289        capacity(): number;
290        /**
291         * Clears key-value pairs from the current buffer.
292         * @since 8
293         * @sysCap SystemCapability.CCRuntime
294         */
295		clear(): void;
296        /**
297         * Obtains the number of times createDefault(Object) returned a value.
298         * @since 8
299         * @sysCap SystemCapability.CCRuntime
300         * @return Returns the number of times createDefault(java.lang.Object) returned a value.
301         */
302        getCreateCount(): number;
303        /**
304         * Obtains the number of times that the queried values are not matched.
305         * @since 8
306         * @sysCap SystemCapability.CCRuntime
307         * @return Returns the number of times that the queried values are not matched.
308         */
309		getMissCount(): number;
310        /**
311         * Obtains the number of times that values are evicted from the buffer.
312         * @since 8
313         * @sysCap SystemCapability.CCRuntime
314         * @return Returns the number of times that values are evicted from the buffer.
315         */
316        getRemovalCount(): number;
317        /**
318         * Obtains the number of times that the queried values are successfully matched.
319         * @since 8
320         * @sysCap SystemCapability.CCRuntime
321         * @return Returns the number of times that the queried values are successfully matched.
322         */
323		getMatchCount(): number;
324        /**
325         * Obtains the number of times that values are added to the buffer.
326         * @since 8
327         * @sysCap SystemCapability.CCRuntime
328         * @return Returns the number of times that values are added to the buffer.
329         */
330        getPutCount(): number;
331        /**
332         * Checks whether the current buffer is empty.
333         * @since 8
334         * @sysCap SystemCapability.CCRuntime
335         * @return Returns true if the current buffer contains no value.
336         */
337		isEmpty​(): boolean;
338        /**
339         * Obtains the value associated with a specified key.
340         * @since 8
341         * @sysCap SystemCapability.CCRuntime
342         * @param key Indicates the key to query.
343         * @return Returns the value associated with the key if the specified key is present in the buffer; returns null otherwise.
344         */
345        get(key: K): V | undefined;
346        /**
347         * Adds a key-value pair to the buffer.
348         * @since 8
349         * @sysCap SystemCapability.CCRuntime
350         * @param key Indicates the key to add.
351         * @param value Indicates the value associated with the key to add.
352         * @return Returns the value associated with the added key; returns the original value if the key to add already exists.
353         */
354		put(key: K, value: V): V;
355        /**
356         * Obtains a list of all values in the current buffer.
357         * @since 8
358         * @sysCap SystemCapability.CCRuntime
359         * @return Returns the list of all values in the current buffer in ascending order, from the most recently accessed to least recently accessed.
360         */
361        values(): V[];
362        /**
363         * Obtains a list of keys for the values in the current buffer.
364         * @since 8
365         * @sysCap SystemCapability.CCRuntime
366         * @return Returns a list of keys sorted from most recently accessed to least recently accessed.
367         */
368		keys​(): K[];
369        /**
370         * Deletes a specified key and its associated value from the current buffer.
371         * @since 8
372         * @sysCap SystemCapability.CCRuntime
373         * @param key key
374         * @return Returns an Optional object containing the deleted key-value pair; returns an empty Optional object if the key does not exist.
375         */
376        remove(key: K): V | undefined;
377        /**
378         * Executes subsequent operations after a value is deleted.
379         * @since 8
380         * @sysCap SystemCapability.CCRuntime
381         * @param isEvict The parameter value is true if this method is called due to insufficient capacity, and the parameter value is false in other cases.
382         * @param key Indicates the deleted key.
383         * @param value Indicates the deleted value.
384         * @param newValue 	The parameter value is the new value associated if the put(java.lang.Object,java.lang.Object) method is called and the key to add already exists. The parameter value is null in other cases.
385         */
386		afterRemoval(isEvict: boolean, key: K, value: V, newValue: V): void;
387        /**
388         * Checks whether the current buffer contains a specified key.
389         * @since 8
390         * @sysCap SystemCapability.CCRuntime
391         * @param key Indicates the key to check.
392         * @return Returns true if the buffer contains the specified key.
393         */
394        contains​(key: K): boolean;
395        /**
396         * Executes subsequent operations if miss to compute a value for the specific key.
397         * @since 8
398         * @sysCap SystemCapability.CCRuntime
399         * @param key Indicates the missed key.
400         * @return Returns the value associated with the key.
401         */
402		createDefault​(key: K): V;
403        /**
404         * Returns an array of key-value pairs of enumeratable properties of a given object.
405         * @since 8
406         * @sysCap SystemCapability.CCRuntime
407         * @return Returns an array of key-value pairs for the enumeratable properties of the given object itself.
408         */
409        entries(): IterableIterator<[K, V]>;
410        /**
411         * Specifies the default iterator for an object.
412         * @since 8
413         * @sysCap SystemCapability.CCRuntime
414         * @return Returns a two - dimensional array in the form of key - value pairs.
415         */
416        [Symbol.iterator](): IterableIterator<[K, V]>;
417    }
418	interface ScopeComparable {
419        /* The comparison function is used by the scope. */
420        compareTo(other: ScopeComparable): boolean;
421    }
422
423	type ScopeType = ScopeComparable | number;
424
425	class Scope{
426        /**
427         * A constructor used to create a Scope instance with the lower and upper bounds specified.
428         * @since 8
429         * @sysCap SystemCapability.CCRuntime
430         * @param lowerObj A ScopeType value
431         * @param upperObj A ScopeType value
432         */
433        constructor(lowerObj: ScopeType, upperObj: ScopeType);
434        /**
435         * Obtains a string representation of the current range.
436         * @since 8
437         * @sysCap SystemCapability.CCRuntime
438         * @return Returns a string representation of the current range object.
439         */
440		toString​(): string;
441        /**
442         * Returns the intersection of a given range and the current range.
443         * @since 8
444         * @sysCap SystemCapability.CCRuntime
445         * @param range A Scope range object
446         * @return Returns the intersection of a given range and the current range.
447         */
448        intersect(range: Scope): Scope;
449        /**
450         * Returns the intersection of the current range and the range specified by the given lower and upper bounds.
451         * @since 8
452         * @sysCap SystemCapability.CCRuntime
453         * @param lowerObj A ScopeType value
454         * @param upperObj A ScopeType value
455         * @return Returns the intersection of the current range and the range specified by the given lower and upper bounds.
456         */
457		intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope;
458        /**
459         * Obtains the upper bound of the current range.
460         * @since 8
461         * @sysCap SystemCapability.CCRuntime
462         * @return Returns the upper bound of the current range.
463         */
464        getUpper(): ScopeType;
465        /**
466         * Obtains the lower bound of the current range.
467         * @since 8
468         * @sysCap SystemCapability.CCRuntime
469         * @return Returns the lower bound of the current range.
470         */
471		getLower(): ScopeType;
472        /**
473         * Creates the smallest range that includes the current range and the given lower and upper bounds.
474         * @since 8
475         * @sysCap SystemCapability.CCRuntime
476         * @param lowerObj A ScopeType value
477         * @param upperObj A ScopeType value
478         * @return Returns the smallest range that includes the current range and the given lower and upper bounds.
479         */
480        expand(lowerObj: ScopeType, upperObj: ScopeType): Scope;
481        /**
482         * Creates the smallest range that includes the current range and a given range.
483         * @since 8
484         * @sysCap SystemCapability.CCRuntime
485         * @param range A Scope range object
486         * @return Returns the smallest range that includes the current range and a given range.
487         */
488		expand(range: Scope): Scope;
489        /**
490         * Creates the smallest range that includes the current range and a given value.
491         * @since 8
492         * @sysCap SystemCapability.CCRuntime
493         * @param value A ScopeType value
494         * @return Returns the smallest range that includes the current range and a given value.
495         */
496        expand(value: ScopeType): Scope;
497        /**
498         * Checks whether a given value is within the current range.
499         * @since 8
500         * @sysCap SystemCapability.CCRuntime
501         * @param range A ScopeType range
502         * @return If the value is within the current range return true,oherwise return false.
503         */
504		contains(value: ScopeType): boolean;
505        /**
506         * Checks whether a given range is within the current range.
507         * @since 8
508         * @sysCap SystemCapability.CCRuntime
509         * @param value A Scope value
510         * @return If the current range is within the given range return true,oherwise return false.
511         */
512        contains(range: Scope): boolean;
513        /**
514         * Clamps a given value to the current range.
515         * @since 8
516         * @sysCap SystemCapability.CCRuntime
517         * @param value A ScopeType value
518         * @return Returns a ScopeType object that a given value is clamped to the current range..
519         */
520        clamp(value: ScopeType): ScopeType;
521    }
522
523	class Base64{
524        /**
525         * Constructor for creating base64 encoding and decoding
526         * @since 8
527         * @sysCap SystemCapability.CCRuntime
528         * @param No input parameter is required.
529         * @return No return value.
530         */
531		constructor();
532        /**
533         * Encodes all bytes from the specified u8 array into a newly-allocated u8 array using the Base64 encoding scheme.
534         * @since 8
535         * @sysCap SystemCapability.CCRuntime
536		 * @param value A Uint8Array value
537         * @return Return the encoded new Uint8Array.
538         */
539		encode(src: Uint8Array): Uint8Array;
540        /**
541         * Encodes the specified byte array into a String using the Base64 encoding scheme.
542         * @since 8
543         * @sysCap SystemCapability.CCRuntime
544		 * @param value A Uint8Array value
545         * @return Return the encoded string.
546         */
547		encodeToString(src: Uint8Array): string;
548        /**
549         * Decodes a Base64 encoded String or input u8 array into a newly-allocated u8 array using the Base64 encoding scheme.
550         * @since 8
551         * @sysCap SystemCapability.CCRuntime
552		 * @param value A Uint8Array value or value A string value
553         * @return Return the decoded Uint8Array.
554         */
555		decode(src: Uint8Array | string): Uint8Array;
556        /**
557         * Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme.
558         * @since 8
559         * @sysCap SystemCapability.CCRuntime
560		 * @param value A Uint8Array value
561         * @return Return the encodes asynchronous new Uint8Array.
562         */
563		encodeAsync(src: Uint8Array): Promise<Uint8Array>;
564        /**
565         * Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme.
566         * @since 8
567         * @sysCap SystemCapability.CCRuntime
568		 * @param value A Uint8Array value
569         * @return Returns the encoded asynchronous string.
570         */
571		 encodeToStringAsync(src: Uint8Array): Promise<string>;
572        /**
573         * Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array.
574         * @since 8
575         * @sysCap SystemCapability.CCRuntime
576		 * @param value A Uint8Array value or value A string value
577         * @return Return the decoded asynchronous Uint8Array.
578         */
579		decodeAsync(src: Uint8Array | string): Promise<Uint8Array>;
580	}
581}
582export default util;