• Home
Name Date Size #Lines LOC

..--

container/12-May-2024-5,5404,865

util/12-May-2024-4,7203,856

LICENSED12-May-20249.9 KiB178150

README.mdD12-May-202441.9 KiB1,030988

README_zh.mdD12-May-202438.8 KiB1,031987

build_ts_js.pyD12-May-20242.1 KiB5838

bundle.jsonD12-May-20241.6 KiB6059

mozilla_docs.txtD12-May-20241.5 KiB4337

README.md

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.

README_zh.md

1# js_util_module子系统/组件
2
3-   [简介](#简介)
4-   [目录](#目录)
5-   [说明](#说明)
6    -   [接口说明](#接口说明)
7    -   [使用说明](#使用说明)
8
9-   [相关仓](#相关仓)
10
11## 简介
12
13UTIL接口用于字符编码TextEncoder、解码TextDecoder、帮助函数HelpFunction、基于Base64的字节编码encode和解码decode、有理数RationalNumber。TextEncoder表示一个文本编码器,接受字符串作为输入,以UTF-8格式进行编码,输出UTF-8字节流。TextDecoder接口表示一个文本解码器,解码器将字节流作为输入,输出stirng字符串。HelpFunction主要是对函数做callback化、promise化以及对错误码进行编写输出,及类字符串的格式化输出。encode接口使用Base64编码方案将指定u8数组中的所有字节编码到新分配的u8数组中或者使用Base64编码方案将指定的字节数组编码为String。decode接口使用Base64编码方案将Base64编码的字符串或输入u8数组解码为新分配的u8数组。RationalNumber有理数主要是对有理数进行比较,获取分子分母等方法。LruBuffer该算法在缓存空间不够的时候,将近期最少使用的数据替换为新数据。该算法源自这样一种访问资源的需求:近期访问的数据,可能在不久的将来会再次访问。于是最少访问的数据就是价值最小的,是最应该踢出缓存空间的数据。Scope接口用于描述一个字段的有效范围。 Scope实例的构造函数用于创建具有指定下限和上限的对象,并要求这些对象必须具有可比性。
14## 目录
15
16```
17base/compileruntime/js_util_module/
18├── Class:TextEncoder                   # TextEncoder类
19│   ├──  new TextEncoder()              # 创建TextEncoder对象
20│   ├──  encode()                       # encode方法
21│   ├──  encoding                       # encoding属性
22│   └──  encodeInto()                   # encodeInto方法
23├── Class:TextDecoder                   # TextDecoder类
24│   ├──  new TextDecoder()              # 创建TextDecoder对象
25│   ├──  decode()                       # decode方法
26│   ├──  encoding                       # encoding属性
27│   ├──  fatal                          # fatal属性
28│   └──  ignoreBOM                      # ignoreBOM属性
29├── printf()                            # printf方法
30├── getErrorString()                    # getErrorString方法
31├── callbackWrapper()                   # callbackWrapper方法
32├── promiseWrapper()                    # promiseWrapper方法
33├── Class:Base64                        # Base64类
34│   ├──  new Base64()                   # 创建Base64对象
35│   ├──  encodeSync()                   # encodeSync方法
36│   ├──  encodeToStringSync()           # encodeToStringSync方法
37│   ├──  decodeSync()                   # decodeSync方法
38│   ├──  encode()                       # encode方法
39│   ├──  encodeToString()               # encodeToString方法
40│   └──  decode()                       # decode方法
41├── Class:RationalNumber                # RationalNumber类
42│   ├──  new RationalNumber()           # 创建RationalNumber对象
43│   ├──  createRationalFromString()     # createRationalFromString方法
44│   ├──  compareTo()                    # compareTo方法
45│   ├──  equals()                       # equals方法
46│   ├──  valueOf()                      # valueOf方法
47│   ├──  getCommonDivisor()             # getCommonDivisor方法
48│   ├──  getDenominator()               # getDenominator方法
49│   ├──  getNumerator()                 # getNumerator方法
50│   ├──  isFinite()                     # isFinite方法
51│   ├──  isNaN()                        # isNaN方法
52│   ├──  isZero()                       # isZero方法
53│   └──  toString()                     # toString方法
54├── Class:LruBuffer                     # LruBuffer类
55│   ├──  new LruBuffer()                # 创建LruBuffer对象
56│   ├──  updateCapacity()               # updateCapacity方法
57│   ├──  toString()                     # toString方法
58│   ├──  values()                       # values方法
59│   ├──  length                         # length属性
60│   ├──  getCapacity()                  # getCapacity方法
61│   ├──  clear()                        # clear方法
62│   ├──  getCreateCount()               # getCreateCount方法
63│   ├──  getMissCount()                 # getMissCount方法
64│   ├──  getRemovalCount()              # getRemovalCount方法
65│   ├──  getMatchCount()                # getMatchCount方法
66│   ├──  getPutCount()                  # getPutCount方法
67│   ├──  isEmpty()                      # isEmpty方法
68│   ├──  get()                          # get方法
69│   ├──  put()                          # put方法
70│   ├──  keys()                         # keys方法
71│   ├──  remove()                       # remove方法
72│   ├──  afterRemoval()                 # afterRemoval方法
73│   ├──  contains()                     # contains方法
74│   ├──  createDefault()                # createDefault方法
75│   ├──  entries()                      # entries方法
76│   └──  [Symbol.iterator]()            # Symboliterator方法
77|—— Class:Scope                         # Scope类
78|   ├── constructor()                   # 创建Scope对象
79|   ├── toString()                      # toString方法
80|   ├── intersect()                     # intersect方法
81|   ├── intersect()                     # intersect方法
82|   ├── getUpper()                      # getUpper方法
83|   ├── getLower()                      # getLower方法
84|   ├── expand()                        # expand方法
85|   ├── expand()                        # expand方法
86|   ├── expand()                        # expand法
87|   ├── contains()                      # contains方法
88|   ├── contains()                      # contains方法
89|   └── clamp()                         # clamp方法
90└── Class:Types                         # Types类
91    ├── isAnyArrayBuffer()              # isAnyArrayBuffer方法
92    ├── isArrayBufferView()             # isArrayBufferView方法
93    ├── isArgumentsObject()             # isArgumentsObject方法
94    ├── isArrayBuffer()                 # isArrayBuffer方法
95    ├── isAsyncFunction()               # isAsyncFunction方法
96    ├── isBigInt64Array()               # isBigInt64Array方法
97    ├── isBigUint64Array()              # isBigUint64Array方法
98    ├── isBooleanObject()               # isBooleanObject方法
99    ├── isBoxedPrimitive()              # isBoxedPrimitive方法
100    ├── isDataView()                    # isDataView方法
101    ├── isDate()                        # isDate方法
102    ├── isExternal()                    # isExternal方法
103    ├── isFloat32Array()                # isFloat32Array方法
104    ├── isFloat64Array()                # isFloat64Array方法
105    ├── isGeneratorFunction()           # isGeneratorFunction方法
106    ├── isGeneratorObject()             # isGeneratorObject方法
107    ├── isInt8Array()                   # isInt8Array方法
108    ├── isInt16Array()                  # isInt16Array方法
109    ├── isInt32Array()                  # isInt32Array方法
110    ├── isMap()                         # isMap方法
111    ├── isMapIterator()                 # isMapIterator方法
112    ├── isModuleNamespaceObject()       # isModuleNamespaceObject方法
113    ├── isNativeError()                 # isNativeError方法
114    ├── isNumberObject()                # isNumberObject方法
115    ├── isPromise()                     # isPromise方法
116    ├── isProxy()                       # isProxy方法
117    ├── isRegExp()                      # isRegExp方法
118    ├── isSet()                         # isSet方法
119    ├── isSetIterator()                 # isSetIterator方法
120    ├── isSharedArrayBuffer()           # isSharedArrayBuffer方法
121    ├── isStringObject()                # isStringObject方法
122    ├── isSymbolObject()                # isSymbolObject方法
123    ├── isTypedArray()                  # isTypedArray方法
124    ├── isUint8Array()                  # isUint8Array方法
125    ├── isUint8ClampedArray()           # isUint8ClampedArray方法
126    ├── isUint16Array()                 # isUint16Array方法
127    ├── isUint32Array()                 # isUint32Array方法
128    ├── isWeakMap()                     # isWeakMap方法
129    └── isWeakSet()                     # isWeakSet方法
130```
131## 说明
132
133### 接口说明
134
135
136| 接口名 | 说明 |
137| -------- | -------- |
138| readonly encoding : string | 在TextEncoder类中,获取编码的格式,只支持UTF-8。 |
139| encode(input : string) : Uint8Array | 输入stirng字符串,编码并输出UTF-8字节流。 |
140| encodeInto(input : string, dest : Uint8Array) : {read : number, written : number} | 输入stirng字符串,dest表示编码后存放位置,返回一个对象,read表示已经编码的字符的个数,written表示已编码字符所占字节的大小。 |
141| constructor(encoding? : string, options? : {fatal? : boolean, ignoreBOM? : boolean}) | 构造函数,第一个参数encoding表示解码的格式。第二个参数表示一些属性。属性中fatal表示是否抛出异常,ignoreBOM表示是否忽略bom标志。 |
142| readonly encoding : string | 在TextDecoder类中,获取设置的解码格式。 |
143| readonly fatal : boolean | 获取抛出异常的设置。 |
144| readonly ignoreBOM : boolean | 获取是否忽略bom标志的设置。 |
145| decode(input : Uint8Array, options?: { stream?: false }) : string | 输入要解码的数据,解出对应的string字符串。第一个参数input表示要解码的数据,第二个参数options表示一个bool标志,表示将跟随附加数据,默认为false。 |
146| encodeSync(src: Uint8Array): Uint8Array; | 使用Base64编码方案将指定u8数组中的所有字节编码到新分配的u8数组中。 |
147| encodeToStringSync(src: Uint8Array): string; | 使用Base64编码方案将指定的字节数组编码为String。 |
148| decodeSync(src: Uint8Array \| string): Uint8Array; | 使用Base64编码方案将Base64编码的字符串或输入u8数组解码为新分配的u8数组。 |
149| encode(src: Uint8Array): Promise\<Uint8Array\>; | 使用Base64编码方案将指定u8数组中的所有字节异步编码到新分配的u8数组中。 |
150| encodeToString(src: Uint8Array): Promise\<string\>; | 使用Base64编码方案将指定的字节数组异步编码为String。 |
151| decode(src: Uint8Array \| string): Promise\<Uint8Array\>; | 使用Base64编码方案将Base64编码的字符串或输入u8数组异步解码为新分配的u8数组。 |
152| static createRationalFromString(rationalString: string): RationalNumber | 基于给定的字符串创建一个RationalNumber对象。 |
153| compareTo(another: RationalNumber): number | 将当前的RationalNumber对象与给定的对象进行比较。 |
154| equals(obj: object): number | 检查给定对象是否与当前 RationalNumber 对象相同。 |
155| valueOf(): number | 将当前的RationalNumber对象进行取整数值或者浮点数值。 |
156| static getCommonDivisor(number1: number, number2: number,): number | 获得两个指定数的最大公约数。 |
157| getDenominator(): number | 获取当前的RationalNumber对象的分母。 |
158| getNumerator(): number | 获取当前的RationalNumber对象的分子。 |
159| isFinite(): boolean | 检查当前的RationalNumber对象是有限的。 |
160| isNaN(): boolean | 检查当前RationalNumber对象是否表示非数字(NaN)值。 |
161| isZero(): boolean | 检查当前RationalNumber对象是否表示零值。 |
162| toString(): string | 获取当前RationalNumber对象的字符串表示形式。 |
163| constructor(capacity?: number) | 创建默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。 |
164| updateCapacity(newCapacity: number): void | 将缓冲区容量更新为指定容量,如果 newCapacity 小于或等于 0,则抛出此异常。 |
165| toString(): string | 返回对象的字符串表示形式,输出对象的字符串表示  |
166| values(): V[] | 获取当前缓冲区中所有值的列表,输出按升序返回当前缓冲区中所有值的列表,从最近访问到最近最少访问。 |
167| length: number | 代表当前缓冲区中值的总数,输出返回当前缓冲区中值的总数。 |
168| getCapacity(): number | 获取当前缓冲区的容量,输出返回当前缓冲区的容量。 |
169| clear(): void | 从当前缓冲区清除键值对,清除键值对后,调用afterRemoval()方法依次对其执行后续操作。 |
170| getCreateCount(): number | 获取createDefault()返回值的次数,输出返回createDefault()返回值的次数。 |
171| getMissCount(): number | 获取查询值不匹配的次数,输出返回查询值不匹配的次数。 |
172| getRemovalCount(): number | 获取从缓冲区中逐出值的次数,输出从缓冲区中驱逐的次数。 |
173| getMatchCount​(): number | 获取查询值匹配成功的次数,输出返回查询值匹配成功的次数。 |
174| getPutCount(): number | 获取将值添加到缓冲区的次数,输出返回将值添加到缓冲区的次数。 |
175| isEmpty(): boolean | 检查当前缓冲区是否为空,输出如果当前缓冲区不包含任何值,则返回 true 。 |
176| get(key: K) : V \| undefined | 表示要查询的键,输出如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 |
177| put(key: K , value: V): V | 将键值对添加到缓冲区,输出与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 |
178| keys(): K[ ] | 获取当前缓冲区中值的键列表,输出返回从最近访问到最近最少访问排序的键列表。 |
179| remove​(key: K): V \| undefined |  从当前缓冲区中删除指定的键及其关联的值。 |
180| afterRemoval(isEvict: boolean, key: K, value : V, newValue : V):void | 删除值后执行后续操作。 |
181| contains(key: K): boolean | 检查当前缓冲区是否包含指定的键,输出如果缓冲区包含指定的键,则返回 true 。 |
182| createDefault(key: K): V | 如果未计算特定键的值,则执行后续操作,参数表示丢失的键,输出返回与键关联的值。 |
183| entries(): [K,V] | 允许迭代包含在这个对象中的所有键值对。每对的键和值都是对象。 |
184| \[Symbol.iterator\](): [K,V] | 返回以键值对得形式得一个二维数组。 |
185| constructor(lowerObj: ScopeType, upperObj : ScopeType) | 创建并返回一个Scope对象,用于创建指定下限和上限的作用域实例的构造函数。 |
186| toString(): string | 该字符串化方法返回一个包含当前范围的字符串表示形式。 |
187| intersect(range: Scope): Scope | 获取给定范围和当前范围的交集。 |
188| intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope | 获取当前范围与给定下限和上限范围的交集。 |
189| getUpper(): ScopeType | 获取当前范围的上限。 |
190| getLower(): ScopeType | 获取当前范围的下限。 |
191| expand(lowerObj: ScopeType, upperObj:  ScopeType): Scope | 创建并返回包括当前范围和给定下限和上限的并集。 |
192| expand(range: Scope): Scope | 创建并返回包括当前范围和给定范围的并集。 |
193| expand(value: ScopeType): Scope | 创建并返回包括当前范围和给定值的并集。 |
194| contains(value: ScopeType): boolean | 检查给定value是否包含在当前范围内。 |
195| contains(range: Scope): boolean | 检查给定range是否在当前范围内。 |
196| clamp(value: ScopeType): ScopeType | 将给定value限定到当前范围内。 |
197| function printf(format: string, ...args: Object[]): string | printf()方法使用第一个参数作为格式字符串(其可以包含零个或多个格式说明符)来返回格式化的字符串。 |
198| function getErrorString(errno: number): string | getErrorString()方法使用一个系统的错误数字作为参数,用来返回系统的错误信息。 |
199| function callbackWrapper(original: Function): (err: Object, value: Object) => void | 参数为一个采用 async 函数(或返回 Promise 的函数)并返回遵循错误优先回调风格的函数,即将 (err, value) => ... 回调作为最后一个参数。 在回调中,第一个参数将是拒绝原因(如果 Promise 已解决,则为 null),第二个参数将是已解决的值。 |
200| function promiseWrapper(original: (err: Object, value: Object) => void): Object | 参数为采用遵循常见的错误优先的回调风格的函数(也就是将 (err, value) => ... 回调作为最后一个参数),并返回一个返回 promise 的版本。 |
201| isAnyArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer或SharedArrayBuffer类型。 |
202| isArrayBufferView(value: Object): boolean | 检查输入的value是否是napi_int8_array或napi_uint8_array或napi_uint8_clamped_array或napi_int16_array或napi_uint16_array或napi_int32_array或napi_uint32_array或napi_float32_array或napi_float64_array数组或DataView类型。 |
203| isArgumentsObject(value: Object): boolean | 检查输入的value是否是一个arguments对象类型。 |
204| isArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer类型。 |
205| isAsyncFunction(value: Object): boolean | 检查输入的value是否是异步函数类型。 |
206| isBigInt64Array(value: Object): boolean | 检查输入的value是否是BigInt64Array数组类型。 |
207| isBigUint64Array(value: Object): boolean | 检查输入的value是否是BigUint64Array数组类型。 |
208| isBooleanObject(value: Object): boolean | 检查输入的value是否是一个布尔对象类型。 |
209| isBoxedPrimitive(value: Object): boolean | 检查输入的value是否是Boolean或Number或String或Symbol对象类型。 |
210| isDataView(value: Object): boolean | 检查输入的value是否是DataView类型。 |
211| isDate(value: Object): boolean | 检查输入的value是否是Date类型。 |
212| isExternal(value: Object): boolean | 检查输入的value是否是一个native External值类型。 |
213| isFloat32Array(value: Object): boolean | 检查输入的value是否是Float32Array数组类型。 |
214| isFloat64Array(value: Object): boolean | 检查输入的value是否是Float64Array数组类型。 |
215| isGeneratorFunction(value: Object): boolean | 检查输入的value是否是一个generator函数类型。 |
216| isGeneratorObject(value: Object): boolean | 检查输入的value是否是一个generator对象类型。 |
217| isInt8Array(value: Object): boolean | 检查输入的value是否是Int8Array数组类型。 |
218| isInt16Array(value: Object): boolean | 检查输入的value是否是Int16Array数组类型。 |
219| isInt32Array(value: Object): boolean | 检查输入的value是否是Int32Array数组类型。 |
220| isMap(value: Object): boolean | 检查输入的value是否是Map类型。 |
221| isMapIterator(value: Object): boolean | 检查输入的value是否是Map的iterator类型。 |
222| isModuleNamespaceObject(value: Object): boolean | 检查输入的value是否是Module Namespace Object对象类型。 |
223| isNativeError(value: Object): boolean | 检查输入的value是否是Error类型。 |
224| isNumberObject(value: Object): boolean | 检查输入的value是否是Number对象类型。 |
225| isPromise(value: Object): boolean | 检查输入的value是否是Promise类型。 |
226| isProxy(value: Object): boolean | 检查输入的value是否是Proxy类型。 |
227| isRegExp(value: Object): boolean | 检查输入的value是否是RegExp类型。 |
228| isSet(value: Object): boolean | 检查输入的value是否是Set类型。 |
229| isSetIterator(value: Object): boolean | 检查输入的value是否是Set的iterator类型。 |
230| isSharedArrayBuffer(value: Object): boolean | 检查输入的value是否是SharedArrayBuffer类型。 |
231| isStringObject(value: Object): boolean | 检查输入的value是否是一个String对象类型。 |
232| isSymbolObject(value: Object): boolean | 检查输入的value是否是一个Symbol对象类型。 |
233| isTypedArray(value: Object): boolean | 检查输入的value是否是TypedArray包含的类型。 |
234| isUint8Array(value: Object): boolean | 检查输入的value是否是Uint8Array数组类型。 |
235| isUint8ClampedArray(value: Object): boolean | 检查输入的value是否是Uint8ClampedArray数组类型。 |
236| isUint16Array(value: Object): boolean | 检查输入的value是否是Uint16Array数组类型。 |
237| isUint32Array(value: Object): boolean | 检查输入的value是否是Uint32Array数组类型。 |
238| isWeakMap(value: Object): boolean | 检查输入的value是否是WeakMap类型。 |
239| isWeakSet(value: Object): boolean | 检查输入的value是否是WeakSet类型。 |
240
241printf中每个说明符都替换为来自相应参数的转换后的值。 支持的说明符有:
242| 式样化字符 | 式样要求 |
243| -------- | -------- |
244|    %s:  | String 将用于转换除 BigInt、Object 和 -0 之外的所有值。|
245|    %d:  | Number 将用于转换除 BigInt 和 Symbol 之外的所有值。|
246|    %i:  | parseInt(value, 10) 用于除 BigInt 和 Symbol 之外的所有值。|
247|    %f:  | parseFloat(value) 用于除 Symbol 之外的所有值。|
248|    %j:  | JSON。 如果参数包含循环引用,则替换为字符串 '[Circular]'。|
249|    %o:  | Object. 具有通用 JavaScript 对象格式的对象的字符串表示形式。类似于具有选项 { showHidden: true, showProxy: true } 的 util.inspect()。这将显示完整的对象,包括不可枚举的属性和代理。|
250|    %O:  | Object. 具有通用 JavaScript 对象格式的对象的字符串表示形式。类似于没有选项的 util.inspect()。 这将显示完整的对象,但不包括不可枚举的属性和代理。|
251|    %c:  | 此说明符被忽略,将跳过任何传入的 CSS 。|
252|    %%:  | 单个百分号 ('%')。 这不消耗待式样化参数。|
253
254### 使用说明
255各接口使用方法如下:
256
2571.readonly encoding()
258
259```
260import util from '@ohos.util'
261var textEncoder = new util.TextEncoder();
262var getEncoding = textEncoder.encoding();
263```
2642.encode()
265```
266import util from '@ohos.util'
267var textEncoder = new util.TextEncoder();
268var result = textEncoder.encode('abc');
269```
2703.encodeInto()
271```
272import util from '@ohos.util'
273var textEncoder = new util.TextEncoder();
274var obj = textEncoder.encodeInto('abc', dest);
275```
2764.textDecoder()
277```
278import util from '@ohos.util'
279var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
280```
2815.readonly encoding()
282```
283import util from '@ohos.util'
284var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
285var getEncoding = textDecoder.encoding();
286```
2876.readonly fatal()
288```
289import util from '@ohos.util'
290var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
291var fatalStr = textDecoder.fatal();
292```
2937.readonly ignoreBOM()
294```
295import util from '@ohos.util'
296var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
297var ignoreBom = textDecoder.ignoreBOM();
298```
2998.decode()
300```
301import util from '@ohos.util'
302var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false});
303var result = textDecoder.decode(input, {stream : true});
304```
3059.printf()
306```
307import util from '@ohos.util'
308var format = "%%%o%%%i%s";
309var value =  function aa(){};
310var value1 = 1.5;
311var value2 = "qwer";
312var result = util.printf(format,value,value1,value2);
313```
31410.getErrorString()
315```
316import util from '@ohos.util'
317var errnum = 13;
318var result = util.getErrorString(errnum);
319```
32011.callbackWrapper()
321```
322import util from '@ohos.util'
323async function promiseFn() {
324    return Promise.resolve('value');
325};
326var cb = util.callbackWrapper(promiseFn);
327cb((err, ret) => {
328    expect(err).strictEqual(null);
329    expect(ret).strictEqual('value');
330})
331```
33212.promiseWrapper()
333```
334import util from '@ohos.util'
335function aysnFun(str1, str2, callback) {
336    if (typeof str1 === 'string' && typeof str1 === 'string') {
337        callback(null, str1 + str2);
338    } else {
339        callback('type err');
340    }
341}
342let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World');
343newPromiseObj.then(res => {
344    expect(res).strictEqual('HelloWorld');
345})
346```
34713.encodeSync()
348```
349import util from '@ohos.util'
350var that = new util.Base64();
351var array = new Uint8Array([115,49,51]);
352var result = that.encodeSync(array);
353```
35414.encodeToStringSync()
355```
356import util from '@ohos.util'
357var that = new util.Base64();
358var array = new Uint8Array([115,49,51]);
359var result = that.encodeToStringSync(array);
360```
36115.decodeSync()
362```
363import util from '@ohos.util'
364var that = new util.Base64()
365var buff = 'czEz';
366var result = that.decodeSync(buff);
367
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.valueOf();
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.valueOf();
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```
45929.toString()
460```
461import util from '@ohos.util'
462var pro = new util.RationalNumber(-2, 1);
463var res = pro.toString();
464```
46530.updateCapacity()
466```
467import util from '@ohos.util'
468var pro = new util.LruBuffer();
469var result = pro.updateCapacity(100);
470```
47131.toString()
472```
473import util from '@ohos.util'
474var pro = new util.LruBuffer();
475pro.put(2,10);
476pro.get(2);
477pro.remove(20);
478var result = pro.toString();
479```
48032.values()
481```
482import util from '@ohos.util'
483var pro = new util.LruBuffer();
484pro.put(2,10);
485pro.put(2,"anhu");
486pro.put("afaf","grfb");
487var result = pro.values();
488```
48933.length
490```
491import util from '@ohos.util'
492var pro = new util.LruBuffer();
493pro.put(2,10);
494pro.put(1,8);
495var result = pro.length;
496```
49734.getCapacity()
498```
499import util from '@ohos.util'
500var pro = new util.LruBuffer();
501var result = pro.getCapacity();
502```
50335.clear()
504```
505import util from '@ohos.util'
506var pro = new util.LruBuffer();
507pro.put(2,10);
508pro.clear();
509```
51036.getCreateCount()
511```
512import util from '@ohos.util'
513var pro = new util.LruBuffer();
514pro.put(1,8);
515var result = pro.getCreateCount();
516```
51737.getMissCount()
518```
519import util from '@ohos.util'
520var pro = new util.LruBuffer();
521pro.put(2,10);
522pro.get(2)
523var result = pro.getMissCount();
524```
52538.getRemovalCount()
526```
527
528import util from '@ohos.util'
529var pro = new util.LruBuffer();
530pro.put(2,10);
531pro.updateCapacity(2);
532pro.put(50,22);
533var result = pro.getRemovalCount();
534
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
560```
561import util from '@ohos.util'
562var pro = new util.LruBuffer();
563pro.put(2,10);
564var result = pro.get(2);
565```
56643.put()
567```
568import util from '@ohos.util'
569var pro = new util.LruBuffer();
570var result = pro.put(2,10);
571```
57244.keys()
573```
574import util from '@ohos.util'
575var pro = new util.LruBuffer();
576pro.put(2,10);
577var result = pro.keys();
578```
57945.remove()
580```
581import util from '@ohos.util'
582var pro = new util.LruBuffer();
583pro.put(2,10);
584var result = pro.remove(20);
585```
58646.contains()
587```
588import util from '@ohos.util'
589var pro = new util.LruBuffer();
590pro.put(2,10);
591var result = pro.contains(20);
592```
59347.createDefault()
594```
595import util from '@ohos.util'
596var pro = new util.LruBuffer();
597var result = pro.createDefault(50);
598```
59948.entries()
600```
601import util from '@ohos.util'
602var pro = new util.LruBuffer();
603pro.put(2,10);
604var result = pro.entries();
605```
60649.\[Symbol.iterator\]()
607```
608import util from '@ohos.util'
609var pro = new util.LruBuffer();
610pro .put(2,10);
611var result = pro[symbol.iterator]();
612```
61350.afterRemoval()
614```
615import util from '@ohos.util'
616var arr = [ ];
617class ChildLruBuffer extends util.LruBuffer
618{
619    constructor()
620    {
621        super();
622    }
623    static getInstance()
624    {
625        if(this.instance ==  null)
626        {
627            this.instance = new ChildLruBuffer();
628        }
629        return this.instance;
630    }
631    afterRemoval(isEvict, key, value, newValue)
632    {
633        if (isEvict === false)
634        {
635            arr = [key, value, newValue];
636        }
637    }
638}
639ChildLruBuffer.getInstance().afterRemoval(false,10,30,null)
640```
641Scope接口中构造新类,实现compareTo方法。
642
643```
644class Temperature {
645    constructor(value) {
646        this._temp = value;
647    }
648    compareTo(value) {
649        return this._temp >= value.getTemp();
650    }
651    getTemp() {
652        return this._temp;
653    }
654    toString() {
655        return this._temp.toString();
656    }
657}
658```
659
66051.constructor()
661
662```
663var tempLower = new Temperature(30);
664var tempUpper = new Temperature(40);
665var range = new Scope(tempLower, tempUpper);
666```
667
66852.toString()
669
670```
671var tempLower = new Temperature(30);
672var tempUpper = new Temperature(40);
673var range = new Scope(tempLower, tempUpper);
674var result = range.toString() // => [30,40]
675```
676
67753.intersect()
678
679```
680var tempLower = new Temperature(30);
681var tempUpper = new Temperature(40);
682var range = new Scope(tempLower, tempUpper);
683var tempMiDF = new Temperature(35);
684var tempMidS = new Temperature(39);
685var rangeFir = new Scope(tempMiDF, tempMidS);
686var result = range.intersect(rangeFir)  // => [35,39]
687```
688
68954.intersect()
690
691```
692var tempLower = new Temperature(30);
693var tempUpper = new Temperature(40);
694var tempMiDF = new Temperature(35);
695var tempMidS = new Temperature(39);
696var range = new Scope(tempLower, tempUpper);
697var result = range.intersect(tempMiDF, tempMidS)  // => [35,39]
698```
699
70055.getUpper()
701
702```
703var tempLower = new Temperature(30);
704var tempUpper = new Temperature(40);
705var range = new Scope(tempLower, tempUpper);
706var result = range.getUpper() // => 40
707```
708
70956.getLower()
710
711```
712var tempLower = new Temperature(30);
713var tempUpper = new Temperature(40);
714var range = new Scope(tempLower, tempUpper);
715var result = range.getLower() // => 30
716```
717
71857.expand()
719
720```
721var tempLower = new Temperature(30);
722var tempUpper = new Temperature(40);
723var tempMiDF = new Temperature(35);
724var tempMidS = new Temperature(39);
725var range = new Scope(tempLower, tempUpper);
726var result = range.expand(tempMiDF, tempMidS)  // => [30,40]
727```
728
72958.expand()
730
731```
732var tempLower = new Temperature(30);
733var tempUpper = new Temperature(40);
734var tempMiDF = new Temperature(35);
735var tempMidS = new Temperature(39);
736var range = new Scope(tempLower, tempUpper);
737var rangeFir = new Scope(tempMiDF, tempMidS);
738var result = range.expand(rangeFir) // => [30,40]
739```
740
74159.expand()
742
743```
744var tempLower = new Temperature(30);
745var tempUpper = new Temperature(40);
746var tempMiDF = new Temperature(35);
747var range = new Scope(tempLower, tempUpper);
748var result = range.expand(tempMiDF)  // => [30,40]
749```
750
75160.contains()
752
753```
754var tempLower = new Temperature(30);
755var tempUpper = new Temperature(40);
756var tempMiDF = new Temperature(35);
757var range = new Scope(tempLower, tempUpper);
758var result = range.contains(tempMiDF) // => true
759```
760
76161.contains()
762
763```
764var tempLower = new Temperature(30);
765var tempUpper = new Temperature(40);
766var range = new Scope(tempLower, tempUpper);
767var tempLess = new Temperature(20);
768var tempMore = new Temperature(45);
769var rangeSec = new Scope(tempLess, tempMore);
770var result = range.contains(rangeSec) // => true
771```
772
77362.clamp()
774
775```
776var tempLower = new Temperature(30);
777var tempUpper = new Temperature(40);
778var tempMiDF = new Temperature(35);
779var range = new Scope(tempLower, tempUpper);
780var result = range.clamp(tempMiDF) // => 35
781```
78263.isAnyArrayBuffer()
783```
784import util from '@ohos.util'
785var proc = new util.Types();
786var result = proc.isAnyArrayBuffer(new ArrayBuffer([]))
787```
78864.isArrayBufferView()
789```
790import util from '@ohos.util'
791var proc = new util.Types();
792var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16)));
793```
79465.isArgumentsObject()
795```
796import util from '@ohos.util'
797function foo() {
798        var result = proc.isArgumentsObject(arguments);
799    }
800var f = foo();
801```
80266.isArrayBuffer()
803```
804import util from '@ohos.util'
805var proc = new util.Types();
806var result = proc.isArrayBuffer(new ArrayBuffer([]));
807```
80867.isAsyncFunction()
809```
810import util from '@ohos.util'
811var proc = new util.Types();
812var result = proc.isAsyncFunction(async function foo() {});
813```
81468.isBigInt64Array()
815```
816import util from '@ohos.util'
817var proc = new util.Types();
818var result = proc.isBigInt64Array(new Int16Array([]));
819```
82069.isBigUint64Array()
821```
822import util from '@ohos.util'
823var proc = new util.Types();
824var result = proc.isBigUint64Array(new Int16Array([]));
825```
82670.isBooleanObject()
827```
828import util from '@ohos.util'
829var proc = new util.Types();
830var result = proc.isBooleanObject(new Boolean(false));
831```
83271.isBoxedPrimitive()
833```
834import util from '@ohos.util'
835var proc = new util.Types();
836var result = proc.isBoxedPrimitive(new Boolean(false));
837```
83872.isDataView()
839```
840import util from '@ohos.util'
841var proc = new util.Types();
842const ab = new ArrayBuffer(20);
843var result = proc.isDataView(new DataView(ab));
844```
84573.isDate()
846```
847import util from '@ohos.util'
848var proc = new util.Types();
849var result = proc.isDate(new Date());
850```
85174.isExternal()
852```
853import util from '@ohos.util'
854const data = util.createExternalType();
855var reult13 = proc.isExternal(data);
856```
85775.isFloat32Array()
858```
859import util from '@ohos.util'
860var proc = new util.Types();
861var result = proc.isFloat32Array(new Float32Array([]));
862```
86376.isFloat64Array()
864```
865import util from '@ohos.util'
866var proc = new util.Types();
867var result = proc.isFloat64Array(new Float64Array([]));
868```
86977.isGeneratorFunction()
870```
871import util from '@ohos.util'
872var proc = new util.Types();
873var result = proc.isGeneratorFunction(function* foo() {});
874```
87578.isGeneratorObject()
876```
877import util from '@ohos.util'
878var proc = new util.Types();
879function* foo() {}
880const generator = foo();
881var result = proc.isGeneratorObject(generator);
882```
88379.isInt8Array()
884```
885import util from '@ohos.util'
886var proc = new util.Types();
887var result = proc.isInt8Array(new Int8Array([]));
888```
88980.isInt16Array()
890```
891import util from '@ohos.util'
892var proc = new util.Types();
893var result = proc.isInt16Array(new Int16Array([]));
894```
89581.isInt32Array()
896```
897import util from '@ohos.util'
898var proc = new util.Types();
899var result = proc.isInt32Array(new Int32Array([]));
900```
90182.isMap()
902```
903import util from '@ohos.util'
904var proc = new util.Types();
905var result = proc.isMap(new Map());
906```
90783.isMapIterator()
908```
909import util from '@ohos.util'
910var proc = new util.Types();
911var result = proc.isMapIterator(map.keys());
912```
91384.isModuleNamespaceObject()
914```
915import util from '@ohos.util'
916var proc = new util.Types();
917var result = proc.isModuleNamespaceObject(util);
918```
91985.isNativeError()
920```
921import util from '@ohos.util'
922var proc = new util.Types();
923var result = proc.isNativeError(new TypeError());
924```
92586.isNumberObject()
926```
927import util from '@ohos.util'
928var proc = new util.Types();
929var result = proc.isNumberObject(new Number(0));
930```
93187.isPromise()
932```
933import util from '@ohos.util'
934var proc = new util.Types();
935var result = proc.isPromise(Promise.resolve(42));
936```
93788.isProxy()
938```
939import util from '@ohos.util'
940var proc = new util.Types();
941const target = {};
942const proxy = new Proxy(target, {});
943var result = proc.isProxy(proxy);
944```
94589.isRegExp()
946```
947import util from '@ohos.util'
948var proc = new util.Types();
949var result = proc.isRegExp(new RegExp('abc'));
950```
95190.isSet()
952```
953import util from '@ohos.util'
954var proc = new util.Types();
955var result = proc.isSet(new Set());
956```
95791.isSetIterator()
958```
959import util from '@ohos.util'
960var proc = new util.Types();
961const set = new Set();
962var result = proc.isSetIterator(set.keys());
963```
96492.isSharedArrayBuffer()
965```
966import util from '@ohos.util'
967var proc = new util.Types();
968var result = proc.isSharedArrayBuffer(new ArrayBuffer([]));
969```
97093.isStringObject()
971```
972import util from '@ohos.util'
973var proc = new util.Types();
974var result = proc.isStringObject(new String('foo'));
975```
97694.isSymbolObject()
977```
978import util from '@ohos.util'
979var proc = new util.Types();
980const symbols = Symbol('foo');
981var result = proc.isSymbolObject(Object(symbols));
982```
98395.isTypedArray()
984```
985import util from '@ohos.util'
986var proc = new util.Types();
987var result = proc.isTypedArray(new Float64Array([]));
988```
98996.isUint8Array()
990```
991import util from '@ohos.util'
992var proc = new util.Types();
993var result = proc.isUint8Array(new Uint8Array([]));
994```
99597.isUint8ClampedArray()
996```
997import util from '@ohos.util'
998var proc = new util.Types();
999var result = proc.isUint8ClampedArray(new Uint8ClampedArray([]));
1000```
100198.isUint16Array()
1002```
1003import util from '@ohos.util'
1004var proc = new util.Types();
1005var result = proc.isUint16Array(new Uint16Array([]));
1006```
100799.isUint32Array()
1008```
1009import util from '@ohos.util'
1010var proc = new util.Types();
1011var result = proc.isUint32Array(new Uint32Array([]));
1012```
1013100.isWeakMap()
1014```
1015import util from '@ohos.util'
1016var proc = new util.Types();
1017var result = proc.isWeakMap(new WeakMap());
1018```
1019101.isWeakSet()
1020```
1021import util from '@ohos.util'
1022var proc = new util.Types();
1023var result = proc.isWeakSet(new WeakSet());
1024```
1025## 相关仓
1026
1027[js_util_module子系统](base/compileruntime/js_util_module-readme_zh.md)
1028
1029## 许可证
1030
1031Util在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_util_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony/js_util_module/blob/master/LICENSE)