• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# js_util_module Subsystems / components
2
3-   [Introduction](#Introduction)
4-   [Directory](#Directory)
5-   [Description](#Description)
6    -   [Interface description](#Interface description)
7    -   [Instruction for use](#Instruction for use)
8
9-   [Related warehouse](#Related warehouse)
10
11## Introduction
12The interface of util is used for character Textencoder, TextDecoder and HelpFunction module.The TextEncoder represents a text encoder that accepts a string as input, encodes it in UTF-8 format, and outputs UTF-8 byte stream. The TextDecoder interface represents a text decoder. The decoder takes the byte stream as the input and outputs the String string. HelpFunction is mainly used to callback and promise functions, write and output error codes, and format class strings.
13Encodes all bytes from the specified u8 array into a newly-allocated u8 array using the Base64 encoding scheme or Encodes the specified byte array into a String using the Base64 encoding scheme.Decodes a Base64 encoded String or input u8 array into a newly-allocated u8 array using the Base64 encoding scheme.The rational number is mainly to compare rational numbers and obtain the numerator and denominator.The LruBuffer algorithm replaces the least used data with new data when the buffer space is insufficient. The algorithm derives from the need to access resources: recently accessed data can be Will visit again in the near future. The least accessed data is the least valuable data that should be kicked out of the cache space. The Scope interface is used to describe the valid range of a field. The constructor for the Scope instance is used to create objects with specified lower and upper bounds and require that these objects be comparable.
14## 目录
15
16```
17base/compileruntime/js_util_module/
18├── Class:TextEncoder                   # TextEncoder class
19│   ├──  new TextEncoder()              # create textencoder object
20│   ├──  encode()                       # encode method
21│   ├──  encoding                       # encoding property
22│   └──  encodeInto()                   # encodeInto method
23├── Class:TextDecoder                   # TextDecoder class
24│   ├──  new TextDecoder()              # create TextDecoder object
25│   ├──  decode()                       # decode method
26│   ├──  encoding                       # encoding property
27│   ├──  fatal                          # fatal property
28│   └──  ignoreBOM                      # ignoreBOM property
29├── printf()                            # printf method
30├── getErrorString()                    # getErrorString method
31├── callbackWrapper()                   # callbackWrapper method
32├── promiseWrapper()                    # promiseWrapper method
33├── Class:Base64                        # Base64 class
34│   ├──  new Base64()                   # create Base64 object
35│   ├──  encodeSync()                   # encodeSync method
36│   ├──  encodeToStringSync()           # encodeToStringSync method
37│   ├──  decodeSync()                   # decodeSync method
38│   ├──  encode()                       # encode method
39│   ├──  encodeToString()               # encodeToString method
40│   └──  decode()                       # decode method
41├── Class:RationalNumber                # RationalNumber class
42│   ├──  new RationalNumber()           # create RationalNumber object
43│   ├──  createRationalFromString()     # creatRationalFromString method
44│   ├──  compareTo()                    # compareTo method
45│   ├──  equals()                       # equals method
46│   ├──  valueOf()                      # valueOf method
47│   ├──  getCommonDivisor()             # getCommonDivisor method
48│   ├──  getDenominator()               # getDenominator method
49│   ├──  getNumerator()                 # getNumerator method
50│   ├──  isFinite()                     # isFinite method
51│   ├──  isNaN()                        # isNaN method
52│   ├──  isZero()                       # isZero method
53│   └──  toString()                     # toString method
54├── Class:LruBuffer                     # LruBuffer class
55│   ├──  new LruBuffer()                # create RationalNumber object
56│   ├──  updateCapacity()               # updateCapacity method
57│   ├──  toString()                     # toString method
58│   ├──  values()                       # values method
59│   ├──  length                         # attribute of length
60│   ├──  getCapacity()                  # getCapacity method
61│   ├──  clear()                        # clear method
62│   ├──  getCreateCount                 # getCreateCount method
63│   ├──  getMissCount()                 # getMissCount method
64│   ├──  getRemovalCount()              # getRemovalCount method
65│   ├──  getMatchCount()                # getMatchCount method
66│   ├──  getPutCount()                  # getPutCount method
67│   ├──  isEmpty()                      # isEmpty method
68│   ├──  get()                          # get method
69│   ├──  put()                          # put method
70│   ├──  keys()                         # keys method
71│   ├──  remove()                       # remove method
72│   ├──  afterRemoval()                 # afterRemoval method
73│   ├──  contains()                     # contains method
74│   ├──  createDefault()                # createDefault method
75│   ├──  entries()                      # entries method
76│   └──  [Symbol.iterator]()            # Symboliterator method
77├── Class:Scope                         # Scope class
78|   ├── constructor()                   # create Scope object
79|   ├── toString()                      # toString method
80|   ├── intersect()                     # intersect method
81|   ├── intersect()                     # intersect method
82|   ├── getUpper()                      # getUpper method
83|   ├── getLower()                      # getLower method
84|   ├── expand()                        # expand method
85|   ├── expand()                        # expand method
86|   ├── expand()                        # expand method
87|   ├── contains()                      # contains method
88|   ├── contains()                      # contains method
89|   └── clamp()                         # clamp method
90└── Class:Types                         # Types class
91    ├── isAnyArrayBuffer()              # isAnyArrayBuffer method
92    ├── isArrayBufferView()             # isArrayBufferView method
93    ├── isArgumentsObject()             # isArgumentsObject method
94    ├── isArrayBuffer()                 # isArrayBuffer method
95    ├── isAsyncFunction()               # isAsyncFunction method
96    ├── isBigInt64Array()               # isBigInt64Array method
97    ├── isBigUint64Array()              # isBigUint64Array method
98    ├── isBooleanObject()               # isBooleanObject method
99    ├── isBoxedPrimitive()              # isBoxedPrimitive method
100    ├── isDataView()                    # isDataView method
101    ├── isDate()                        # isDate method
102    ├── isExternal()                    # isExternal method
103    ├── isFloat32Array()                # isFloat32Arraymethod
104    ├── isFloat64Array()                # isFloat64Array method
105    ├── isGeneratorFunction()           # isGeneratorFunction method
106    ├── isGeneratorObject()             # isGeneratorObject method
107    ├── isInt8Array()                   # isInt8Array method
108    ├── isInt16Array()                  # isInt16Array method
109    ├── isInt32Array()                  # isInt32Array method
110    ├── isMap()                         # isMap method
111    ├── isMapIterator()                 # isMapIterator method
112    ├── isModuleNamespaceObject()       # isModuleNamespaceObject method
113    ├── isNativeError()                 # isNativeError method
114    ├── isNumberObject()                # isNumberObject method
115    ├── isPromise()                     # isPromise method
116    ├── isProxy()                       # isProxy method
117    ├── isRegExp()                      # isRegExp method
118    ├── isSet()                         # isSet method
119    ├── isSetIterator()                 # isSetIterator method
120    ├── isSharedArrayBuffer()           # isSharedArrayBuffer method
121    ├── isStringObject()                # isStringObject method
122    ├── isSymbolObject()                # isSymbolObject method
123    ├── isTypedArray()                  # isTypedArray method
124    ├── isUint8Array()                  # isUint8Array method
125    ├── isUint8ClampedArray()           # isUint8ClampedArray method
126    ├── isUint16Array()                 # isUint16Array method
127    ├── isUint32Array()                 # isUint32Array method
128    ├── isWeakMap()                     # isWeakMap method
129    └── isWeakSet()                     # isWeakSet method
130```
131
132## Description
133
134### Interface description
135| Interface name | Description |
136| -------- | -------- |
137| readonly encoding : string | In the TextEncoder module, get the encoding format, only UTF-8 is supported. |
138| encode(input : string) : Uint8Array | Input string string, encode and output UTF-8 byte stream. |
139| encodeInto(input : string, dest : Uint8Array) : {read : number, written : number} | Enter the string string, dest represents the storage location after encoding, and returns an object, read represents the number of characters that have been encoded,and written represents the size of bytes occupied by the encoded characters. |
140| constructor(encoding? : string, options? : {fatal? : boolean, ignoreBOM? : boolean}) | Constructor, the first parameter encoding indicates the format of decoding.The second parameter represents some attributes.Fatal in the attribute indicates whether an exception is thrown, and ignoreBOM indicates whether to ignore the bom flag. |
141| readonly encoding : string | In the TextDecoder module, get the set decoding format. |
142| readonly fatal : boolean | Get the setting that throws the exception. |
143| readonly ignoreBOM : boolean | Get whether to ignore the setting of the bom flag. |
144| decode(input : Uint8Array, options?: { stream?: false }) : string | Input the data to be decoded, and solve the corresponding string character string.The first parameter input represents the data to be decoded, and the second parameter options represents a bool flag, which means that additional data will be followed. The default is false. |
145| encodeSync(src: Uint8Array): Uint8Array; | Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. |
146| encodeToStringSync(src: Uint8Array): string; | Encodes the specified byte array as a String using the Base64 encoding scheme. |
147| decodeSync(src: Uint8Array \| string): Uint8Array; | Decodes the Base64-encoded string or input u8 array into the newly allocated u8 array using the Base64 encoding scheme. |
148| encode(src: Uint8Array): Promise\<Uint8Array\>; | Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. |
149| encodeToString(src: Uint8Array): Promise\<string\>; | Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. |
150| decode(src: Uint8Array \| string): Promise\<Uint8Array\>; | Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. |
151| static createRationalFromString(rationalString: string): RationalNumber | Create a RationalNumber object based on the given string. |
152| compareTo(another: RationalNumber): number | Compare the current RationalNumber object with the given object. |
153| equals(obj: object): number | Check if the given object is the same as the current RationalNumber object.|
154| valueOf(): number | Take the current RationalNumber object to an integer value or a floating point value. |
155| static getCommonDivisor(number1: number, number2: number,): number | Obtain the greatest common divisor of two specified numbers. |
156| getDenominator(): number | Get the denominator of the current RationalNumber object. |
157| getNumerator(): number | Get the numerator of the current RationalNumber object. |
158| isFinite(): boolean | Check that the current RationalNumber object is limited. |
159| isNaN(): boolean | Check whether the current RationalNumber object represents a non-number (NaN) value. |
160| isZero(): boolean | Check whether the current RationalNumber object represents a zero value. |
161| toString(): string | Get the string representation of the current RationalNumber object. |
162| constructor(capacity?: number) | The Create Default constructor is used to create a new LruBuffer instance with a default capacity of 64. |
163| updateCapacity(newCapacity: number): void | Updates the buffer capacity to the specified capacity. This exception is thrown if newCapacity is less than or equal to 0. |
164| toString(): string | Returns the string representation of the object and outputs the string representation of the object. |
165| values(): V[ ] | Gets a list of all values in the current buffer, and the output returns a list of all values in the current buffer in ascending order, from most recently accessed to least recently accessed. |
166| length: number | represents the total number of values in the current buffer. The output returns the total number of values in the current buffer. |
167| getCapacity(): number | Gets the capacity of the current buffer. The output returns the capacity of the current buffer. |
168| clear(): void | The key value pairs are cleared from the current buffer, after the key value is cleared, the afterRemoval () method is invoked to perform subsequent operations in turn. |
169| getCreateCount(): number | Get the number of times the returned value of createdefault(), and output the number of times the returned value of createdefault(). |
170| getMissCount(): number | Get the number of times the query value does not match, and output the number of times the query value does not match. |
171| getRemovalCount(): number | Gets the number of evictions from the buffer, and outputs the number of evictions from the buffer. |
172| getMatchCount​(): number | Obtain the number of successful matching of query values, and output the number of successful matching of query values. |
173| getPutCount(): number | Gets the number of times the value was added to the buffer, and the output returns the number of times the value was added to the buffer. |
174| isEmpty(): boolean | Checks whether the current buffer is empty and returns true if the current buffer does not contain any values. |
175| get(key: K):V \| undefined | Indicates the key to query. If the specified key exists in the buffer, the value associated with the key will be returned; Otherwise, undefined is returned. |
176| put(key: K, value: V): V | Adding the key value pair to the buffer and outputting the value associated with the added key; If the key to be added already exists, the original value is returned. If the key or value is empty, this exception is thrown. |
177| keys(): K[ ] | Get the key list of the value in the current buffer, and the output returns the key list sorted from the most recent access to the least recent access. |
178| remove​(key: K):V \| undefined | Deletes the specified key and its associated value from the current buffer. |
179| afterRemoval(isEvict: boolean, key: K, value: V, newValue: V): void | Perform subsequent operations after deleting the value. |
180| contains(key: K): boolean | Checks whether the current buffer contains the specified key, and returns true if the buffer contains the specified key. |
181| createDefault(key: K): V | If the value of a specific key is not calculated, subsequent operations are performed. The parameter represents the missing key, and the output returns the value associated with the key. |
182| entries(): [K,V] | Allows you to iterate over all key value pairs contained in this object. The keys and values of each pair are objects. |
183| \[Symbol.iterator\](): [K,V]| Returns a two-dimensional array in the form of key value pairs. |
184| constructor(lowerObj: ScopeType, upperObj: ScopeType) | Creates and returns a Scope object that creates a constructor for a scope instance that specifies a lower and upper bound. |
185| toString():string | The stringification method returns a  string representation that contains the current range. |
186| intersect(range: Scope): Scope | Gets the intersection of the given range and the current range. |
187| intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope | Gets the intersection of the current range with a given lower and upper bound range. |
188| getUpper(): ScopeType | Gets the upper bound of the current scope. |
189| getLower(): ScopeType | Gets the lower bound of the current scope. |
190| expand(lowerObj: ScopeType, upperObj:  ScopeType): Scope | Creates and returns a union that includes the current range and a given lower and upper bound. |
191| expand(range: Scope): Scope | Creates and returns a union that includes the current range and the given range. |
192| expand(value: ScopeType): Scope | Creates and returns a union that includes the current range and the given value. |
193| contains(value: ScopeType): boolean | Checks whether the given value is included in the current range. |
194| contains(range: Scope): boolean | Checks whether the given range is within the current range. |
195| clamp(value: ScopeType): ScopeType | Clips the specified value to the current range. |
196| function printf(format: string, ...args: Object[]): string | The util.format() method returns a formatted string using the first argument as a printf-like format string which can contain zero or more format specifiers. |
197| function getErrorString(errno: number): string |  The geterrorstring () method uses a system error number as a parameter to return system error information. |
198| function callbackWrapper(original: Function): (err: Object, value: Object) => void | Takes an async function (or a function that returns a Promise) and returns a function following the error-first callback style, i.e. taking an (err, value) => ... callback as the last argument. In the callback, the first argument will be the rejection reason (or null if the Promise resolved), and the second argument will be the resolved value. |
199| function promiseWrapper(original: (err: Object, value: Object) => void): Object | Takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises. |
200| isAnyArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer or sharedarraybuffer type. |
201| isArrayBufferView(value: Object): boolean | Check whether the entered value is napi_ int8_ array or napi_ uint8_ array or naPi_ uint8_ clamped_ array or naPi_ int16_ array or naPi_ uint16_ array or napi_ int32_ array or napi_ uint32_ array or napi_ float32_ array or napi_ float64_ array array or DataView type. |
202| isArgumentsObject(value: Object): boolean | Check whether the entered value is an arguments object type. |
203| isArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer type. |
204| isAsyncFunction(value: Object): boolean | Check whether the value entered is an asynchronous function type. |
205| isBigInt64Array(value: Object): boolean | Check whether the entered value is of bigint64array array type. |
206| isBigUint64Array(value: Object): boolean | Check whether the entered value is of biguint64array array array type. |
207| isBooleanObject(value: Object): boolean | Check whether the entered value is a Boolean object type. |
208| isBoxedPrimitive(value: Object): boolean | Check whether the entered value is a Boolean or number or string or symbol object type. |
209| isDataView(value: Object): boolean | Check whether the entered value is of DataView type. |
210| isDate(value: Object): boolean | Check whether the entered value is of type date. |
211| isExternal(value: Object): boolean | Check whether the entered value is a native external value type. |
212| isFloat32Array(value: Object): boolean | Check whether the entered value is of float32array array type. |
213| isFloat64Array(value: Object): boolean | Check whether the entered value is of float64array array type. |
214| isGeneratorFunction(value: Object): boolean | Check whether the input value is a generator function type. |
215| isGeneratorObject(value: Object): boolean | Check whether the entered value is a generator object type. |
216| isInt8Array(value: Object): boolean | Check whether the entered value is of int8array array type. |
217| isInt16Array(value: Object): boolean | Check whether the entered value is the int16array type. |
218| isInt32Array(value: Object): boolean | Check whether the entered value is the int32array array type. |
219| isMap(value: Object): boolean | Check whether the entered value is of map type. |
220| isMapIterator(value: Object): boolean | Check whether the entered value is the iterator type of map. |
221| isModuleNamespaceObject(value: Object): boolean | Check whether the entered value is the module namespace object object type. |
222| isNativeError(value: Object): boolean | Check whether the value entered is of type error. |
223| isNumberObject(value: Object): boolean | Check whether the entered value is of the number object type. |
224| isPromise(value: Object): boolean | Check whether the entered value is of promise type. |
225| isProxy(value: Object): boolean | Check whether the value entered is of proxy type. |
226| isRegExp(value: Object): boolean | Check whether the entered value is of type regexp. |
227| isSet(value: Object): boolean | Check whether the entered value is of type set. |
228| isSetIterator(value: Object): boolean | Check whether the entered value is the iterator type of set. |
229| isSharedArrayBuffer(value: Object): boolean | Check whether the entered value is of type sharedarraybuffer. |
230| isStringObject(value: Object): boolean | Check whether the entered value is a string object type. |
231| isSymbolObject(value: Object): boolean | Check whether the entered value is a symbol object type. |
232| isTypedArray(value: Object): boolean | Check whether the entered value is a type contained in typedarray. |
233| isUint8Array(value: Object): boolean | Check whether the entered value is the uint8array array type. |
234| isUint8ClampedArray(value: Object): boolean | Check whether the entered value is the uint8clapedarray array type. |
235| isUint16Array(value: Object): boolean | Check whether the entered value is the uint16array array array type. |
236| isUint32Array(value: Object): boolean | Check whether the entered value is the uint32array array type. |
237| isWeakMap(value: Object): boolean | Check whether the entered value is of type weakmap. |
238| isWeakSet(value: Object): boolean | Check whether the entered value is of type weakset. |
239
240Each specifier in printf is replaced with a converted value from the corresponding parameter. Supported specifiers are:
241| Stylized character | Style requirements |
242| -------- | -------- |
243|    %s:  | String will be used to convert all values except BigInt, Object and -0. |
244|    %d:  | Number will be used to convert all values except BigInt and Symbol. |
245|    %i:  | parseInt(value, 10) is used for all values except BigInt and Symbol. |
246|    %f:  | parseFloat(value) is used for all values expect Symbol. |
247|    %j:  | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
248|    %o:  | Object. A string representation of an object with generic JavaScript object formatting. Similar to util.inspect() with options { showHidden: true, showProxy: true }. This will show the full object including non-enumerable properties and proxies. |
249|    %O:  | Object. A string representation of an object with generic JavaScript object formatting. Similar to util.inspect() without options. This will show the full object not including non-enumerable properties and proxies. |
250|    %c:  | CSS. This specifier is ignored and will skip any CSS passed in. |
251|    %%:  | single percent sign ('%'). This does not consume an argument. |
252
253### Instruction for use
254
255
256The use methods of each interface are as follows:
257
2581.readonly encoding()
259
260```
261import util from '@ohos.util'
262var textEncoder = new util.TextEncoder();
263var getEncoding = textEncoder.encoding();
264```
2652.encode()
266```
267import util from '@ohos.util'
268var textEncoder = new util.TextEncoder();
269var result = textEncoder.encode('abc');
270```
2713.encodeInto()
272```
273import util from '@ohos.util'
274var textEncoder = new util.TextEncoder();
275var obj = textEncoder.encodeInto('abc', dest);
276```
2774.textDecoder()
278```
279import util from '@ohos.util'
280var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
281```
2825.readonly encoding()
283```
284import util from '@ohos.util'
285var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
286var getEncoding = textDecoder.encoding();
287```
2886.readonly fatal()
289```
290import util from '@ohos.util'
291var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
292var fatalStr = textDecoder.fatal();
293```
2947.readonly ignoreBOM()
295```
296import util from '@ohos.util'
297var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
298var ignoreBom = textDecoder.ignoreBOM();
299```
3008.decode()
301```
302import util from '@ohos.util'
303var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
304var result = textDecoder.decode(input, {stream : true});
305```
3069.printf()
307```
308import util from '@ohos.util'
309var format = "%%%o%%%i%s";
310var value =  function aa(){};
311var value1 = 1.5;
312var value2 = "qwer";
313var result = util.printf(format,value,value1,value2);
314```
31510.getErrorString()
316```
317import util from '@ohos.util'
318var errnum = 13;
319var result = util.getErrorString(errnum);
320```
32111.callbackWrapper()
322```
323import util from '@ohos.util'
324async function promiseFn() {
325    return Promise.resolve('value');
326};
327var cb = util.callbackWrapper(promiseFn);
328cb((err, ret) => {
329    expect(err).strictEqual(null);
330    expect(ret).strictEqual('value');
331})
332```
33312.promiseWrapper()
334```
335import util from '@ohos.util'
336function aysnFun(str1, str2, callback) {
337    if (typeof str1 === 'string' && typeof str1 === 'string') {
338        callback(null, str1 + str2);
339    } else {
340        callback('type err');
341    }
342}
343let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World');
344newPromiseObj.then(res => {
345    expect(res).strictEqual('HelloWorld');
346})
347```
34813.encodeSync()
349```
350import util from '@ohos.util'
351var that = new util.Base64();
352var array = new Uint8Array([115,49,51]);
353var result = that.encodeSync(array);
354```
35514.encodeToStringSync()
356```
357import util from '@ohos.util'
358var that = new util.Base64();
359var array = new Uint8Array([115,49,51]);
360var result = that.encodeToStringSync(array);
361```
36215.decodeSync()
363```
364import util from '@ohos.util'
365var that = new util.Base64()
366var buff = 'czEz';
367var result = that.decodeSync(buff);
368```
36916.encode()
370```
371import util from '@ohos.util'
372var that = new util.Base64()
373var array = new Uint8Array([115,49,51]);
374await that.encode(array).then(val=>{
375})
376done()
377```
37817.encodeToString()
379```
380import util from '@ohos.util'
381var that = new util.Base64()
382var array = new Uint8Array([115,49,51]);
383await that.encodeToString(array).then(val=>{
384})
385done()
386```
38718.decode()
388```
389import util from '@ohos.util'
390var that = new util.Base64()
391var buff = 'czEz';
392await that.decode(buff).then(val=>{
393})
394done()
395```
39619.createRationalFromString()
397```
398import util from '@ohos.util'
399var pro = new util.RationalNumber(0, 0);
400var res = pro.createRationalFromString("-1:2");
401var result1 = res.value();
402```
40320.compareTo()
404```
405import util from '@ohos.util'
406var pro = new util.RationalNumber(2, 1);
407var proc = new util.RationalNumber(3, 4);
408var res = pro.compareTo(proc);
409```
41021.equals()
411```
412import util from '@ohos.util'
413var pro = new util.RationalNumber(2, 1);
414var proc = new util.RationalNumber(3, 4);
415var res = pro.equals(proc);
416```
41722.valueOf()
418```
419import util from '@ohos.util'
420var pro = new util.RationalNumber(2, 1);
421var res = pro.value();
422```
42323.getCommonDivisor()
424```
425import util from '@ohos.util'
426var pro = new util.RationalNumber(0, 0);
427var res = pro.getCommonDivisor(4, 8);
428```
42924.getDenominator()
430```
431import util from '@ohos.util'
432var pro = new util.RationalNumber(2, 1);
433var res = pro.getDenominator();
434```
43525.getNumerator()
436```
437import util from '@ohos.util'
438var pro = new util.RationalNumber(-2, 1);
439var res = pro.getNumerator();
440```
44126.isFinite()
442```
443import util from '@ohos.util'
444var pro = new util.RationalNumber(-2, 1);
445var res = pro.isFinite();
446```
44727.isNaN()
448```
449import util from '@ohos.util'
450var pro = new util.RationalNumber(-2, 1);
451var res = pro.isNaN();
452```
45328.isZero()
454```
455import util from '@ohos.util'
456var pro = new util.RationalNumber(-2, 1);
457var res = pro.isZero();
458
459```
46029.toString()
461```
462import util from '@ohos.util'
463var pro = new util.RationalNumber(-2, 1);
464var res = pro.toString();
465
466```
46730.updateCapacity()
468```
469import util from '@ohos.util'
470var pro = new util.LruBuffer();
471var result = pro.updateCapacity(100);
472```
47331.toString()
474```
475import util from '@ohos.util'
476var pro = new util.LruBuffer();
477pro.put(2,10);
478pro.get(2);
479pro.remove(20);
480var result = pro.toString();
481```
48232.values()
483```
484import util from '@ohos.util'
485var pro = new util.LruBuffer();
486pro.put(2,10);
487pro.put(2,"anhu");
488pro.put("afaf","grfb");
489var result = pro.values();
490```
49133.length
492```
493import util from '@ohos.util'
494var pro = new util.LruBuffer();
495pro.put(2,10);
496pro.put(1,8);
497var result = pro.length;
498```
49934.getCapacity()
500```
501import util from '@ohos.util'
502var pro = new util.LruBuffer();
503var result = pro.getCapacity();
504```
50535.clear()
506```
507import util from '@ohos.util'
508var pro = new util.LruBuffer();
509pro.put(2,10);
510pro.clear();
511```
51236.getCreateCount()
513```
514import util from '@ohos.util'
515var pro = new util.LruBuffer();
516pro.put(1,8);
517var result = pro.getCreateCount();
518```
51937.getMissCount()
520```
521import util from '@ohos.util'
522var pro = new util.LruBuffer();
523pro.put(2,10);
524pro.get(2)
525var result = pro.getMissCount();
526```
52738.getRemovalCount()
528```
529import util from '@ohos.util'
530var pro = new util.LruBuffer();
531pro.put(2,10);
532pro.updateCapacity(2);
533pro.put(50,22);
534var result = pro.getRemovalCount();
535```
53639.getMatchCount()
537```
538import util from '@ohos.util'
539var pro = new util.LruBuffer();
540pro.put(2,10);
541pro.get(2);
542var result = pro.getMatchCount();
543```
54440.getPutCount()
545```
546import util from '@ohos.util'
547var pro = new util.LruBuffer();
548pro.put(2,10);
549var result = pro.getPutCount();
550```
55141.isEmpty()
552```
553import util from '@ohos.util'
554var pro = new util.LruBuffer();
555pro.put(2,10);
556var result = pro.isEmpty();
557```
55842.get()
559```
560import util from '@ohos.util'
561var pro = new util.LruBuffer();
562pro.put(2,10);
563var result = pro.get(2);
564```
56543.put()
566```
567import util from '@ohos.util'
568var pro = new util.LruBuffer();
569var result = pro.put(2,10);
570```
57144.keys()
572```
573import util from '@ohos.util'
574var pro = new util.LruBuffer();
575 pro.put(2,10);
576var result = pro.keys();
577```
57845.remove()
579```
580import util from '@ohos.util'
581var pro = new util.LruBuffer();
582pro.put(2,10);
583var result = pro.remove(20);
584```
58546.contains()
586```
587import util from '@ohos.util'
588var pro = new util.LruBuffer();
589pro.put(2,10);
590var result = pro.contains(20);
591```
59247.createDefault()
593```
594import util from '@ohos.util'
595var pro = new util.LruBuffer();
596var result = pro.createDefault(50);
597```
59848.entries()
599```
600import util from '@ohos.util'
601var pro = new util.LruBuffer();
602pro.put(2,10);
603var result = pro.entries();
604```
60549.\[Symbol.iterator\]()
606```
607import util from '@ohos.util'
608var pro = new util.LruBuffer();
609pro.put(2,10);
610var result = pro[symbol.iterator]();
611```
61250.afterRemoval()
613```
614import util from '@ohos.util'
615var arr = [];
616class ChildLruBuffer extends util.LruBuffer
617{
618    constructor()
619    {
620        super();
621    }
622    static getInstance()
623    {
624        if(this.instance ==  null)
625        {
626            this.instance = new ChildLruBuffer();
627        }
628        return this.instance;
629    }
630    afterRemoval(isEvict, key, value, newValue)
631    {
632        if (isEvict === false)
633        {
634            arr = [key, value, newValue];
635        }
636    }
637}
638ChildLruBuffer.getInstance().afterRemoval(false,10,30,null)
639```
640Construct a new class in the Scope interface to implement the compareTo method.
641
642```
643class Temperature {
644    constructor(value) {
645        this._temp = value;
646    }
647    compareTo(value) {
648        return this._temp >= value.getTemp();
649    }
650    getTemp() {
651        return this._temp;
652    }
653    toString() {
654        return this._temp.toString();
655    }
656}
657```
658
65951.constructor()
660
661```
662var tempLower = new Temperature(30);
663var tempUpper = new Temperature(40);
664var range = new Scope(tempLower, tempUpper);
665```
666
66752.toString()
668
669```
670var tempLower = new Temperature(30);
671var tempUpper = new Temperature(40);
672var range = new Scope(tempLower, tempUpper);
673var result = range.toString() // => [30,40]
674```
675
67653.intersect()
677
678```
679var tempLower = new Temperature(30);
680var tempUpper = new Temperature(40);
681var range = new Scope(tempLower, tempUpper);
682var tempMiDF = new Temperature(35);
683var tempMidS = new Temperature(39);
684var rangeFir = new Scope(tempMiDF, tempMidS);
685var result = range.intersect(rangeFir)  // => [35,39]
686```
687
68854.intersect()
689
690```
691var tempLower = new Temperature(30);
692var tempUpper = new Temperature(40);
693var tempMiDF = new Temperature(35);
694var tempMidS = new Temperature(39);
695var range = new Scope(tempLower, tempUpper);
696var result = range.intersect(tempMiDF, tempMidS)  // => [35,39]
697```
698
69955.getUpper()
700
701```
702var tempLower = new Temperature(30);
703var tempUpper = new Temperature(40);
704var range = new Scope(tempLower, tempUpper);
705var result = range.getUpper() // => 40
706```
707
70856.getLower()
709
710```
711var tempLower = new Temperature(30);
712var tempUpper = new Temperature(40);
713var range = new Scope(tempLower, tempUpper);
714var result = range.getLower() // => 30
715```
716
71757.expand()
718
719```
720var tempLower = new Temperature(30);
721var tempUpper = new Temperature(40);
722var tempMiDF = new Temperature(35);
723var tempMidS = new Temperature(39);
724var range = new Scope(tempLower, tempUpper);
725var result = range.expand(tempMiDF, tempMidS)  // => [30,40]
726```
727
72858.expand()
729
730```
731var tempLower = new Temperature(30);
732var tempUpper = new Temperature(40);
733var tempMiDF = new Temperature(35);
734var tempMidS = new Temperature(39);
735var range = new Scope(tempLower, tempUpper);
736var rangeFir = new Scope(tempMiDF, tempMidS);
737var result = range.expand(rangeFir) // => [30,40]
738```
739
74059.expand()
741
742```
743var tempLower = new Temperature(30);
744var tempUpper = new Temperature(40);
745var tempMiDF = new Temperature(35);
746var range = new Scope(tempLower, tempUpper);
747var result = range.expand(tempMiDF)  // => [30,40]
748```
749
75060.contains()
751
752```
753var tempLower = new Temperature(30);
754var tempUpper = new Temperature(40);
755var tempMiDF = new Temperature(35);
756var range = new Scope(tempLower, tempUpper);
757var result = range.contains(tempMiDF) // => true
758```
759
76061.contains()
761
762```
763var tempLower = new Temperature(30);
764var tempUpper = new Temperature(40);
765var range = new Scope(tempLower, tempUpper);
766var tempLess = new Temperature(20);
767var tempMore = new Temperature(45);
768var rangeSec = new Scope(tempLess, tempMore);
769var result = range.contains(rangeSec) // => true
770```
771
77262.clamp()
773
774```
775var tempLower = new Temperature(30);
776var tempUpper = new Temperature(40);
777var tempMiDF = new Temperature(35);
778var range = new Scope(tempLower, tempUpper);
779var result = range.clamp(tempMiDF) // => 35
780```
78163.isAnyArrayBuffer()
782```
783import util from '@ohos.util'
784var proc = new util.Types();
785var result = proc.isAnyArrayBuffer(new ArrayBuffer([]))
786```
78764.isArrayBufferView()
788```
789import util from '@ohos.util'
790var proc = new util.Types();
791var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16)));
792```
79365.isArgumentsObject()
794```
795import util from '@ohos.util'
796function foo() {
797        var result = proc.isArgumentsObject(arguments);
798    }
799var f = foo();
800```
80166.isArrayBuffer()
802```
803import util from '@ohos.util'
804var proc = new util.Types();
805var result = proc.isArrayBuffer(new ArrayBuffer([]));
806```
80767.isAsyncFunction()
808```
809import util from '@ohos.util'
810var proc = new util.Types();
811var result = proc.isAsyncFunction(async function foo() {});
812```
81368.isBigInt64Array()
814```
815import util from '@ohos.util'
816var proc = new util.Types();
817var result = proc.isBigInt64Array(new Int16Array([]));
818```
81969.isBigUint64Array()
820```
821import util from '@ohos.util'
822var proc = new util.Types();
823var result = proc.isBigUint64Array(new Int16Array([]));
824```
82570.isBooleanObject()
826```
827import util from '@ohos.util'
828var proc = new util.Types();
829var result = proc.isBooleanObject(new Boolean(false));
830```
83171.isBoxedPrimitive()
832```
833import util from '@ohos.util'
834var proc = new util.Types();
835var result = proc.isBoxedPrimitive(new Boolean(false));
836```
83772.isDataView()
838```
839import util from '@ohos.util'
840var proc = new util.Types();
841const ab = new ArrayBuffer(20);
842var result = proc.isDataView(new DataView(ab));
843```
84473.isDate()
845```
846import util from '@ohos.util'
847var proc = new util.Types();
848var result = proc.isDate(new Date());
849```
85074.isExternal()
851```
852import util from '@ohos.util'
853const data = util.createExternalType();
854var reult13 = proc.isExternal(data);
855```
85675.isFloat32Array()
857```
858import util from '@ohos.util'
859var proc = new util.Types();
860var result = proc.isFloat32Array(new Float32Array([]));
861```
86276.isFloat64Array()
863```
864import util from '@ohos.util'
865var proc = new util.Types();
866var result = proc.isFloat64Array(new Float64Array([]));
867```
86877.isGeneratorFunction()
869```
870import util from '@ohos.util'
871var proc = new util.Types();
872var result = proc.isGeneratorFunction(function* foo() {});
873```
87478.isGeneratorObject()
875```
876import util from '@ohos.util'
877var proc = new util.Types();
878function* foo() {}
879const generator = foo();
880var result = proc.isGeneratorObject(generator);
881```
88279.isInt8Array()
883```
884import util from '@ohos.util'
885var proc = new util.Types();
886var result = proc.isInt8Array(new Int8Array([]));
887```
88880.isInt16Array()
889```
890import util from '@ohos.util'
891var proc = new util.Types();
892var result = proc.isInt16Array(new Int16Array([]));
893```
89481.isInt32Array()
895```
896import util from '@ohos.util'
897var proc = new util.Types();
898var result = proc.isInt32Array(new Int32Array([]));
899```
90082.isMap()
901```
902import util from '@ohos.util'
903var proc = new util.Types();
904var result = proc.isMap(new Map());
905```
90683.isMapIterator()
907```
908import util from '@ohos.util'
909var proc = new util.Types();
910var result = proc.isMapIterator(map.keys());
911```
91284.isModuleNamespaceObject()
913```
914import util from '@ohos.util'
915var proc = new util.Types();
916var result = proc.isModuleNamespaceObject(util);
917```
91885.isNativeError()
919```
920import util from '@ohos.util'
921var proc = new util.Types();
922var result = proc.isNativeError(new TypeError());
923```
92486.isNumberObject()
925```
926import util from '@ohos.util'
927var proc = new util.Types();
928var result = proc.isNumberObject(new Number(0));
929```
93087.isPromise()
931```
932import util from '@ohos.util'
933var proc = new util.Types();
934var result = proc.isPromise(Promise.resolve(42));
935```
93688.isProxy()
937```
938import util from '@ohos.util'
939var proc = new util.Types();
940const target = {};
941const proxy = new Proxy(target, {});
942var result = proc.isProxy(proxy);
943```
94489.isRegExp()
945```
946import util from '@ohos.util'
947var proc = new util.Types();
948var result = proc.isRegExp(new RegExp('abc'));
949```
95090.isSet()
951```
952import util from '@ohos.util'
953var proc = new util.Types();
954var result = proc.isSet(new Set());
955```
95691.isSetIterator()
957```
958import util from '@ohos.util'
959var proc = new util.Types();
960const set = new Set();
961var result = proc.isSetIterator(set.keys());
962```
96392.isSharedArrayBuffer()
964```
965import util from '@ohos.util'
966var proc = new util.Types();
967var result = proc.isSharedArrayBuffer(new ArrayBuffer([]));
968```
96993.isStringObject()
970```
971import util from '@ohos.util'
972var proc = new util.Types();
973var result = proc.isStringObject(new String('foo'));
974```
97594.isSymbolObject()
976```
977import util from '@ohos.util'
978var proc = new util.Types();
979const symbols = Symbol('foo');
980var result = proc.isSymbolObject(Object(symbols));
981```
98295.isTypedArray()
983```
984import util from '@ohos.util'
985var proc = new util.Types();
986var result = proc.isTypedArray(new Float64Array([]));
987```
98896.isUint8Array()
989```
990import util from '@ohos.util'
991var proc = new util.Types();
992var result = proc.isUint8Array(new Uint8Array([]));
993```
99497.isUint8ClampedArray()
995```
996import util from '@ohos.util'
997var proc = new util.Types();
998var result = proc.isUint8ClampedArray(new Uint8ClampedArray([]));
999```
100098.isUint16Array()
1001```
1002import util from '@ohos.util'
1003var proc = new util.Types();
1004var result = proc.isUint16Array(new Uint16Array([]));
1005```
100699.isUint32Array()
1007```
1008import util from '@ohos.util'
1009var proc = new util.Types();
1010var result = proc.isUint32Array(new Uint32Array([]));
1011```
1012100.isWeakMap()
1013```
1014import util from '@ohos.util'
1015var proc = new util.Types();
1016var result = proc.isWeakMap(new WeakMap());
1017```
1018101.isWeakSet()
1019```
1020import util from '@ohos.util'
1021var proc = new util.Types();
1022var result = proc.isWeakSet(new WeakSet());
1023```
1024## Related warehouse
1025
1026[js_util_module subsystem](base/compileruntime/js_util_module-readme.md)
1027
1028## License
1029
1030Util is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_util_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony/js_util_module/blob/master/LICENSE) for the full license text.