From 1956f2e85ded9813cbdb0c20975c57e3f8fd791f Mon Sep 17 00:00:00 2001 From: lengchangjing Date: Wed, 20 Jul 2022 15:53:10 +0800 Subject: [PATCH] Switch component name from ts_js_lang_library to ets_utils for js_api_module,js_util_module,js_sys_module,js_worker_module Related Issue https://gitee.com/openharmony/manifest/issues/I5HDQT Description Switch component name from ts_js_lang_library to ets_utils for js_api_module,js_util_module,js_sys_module,js_worker_module Signed-off-by: lengchangjing --- js_sys_module/LICENSE => LICENSE | 0 README.en.md | 2210 ++++++++++++++++ README.md | 2211 +++++++++++++++++ bundle.json | 68 + js_api_module/LICENSE | 177 -- js_api_module/README.md | 457 ---- js_api_module/README_zh.md | 456 ---- js_api_module/bundle.json | 64 - js_api_module/convertxml/BUILD.gn | 12 +- js_api_module/convertxml/js_convertxml.cpp | 0 js_api_module/convertxml/js_convertxml.h | 0 .../convertxml/native_module_convertxml.cpp | 0 js_api_module/test_uri/unittest/BUILD.gn | 4 +- js_api_module/test_uri/unittest/test.h | 0 js_api_module/test_uri/unittest/test_napi.cpp | 0 js_api_module/test_xml/unittest/BUILD.gn | 4 +- js_api_module/uri/BUILD.gn | 12 +- js_api_module/uri/js_uri.cpp | 0 js_api_module/uri/js_uri.h | 0 js_api_module/uri/native_module_uri.cpp | 0 js_api_module/url/BUILD.gn | 12 +- js_api_module/url/js_url.cpp | 0 js_api_module/url/js_url.h | 0 js_api_module/url/native_module_url.cpp | 0 js_api_module/xml/BUILD.gn | 12 +- js_sys_module/README.md | 365 --- js_sys_module/README_zh.md | 366 --- js_sys_module/bundle.json | 59 - js_sys_module/dfx/BUILD.gn | 6 +- js_sys_module/process/BUILD.gn | 6 +- js_sys_module/test/unittest/BUILD.gn | 4 +- js_sys_module/test/unittest/test.h | 0 js_sys_module/test/unittest/test_process.cpp | 0 js_util_module/LICENSE | 177 -- js_util_module/README.md | 1031 -------- js_util_module/README_zh.md | 1032 -------- js_util_module/bundle.json | 59 - js_util_module/container/BUILD.gn | 10 +- js_util_module/container/build_ts_js.py | 2 +- js_util_module/util/BUILD.gn | 12 +- js_util_module/util/js_base64.cpp | 0 js_util_module/util/js_base64.h | 0 js_util_module/util/js_textdecoder.cpp | 0 js_util_module/util/js_textdecoder.h | 0 js_util_module/util/js_textencoder.cpp | 0 js_util_module/util/js_textencoder.h | 0 js_util_module/util/native_module_util.cpp | 0 js_worker_module/BUILD.gn | 10 +- js_worker_module/LICENSE | 177 -- js_worker_module/README.md | 367 --- js_worker_module/README.zh.md | 368 --- js_worker_module/bundle.json | 58 - js_worker_module/helper/napi_helper.cpp | 2 +- js_worker_module/plugin/timer.cpp | 2 +- js_worker_module/plugin/timer.h | 4 +- js_worker_module/worker/message_queue.cpp | 2 +- .../worker/native_module_worker.cpp | 2 +- js_worker_module/worker/thread.cpp | 2 +- js_worker_module/worker/worker.cpp | 4 +- js_worker_module/worker/worker.h | 8 +- js_worker_module/worker/worker_runner.cpp | 4 +- js_worker_module/worker/worker_runner.h | 2 +- 62 files changed, 4558 insertions(+), 5282 deletions(-) rename js_sys_module/LICENSE => LICENSE (100%) create mode 100644 README.en.md create mode 100644 README.md create mode 100644 bundle.json delete mode 100755 js_api_module/LICENSE delete mode 100755 js_api_module/README.md delete mode 100755 js_api_module/README_zh.md delete mode 100644 js_api_module/bundle.json mode change 100755 => 100644 js_api_module/convertxml/BUILD.gn mode change 100755 => 100644 js_api_module/convertxml/js_convertxml.cpp mode change 100755 => 100644 js_api_module/convertxml/js_convertxml.h mode change 100755 => 100644 js_api_module/convertxml/native_module_convertxml.cpp mode change 100755 => 100644 js_api_module/test_uri/unittest/BUILD.gn mode change 100755 => 100644 js_api_module/test_uri/unittest/test.h mode change 100755 => 100644 js_api_module/test_uri/unittest/test_napi.cpp mode change 100755 => 100644 js_api_module/uri/BUILD.gn mode change 100755 => 100644 js_api_module/uri/js_uri.cpp mode change 100755 => 100644 js_api_module/uri/js_uri.h mode change 100755 => 100644 js_api_module/uri/native_module_uri.cpp mode change 100755 => 100644 js_api_module/url/BUILD.gn mode change 100755 => 100644 js_api_module/url/js_url.cpp mode change 100755 => 100644 js_api_module/url/js_url.h mode change 100755 => 100644 js_api_module/url/native_module_url.cpp delete mode 100755 js_sys_module/README.md delete mode 100755 js_sys_module/README_zh.md delete mode 100644 js_sys_module/bundle.json mode change 100755 => 100644 js_sys_module/test/unittest/BUILD.gn mode change 100755 => 100644 js_sys_module/test/unittest/test.h mode change 100755 => 100644 js_sys_module/test/unittest/test_process.cpp delete mode 100755 js_util_module/LICENSE delete mode 100755 js_util_module/README.md delete mode 100644 js_util_module/README_zh.md delete mode 100644 js_util_module/bundle.json mode change 100755 => 100644 js_util_module/util/BUILD.gn mode change 100755 => 100644 js_util_module/util/js_base64.cpp mode change 100755 => 100644 js_util_module/util/js_base64.h mode change 100755 => 100644 js_util_module/util/js_textdecoder.cpp mode change 100755 => 100644 js_util_module/util/js_textdecoder.h mode change 100755 => 100644 js_util_module/util/js_textencoder.cpp mode change 100755 => 100644 js_util_module/util/js_textencoder.h mode change 100755 => 100644 js_util_module/util/native_module_util.cpp delete mode 100644 js_worker_module/LICENSE delete mode 100644 js_worker_module/README.md delete mode 100644 js_worker_module/README.zh.md delete mode 100644 js_worker_module/bundle.json diff --git a/js_sys_module/LICENSE b/LICENSE similarity index 100% rename from js_sys_module/LICENSE rename to LICENSE diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..b7a520c --- /dev/null +++ b/README.en.md @@ -0,0 +1,2210 @@ +# ets_utils + +- [Submodule](#Submodule) + - [1.js_api_module submodule](#1.js_api_module submodule) + - [1.1.Introduction](#1.1.Introduction) + - [1.2.Contents](#1.2.Contents) + - [1.3.Illustrate](#1.3.Illustrate) + - [1.3.1.Interface Description](#1.3.1.Interface Description) + - [1.3.2.Instructions for use](#1.3.2.Instructions for use) + - [2.js_util_module submodule](#2.js_util_module submodule) + - [2.1.Introduction](#2.1.Introduction) + - [2.2.Contents](#2.2.Contents) + - [2.3.Illustrate](#2.3.Illustrate) + - [2.3.1.Interface Description](#2.3.1.Interface Description) + - [2.3.2.Instructions for use](#2.3.2.Instructions for use) + - [3.js_sys_module submodule](#3.js_sys_module submodule) + - [3.1.Introduction](#3.1.Introduction) + - [3.2.Contents](#3.2.Contents) + - [3.3.Illustrate](#3.3.Illustrate) + - [3.3.1.Interface Description](#3.3.1.Interface Description) + - [3.3.2.Instructions for use](#3.3.2.Instructions for use) + - [4.js_worker_module submodule](#4.js_worker_module submodule) + - [4.1.Introduction](#4.1.Introduction) + - [4.2.Interface description](#4.2.Interface description) + - [4.2.1.Worker object description](#4.2.1.Worker object description) + - [4.2.1.1.Interface](#4.2.1.1.Interface) + - [4.2.1.2.Attribute](#4.2.1.2.Attribute) + - [4.2.2.parentPort object description](#4.2.2.parentPort object description) + - [4.2.2.1.Interface](#4.2.2.1.Interface) + - [4.2.2.2.Attribute](#4.2.2.2.Attribute) +- [Related warehouse](#Related warehouse) +- [License](#License) + +## 1.js_api_module_submodule +### 1.1.Introduction + +The interface of URL is used to parse, construct, normalize, and encode URLs. The constructor of URL creates a new URL object. In order to make changes to the resolved components of the URL or to the URL. The URLSearchParams interface defines some practical methods to process URL query strings. + +URI Represents a Uniform Resource Identifier (URI) reference. + +XML representation refers to extensible markup language. + +The XmlSerializer interface is used to generate an xml file. The constructor of XmlSerializer creates a new XmlSerializer object, and calls the method of the XmlSerializer object to generate an xml file. The XmlPullParser interface is used to parse the existing xml file. The constructor of XmlPullParser creates a new XmlPullParser object, and calls the method of the XmlPullParser object to parse the xml file. + +### 1.2.Contents + +``` +commomlibrary/ets_utils/js_api_module/ +├── Class:URL # URL class +│ ├── new URL(input[, base]) # Create URL object +│ ├── hash # hash attribute +│ ├── host # host attribute +│ ├── hostname # hostname attribute +│ ├── href # href attribute +│ ├── origin # origin attribute +│ ├── password # password attribute +│ ├── pathname # pathname attribute +│ ├── port # port attribute +│ ├── protocol # protocol attribute +│ ├── search # search attribute +│ ├── searchParams # searchParams attribute +│ ├── username # username attribute +│ ├── toString() # toString method +│ └── toJSON() # toJSON method +├── Class: URLSearchParams # URLSearchParams class +│ ├── new URLSearchParams() # Create URLSearchParams object +│ ├── new URLSearchParams(string) # Create URLSearchParams object +│ ├── new URLSearchParams(obj) # Create URLSearchParams object +│ ├── new URLSearchParams(iterable) # Create URLSearchParams object +│ ├── append(name, value) # append method +│ ├── delete(name) # delete method +│ ├── entries() # entries method +│ ├── forEach(fn[, thisArg]) # forEach method +│ ├── get(name) # get method +│ ├── getAll(name) # getAll method +│ ├── has(name) # has method +│ ├── keys() # keys method +│ ├── set(name, value) # set method +│ ├── sort() # sort method +│ ├── toString() # toString method +│ ├── values() # values method +│ └── urlSearchParams[Symbol.iterator]() # Create URLSearchParams object +├── Class:URI # URI class +│ ├── URI(str: string) # Create URI object +│ ├── scheme # scheme attribute +│ ├── authority # authority attribute +│ ├── ssp # ssp attribute +│ ├── userinfo # userinfo attribute +│ ├── host # host attribute +│ ├── port # port attribute +│ ├── query # query attribute +│ ├── fragment # fragment attribute +│ ├── path # path method +│ ├── equals(ob: Object) # equals method +│ ├── normalize() # normalize method +│ ├── checkIsAbsolute() # checkIsAbsolute method +│ ├── normalize() # normalize method +│ ├── toString() # toString method +├── Class:ConvertXml # ConvertXml class +│ ├── ConvertXml() # Create convertxml class object +│ └── convert(xml: string, options: Object) # convert method +├── Class:XmlSerializer # XmlSerializer class +│ ├── new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) # Create XmlSerializer class object +│ ├── setAttributes(name: string, value: string) # Set Attributes method +│ ├── addEmptyElement(name: string) # Add an empty element method +│ ├── setDeclaration() # Set the Declaration method +│ ├── startElement(name: string) # Set the start element method +│ ├── endElement() # Set the end element method +│ ├── setNamespace(prefix: string, namespace: string) # Namespace method +│ ├── setCommnet(text: string) # Set up Commnet method +│ ├── setCData(text: string) # Set the CData method +│ ├── setText(text: string) # Set the Text method +│ ├── setDocType(text: string) # Set DocType method +└── Class: XmlPullParser # XmlPullParser class + ├── new (buffer: ArrayBuffer | DataView, encoding?: string) # Create XmlPullParser object + └── parse(option: ParseOptions) # parse method +``` + +### 1.3.Illustrate + +#### 1.3.1.Interface Description + + +| Interface name | Illustrate | +| -------- | -------- | +| new URL(url: string,base?:string \| URL) | Create and return a URL object that references the URL specified by the absolute URL string, the relative URL string, and the basic URL string. | +| tostring():string | The stringification method returns a USVString containing the complete URL. It is equivalent to the read-only URL.href. | +| toJSON():string | This method returns a USVString, which contains a serialized URL version. | +| new URLSearchParams() | The URLSearchParams() constructor has no parameters. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | +| new URLSearchParams(string) | The input parameter of URLSearchParams(string) constructor is string data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | +| new URLSearchParams(obj) | URLSearchParams(obj) The input parameter of the constructor is the obj data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | +| new URLSearchParams(iterable) | URLSearchParams(iterable) The input parameter of the constructor is the iterable data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | +| has(name: string): boolean | Retrieve whether the searchParams object contains name. If yes, it returns true, otherwise it returns false. | +| set(name: string, value string): void | Retrieve whether the searchParams object contains a key-value pair whose key is name. If not, add the key-value pair, if any, modify the value corresponding to the first key in the object, and delete the remaining key-value pairs whose key is name. | +| sort(): void | According to the Unicode code point of the key, sort all key/value pairs contained in this object and return undefined. | +| toString(): string | According to the searchParams object, the query string applicable in the URL is returned. | +| keys(): iterableIterator\ | Return an iterator, which allows iterating through all the key values contained in the object. | +| values(): iterableIterator\ | Returns an iterator, which allows iterating over all the value values contained in the object. | +| append(name: string, value: string): void | Insert the name, value key-value pair in the searchParams object. | +| delete(name: string): void | Traverse the searchParams object, find all the names, and delete the corresponding key-value pairs. | +| get(name: string): string | Retrieve the first name in the searchParams object and return the value corresponding to the name key. | +| getAll(name: string): string[] | Retrieve all names in the searchParams object and return all the values corresponding to the name key. | +| entries(): iterableIterator<[string, string]> | Returns an iterator that allows iterating through all key/value pairs contained in the searchParams object. | +| forEach(): void | Through the callback function to traverse the key-value pairs on the URLSearchParams instance object. | +| urlSearchParams\[Symbol.iterator]() | Returns an ES6 iterator for each name-value pair in the query string. Each item of the iterator is a JavaScript array. | +| URI​(str: string) | Construct the URI by parsing the given input parameter (String str). This constructor parses the given string strictly in accordance with the grammatical provisions in RFC 2396 Appendix A. | +| getScheme​() | Return the scheme component of this URI, or null if the scheme is not defined. | +| getAuthority​() | Returns the decoded authority component of this URI, or null if authority is not defined. The string returned by this method is the same as the string returned by the getRawAuthority method, except that all escaped octet sequences are decoded. | +| getSchemeSpecificPart​() | Returns the decoding scheme-specific part of this URI. The string returned by this method is the same as the string returned by the getRawSchemeSpecificPart method, except that all escaped octet sequences are decoded. | +| getUserInfo​() | Returns the decoded userinfo component of this URI. The userinfo component of the URI (if defined) only contains characters in unreserved, punctuation, escape, and other categories. | +| getHost​() | Return the host component of this URI, or null if host is not defined. | +| getPort​() | Return the port of this URI, or -1 if the port is not defined. The port component of the URI (if defined) is a non-negative integer. | +| getQuery​() | Returns the decoded query component of this URI, or null if the query is not defined. The string returned by this method is the same as the string returned by the getRawQuery method, except that all escaped octet sequences are decoded. | +| getFragment​() | Returns the decoded fragment component of this URI, or null if the fragment is not defined. The string returned by this method is the same as the string returned by the getRawFragment method, except that all escaped octet sequences are decoded. | +| getPath​() | Returns the decoded path component of this URI, or null if path is not defined. The string returned by this method is the same as the string returned by the getRawPath method, except that all escaped octet sequences are decoded. | +| equals(ob: Object) | Test whether this URI is equal to another object. If the given object is not a URI, this method immediately returns false. | +| normalize​() | Normalize the path of this URI. If this URI is opaque, or its path is already in normal form, then this URI is returned. Otherwise, a new URI identical to this URI will be constructed. | +| checkIsAbsolute() | Determine whether this URI is absolute. If and only if it has a scheme component, the URI is absolute and the return value is true, otherwise the return value is false. | +| toString() | Return the content of this URI as a string. | +| ConvertXml() | The constructor used to construct the convertxml class object. This constructor does not need to pass in parameters. | +| convert(xml: string, options: Object) | Returns a JavaScript object that converts an XML string as required by the option. | +| XmlSerializer(buffer: ArrayBuffer \| DataView, encoding?: string) | Create and return an XmlSerializer object. The XmlSerializer object passes two parameters. The first parameter is ArrayBuffer or DataView, and the second parameter is the file format (UTF-8 by default). | +| setAttributes(name: string, value: string): void | Write the Attributes attribute to the xml file. | +| addEmptyElement(name: string): void | Write an empty element. | +| setDeclaration(): void | Set the Declaration to use the encoding to write the xml declaration. For example: | +| startElement(name: string): void | Write the elemnet start tag with the given name.| +| endElement(): void | Write the end tag of the element. | +| setNamespace(prefix: string, namespace: string): void | Write the namespace of the current element tag. | +| setCommnet(text: string): void | Write the comment attribute. | +| setCData(text: string): void | Write the CData attribute. | +| setText(text: string): void | Write the Text property. | +| setDocType(text: string): void | Write the DocType attribute. | +| XmlPullParser(buffer: ArrayBuffer \| DataView, encoding?: string) | Create and return an XmlPullParser object. The XmlPullParser object passes two parameters. The first parameter is ArrayBuffer or DataView, and the second parameter is the file format (default is UTF-8). | +| parse(option: ParseOptions): void | This interface is used to parse xml. The ParseOptions parameter is an interface containing five optional parameters {supportDoctype?: boolea ignoreNameSpace?: boolean tagValueCallbackFunction?: (name: string, value: string) => boolean attributeValueCallbackFunction?: (name: string, value: string) => boolean) tokenValueCallbackFunction?: (eventType: EventType, value: ParseInfo) => boolean }. The input parameter 1 of the tokenValueCallbackFunction callback function is the event type, and the input parameter 2 is the info interface containing get attributes such as getColumnNumber and getDepth. The user can obtain the depth and other information in the current parsing process through methods such as info.getDepth(). | +#### 1.3.2.Instructions for use + +The usage of each interface is as follows: + + +1、new URL(url: string,base?:string|URL) +``` +let b = new URL('https://developer.mozilla.org'); // => 'https://developer.mozilla.org/' + +let a = new URL( 'sca/./path/path/../scasa/text', 'http://www.example.com'); +// => 'http://www.example.com/sca/path/scasa/text' +``` +2、tostring():string +``` +const url = new URL('http://10.0xFF.O400.235:8080/directory/file?query#fragment'); +url.toString() // => 'http://10.0xff.o400.235:8080/directory/file?query#fragment' + +const url = new URL("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"); +url.toString() // => 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html' + +const url = new URL("http://username:password@host:8080/directory/file?query#fragment"); +url.toString() // => 'http://username:password@host:8080/directory/file?query#fragment' +``` +3、toJSON():string +``` +const url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/toString"); +url.toJSON(); // => 'https://developer.mozilla.org/en-US/docs/Web/API/URL/toString' +``` +4、new URLSearchParams() +``` +let params = new URLSearchParams('foo=1&bar=2'); +``` +5、new URLSearchParams(string) +``` +params = new URLSearchParams('user=abc&query=xyz'); +console.log(params.get('user')); +// Prints 'abc' +``` +6、new URLSearchParams(obj) +``` +const params = new URLSearchParams({ + user: 'abc', + query: ['first', 'second'] +}); +console.log(params.getAll('query')); +// Prints [ 'first,second' ] +``` +7、new URLSearchParams(iterable) +``` +let params; + +// Using an array +params = new URLSearchParams([ + ['user', 'abc'], + ['query', 'first'], + ['query', 'second'], +]); +console.log(params.toString()); +// Prints 'user = abc & query = first&query = second' +``` +8、has(name: string): boolean +``` +console.log(params.has('bar')); // =>true +``` +9、set(name: string, value string): void +``` +params.set('baz', 3); +``` +10、sort(): void +``` +params .sort(); +``` +11、toString(): string +``` +console.log(params .toString()); // =>bar=2&baz=3&foo=1' +``` +12、keys(): iterableIterator\ +``` +for(var key of params.keys()) { + console.log(key); +} // =>bar baz foo +``` +13、values(): iterableIterator\ +``` +for(var value of params.values()) { + console.log(value); +} // =>2 3 1 +``` +14、append(name: string, value: string): void +``` +params.append('foo', 3); // =>bar=2&baz=3&foo=1&foo=3 +``` +15、delete(name: string): void +``` +params.delete('baz'); // => bar=2&foo=1&foo=3 +``` +16、get(name: string): string +``` +params.get('foo'); // => 1 +``` +17、getAll(name: string): string[] +``` +params.getAll('foo'); // =>[ '1', '3' ] +``` +18、entries(): iterableIterator<[string, string]> +``` +for(var pair of searchParams.entries()) { + console.log(pair[0]+ ', '+ pair[1]); +} // => bar, 2 foo, 1 foo, 3 +``` +19、forEach(): void +``` +url.searchParams.forEach((value, name, searchParams) => { + console.log(name, value, url.searchParams === searchParams); +}); +// => foo 1 true +// => bar 2 true +``` +20、urlSearchParams[Symbol.iterator] () +``` +const params = new URLSearchParams('foo=bar&xyz=baz'); +for (const [name, value] of params) { + console.log(name, value); +} +// Prints: +// foo bar +// xyz bar +``` + + +21、URI​(String str) +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +``` +22、scheme +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.scheme // => "http"; +``` +23、authority +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.authority // => "gg:gaogao@www.baidu.com:99"; +``` +24、ssp +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.ssp " // => gg:gaogao@www.baidu.com:99/path/path?query"; +``` +25、userinfo +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.userinfo // => "gg:gaogao"; +``` +26、host +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.host // => "www.baidu.com"; +``` +27、port +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.port // => "99"; +``` +28、query +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.query // => "query"; +``` +29、fragment +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.fragment // => "fagment"; +``` +30、path +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.path // => "/path/path"; +``` +31、equals(Object ob) +``` +let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment'); +let gaogao1 = gaogao; +let res = gaogao.equals(gaogao1); +console.log(res); // => true; +``` +32、normalize​() +``` +let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment'); +let res = gaogao.normalize(); +console.log(res.path); // => "/path/path1" +console.log(res.toString()); // => "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment" +``` +33、checkIsAbsolute() +``` +let gaogao = new Uri.URI('f/tp://username:password@www.baidu.com:88/path?query#fagment'); +let res = gaogao.checkIsAbsolute(); +console.log(res); //=> false; +``` +34、toString() +``` +let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'); +let res = gaogao.toString(); +console.log(res.toString()); // => 'http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'; +``` + + +35、ConvertXml() +``` +var convertml = new convertXml.ConvertXml(); +``` +36、convert(xml: string, options: Object) +``` +var result = convertml.convert(xml, {compact: false, spaces: 4}); +``` +37、new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) +``` + +var arrayBuffer = new ArrayBuffer(1024); +var bufView = new DataView(arrayBuffer); +var thatSer = new xml.XmlSerializer(bufView); +``` +38、setDeclaration():void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setDeclaration() // => ; +``` +39、setCommnet(text: string):void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setCommnet("Hello, World!"); // => ; +``` +40、setCData(text: string) :void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); // => +``` +41、setDocType(text: string):void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setDocType("foo"); // => +``` +42、setNamespace(prefix: string, namespace: string): void +43、startElement(name: string): void +44、setAttributes(name: string, value: string): void +45、endElement(): void +46、setText(text: string): void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); +thatSer.startElement("table"); +thatSer.setAttributes("importance", "high"); +thatSer.setText("Happy"); +endElement(); // => Happy +``` +47、addEmptyElement(name: string): void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.addEmptyElement("b"); // => +``` +48、new (buffer: ArrayBuffer | DataView, encoding?: string) +``` +var strXml = + '' + + '' + + ' Happy' + + ''; +var arrayBuffer = new ArrayBuffer(strXml.length*2); +var bufView = new Uint8Array(arrayBuffer); +var strLen = strXml.length; +for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i);//设置arraybuffer 方式 +} +var that = new xml.XmlPullParser(arrayBuffer); + +``` +49、parse(option: ParseOptions): void +``` +var strXml = + '' + + '' + + ' Happy' + + ''; +var arrayBuffer = new ArrayBuffer(strXml.length*2); +var bufView = new Uint8Array(arrayBuffer); +var strLen = strXml.length; +for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i); +} +var that = new xml.XmlPullParser(arrayBuffer); +var arrTag = {}; +arrTag[0] = '132'; +var i = 1; +function func(key, value){ + arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); + i++; + return true; +} +var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}; +that.parse(options); +``` + +## 2.js_util_module submodule +### 2.1.Introduction +The 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. +Encodes 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. +### 2.2.contants + +``` +commomlibrary/ets_utils/js_util_module/ +├── Class:TextEncoder # TextEncoder class +│ ├── new TextEncoder() # create textencoder object +│ ├── encode() # encode method +│ ├── encoding # encoding property +│ └── encodeInto() # encodeInto method +├── Class:TextDecoder # TextDecoder class +│ ├── new TextDecoder() # create TextDecoder object +│ ├── decode() # decode method +│ ├── encoding # encoding property +│ ├── fatal # fatal property +│ └── ignoreBOM # ignoreBOM property +├── printf() # printf method +├── getErrorString() # getErrorString method +├── callbackWrapper() # callbackWrapper method +├── promiseWrapper() # promiseWrapper method +├── Class:Base64 # Base64 class +│ ├── new Base64() # create Base64 object +│ ├── encodeSync() # encodeSync method +│ ├── encodeToStringSync() # encodeToStringSync method +│ ├── decodeSync() # decodeSync method +│ ├── encode() # encode method +│ ├── encodeToString() # encodeToString method +│ └── decode() # decode method +├── Class:RationalNumber # RationalNumber class +│ ├── new RationalNumber() # create RationalNumber object +│ ├── createRationalFromString() # creatRationalFromString method +│ ├── compareTo() # compareTo method +│ ├── equals() # equals method +│ ├── valueOf() # valueOf method +│ ├── getCommonDivisor() # getCommonDivisor method +│ ├── getDenominator() # getDenominator method +│ ├── getNumerator() # getNumerator method +│ ├── isFinite() # isFinite method +│ ├── isNaN() # isNaN method +│ ├── isZero() # isZero method +│ └── toString() # toString method +├── Class:LruBuffer # LruBuffer class +│ ├── new LruBuffer() # create RationalNumber object +│ ├── updateCapacity() # updateCapacity method +│ ├── toString() # toString method +│ ├── values() # values method +│ ├── length # attribute of length +│ ├── getCapacity() # getCapacity method +│ ├── clear() # clear method +│ ├── getCreateCount # getCreateCount method +│ ├── getMissCount() # getMissCount method +│ ├── getRemovalCount() # getRemovalCount method +│ ├── getMatchCount() # getMatchCount method +│ ├── getPutCount() # getPutCount method +│ ├── isEmpty() # isEmpty method +│ ├── get() # get method +│ ├── put() # put method +│ ├── keys() # keys method +│ ├── remove() # remove method +│ ├── afterRemoval() # afterRemoval method +│ ├── contains() # contains method +│ ├── createDefault() # createDefault method +│ ├── entries() # entries method +│ └── [Symbol.iterator]() # Symboliterator method +├── Class:Scope # Scope class +| ├── constructor() # create Scope object +| ├── toString() # toString method +| ├── intersect() # intersect method +| ├── intersect() # intersect method +| ├── getUpper() # getUpper method +| ├── getLower() # getLower method +| ├── expand() # expand method +| ├── expand() # expand method +| ├── expand() # expand method +| ├── contains() # contains method +| ├── contains() # contains method +| └── clamp() # clamp method +└── Class:Types # Types class + ├── isAnyArrayBuffer() # isAnyArrayBuffer method + ├── isArrayBufferView() # isArrayBufferView method + ├── isArgumentsObject() # isArgumentsObject method + ├── isArrayBuffer() # isArrayBuffer method + ├── isAsyncFunction() # isAsyncFunction method + ├── isBigInt64Array() # isBigInt64Array method + ├── isBigUint64Array() # isBigUint64Array method + ├── isBooleanObject() # isBooleanObject method + ├── isBoxedPrimitive() # isBoxedPrimitive method + ├── isDataView() # isDataView method + ├── isDate() # isDate method + ├── isExternal() # isExternal method + ├── isFloat32Array() # isFloat32Arraymethod + ├── isFloat64Array() # isFloat64Array method + ├── isGeneratorFunction() # isGeneratorFunction method + ├── isGeneratorObject() # isGeneratorObject method + ├── isInt8Array() # isInt8Array method + ├── isInt16Array() # isInt16Array method + ├── isInt32Array() # isInt32Array method + ├── isMap() # isMap method + ├── isMapIterator() # isMapIterator method + ├── isModuleNamespaceObject() # isModuleNamespaceObject method + ├── isNativeError() # isNativeError method + ├── isNumberObject() # isNumberObject method + ├── isPromise() # isPromise method + ├── isProxy() # isProxy method + ├── isRegExp() # isRegExp method + ├── isSet() # isSet method + ├── isSetIterator() # isSetIterator method + ├── isSharedArrayBuffer() # isSharedArrayBuffer method + ├── isStringObject() # isStringObject method + ├── isSymbolObject() # isSymbolObject method + ├── isTypedArray() # isTypedArray method + ├── isUint8Array() # isUint8Array method + ├── isUint8ClampedArray() # isUint8ClampedArray method + ├── isUint16Array() # isUint16Array method + ├── isUint32Array() # isUint32Array method + ├── isWeakMap() # isWeakMap method + └── isWeakSet() # isWeakSet method +``` + +### 2.3.Description + +#### 2.3.1.Interface description +| Interface name | Description | +| -------- | -------- | +| constructor(encoding? : string) | Constructor, the parameter encoding indicates the format of encoding. Default utf-8, Support gb18030, gbk, gb2312. | +| readonly encoding : string | In the TextEncoder module, get the encoding format. | +| encode(input : string) : Uint8Array | Input string string, encoding according to encoding and output uint8 byte stream. | +| 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. | +| 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. | +| readonly encoding : string | In the TextDecoder module, get the set decoding format. | +| readonly fatal : boolean | Get the setting that throws the exception. | +| readonly ignoreBOM : boolean | Get whether to ignore the setting of the bom flag. | +| 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. | +| encodeSync(src: Uint8Array): Uint8Array; | Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | +| encodeToStringSync(src: Uint8Array): string; | Encodes the specified byte array as a String using the Base64 encoding scheme. | +| 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. | +| encode(src: Uint8Array): Promise\; | Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | +| encodeToString(src: Uint8Array): Promise\; | Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. | +| decode(src: Uint8Array \| string): Promise\; | Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. | +| static createRationalFromString(rationalString: string): RationalNumber | Create a RationalNumber object based on the given string. | +| compareTo(another: RationalNumber): number | Compare the current RationalNumber object with the given object. | +| equals(obj: object): number | Check if the given object is the same as the current RationalNumber object.| +| valueOf(): number | Take the current RationalNumber object to an integer value or a floating point value. | +| static getCommonDivisor(number1: number, number2: number,): number | Obtain the greatest common divisor of two specified numbers. | +| getDenominator(): number | Get the denominator of the current RationalNumber object. | +| getNumerator(): number | Get the numerator of the current RationalNumber object. | +| isFinite(): boolean | Check that the current RationalNumber object is limited. | +| isNaN(): boolean | Check whether the current RationalNumber object represents a non-number (NaN) value. | +| isZero(): boolean | Check whether the current RationalNumber object represents a zero value. | +| toString(): string | Get the string representation of the current RationalNumber object. | +| constructor(capacity?: number) | The Create Default constructor is used to create a new LruBuffer instance with a default capacity of 64. | +| 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. | +| toString(): string | Returns the string representation of the object and outputs the string representation of the object. | +| 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. | +| length: number | represents the total number of values in the current buffer. The output returns the total number of values in the current buffer. | +| getCapacity(): number | Gets the capacity of the current buffer. The output returns the capacity of the current buffer. | +| 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. | +| getCreateCount(): number | Get the number of times the returned value of createdefault(), and output the number of times the returned value of createdefault(). | +| 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. | +| getRemovalCount(): number | Gets the number of evictions from the buffer, and outputs the number of evictions from the buffer. | +| getMatchCount​(): number | Obtain the number of successful matching of query values, and output the number of successful matching of query values. | +| 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. | +| isEmpty(): boolean | Checks whether the current buffer is empty and returns true if the current buffer does not contain any values. | +| 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. | +| 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. | +| 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. | +| remove​(key: K):V \| undefined | Deletes the specified key and its associated value from the current buffer. | +| afterRemoval(isEvict: boolean, key: K, value: V, newValue: V): void | Perform subsequent operations after deleting the value. | +| contains(key: K): boolean | Checks whether the current buffer contains the specified key, and returns true if the buffer contains the specified key. | +| 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. | +| 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. | +| \[Symbol.iterator\](): [K,V]| Returns a two-dimensional array in the form of key value pairs. | +| 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. | +| toString():string | The stringification method returns a string representation that contains the current range. | +| intersect(range: Scope): Scope | Gets the intersection of the given range and the current range. | +| intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope | Gets the intersection of the current range with a given lower and upper bound range. | +| getUpper(): ScopeType | Gets the upper bound of the current scope. | +| getLower(): ScopeType | Gets the lower bound of the current scope. | +| expand(lowerObj: ScopeType, upperObj: ScopeType): Scope | Creates and returns a union that includes the current range and a given lower and upper bound. | +| expand(range: Scope): Scope | Creates and returns a union that includes the current range and the given range. | +| expand(value: ScopeType): Scope | Creates and returns a union that includes the current range and the given value. | +| contains(value: ScopeType): boolean | Checks whether the given value is included in the current range. | +| contains(range: Scope): boolean | Checks whether the given range is within the current range. | +| clamp(value: ScopeType): ScopeType | Clips the specified value to the current range. | +| 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. | +| function getErrorString(errno: number): string | The geterrorstring () method uses a system error number as a parameter to return system error information. | +| 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. | +| 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. | +| isAnyArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer or sharedarraybuffer type. | +| 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. | +| isArgumentsObject(value: Object): boolean | Check whether the entered value is an arguments object type. | +| isArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer type. | +| isAsyncFunction(value: Object): boolean | Check whether the value entered is an asynchronous function type. | +| isBigInt64Array(value: Object): boolean | Check whether the entered value is of bigint64array array type. | +| isBigUint64Array(value: Object): boolean | Check whether the entered value is of biguint64array array array type. | +| isBooleanObject(value: Object): boolean | Check whether the entered value is a Boolean object type. | +| isBoxedPrimitive(value: Object): boolean | Check whether the entered value is a Boolean or number or string or symbol object type. | +| isDataView(value: Object): boolean | Check whether the entered value is of DataView type. | +| isDate(value: Object): boolean | Check whether the entered value is of type date. | +| isExternal(value: Object): boolean | Check whether the entered value is a native external value type. | +| isFloat32Array(value: Object): boolean | Check whether the entered value is of float32array array type. | +| isFloat64Array(value: Object): boolean | Check whether the entered value is of float64array array type. | +| isGeneratorFunction(value: Object): boolean | Check whether the input value is a generator function type. | +| isGeneratorObject(value: Object): boolean | Check whether the entered value is a generator object type. | +| isInt8Array(value: Object): boolean | Check whether the entered value is of int8array array type. | +| isInt16Array(value: Object): boolean | Check whether the entered value is the int16array type. | +| isInt32Array(value: Object): boolean | Check whether the entered value is the int32array array type. | +| isMap(value: Object): boolean | Check whether the entered value is of map type. | +| isMapIterator(value: Object): boolean | Check whether the entered value is the iterator type of map. | +| isModuleNamespaceObject(value: Object): boolean | Check whether the entered value is the module namespace object object type. | +| isNativeError(value: Object): boolean | Check whether the value entered is of type error. | +| isNumberObject(value: Object): boolean | Check whether the entered value is of the number object type. | +| isPromise(value: Object): boolean | Check whether the entered value is of promise type. | +| isProxy(value: Object): boolean | Check whether the value entered is of proxy type. | +| isRegExp(value: Object): boolean | Check whether the entered value is of type regexp. | +| isSet(value: Object): boolean | Check whether the entered value is of type set. | +| isSetIterator(value: Object): boolean | Check whether the entered value is the iterator type of set. | +| isSharedArrayBuffer(value: Object): boolean | Check whether the entered value is of type sharedarraybuffer. | +| isStringObject(value: Object): boolean | Check whether the entered value is a string object type. | +| isSymbolObject(value: Object): boolean | Check whether the entered value is a symbol object type. | +| isTypedArray(value: Object): boolean | Check whether the entered value is a type contained in typedarray. | +| isUint8Array(value: Object): boolean | Check whether the entered value is the uint8array array type. | +| isUint8ClampedArray(value: Object): boolean | Check whether the entered value is the uint8clapedarray array type. | +| isUint16Array(value: Object): boolean | Check whether the entered value is the uint16array array array type. | +| isUint32Array(value: Object): boolean | Check whether the entered value is the uint32array array type. | +| isWeakMap(value: Object): boolean | Check whether the entered value is of type weakmap. | +| isWeakSet(value: Object): boolean | Check whether the entered value is of type weakset. | + +Each specifier in printf is replaced with a converted value from the corresponding parameter. Supported specifiers are: +| Stylized character | Style requirements | +| -------- | -------- | +| %s: | String will be used to convert all values except BigInt, Object and -0. | +| %d: | Number will be used to convert all values except BigInt and Symbol. | +| %i: | parseInt(value, 10) is used for all values except BigInt and Symbol. | +| %f: | parseFloat(value) is used for all values expect Symbol. | +| %j: | JSON. Replaced with the string '[Circular]' if the argument contains circular references. | +| %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. | +| %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. | +| %c: | CSS. This specifier is ignored and will skip any CSS passed in. | +| %%: | single percent sign ('%'). This does not consume an argument. | + +#### 2.3.2.Instruction for use + + +The use methods of each interface are as follows: + +1.readonly encoding() + +``` +import util from '@ohos.util' +var textEncoder = new util.TextEncoder(); +var getEncoding = textEncoder.encoding(); +``` +2.encode() +``` +import util from '@ohos.util' +var textEncoder = new util.TextEncoder(); +var result = textEncoder.encode('abc'); +``` +3.encodeInto() +``` +import util from '@ohos.util' +var textEncoder = new util.TextEncoder(); +var obj = textEncoder.encodeInto('abc', dest); +``` +4.textDecoder() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +``` +5.readonly encoding() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var getEncoding = textDecoder.encoding(); +``` +6.readonly fatal() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var fatalStr = textDecoder.fatal(); +``` +7.readonly ignoreBOM() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var ignoreBom = textDecoder.ignoreBOM(); +``` +8.decode() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var result = textDecoder.decode(input, {stream : true}); +``` +9.printf() +``` +import util from '@ohos.util' +var format = "%%%o%%%i%s"; +var value = function aa(){}; +var value1 = 1.5; +var value2 = "qwer"; +var result = util.printf(format,value,value1,value2); +``` +10.getErrorString() +``` +import util from '@ohos.util' +var errnum = 13; +var result = util.getErrorString(errnum); +``` +11.callbackWrapper() +``` +import util from '@ohos.util' +async function promiseFn() { + return Promise.resolve('value'); +}; +var cb = util.callbackWrapper(promiseFn); +cb((err, ret) => { + expect(err).strictEqual(null); + expect(ret).strictEqual('value'); +}) +``` +12.promiseWrapper() +``` +import util from '@ohos.util' +function aysnFun(str1, str2, callback) { + if (typeof str1 === 'string' && typeof str1 === 'string') { + callback(null, str1 + str2); + } else { + callback('type err'); + } +} +let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); +newPromiseObj.then(res => { + expect(res).strictEqual('HelloWorld'); +}) +``` +13.encodeSync() +``` +import util from '@ohos.util' +var that = new util.Base64(); +var array = new Uint8Array([115,49,51]); +var result = that.encodeSync(array); +``` +14.encodeToStringSync() +``` +import util from '@ohos.util' +var that = new util.Base64(); +var array = new Uint8Array([115,49,51]); +var result = that.encodeToStringSync(array); +``` +15.decodeSync() +``` +import util from '@ohos.util' +var that = new util.Base64() +var buff = 'czEz'; +var result = that.decodeSync(buff); +``` +16.encode() +``` +import util from '@ohos.util' +var that = new util.Base64() +var array = new Uint8Array([115,49,51]); +await that.encode(array).then(val=>{ +}) +done() +``` +17.encodeToString() +``` +import util from '@ohos.util' +var that = new util.Base64() +var array = new Uint8Array([115,49,51]); +await that.encodeToString(array).then(val=>{ +}) +done() +``` +18.decode() +``` +import util from '@ohos.util' +var that = new util.Base64() +var buff = 'czEz'; +await that.decode(buff).then(val=>{ +}) +done() +``` +19.createRationalFromString() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(0, 0); +var res = pro.createRationalFromString("-1:2"); +var result1 = res.value(); +``` +20.compareTo() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var proc = new util.RationalNumber(3, 4); +var res = pro.compareTo(proc); +``` +21.equals() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var proc = new util.RationalNumber(3, 4); +var res = pro.equals(proc); +``` +22.valueOf() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var res = pro.value(); +``` +23.getCommonDivisor() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(0, 0); +var res = pro.getCommonDivisor(4, 8); +``` +24.getDenominator() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var res = pro.getDenominator(); +``` +25.getNumerator() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.getNumerator(); +``` +26.isFinite() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.isFinite(); +``` +27.isNaN() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.isNaN(); +``` +28.isZero() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.isZero(); + +``` +29.toString() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.toString(); + +``` +30.updateCapacity() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.updateCapacity(100); +``` +31.toString() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.get(2); +pro.remove(20); +var result = pro.toString(); +``` +32.values() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.put(2,"anhu"); +pro.put("afaf","grfb"); +var result = pro.values(); +``` +33.length +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.put(1,8); +var result = pro.length; +``` +34.getCapacity() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.getCapacity(); +``` +35.clear() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.clear(); +``` +36.getCreateCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(1,8); +var result = pro.getCreateCount(); +``` +37.getMissCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.get(2) +var result = pro.getMissCount(); +``` +38.getRemovalCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.updateCapacity(2); +pro.put(50,22); +var result = pro.getRemovalCount(); +``` +39.getMatchCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.get(2); +var result = pro.getMatchCount(); +``` +40.getPutCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.getPutCount(); +``` +41.isEmpty() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.isEmpty(); +``` +42.get() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.get(2); +``` +43.put() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.put(2,10); +``` +44.keys() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); + pro.put(2,10); +var result = pro.keys(); +``` +45.remove() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.remove(20); +``` +46.contains() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.contains(20); +``` +47.createDefault() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.createDefault(50); +``` +48.entries() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.entries(); +``` +49.\[Symbol.iterator\]() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro[symbol.iterator](); +``` +50.afterRemoval() +``` +import util from '@ohos.util' +var arr = []; +class ChildLruBuffer extends util.LruBuffer +{ + constructor() + { + super(); + } + static getInstance() + { + if(this.instance == null) + { + this.instance = new ChildLruBuffer(); + } + return this.instance; + } + afterRemoval(isEvict, key, value, newValue) + { + if (isEvict === false) + { + arr = [key, value, newValue]; + } + } +} +ChildLruBuffer.getInstance().afterRemoval(false,10,30,null) +``` +Construct a new class in the Scope interface to implement the compareTo method. + +``` +class Temperature { + constructor(value) { + this._temp = value; + } + compareTo(value) { + return this._temp >= value.getTemp(); + } + getTemp() { + return this._temp; + } + toString() { + return this._temp.toString(); + } +} +``` + +51.constructor() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +``` + +52.toString() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var result = range.toString() // => [30,40] +``` + +53.intersect() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var rangeFir = new Scope(tempMiDF, tempMidS); +var result = range.intersect(rangeFir) // => [35,39] +``` + +54.intersect() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var range = new Scope(tempLower, tempUpper); +var result = range.intersect(tempMiDF, tempMidS) // => [35,39] +``` + +55.getUpper() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var result = range.getUpper() // => 40 +``` + +56.getLower() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var result = range.getLower() // => 30 +``` + +57.expand() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var range = new Scope(tempLower, tempUpper); +var result = range.expand(tempMiDF, tempMidS) // => [30,40] +``` + +58.expand() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var range = new Scope(tempLower, tempUpper); +var rangeFir = new Scope(tempMiDF, tempMidS); +var result = range.expand(rangeFir) // => [30,40] +``` + +59.expand() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var range = new Scope(tempLower, tempUpper); +var result = range.expand(tempMiDF) // => [30,40] +``` + +60.contains() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var range = new Scope(tempLower, tempUpper); +var result = range.contains(tempMiDF) // => true +``` + +61.contains() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var tempLess = new Temperature(20); +var tempMore = new Temperature(45); +var rangeSec = new Scope(tempLess, tempMore); +var result = range.contains(rangeSec) // => true +``` + +62.clamp() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var range = new Scope(tempLower, tempUpper); +var result = range.clamp(tempMiDF) // => 35 +``` +63.isAnyArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAnyArrayBuffer(new ArrayBuffer([])) +``` +64.isArrayBufferView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16))); +``` +65.isArgumentsObject() +``` +import util from '@ohos.util' +function foo() { + var result = proc.isArgumentsObject(arguments); + } +var f = foo(); +``` +66.isArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBuffer(new ArrayBuffer([])); +``` +67.isAsyncFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAsyncFunction(async function foo() {}); +``` +68.isBigInt64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigInt64Array(new Int16Array([])); +``` +69.isBigUint64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigUint64Array(new Int16Array([])); +``` +70.isBooleanObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBooleanObject(new Boolean(false)); +``` +71.isBoxedPrimitive() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBoxedPrimitive(new Boolean(false)); +``` +72.isDataView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const ab = new ArrayBuffer(20); +var result = proc.isDataView(new DataView(ab)); +``` +73.isDate() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isDate(new Date()); +``` +74.isExternal() +``` +import util from '@ohos.util' +const data = util.createExternalType(); +var reult13 = proc.isExternal(data); +``` +75.isFloat32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat32Array(new Float32Array([])); +``` +76.isFloat64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat64Array(new Float64Array([])); +``` +77.isGeneratorFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isGeneratorFunction(function* foo() {}); +``` +78.isGeneratorObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +function* foo() {} +const generator = foo(); +var result = proc.isGeneratorObject(generator); +``` +79.isInt8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt8Array(new Int8Array([])); +``` +80.isInt16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt16Array(new Int16Array([])); +``` +81.isInt32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt32Array(new Int32Array([])); +``` +82.isMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMap(new Map()); +``` +83.isMapIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMapIterator(map.keys()); +``` +84.isModuleNamespaceObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isModuleNamespaceObject(util); +``` +85.isNativeError() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNativeError(new TypeError()); +``` +86.isNumberObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNumberObject(new Number(0)); +``` +87.isPromise() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isPromise(Promise.resolve(42)); +``` +88.isProxy() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const target = {}; +const proxy = new Proxy(target, {}); +var result = proc.isProxy(proxy); +``` +89.isRegExp() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isRegExp(new RegExp('abc')); +``` +90.isSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSet(new Set()); +``` +91.isSetIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const set = new Set(); +var result = proc.isSetIterator(set.keys()); +``` +92.isSharedArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); +``` +93.isStringObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isStringObject(new String('foo')); +``` +94.isSymbolObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const symbols = Symbol('foo'); +var result = proc.isSymbolObject(Object(symbols)); +``` +95.isTypedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isTypedArray(new Float64Array([])); +``` +96.isUint8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8Array(new Uint8Array([])); +``` +97.isUint8ClampedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); +``` +98.isUint16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint16Array(new Uint16Array([])); +``` +99.isUint32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint32Array(new Uint32Array([])); +``` +100.isWeakMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakMap(new WeakMap()); +``` +101.isWeakSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakSet(new WeakSet()); +``` + +## 3.js_sys_module submodule +### 3.1.Introduction +Process is mainly used to obtain the relevant ID of the process, obtain and modify the working directory of the process, exit and close the process. The childprocess object can be used to create a new process. The main process can obtain the standard input and output of the child process, send signals and close the child process. +### 3.2.Directory + +``` +commomlibrary/ets_utils/js_sys_module/ +├── Class:PROCESS # class of PROCESS +├── Uid # attribute of Uid +├── Gid # attribute of Gid +├── EUid # attribute of EUid +├── EGid # attribute of EGid +├── Groups # attribute of Groups +├── Pid # attribute of Pid +├── Ppid # attribute of Ppid +├── chdir() # method of chdir +├── uptime() # method of uptime +├── kill() # method of kill +├── abort() # method of abort +├── on() # method of on +├── tid # method of tid +├── getStartRealtime() # method of getStartRealtime +├── getAvailableCores() # method of getAvailableCores +├── getPastCputime() # method of getPastCputime +├── isIsolatedProcess() # method of isIsolatedProcess +├── is64Bit() # method of is64Bit +├── isAppUid() # method of isAppUid +├── getUidForName() # method of getUidForName +├── getThreadPriority() # method of getThreadPriority +├── getSystemConfig() # method of getSystemConfig +├── getEnvironmentVar() # method of getEnvironmentVar +├── exit() # method of exit +├── cwd() # method of cwd +├── off() # method of off +├── runCmd() # method of runCmd +└─── Class:CHILDPROCESS # class of CHILDPROCESS + ├── close() # method of close + ├── kill() # method of kill + ├── getOutput() # method of getOutput + ├── getErrorOutput() # method of getErrorOutput + ├── wait() # method of wait + ├── killed # attribute of killed + ├── pid # attribute of pid + ├── ppid # attribute of ppid + └── exitCode # attribute of exitCode +``` + +### 3.3.Description + +#### 3.3.1.Interface description +| Interface name | description | +| -------- | -------- | +| const uid :number | returns the digital user ID of the process. | +| const gid :number | returns the numeric group ID of the process. | +| const euid :number | returns the numeric valid user identity of the process. | +| const egid :number | returns the numeric valid group ID of the node.js process. | +| const groups :number[] | returns an array with supplementary group ID. | +| const pid :number | returns the PID of the process. | +| const ppid :number | returns the PID of the parent process of the current process. | +| chdir(dir:string) :void | change the current working directory of the node.js process. | +| uptime() :number | returns the number of seconds the current system has been running. | +| Kill(pid:number, signal:number) :boolean | send the signal to the identified process PID, and true means the sending is successful. | +| abort() :void | cause the node.js process to exit immediately and generate a core file. | +| on(type:string ,listener:EventListener) :void | used to store events triggered by users. | +| exit(code:number):void | cause the node.js process to exit immediately. | +| cwd():string | returns the current working directory of the node.js process. | +| off(type: string): boolean | clear the events stored by the user. True means the clearing is successful. | +| runCmd(command: string, options?: { timeout : number, killSignal : number \| string, maxBuffer : number }): ChildProcess |through runcmd, you can fork a new process to run a shell and return the childprocess object. The first parameter command refers to the shell to be run, and the second parameter options refers to some running parameters of the child process. These parameters mainly refer to timeout, killsignal and maxbuffer. If timeout is set, the child process will send a signal killsignal after timeout is exceeded. Maxbuffer is used to limit the maximum stdout and stderr sizes that can be received. | +| wait(): Promise\ | is used to wait for the child process to run and return the promise object, whose value is the exit code of the child process. | +| getOutput(): Promise\ | used to get the standard output of the child process. | +| getErrorOutput(): Promise\ | used to get the standard error output of the child process. | +| const tid:number | Returns the TID of the process. | +| getStartRealtime() :number | Gets the real time elapsed (in milliseconds) from system startup to process startup. | +| getAvailableCores() :number[] | Gets the CPU kernel available to the current process on the multi-core device. | +| getPastCputime() :number | Gets the CPU time (in milliseconds) from the start of the process to the current time. | +| isIsolatedProcess(): boolean | Check if the process is quarantined. | +| is64Bit(): boolean | Check whether the process is running in a 64 bit environment. | +| isAppUid(v:number): boolean | Checks whether the specified uid belongs to a specific application. | +| getUidForName(v:string): number | Obtain the user group ID to which the user belongs according to the user name | +| getThreadPriority(v:number): number | Gets the thread priority based on the specified TID. | +| getSystemConfig(name:number): number | Gets the configuration of the system according to the specified system configuration name. | +| getEnvironmentVar(name:string): string | Obtain the corresponding value according to the name of the environment variable. | +| close(): void | used to close the running child process. | +| kill(signal: number \| string): void | used to send signals to child processes. | +| readonly killed: boolean | indicates whether the signal is sent successfully, and true indicates that the signal is sent successfully. | +| readonly exitCode: number | indicates the exit code of the child process. | +| readonly pid: number | represents the child process ID. | +| readonly ppid: number | represents the main process ID. | + +#### 3.3.2.Interface instructions + +Example of using interface: +1.uid() +``` +uid(){ + var res = Process.uid; +} +``` +2.gid() +``` +gid(){ + var result = Process.gid; +} +``` +3.euid() +``` +euid(){ + var and = Process.euid; +} +``` +4.egid() +``` +egid(){ + var resb = Process.egid; +} +``` +5.groups() +``` +groups(){ + var answer = Process.groups; +} +``` +6.pid() +``` +pid(){ + var result = Process.pid; +} +``` +7.ppid() +``` +ppid(){ + var result = Process.ppid; +} +``` +8.chdir() +``` +chdir(){ + Process.chdir("123456"); +} +``` +9.uptime() +``` +uptime(){ + var num = Process.uptime(); +} +``` +10.kill() +``` +kill(){ + var ansu = Process.kill(5,23); +} +``` +11.abort() +``` +abort(){ + Process.abort(); +} +``` +12.on() +``` +on(){ + function add(num){ + var value = num + 5; + return value; + } + Process.on("add",add); +} +``` +13.exit() +``` +exit(){ + Process.exit(15); +} +``` +14.Cwd() +``` +Cwd(){ + var result = Process.cwd(); +} +``` +15.off() + +``` +off(){ + var result = Process.off("add"); +} +``` +16.runCmd() +``` +runCmd(){ + var child = process.runCmd('echo abc') + // killSignal can be a number or a string + var child = process.runCmd('echo abc;', {killSignal : 'SIGKILL'}); + var child = process.runCmd('sleep 5; echo abc;', {timeout : 1, killSignal : 9, maxBuffer : 2}) +} +``` +17.wait() +``` +wait() +{ + var child = process.runCmd('ls') + var status = child.wait(); + status.then(val => { + console.log(val); + }) +} +``` +18.getOutput() +``` +getOutput(){ + var child = process.runCmd('echo bcd;'); + var res = child.getOutput(); + child.wait(); + res.then(val => { + console.log(val); + }) +} +``` +19.getErrorOutput() +``` +getErrorOutput(){ + var child = process.runCmd('makdir 1.txt'); // execute an error command + var res = child.getErrorOutput(); + child.wait(); + res.then(val => { + console.log(val); + }) +} +``` +20.close() +``` +close(){ + var child = process.runCmd('ls; sleep 5s;') + var result = child.close() +} +``` +21.kill() +``` +kill(){ + var child = process.runCmd('ls; sleep 5s;') + var result = child.kill('SIGHUP'); + child.wait(); + var temp = child.killed; +} +``` +22.killed +``` +{ + var child = process.runCmd('ls; sleep 5;') + child.kill(3); + var killed_ = child.killed; + child.wait(); +} +``` +23.exitCode +``` +{ + var child = process.runCmd('ls; sleep 5;') + child.kill(9); + child.wait(); + var exitCode_ = child.exitCode; +} +``` +24.pid +``` +pid +{ + var child = process.runCmd('ls; sleep 5;') + var pid_ = child.pid; + child.wait(); +} +``` +25.ppid +``` +ppid +{ + var child = process.runCmd('ls; sleep 5;') + var ppid_ = child.ppid; + child.wait(); +} +``` +26.tid +``` +tid(){ + var ansu = Process.tid; +} +``` +27.isIsolatedProcess() +``` +isIsolatedProcess(){ + var ansu = Process.isIsolatedProcess()(); +} +``` +28.isAppUid() +``` +isAppUid(){ + var ansu = Process.isAppUid(10000); +} +``` +29.is64Bit() +``` +is64Bit(){ + var ansu = Process.is64Bit(); +} +``` +30.getUidForName() +``` +getUidForName(){ + var buf = "root"; + var ansu = Process.getUidForName(buf); +} +``` +31.getEnvironmentVar() +``` +getEnvironmentVar(){ + var ansu = Process.getEnvironmentVar('USER'); +} +``` +32.getAvailableCores() +``` +getAvailableCores(){ + var ansu = Process.getAvailableCores(); +} +``` +33.getThreadPriority() +``` +getThreadPriority(){ + var result = Process.getTid(); + var ansu = getThreadPriority(result); +} +``` +34.getStartRealtime() +``` +getStartRealtime(){ + var ansu = Process.getStartRealtime(); +} +``` +35.getPastCputime() +``` +getPastCputime(){ + var ansu = Process.getPastCputime(); +} +``` +36.getSystemConfig() +``` +getSystemConfig(){ + var _SC_ARG_MAX = 0; + var ansu = Process.getSystemConfig(_SC_ARG_MAX) +} +``` + +## 4.js_worker_module submodule + +### 4.1.Introduction + +Worker enables JS to have the ability of multithreading, and completes the communication between worker thread and host thread through PostMessage. + +### 4.2.Interface description +For interface implementation, see: js_worker_module/jsapi/worker + +#### 4.2.1.Worker object description + +The object object used by the host thread to communicate with the worker thread. + +##### 4.2.1.1.Interface + +1. + +- name + +|constructor(scriptURL:string, options? WorkerOptions) | worker constructor to Creates a worker instance | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +``` + +2. + +- name + +| postMessage(message:Object, options?:PostMessageOptions) | Sends a message to the worker thread | +|---|---| +| postMessage(message:Object, transfer:ArrayBuffer[]) | Sends a message to the worker thread | + +- example + +``` +// example 1 +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// example 2 +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +var buffer = new ArrayBuffer(8); +worker.postMessage(buffer, [buffer]); +``` + +3. + +- name + +| on(type:string, listener:EventListener) | Adds an event listener to the worker | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.on("alert", (e)=>{ + console.log("worker on..."); +}) +``` + +4. + +- name + +| once(type:string, listener:EventListener) | Adds an event listener to the worker and removes the event listener automically after it is invoked once | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.once("alert", (e)=>{ + console.log("worker on..."); +}) +``` + +5. + +- name + +| off(type:string, listener?:EventListener) | Removes an event listener to the worker | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.off("alert"); +``` + +6. + +- name + +| terminate() | Terminates the worker thread to stop the worker from receiving messages | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.terminate(); +``` + +7. + +- name + +| removeEventListener(type:string, listener?:EventListener) | Removes an event defined for the worker | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.removeEventListener("alert"); +``` + +8. + +- name + +| dispatchEvent(event: Event) | Dispatches the event defined for the worker | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.dispatchEvent({type:"alert"}); +``` + +9. + +- name + +| removeAllListener() | Removes all event listeners for the worker | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.removeAllListener(); +``` + +##### 4.2.1.2.Attribute + +1. + +- name + +| onexit?:(code:number)=>void | The onexit attribute of the worker specifies the event handler to be called when the worker exits. The handler is executed in the host thread | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onexit = function(e) { + console.log("onexit..."); +} +``` + +2. + +- name + +| onerror?:(ev:ErrorEvent)=>void | The onerror attribute of the worker specifies the event handler to be called when an exception occurs during worker execution. The event handler is executed in the host thread | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onerror = function(e) { + console.log("onerror..."); +} +``` + +3. + +- name + +| onmessage?:(ev:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler to be called then the host thread receives a message created by itself and sent by the worker through the parentPort.postMessage. The event handler is executed in the host thread | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onmessage = function(e) { + console.log("onmessage..."); +} +``` + +4. + +- name + +| onmessageerror?:(event:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler when the worker receives a message that cannot be serialized. The event handler is executed in the host thread | +|---|---| + +- example + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onmessageerror = function(e) { + console.log("onmessageerror..."); +} +``` + +#### 4.2.2.parentPort object description + +Object of the worker thread used to communicate with the host thread + +##### 4.2.2.1.Interface + +1. + +- name + +| postMessage(message:Object, options?:PostMessageOptions) | Send a message to host thread | +|---|---| +| postMessage(message:Object, transfer:ArrayBuffer[]) | Send a message to host thread | + +- example + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + parentPort.postMessage("hello world from worker.js"); +} +``` + +2. + +- name + +| close() | Close the worker thread to stop the worker from receiving messages | +|---|---| + +- example + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + parentPort.close(); +} +``` + +##### 4.2.2.2.Attribute + +1. + +- name + +| onmessage?:(event:MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called then the worker thread receives a message sent by the host thread through worker postMessage. The event handler is executed in the worker thread | +|---|---| + +- example + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + console.log("receive main.js message"); +} +``` + +2. + +- name + +| onerror?:(ev: ErrorEvent)=>void | The onerror attribute of parentPort specifies the event handler to be called when an exception occurs during worker execution. The event handler is executed in the worker thread | +|---|---| + +- example + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onerror = function(e) { + console.log("onerror..."); +} + +``` + +3. + +- name + +| onmessageerror?:(event: MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called then the worker receives a message that cannot be deserialized. The event handler is executed in the worker thread. | +|---|---| + +- example + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessageerror = function(e) { + console.log("onmessageerror..."); +} +``` + +### Repositories Involved + +- ace_ace_engine(foundation/arkui/ace_engine-readme.md) +- ace_napi(foundation/arkui/napi-readme.md) + +## Related warehouse +[ets_utils Subsystem](commonlibrary/ets_utils/README.en.md) + +## License + +URL is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_api_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony-sig/commonlibrary_ets_utils/blob/master/LICENSE) for the full license text. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b05077e --- /dev/null +++ b/README.md @@ -0,0 +1,2211 @@ +# ets_utils组件 +- [子模块](#子模块) + - [1.js_api_module子模块](#1.js_api_module子模块) + - [1.1.简介](#1.1.简介) + - [1.2.目录](#1.2.目录) + - [1.3.说明](#1.3.说明) + - [1.3.1.接口说明](#1.3.1.接口说明) + - [1.3.2.使用说明](#1.3.2.使用说明) + - [2.js_util_module子模块](#2.js_util_module子模块) + - [2.1.简介](#2.1.简介) + - [2.2.目录](#2.2.目录) + - [2.3.说明](#2.3.说明) + - [2.3.1.接口说明](#2.3.1.接口说明) + - [2.3.2.使用说明](#2.3.2.使用说明) + - [3.js_sys_module子模块](#3.js_sys_module子模块) + - [3.1.简介](#3.1.简介) + - [3.2.目录](#3.2.目录) + - [3.3.说明](#3.3.说明) + - [3.3.1.接口说明](#3.3.1.接口说明) + - [3.3.2.使用说明](#3.3.2.使用说明) + - [4.js_worker_module子模块](#4.js_worker_module子模块) + - [4.1.简介](#4.1.简介) + - [4.2.接口说明](#4.2.接口说明) + - [4.2.1.Worker对象描述](#4.2.1.Worker对象描述) + - [4.2.1.1.接口](#4.2.1.1.接口) + - [4.2.1.2.属性](#4.2.1.2.属性) + - [4.2.2.Worker对象描述](#4.2.2.Worker对象描述) + - [4.2.2.1.接口](#4.2.2.1.接口) + - [4.2.2.1.属性](#4.2.2.1.属性) + - [4.3.涉及仓](#4.3.涉及仓) + +# 子模块 +## 1.js_api_module子模块 +### 1.1.简介 + +URL接口用于解析,构造,规范化和编码 URLs。 URL的构造函数创建新的URL对象。 以便对URL的已解析组成部分或对URL进行更改。URLSearchParams 接口定义了一些实用的方法来处理 URL 的查询字符串。 + +URI表示统一资源标识符引用。 + +xml表示指可扩展标记语言。 + +XmlSerializer接口用于生成一个xml文件。 XmlSerializer的构造函数创建新的XmlSerializer对象,调用XmlSerializer对象的方法生成一个xml文件。XmlPullParser 接口用于解析已有的xml文件,XmlPullParser的构造函数创建新的XmlPullParser对象,调用XmlPullParser对象的方法解析xml。 + +### 1.2.目录 + +``` +commonlibrary/ets_utils/js_api_module/ +├── Class:URL # URL类 +│ ├── new URL(input[, base]) # 创建URL对象 +│ ├── hash # hash属性 +│ ├── host # host属性 +│ ├── hostname # hostname属性 +│ ├── href # href属性 +│ ├── origin # origin属性 +│ ├── password # password属性 +│ ├── pathname # pathname属性 +│ ├── port # port属性 +│ ├── protocol # protocol属性 +│ ├── search # search属性 +│ ├── searchParams # searchParams属性 +│ ├── username # username属性 +│ ├── toString() # toString方法 +│ └── toJSON() # toJSON方法 +├── Class: URLSearchParams # URLSearchParams类 +│ ├── new URLSearchParams() # 创建URLSearchParams对象 +│ ├── new URLSearchParams(string) # 创建URLSearchParams对象 +│ ├── new URLSearchParams(obj) # 创建URLSearchParams对象 +│ ├── new URLSearchParams(iterable) # 创建URLSearchParams对象 +│ ├── append(name, value) # append方法 +│ ├── delete(name) # delete方法 +│ ├── entries() # entries方法 +│ ├── forEach(fn[, thisArg]) # forEach方法 +│ ├── get(name) # get方法 +│ ├── getAll(name) # getAll方法 +│ ├── has(name) # has方法 +│ ├── keys() # keys方法 +│ ├── set(name, value) # set方法 +│ ├── sort() # sort方法 +│ ├── toString() # toString方法 +│ ├── values() # values方法 +│ └── urlSearchParams[Symbol.iterator]() # 创建URLSearchParams对象 +├── Class:URI # URI类 +│ ├── URI(str: string) # 创建URI对象 +│ ├── scheme # scheme属性 +│ ├── authority # authority属性 +│ ├── ssp # ssp属性 +│ ├── userinfo # userinfo属性 +│ ├── host # host属性 +│ ├── port # port属性 +│ ├── query # query属性 +│ ├── fragment # fragment属性 +│ ├── path # path属性 +│ ├── equals(ob: Object) # equals方法 +│ ├── normalize() # normalize方法 +│ ├── checkIsAbsolute() # checkIsAbsolute方法 +│ ├── normalize() # normalize方法 +│ └── toString() # toString方法 +├── Class:ConvertXml # ConvertXml类 +│ ├── ConvertXml() # 创建ConvertXml类对象 +│ └── convert(xml: string, options: Object) # convert方法 +├── Class:XmlSerializer # XmlSerializer类 +│ ├── new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) # 创建XmlSerializer类对象 +│ ├── setAttributes(name: string, value: string) # 设置Attributes方法 +│ ├── addEmptyElement(name: string) # 添加一个空元素方法 +│ ├── setDeclaration() # 设置Declaration方法 +│ ├── startElement(name: string) # 设置开始元素方法 +│ ├── endElement() # 设置结束元素方法 +│ ├── setNamespace(prefix: string, namespace: string) # 设置命名空间方法 +│ ├── setCommnet(text: string) # 设置Commnet方法 +│ ├── setCData(text: string) # 设置CData方法 +│ ├── setText(text: string) # 设置Text方法 +│ └── setDocType(text: string) # 设置DocType方法 +└── Class: XmlPullParser # XmlPullParser类 + ├── new (buffer: ArrayBuffer | DataView, encoding?: string) # 创建XmlPullParser对象 + └── parse(option: ParseOptions) # parse方法 +``` + +### 1.3.说明 + +#### 1.3.1.接口说明 + + +| 接口名 | 说明 | +| -------- | -------- | +| URL(url: string,base?:string \| URL) | 创建并返回一个URL对象,该URL对象引用使用绝对URL字符串,相对URL字符串和基本URL字符串指定的URL。 | +| tostring():string | 该字符串化方法返回一个包含完整 URL 的 USVString。它的作用等同于只读的 URL.href。 | +| toJSON():string | 该方法返回一个USVString,其中包含一个序列化的URL版本。 | +| new URLSearchParams() | URLSearchParams() 构造器无入参,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | +| new URLSearchParams(string) | URLSearchParams(string) 构造器的入参为string数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | +| new URLSearchParams(obj) | URLSearchParams(obj) 构造器的入参为obj数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | +| new URLSearchParams(iterable) | URLSearchParams(iterable) 构造器的入参为iterable数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | +| has(name: string): boolean | 检索searchParams对象中是否含有name。有则返回true,否则返回false。 | +| set(name: string, value string): void | 检索searchParams对象中是否含有key为name的键值对。没有的话则添加该键值对,有的话则修改对象中第一个key所对应的value,并删除键为name的其余键值对。 | +| sort(): void | 根据键的Unicode代码点,对包含在此对象中的所有键/值对进行排序,并返回undefined。 | +| toString(): string | 根据searchParams对象,返回适用在URL中的查询字符串。 | +| keys(): iterableIterator\ | 返回一个iterator,遍历器允许遍历对象中包含的所有key值。 | +| values(): iterableIterator\ | 返回一个iterator,遍历器允许遍历对象中包含的所有value值。 | +| append(name: string, value: string): void | 在searchParams对象中插入name, value键值对。 | +| delete(name: string): void | 遍历searchParams对象,查找所有的name,删除对应的键值对。 | +| get(name: string): string | 检索searchParams对象中第一个name,返回name键对应的值。 | +| getAll(name: string): string[] | 检索searchParams对象中所有name,返回name键对应的所有值。 | +| entries(): iterableIterator<[string, string]> | 返回一个iterator,允许遍历searchParams对象中包含的所有键/值对。 | +| forEach(): void | 通过回调函数来遍历URLSearchParams实例对象上的键值对。 | +| urlSearchParams\[Symbol.iterator]() | 返回查询字符串中每个名称-值对的ES6迭代器。迭代器的每个项都是一个JavaScript数组。 | +| URI​(str: string) | 通过解析给定入参(String str)来构造URI。此构造函数严格按照RFC 2396附录A中的语法规定解析给定字符串。 | +| scheme​ | 返回此 URI 的scheme部分,如果scheme未定义,则返回 null | +| authority​ | 返回此 URI 的解码authority部分,如果authority未定义,则返回 null。 | +| ssp​ | 返回此 URI 的解码scheme-specific部分。 | +| userinfo​ | 返回此 URI 的解码userinfo部分。包含passworld和username。 | +| host​ | 返回此 URI 的host部分,如果host未定义,则返回 null。 | +| port​ | 返回此 URI 的port部分,如果port未定义,则返回 -1。URI 的port组件(如果已定义)是一个非负整数。 | +| query​ | 返回此 URI 的query部分,如果query未定义,则返回 null。 | +| fragment​ | 返回此 URI 的解码fragment组件,如果fragment未定义,则返回 null。| +| path​ | 返回此 URI 的解码path组件,如果path未定义,则返回 null。 | +| equals(ob: Object) | 测试此 URI 是否与另一个对象相等。如果给定的对象不是 URI,则此方法立即返回 false。 | +| normalize​() | 规范化这个 URI 的路径。如果这个 URI 的path不规范,将规范后构造一个新 URI对象返回。 | +| checkIsAbsolute​() | 判断这个 URI 是否是绝对的。当且仅当它具有scheme部分时,URI 是绝对的,返回值为true,否则返回值为false。 | +| ConvertXml() | 用于构造ConvertXml类对象的构造函数。此构造函数无需传入参数。 | +| convert(xml: string, options: Object) | 返回按选项要求转化xml字符串的JavaScrip对象。 | +| XmlSerializer(buffer: ArrayBuffer \| DataView, encoding?: string) | 创建并返回一个XmlSerializer对象,该XmlSerializer对象传参两个第一参数是ArrayBuffer或DataView一段内存,第二个参数为文件格式(默认为UTF-8)。 | +| setAttributes(name: string, value: string): void | 给xml文件中写入属性Attributes属性。 | +| addEmptyElement(name: string): void | 写入一个空元素。 | +| setDeclaration(): void | 设置Declaration使用编码写入xml声明。例如:<?xml version=“1.0”encoding=“utf-8”> | +| startElement(name: string): void | 写入具有给定名称的elemnet开始标记。| +| endElement(): void | 写入元素的结束标记。 | +| setNamespace(prefix: string, namespace: string): void | 写入当前元素标记的命名空间。 | +| setCommnet(text: string): void | 写入comment属性。 | +| setCData(text: string): void | 写入CData属性。 | +| setText(text: string): void | 写入Text属性。 | +| setDocType(text: string): void | 写入DocType属性。 | +| XmlPullParser(buffer: ArrayBuffer \| DataView, encoding?: string) | 创建并返回一个XmlPullParser对象,该XmlPullParser对象传参两个第一参数是ArrayBuffer或DataView一段内存,第二个参数为文件格式(默认为UTF-8)。 | +| parse(option: ParseOptions): void | 该接口用于解析xml,ParseOptions参数为一个接口包含五个可选参{supportDoctype?: boolea ignoreNameSpace?: boolean tagValueCallbackFunction?: (name: string, value: string) => boolean attributeValueCallbackFunction?: (name: string, value: string) => boolean) tokenValueCallbackFunction?: (eventType: EventType, value: ParseInfo) => boolean }。其中tokenValueCallbackFunction回调函数的入参1是事件类型,入参2是包含getColumnNumber、getDepth等get属性的info接口,用户可通过info.getDepth()等方法来获取当前解析过程中的depth等信息。 | +#### 1.3.2.使用说明 + +各接口使用方法如下: + + +1、new URL(url: string,base?:string|URL) +``` +let b = new URL('https://developer.mozilla.org'); // => 'https://developer.mozilla.org/' + +let a = new URL( 'sca/./path/path/../scasa/text', 'http://www.example.com'); +// => 'http://www.example.com/sca/path/scasa/text' +``` +2、tostring():string +``` +const url = new URL('http://10.0xFF.O400.235:8080/directory/file?query#fragment'); +url.toString() // => 'http://10.0xff.o400.235:8080/directory/file?query#fragment' + +const url = new URL("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"); +url.toString() // => 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html' + +const url = new URL("http://username:password@host:8080/directory/file?query#fragment"); +url.toString() // => 'http://username:password@host:8080/directory/file?query#fragment' +``` +3、toJSON():string +``` +const url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/toString"); +url.toJSON(); // => 'https://developer.mozilla.org/en-US/docs/Web/API/URL/toString' +``` +4、new URLSearchParams() +``` +let params = new URLSearchParams('foo=1&bar=2'); +``` +5、new URLSearchParams(string) +``` +params = new URLSearchParams('user=abc&query=xyz'); +console.log(params.get('user')); +// Prints 'abc' +``` +6、new URLSearchParams(obj) +``` +const params = new URLSearchParams({ + user: 'abc', + query: ['first', 'second'] +}); +console.log(params.getAll('query')); +// Prints [ 'first,second' ] +``` +7、new URLSearchParams(iterable) +``` +let params; + +// Using an array +params = new URLSearchParams([ + ['user', 'abc'], + ['query', 'first'], + ['query', 'second'], +]); +console.log(params.toString()); +// Prints 'user = abc & query = first&query = second' +``` +8、has(name: string): boolean +``` +console.log(params.has('bar')); // =>true +``` +9、set(name: string, value string): void +``` +params.set('baz', 3); +``` +10、sort(): void +``` +params .sort(); +``` +11、toString(): string +``` +console.log(params .toString()); // =>bar=2&baz=3&foo=1' +``` +12、keys(): iterableIterator\ +``` +for(var key of params.keys()) { + console.log(key); +} // =>bar baz foo +``` +13、values(): iterableIterator\ +``` +for(var value of params.values()) { + console.log(value); +} // =>2 3 1 +``` +14、append(name: string, value: string): void +``` +params.append('foo', 3); // =>bar=2&baz=3&foo=1&foo=3 +``` +15、delete(name: string): void +``` +params.delete('baz'); // => bar=2&foo=1&foo=3 +``` +16、get(name: string): string +``` +params.get('foo'); // => 1 +``` +17、getAll(name: string): string[] +``` +params.getAll('foo'); // =>[ '1', '3' ] +``` +18、entries(): iterableIterator<[string, string]> +``` +for(var pair of searchParams.entries()) { + console.log(pair[0]+ ', '+ pair[1]); +} // => bar, 2 foo, 1 foo, 3 +``` +19、forEach(): void +``` +url.searchParams.forEach((value, name, searchParams) => { + console.log(name, value, url.searchParams === searchParams); +}); +// => foo 1 true +// => bar 2 true +``` +20、urlSearchParams[Symbol.iterator] () +``` +const params = new URLSearchParams('foo=bar&xyz=baz'); +for (const [name, value] of params) { + console.log(name, value); +} +// Prints: +// foo bar +// xyz bar +``` + + +21、URI​(str: string) +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +``` +22、scheme +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.scheme // => "http"; +``` +23、authority +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.authority // => "gg:gaogao@www.baidu.com:99"; +``` +24、ssp +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.ssp " // => gg:gaogao@www.baidu.com:99/path/path?query"; +``` +25、userinfo +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.userinfo // => "gg:gaogao"; +``` +26、host +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.host // => "www.baidu.com"; +``` +27、port +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.port // => "99"; +``` +28、query +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.query // => "query"; +``` +29、fragment +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.fragment // => "fagment"; +``` +30、path +``` +let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); +gaogao.path // => "/path/path"; +``` +31、equals(ob: Object) +``` +let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment'); +let gaogao1 = gaogao; +let res = gaogao.equals(gaogao1); +console.log(res); // => true; +``` +32、normalize​() +``` +let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment'); +let res = gaogao.normalize(); +console.log(res.path); // => "/path/path1" +console.log(res.toString()); // => "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment" +``` +33、checkIsAbsolute​() +``` +let gaogao = new Uri.URI('f/tp://username:password@www.baidu.com:88/path?query#fagment'); +let res = gaogao.checkIsAbsolute(); +console.log(res); //=> false; +``` +34、toString() +``` +let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'); +let res = gaogao.toString(); +console.log(res.toString()); // => 'http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'; +``` + + +35、ConvertXml() +``` +var convertml = new convertXml.ConvertXml(); +``` +36、convert(xml: string, options: Object) +``` +var result = convertml.convert(xml, {compact: false, spaces: 4}); +``` +37、new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) +``` + +var arrayBuffer = new ArrayBuffer(1024); +var bufView = new DataView(arrayBuffer); +var thatSer = new xml.XmlSerializer(bufView); +``` +38、setDeclaration():void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setDeclaration() // => ; +``` +39、setCommnet(text: string):void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setCommnet("Hello, World!"); // => ; +``` +40、setCData(text: string) :void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); // => +``` +41、setDocType(text: string):void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setDocType("foo"); // => +``` +42、setNamespace(prefix: string, namespace: string): void +43、startElement(name: string): void +44、setAttributes(name: string, value: string): void +45、endElement(): void +46、setText(text: string): void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); +thatSer.startElement("table"); +thatSer.setAttributes("importance", "high"); +thatSer.setText("Happy"); +endElement(); // => Happy +``` +47、addEmptyElement(name: string): void +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.addEmptyElement("b"); // => +``` +48、new (buffer: ArrayBuffer | DataView, encoding?: string) +``` +var strXml = + '' + + '' + + ' Happy' + + ''; +var arrayBuffer = new ArrayBuffer(strXml.length*2); +var bufView = new Uint8Array(arrayBuffer); +var strLen = strXml.length; +for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i);//设置arraybuffer 方式 +} +var that = new xml.XmlPullParser(arrayBuffer); + +``` +49、parse(option: ParseOptions): void +``` +var strXml = + '' + + '' + + ' Happy' + + ''; +var arrayBuffer = new ArrayBuffer(strXml.length*2); +var bufView = new Uint8Array(arrayBuffer); +var strLen = strXml.length; +for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i); +} +var that = new xml.XmlPullParser(arrayBuffer); +var arrTag = {}; +arrTag[0] = '132'; +var i = 1; +function func(key, value){ + arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); + i++; + return true; +} +var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} +that.parse(options); +``` + +## 2.js_util_module子模块 +### 2.1.简介 + +UTIL接口用于字符编码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实例的构造函数用于创建具有指定下限和上限的对象,并要求这些对象必须具有可比性。 +### 2.2.目录 + +``` +commomlibrary/ets_utils/js_util_module/ +├── Class:TextEncoder # TextEncoder类 +│ ├── new TextEncoder() # 创建TextEncoder对象 +│ ├── encode() # encode方法 +│ ├── encoding # encoding属性 +│ └── encodeInto() # encodeInto方法 +├── Class:TextDecoder # TextDecoder类 +│ ├── new TextDecoder() # 创建TextDecoder对象 +│ ├── decode() # decode方法 +│ ├── encoding # encoding属性 +│ ├── fatal # fatal属性 +│ └── ignoreBOM # ignoreBOM属性 +├── printf() # printf方法 +├── getErrorString() # getErrorString方法 +├── callbackWrapper() # callbackWrapper方法 +├── promiseWrapper() # promiseWrapper方法 +├── Class:Base64 # Base64类 +│ ├── new Base64() # 创建Base64对象 +│ ├── encodeSync() # encodeSync方法 +│ ├── encodeToStringSync() # encodeToStringSync方法 +│ ├── decodeSync() # decodeSync方法 +│ ├── encode() # encode方法 +│ ├── encodeToString() # encodeToString方法 +│ └── decode() # decode方法 +├── Class:RationalNumber # RationalNumber类 +│ ├── new RationalNumber() # 创建RationalNumber对象 +│ ├── createRationalFromString() # createRationalFromString方法 +│ ├── compareTo() # compareTo方法 +│ ├── equals() # equals方法 +│ ├── valueOf() # valueOf方法 +│ ├── getCommonDivisor() # getCommonDivisor方法 +│ ├── getDenominator() # getDenominator方法 +│ ├── getNumerator() # getNumerator方法 +│ ├── isFinite() # isFinite方法 +│ ├── isNaN() # isNaN方法 +│ ├── isZero() # isZero方法 +│ └── toString() # toString方法 +├── Class:LruBuffer # LruBuffer类 +│ ├── new LruBuffer() # 创建LruBuffer对象 +│ ├── updateCapacity() # updateCapacity方法 +│ ├── toString() # toString方法 +│ ├── values() # values方法 +│ ├── length # length属性 +│ ├── getCapacity() # getCapacity方法 +│ ├── clear() # clear方法 +│ ├── getCreateCount() # getCreateCount方法 +│ ├── getMissCount() # getMissCount方法 +│ ├── getRemovalCount() # getRemovalCount方法 +│ ├── getMatchCount() # getMatchCount方法 +│ ├── getPutCount() # getPutCount方法 +│ ├── isEmpty() # isEmpty方法 +│ ├── get() # get方法 +│ ├── put() # put方法 +│ ├── keys() # keys方法 +│ ├── remove() # remove方法 +│ ├── afterRemoval() # afterRemoval方法 +│ ├── contains() # contains方法 +│ ├── createDefault() # createDefault方法 +│ ├── entries() # entries方法 +│ └── [Symbol.iterator]() # Symboliterator方法 +|—— Class:Scope # Scope类 +| ├── constructor() # 创建Scope对象 +| ├── toString() # toString方法 +| ├── intersect() # intersect方法 +| ├── intersect() # intersect方法 +| ├── getUpper() # getUpper方法 +| ├── getLower() # getLower方法 +| ├── expand() # expand方法 +| ├── expand() # expand方法 +| ├── expand() # expand法 +| ├── contains() # contains方法 +| ├── contains() # contains方法 +| └── clamp() # clamp方法 +└── Class:Types # Types类 + ├── isAnyArrayBuffer() # isAnyArrayBuffer方法 + ├── isArrayBufferView() # isArrayBufferView方法 + ├── isArgumentsObject() # isArgumentsObject方法 + ├── isArrayBuffer() # isArrayBuffer方法 + ├── isAsyncFunction() # isAsyncFunction方法 + ├── isBigInt64Array() # isBigInt64Array方法 + ├── isBigUint64Array() # isBigUint64Array方法 + ├── isBooleanObject() # isBooleanObject方法 + ├── isBoxedPrimitive() # isBoxedPrimitive方法 + ├── isDataView() # isDataView方法 + ├── isDate() # isDate方法 + ├── isExternal() # isExternal方法 + ├── isFloat32Array() # isFloat32Array方法 + ├── isFloat64Array() # isFloat64Array方法 + ├── isGeneratorFunction() # isGeneratorFunction方法 + ├── isGeneratorObject() # isGeneratorObject方法 + ├── isInt8Array() # isInt8Array方法 + ├── isInt16Array() # isInt16Array方法 + ├── isInt32Array() # isInt32Array方法 + ├── isMap() # isMap方法 + ├── isMapIterator() # isMapIterator方法 + ├── isModuleNamespaceObject() # isModuleNamespaceObject方法 + ├── isNativeError() # isNativeError方法 + ├── isNumberObject() # isNumberObject方法 + ├── isPromise() # isPromise方法 + ├── isProxy() # isProxy方法 + ├── isRegExp() # isRegExp方法 + ├── isSet() # isSet方法 + ├── isSetIterator() # isSetIterator方法 + ├── isSharedArrayBuffer() # isSharedArrayBuffer方法 + ├── isStringObject() # isStringObject方法 + ├── isSymbolObject() # isSymbolObject方法 + ├── isTypedArray() # isTypedArray方法 + ├── isUint8Array() # isUint8Array方法 + ├── isUint8ClampedArray() # isUint8ClampedArray方法 + ├── isUint16Array() # isUint16Array方法 + ├── isUint32Array() # isUint32Array方法 + ├── isWeakMap() # isWeakMap方法 + └── isWeakSet() # isWeakSet方法 +``` +### 2.3.说明 + +#### 2.3.1.接口说明 + + +| 接口名 | 说明 | +| -------- | -------- | +| constructor(encoding? : string) | 构造函数,参数encoding表示编码的格式。默认utf-8, 支持gb18030, gbk, gb2312. | +| readonly encoding : string | 在TextEncoder类中,获取编码的格式,只支持UTF-8。 | +| encode(input : string) : Uint8Array | 输入stirng字符串,根据encodeing编码并输出uint8字节流。 | +| encodeInto(input : string, dest : Uint8Array) : {read : number, written : number} | 输入stirng字符串,dest表示编码后存放位置,返回一个对象,read表示已经编码的字符的个数,written表示已编码字符所占字节的大小。 | +| constructor(encoding? : string, options? : {fatal? : boolean, ignoreBOM? : boolean}) | 构造函数,第一个参数encoding表示解码的格式。第二个参数表示一些属性。属性中fatal表示是否抛出异常,ignoreBOM表示是否忽略bom标志。 | +| readonly encoding : string | 在TextDecoder类中,获取设置的解码格式。 | +| readonly fatal : boolean | 获取抛出异常的设置。 | +| readonly ignoreBOM : boolean | 获取是否忽略bom标志的设置。 | +| decode(input : Uint8Array, options?: { stream?: false }) : string | 输入要解码的数据,解出对应的string字符串。第一个参数input表示要解码的数据,第二个参数options表示一个bool标志,表示将跟随附加数据,默认为false。 | +| encodeSync(src: Uint8Array): Uint8Array; | 使用Base64编码方案将指定u8数组中的所有字节编码到新分配的u8数组中。 | +| encodeToStringSync(src: Uint8Array): string; | 使用Base64编码方案将指定的字节数组编码为String。 | +| decodeSync(src: Uint8Array \| string): Uint8Array; | 使用Base64编码方案将Base64编码的字符串或输入u8数组解码为新分配的u8数组。 | +| encode(src: Uint8Array): Promise\; | 使用Base64编码方案将指定u8数组中的所有字节异步编码到新分配的u8数组中。 | +| encodeToString(src: Uint8Array): Promise\; | 使用Base64编码方案将指定的字节数组异步编码为String。 | +| decode(src: Uint8Array \| string): Promise\; | 使用Base64编码方案将Base64编码的字符串或输入u8数组异步解码为新分配的u8数组。 | +| static createRationalFromString(rationalString: string): RationalNumber | 基于给定的字符串创建一个RationalNumber对象。 | +| compareTo(another: RationalNumber): number | 将当前的RationalNumber对象与给定的对象进行比较。 | +| equals(obj: object): number | 检查给定对象是否与当前 RationalNumber 对象相同。 | +| valueOf(): number | 将当前的RationalNumber对象进行取整数值或者浮点数值。 | +| static getCommonDivisor(number1: number, number2: number,): number | 获得两个指定数的最大公约数。 | +| getDenominator(): number | 获取当前的RationalNumber对象的分母。 | +| getNumerator(): number | 获取当前的RationalNumber对象的分子。 | +| isFinite(): boolean | 检查当前的RationalNumber对象是有限的。 | +| isNaN(): boolean | 检查当前RationalNumber对象是否表示非数字(NaN)值。 | +| isZero(): boolean | 检查当前RationalNumber对象是否表示零值。 | +| toString(): string | 获取当前RationalNumber对象的字符串表示形式。 | +| constructor(capacity?: number) | 创建默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。 | +| updateCapacity(newCapacity: number): void | 将缓冲区容量更新为指定容量,如果 newCapacity 小于或等于 0,则抛出此异常。 | +| toString(): string | 返回对象的字符串表示形式,输出对象的字符串表示 | +| values(): V[] | 获取当前缓冲区中所有值的列表,输出按升序返回当前缓冲区中所有值的列表,从最近访问到最近最少访问。 | +| length: number | 代表当前缓冲区中值的总数,输出返回当前缓冲区中值的总数。 | +| getCapacity(): number | 获取当前缓冲区的容量,输出返回当前缓冲区的容量。 | +| clear(): void | 从当前缓冲区清除键值对,清除键值对后,调用afterRemoval()方法依次对其执行后续操作。 | +| getCreateCount(): number | 获取createDefault()返回值的次数,输出返回createDefault()返回值的次数。 | +| getMissCount(): number | 获取查询值不匹配的次数,输出返回查询值不匹配的次数。 | +| getRemovalCount(): number | 获取从缓冲区中逐出值的次数,输出从缓冲区中驱逐的次数。 | +| getMatchCount​(): number | 获取查询值匹配成功的次数,输出返回查询值匹配成功的次数。 | +| getPutCount(): number | 获取将值添加到缓冲区的次数,输出返回将值添加到缓冲区的次数。 | +| isEmpty(): boolean | 检查当前缓冲区是否为空,输出如果当前缓冲区不包含任何值,则返回 true 。 | +| get(key: K) : V \| undefined | 表示要查询的键,输出如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 | +| put(key: K , value: V): V | 将键值对添加到缓冲区,输出与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 | +| keys(): K[ ] | 获取当前缓冲区中值的键列表,输出返回从最近访问到最近最少访问排序的键列表。 | +| remove​(key: K): V \| undefined | 从当前缓冲区中删除指定的键及其关联的值。 | +| afterRemoval(isEvict: boolean, key: K, value : V, newValue : V):void | 删除值后执行后续操作。 | +| contains(key: K): boolean | 检查当前缓冲区是否包含指定的键,输出如果缓冲区包含指定的键,则返回 true 。 | +| createDefault(key: K): V | 如果未计算特定键的值,则执行后续操作,参数表示丢失的键,输出返回与键关联的值。 | +| entries(): [K,V] | 允许迭代包含在这个对象中的所有键值对。每对的键和值都是对象。 | +| \[Symbol.iterator\](): [K,V] | 返回以键值对得形式得一个二维数组。 | +| constructor(lowerObj: ScopeType, upperObj : ScopeType) | 创建并返回一个Scope对象,用于创建指定下限和上限的作用域实例的构造函数。 | +| toString(): string | 该字符串化方法返回一个包含当前范围的字符串表示形式。 | +| intersect(range: Scope): Scope | 获取给定范围和当前范围的交集。 | +| intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope | 获取当前范围与给定下限和上限范围的交集。 | +| getUpper(): ScopeType | 获取当前范围的上限。 | +| getLower(): ScopeType | 获取当前范围的下限。 | +| expand(lowerObj: ScopeType, upperObj: ScopeType): Scope | 创建并返回包括当前范围和给定下限和上限的并集。 | +| expand(range: Scope): Scope | 创建并返回包括当前范围和给定范围的并集。 | +| expand(value: ScopeType): Scope | 创建并返回包括当前范围和给定值的并集。 | +| contains(value: ScopeType): boolean | 检查给定value是否包含在当前范围内。 | +| contains(range: Scope): boolean | 检查给定range是否在当前范围内。 | +| clamp(value: ScopeType): ScopeType | 将给定value限定到当前范围内。 | +| function printf(format: string, ...args: Object[]): string | printf()方法使用第一个参数作为格式字符串(其可以包含零个或多个格式说明符)来返回格式化的字符串。 | +| function getErrorString(errno: number): string | getErrorString()方法使用一个系统的错误数字作为参数,用来返回系统的错误信息。 | +| function callbackWrapper(original: Function): (err: Object, value: Object) => void | 参数为一个采用 async 函数(或返回 Promise 的函数)并返回遵循错误优先回调风格的函数,即将 (err, value) => ... 回调作为最后一个参数。 在回调中,第一个参数将是拒绝原因(如果 Promise 已解决,则为 null),第二个参数将是已解决的值。 | +| function promiseWrapper(original: (err: Object, value: Object) => void): Object | 参数为采用遵循常见的错误优先的回调风格的函数(也就是将 (err, value) => ... 回调作为最后一个参数),并返回一个返回 promise 的版本。 | +| isAnyArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer或SharedArrayBuffer类型。 | +| 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类型。 | +| isArgumentsObject(value: Object): boolean | 检查输入的value是否是一个arguments对象类型。 | +| isArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer类型。 | +| isAsyncFunction(value: Object): boolean | 检查输入的value是否是异步函数类型。 | +| isBigInt64Array(value: Object): boolean | 检查输入的value是否是BigInt64Array数组类型。 | +| isBigUint64Array(value: Object): boolean | 检查输入的value是否是BigUint64Array数组类型。 | +| isBooleanObject(value: Object): boolean | 检查输入的value是否是一个布尔对象类型。 | +| isBoxedPrimitive(value: Object): boolean | 检查输入的value是否是Boolean或Number或String或Symbol对象类型。 | +| isDataView(value: Object): boolean | 检查输入的value是否是DataView类型。 | +| isDate(value: Object): boolean | 检查输入的value是否是Date类型。 | +| isExternal(value: Object): boolean | 检查输入的value是否是一个native External值类型。 | +| isFloat32Array(value: Object): boolean | 检查输入的value是否是Float32Array数组类型。 | +| isFloat64Array(value: Object): boolean | 检查输入的value是否是Float64Array数组类型。 | +| isGeneratorFunction(value: Object): boolean | 检查输入的value是否是一个generator函数类型。 | +| isGeneratorObject(value: Object): boolean | 检查输入的value是否是一个generator对象类型。 | +| isInt8Array(value: Object): boolean | 检查输入的value是否是Int8Array数组类型。 | +| isInt16Array(value: Object): boolean | 检查输入的value是否是Int16Array数组类型。 | +| isInt32Array(value: Object): boolean | 检查输入的value是否是Int32Array数组类型。 | +| isMap(value: Object): boolean | 检查输入的value是否是Map类型。 | +| isMapIterator(value: Object): boolean | 检查输入的value是否是Map的iterator类型。 | +| isModuleNamespaceObject(value: Object): boolean | 检查输入的value是否是Module Namespace Object对象类型。 | +| isNativeError(value: Object): boolean | 检查输入的value是否是Error类型。 | +| isNumberObject(value: Object): boolean | 检查输入的value是否是Number对象类型。 | +| isPromise(value: Object): boolean | 检查输入的value是否是Promise类型。 | +| isProxy(value: Object): boolean | 检查输入的value是否是Proxy类型。 | +| isRegExp(value: Object): boolean | 检查输入的value是否是RegExp类型。 | +| isSet(value: Object): boolean | 检查输入的value是否是Set类型。 | +| isSetIterator(value: Object): boolean | 检查输入的value是否是Set的iterator类型。 | +| isSharedArrayBuffer(value: Object): boolean | 检查输入的value是否是SharedArrayBuffer类型。 | +| isStringObject(value: Object): boolean | 检查输入的value是否是一个String对象类型。 | +| isSymbolObject(value: Object): boolean | 检查输入的value是否是一个Symbol对象类型。 | +| isTypedArray(value: Object): boolean | 检查输入的value是否是TypedArray包含的类型。 | +| isUint8Array(value: Object): boolean | 检查输入的value是否是Uint8Array数组类型。 | +| isUint8ClampedArray(value: Object): boolean | 检查输入的value是否是Uint8ClampedArray数组类型。 | +| isUint16Array(value: Object): boolean | 检查输入的value是否是Uint16Array数组类型。 | +| isUint32Array(value: Object): boolean | 检查输入的value是否是Uint32Array数组类型。 | +| isWeakMap(value: Object): boolean | 检查输入的value是否是WeakMap类型。 | +| isWeakSet(value: Object): boolean | 检查输入的value是否是WeakSet类型。 | + +printf中每个说明符都替换为来自相应参数的转换后的值。 支持的说明符有: +| 式样化字符 | 式样要求 | +| -------- | -------- | +| %s: | String 将用于转换除 BigInt、Object 和 -0 之外的所有值。| +| %d: | Number 将用于转换除 BigInt 和 Symbol 之外的所有值。| +| %i: | parseInt(value, 10) 用于除 BigInt 和 Symbol 之外的所有值。| +| %f: | parseFloat(value) 用于除 Symbol 之外的所有值。| +| %j: | JSON。 如果参数包含循环引用,则替换为字符串 '[Circular]'。| +| %o: | Object. 具有通用 JavaScript 对象格式的对象的字符串表示形式。类似于具有选项 { showHidden: true, showProxy: true } 的 util.inspect()。这将显示完整的对象,包括不可枚举的属性和代理。| +| %O: | Object. 具有通用 JavaScript 对象格式的对象的字符串表示形式。类似于没有选项的 util.inspect()。 这将显示完整的对象,但不包括不可枚举的属性和代理。| +| %c: | 此说明符被忽略,将跳过任何传入的 CSS 。| +| %%: | 单个百分号 ('%')。 这不消耗待式样化参数。| + +#### 2.3.2.使用说明 +各接口使用方法如下: + +1.readonly encoding() + +``` +import util from '@ohos.util' +var textEncoder = new util.TextEncoder(); +var getEncoding = textEncoder.encoding(); +``` +2.encode() +``` +import util from '@ohos.util' +var textEncoder = new util.TextEncoder(); +var result = textEncoder.encode('abc'); +``` +3.encodeInto() +``` +import util from '@ohos.util' +var textEncoder = new util.TextEncoder(); +var obj = textEncoder.encodeInto('abc', dest); +``` +4.textDecoder() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +``` +5.readonly encoding() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var getEncoding = textDecoder.encoding(); +``` +6.readonly fatal() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var fatalStr = textDecoder.fatal(); +``` +7.readonly ignoreBOM() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var ignoreBom = textDecoder.ignoreBOM(); +``` +8.decode() +``` +import util from '@ohos.util' +var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); +var result = textDecoder.decode(input, {stream : true}); +``` +9.printf() +``` +import util from '@ohos.util' +var format = "%%%o%%%i%s"; +var value = function aa(){}; +var value1 = 1.5; +var value2 = "qwer"; +var result = util.printf(format,value,value1,value2); +``` +10.getErrorString() +``` +import util from '@ohos.util' +var errnum = 13; +var result = util.getErrorString(errnum); +``` +11.callbackWrapper() +``` +import util from '@ohos.util' +async function promiseFn() { + return Promise.resolve('value'); +}; +var cb = util.callbackWrapper(promiseFn); +cb((err, ret) => { + expect(err).strictEqual(null); + expect(ret).strictEqual('value'); +}) +``` +12.promiseWrapper() +``` +import util from '@ohos.util' +function aysnFun(str1, str2, callback) { + if (typeof str1 === 'string' && typeof str1 === 'string') { + callback(null, str1 + str2); + } else { + callback('type err'); + } +} +let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); +newPromiseObj.then(res => { + expect(res).strictEqual('HelloWorld'); +}) +``` +13.encodeSync() +``` +import util from '@ohos.util' +var that = new util.Base64(); +var array = new Uint8Array([115,49,51]); +var result = that.encodeSync(array); +``` +14.encodeToStringSync() +``` +import util from '@ohos.util' +var that = new util.Base64(); +var array = new Uint8Array([115,49,51]); +var result = that.encodeToStringSync(array); +``` +15.decodeSync() +``` +import util from '@ohos.util' +var that = new util.Base64() +var buff = 'czEz'; +var result = that.decodeSync(buff); + +``` +16.encode() +``` +import util from '@ohos.util' +var that = new util.Base64() +var array = new Uint8Array([115,49,51]); +await that.encode(array).then(val=>{ +}) +done() +``` +17.encodeToString() +``` +import util from '@ohos.util' +var that = new util.Base64() +var array = new Uint8Array([115,49,51]); +await that.encodeToString(array).then(val=>{ +}) +done() +``` +18.decode() +``` +import util from '@ohos.util' +var that = new util.Base64() +var buff = 'czEz'; +await that.decode(buff).then(val=>{ +}) +done() +``` +19.createRationalFromString() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(0, 0); +var res = pro.createRationalFromString("-1:2"); +var result1 = res.valueOf(); +``` +20.compareTo() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var proc = new util.RationalNumber(3, 4); +var res = pro.compareTo(proc); +``` +21.equals() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var proc = new util.RationalNumber(3, 4); +var res = pro.equals(proc); +``` +22.valueOf() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var res = pro.valueOf(); +``` +23.getCommonDivisor() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(0, 0); +var res = pro.getCommonDivisor(4, 8); +``` +24.getDenominator() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(2, 1); +var res = pro.getDenominator(); +``` +25.getNumerator() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.getNumerator(); +``` +26.isFinite() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.isFinite(); +``` +27.isNaN() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.isNaN(); +``` +28.isZero() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.isZero(); +``` +29.toString() +``` +import util from '@ohos.util' +var pro = new util.RationalNumber(-2, 1); +var res = pro.toString(); +``` +30.updateCapacity() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.updateCapacity(100); +``` +31.toString() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.get(2); +pro.remove(20); +var result = pro.toString(); +``` +32.values() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.put(2,"anhu"); +pro.put("afaf","grfb"); +var result = pro.values(); +``` +33.length +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.put(1,8); +var result = pro.length; +``` +34.getCapacity() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.getCapacity(); +``` +35.clear() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.clear(); +``` +36.getCreateCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(1,8); +var result = pro.getCreateCount(); +``` +37.getMissCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.get(2) +var result = pro.getMissCount(); +``` +38.getRemovalCount() +``` + +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.updateCapacity(2); +pro.put(50,22); +var result = pro.getRemovalCount(); + +``` +39.getMatchCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +pro.get(2); +var result = pro.getMatchCount(); +``` +40.getPutCount() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.getPutCount(); +``` +41.isEmpty() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.isEmpty(); +``` +42.get() + +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.get(2); +``` +43.put() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.put(2,10); +``` +44.keys() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.keys(); +``` +45.remove() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.remove(20); +``` +46.contains() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.contains(20); +``` +47.createDefault() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +var result = pro.createDefault(50); +``` +48.entries() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro.put(2,10); +var result = pro.entries(); +``` +49.\[Symbol.iterator\]() +``` +import util from '@ohos.util' +var pro = new util.LruBuffer(); +pro .put(2,10); +var result = pro[symbol.iterator](); +``` +50.afterRemoval() +``` +import util from '@ohos.util' +var arr = [ ]; +class ChildLruBuffer extends util.LruBuffer +{ + constructor() + { + super(); + } + static getInstance() + { + if(this.instance == null) + { + this.instance = new ChildLruBuffer(); + } + return this.instance; + } + afterRemoval(isEvict, key, value, newValue) + { + if (isEvict === false) + { + arr = [key, value, newValue]; + } + } +} +ChildLruBuffer.getInstance().afterRemoval(false,10,30,null) +``` +Scope接口中构造新类,实现compareTo方法。 + +``` +class Temperature { + constructor(value) { + this._temp = value; + } + compareTo(value) { + return this._temp >= value.getTemp(); + } + getTemp() { + return this._temp; + } + toString() { + return this._temp.toString(); + } +} +``` + +51.constructor() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +``` + +52.toString() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var result = range.toString() // => [30,40] +``` + +53.intersect() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var rangeFir = new Scope(tempMiDF, tempMidS); +var result = range.intersect(rangeFir) // => [35,39] +``` + +54.intersect() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var range = new Scope(tempLower, tempUpper); +var result = range.intersect(tempMiDF, tempMidS) // => [35,39] +``` + +55.getUpper() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var result = range.getUpper() // => 40 +``` + +56.getLower() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var result = range.getLower() // => 30 +``` + +57.expand() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var range = new Scope(tempLower, tempUpper); +var result = range.expand(tempMiDF, tempMidS) // => [30,40] +``` + +58.expand() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var tempMidS = new Temperature(39); +var range = new Scope(tempLower, tempUpper); +var rangeFir = new Scope(tempMiDF, tempMidS); +var result = range.expand(rangeFir) // => [30,40] +``` + +59.expand() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var range = new Scope(tempLower, tempUpper); +var result = range.expand(tempMiDF) // => [30,40] +``` + +60.contains() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var range = new Scope(tempLower, tempUpper); +var result = range.contains(tempMiDF) // => true +``` + +61.contains() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var range = new Scope(tempLower, tempUpper); +var tempLess = new Temperature(20); +var tempMore = new Temperature(45); +var rangeSec = new Scope(tempLess, tempMore); +var result = range.contains(rangeSec) // => true +``` + +62.clamp() + +``` +var tempLower = new Temperature(30); +var tempUpper = new Temperature(40); +var tempMiDF = new Temperature(35); +var range = new Scope(tempLower, tempUpper); +var result = range.clamp(tempMiDF) // => 35 +``` +63.isAnyArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAnyArrayBuffer(new ArrayBuffer([])) +``` +64.isArrayBufferView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16))); +``` +65.isArgumentsObject() +``` +import util from '@ohos.util' +function foo() { + var result = proc.isArgumentsObject(arguments); + } +var f = foo(); +``` +66.isArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isArrayBuffer(new ArrayBuffer([])); +``` +67.isAsyncFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isAsyncFunction(async function foo() {}); +``` +68.isBigInt64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigInt64Array(new Int16Array([])); +``` +69.isBigUint64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBigUint64Array(new Int16Array([])); +``` +70.isBooleanObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBooleanObject(new Boolean(false)); +``` +71.isBoxedPrimitive() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isBoxedPrimitive(new Boolean(false)); +``` +72.isDataView() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const ab = new ArrayBuffer(20); +var result = proc.isDataView(new DataView(ab)); +``` +73.isDate() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isDate(new Date()); +``` +74.isExternal() +``` +import util from '@ohos.util' +const data = util.createExternalType(); +var reult13 = proc.isExternal(data); +``` +75.isFloat32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat32Array(new Float32Array([])); +``` +76.isFloat64Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isFloat64Array(new Float64Array([])); +``` +77.isGeneratorFunction() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isGeneratorFunction(function* foo() {}); +``` +78.isGeneratorObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +function* foo() {} +const generator = foo(); +var result = proc.isGeneratorObject(generator); +``` +79.isInt8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt8Array(new Int8Array([])); +``` +80.isInt16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt16Array(new Int16Array([])); +``` +81.isInt32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isInt32Array(new Int32Array([])); +``` +82.isMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMap(new Map()); +``` +83.isMapIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isMapIterator(map.keys()); +``` +84.isModuleNamespaceObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isModuleNamespaceObject(util); +``` +85.isNativeError() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNativeError(new TypeError()); +``` +86.isNumberObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isNumberObject(new Number(0)); +``` +87.isPromise() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isPromise(Promise.resolve(42)); +``` +88.isProxy() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const target = {}; +const proxy = new Proxy(target, {}); +var result = proc.isProxy(proxy); +``` +89.isRegExp() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isRegExp(new RegExp('abc')); +``` +90.isSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSet(new Set()); +``` +91.isSetIterator() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const set = new Set(); +var result = proc.isSetIterator(set.keys()); +``` +92.isSharedArrayBuffer() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); +``` +93.isStringObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isStringObject(new String('foo')); +``` +94.isSymbolObject() +``` +import util from '@ohos.util' +var proc = new util.Types(); +const symbols = Symbol('foo'); +var result = proc.isSymbolObject(Object(symbols)); +``` +95.isTypedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isTypedArray(new Float64Array([])); +``` +96.isUint8Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8Array(new Uint8Array([])); +``` +97.isUint8ClampedArray() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); +``` +98.isUint16Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint16Array(new Uint16Array([])); +``` +99.isUint32Array() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isUint32Array(new Uint32Array([])); +``` +100.isWeakMap() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakMap(new WeakMap()); +``` +101.isWeakSet() +``` +import util from '@ohos.util' +var proc = new util.Types(); +var result = proc.isWeakSet(new WeakSet()); +``` + +## 3.js_sys_module子模块 +### 3.1.简介 +进程主要用于获取进程的相关ID,获取和修改进程的工作目录,退出和关闭进程。 childprocess 对象可用于创建新进程。 主进程可以获取子进程的标准输入输出,发送信号,关闭子进程。 +### 3.2.目录 + +``` +commomlibrary/ets_utils/js_sys_module/ +├── Class:PROCESS # PROCESS类 +├── Uid # Uid属性 +├── Gid # Gid属性 +├── EUid # EUid属性 +├── EGid # EGid属性 +├── Groups # Groups属性 +├── Pid # Pid属性 +├── Ppid # Ppid属性 +├── chdir() # chdir方法 +├── uptime() # uptime方法 +├── kill() # kill方法 +├── abort() # abort方法 +├── on() # on方法 +├── tid # tid方法 +├── getStartRealtime() # getStartRealtime方法 +├── getAvailableCores() # getAvailableCores方法 +├── getPastCputime() # getPastCputime方法 +├── isIsolatedProcess() # isIsolatedProcess方法 +├── is64Bit() # is64Bit方法 +├── isAppUid() # isAppUid方法 +├── getUidForName() # getUidForName方法 +├── getThreadPriority() # getThreadPriority方法 +├── getSystemConfig() # getSystemConfig方法 +├── getEnvironmentVar() # getEnvironmentVar方法 +├── exit() # exit方法 +├── cwd() # cwd方法 +├── off() # off方法 +├── runCmd() # runCmd方法 +└─── Class:CHILDPROCESS # class of CHILDPROCESS类 + ├── close() # close方法 + ├── kill() # kill方法 + ├── getOutput() # getOutput方法 + ├── getErrorOutput() # getErrorOutput方法 + ├── wait() # wait方法 + ├── killed # killed属性 + ├── pid # pid属性 + ├── ppid # ppid属性 + └── exitCode # exitCode属性 +``` + +### 3.3.说明 + +#### 3.3.1.接口说明 +| 接口名 | 说明 | +| -------- | -------- | +| const uid :number | 返回进程的数字用户 ID。 | +| const gid :number | 返回进程的数字组 ID。 | +| const euid :number | 返回进程的数字有效用户身份。 | +| const egid :number | 返回 node.js 进程的数字有效组 ID。 | +| const groups :number[] | 返回具有补充组 ID 的数组。 | +| const pid :number | 返回进程的PID。 | +| const ppid :number | 返回当前进程的父进程的PID。 | +| chdir(dir:string) :void | 更改 node.js 进程的当前工作目录。 | +| uptime() :number | 返回当前系统已经运行的秒数。 | +| Kill(pid:number, signal:number) :boolean | 将信号发送到识别的进程PID,true表示发送成功。 | +| abort() :void | 导致 node.js 进程立即退出并生成核心文件。 | +| on(type:string ,listener:EventListener) :void | 用于存储用户触发的事件。 | +| exit(code:number):void | 导致 node.js 进程立即退出。 | +| cwd():string | 返回 node.js 进程的当前工作目录。 | +| off(type: string): boolean | 清除用户存储的事件。 True 表示清算成功。 | +| runCmd(command: string, options?: { timeout : number, killSignal : number \| string, maxBuffer : number }): ChildProcess |通过runcmd,你可以fork一个新进程来运行一个shell并返回childprocess对象。 第一个参数command指的是要运行的shell,第二个参数options指的是子进程的一些运行参数。 这些参数主要是指 timeout、killsignal 和 maxbuffer。 如果设置了timeout,则子进程会在超时后发送killsignal信号。 Maxbuffer 用于限制可以接收的最大 stdout 和 stderr 大小。 | +| wait(): Promise\ | 用于等待子进程运行并返回promise对象,其值为子进程的退出码。 | +| getOutput(): Promise\ | 用于获取子进程的标准输出。 | +| getErrorOutput(): Promise\ | 用于获取子进程的标准错误输出。 | +| const tid:number | 返回进程的 TID。 | +| getStartRealtime() :number | 获取从系统启动到进程启动所经过的实时时间(以毫秒为单位)。 | +| getAvailableCores() :number[] | 获取多核设备上当前进程可用的 CPU 内核。 | +| getPastCputime() :number | 获取从进程开始到当前时间的 CPU 时间(以毫秒为单位)。 | +| isIsolatedProcess(): boolean | 检查进程是否被隔离。 | +| is64Bit(): boolean | 检查进程是否在 64 位环境中运行。 | +| isAppUid(v:number): boolean | 检查指定的 uid 是否属于特定应用程序。 | +| getUidForName(v:string): number | 根据用户名获取用户所属的用户组ID | +| getThreadPriority(v:number): number | 根据指定的 TID 获取线程优先级。 | +| getSystemConfig(name:number): number | 根据指定的系统配置名称获取系统的配置。 | +| getEnvironmentVar(name:string): string | 根据环境变量的名称获取对应的值。 | +| close(): void | 用于关闭正在运行的子进程。 | +| kill(signal: number \| string): void | 用于向子进程发送信号。 | +| readonly killed: boolean | 表示信号是否发送成功,true表示信号发送成功。 | +| readonly exitCode: number | 表示子进程的退出代码。 | +| readonly pid: number | 表示子进程ID。 | +| readonly ppid: number | 代表主进程ID。 | + +#### 3.3.2.使用说明 + +各接口使用方法如下: +1.uid() +``` +uid(){ + var res = Process.uid; +} +``` +2.gid() +``` +gid(){ + var result = Process.gid; +} +``` +3.euid() +``` +euid(){ + var and = Process.euid; +} +``` +4.egid() +``` +egid(){ + var resb = Process.egid; +} +``` +5.groups() +``` +groups(){ + var answer = Process.groups; +} +``` +6.pid() +``` +pid(){ + var result = Process.pid; +} +``` +7.ppid() +``` +ppid(){ + var result = Process.ppid; +} +``` +8.chdir() +``` +chdir(){ + Process.chdir("123456"); +} +``` +9.uptime() +``` +uptime(){ + var num = Process.uptime(); +} +``` +10.kill() +``` +kill(){ + var ansu = Process.kill(5,23); +} +``` +11.abort() +``` +abort(){ + Process.abort(); +} +``` +12.on() +``` +on(){ + function add(num){ + var value = num + 5; + return value; + } + Process.on("add",add); +} +``` +13.exit() +``` +exit(){ + Process.exit(15); +} +``` +14.Cwd() +``` +Cwd(){ + var result = Process.cwd(); +} +``` +15.off() + +``` +off(){ + var result = Process.off("add"); +} +``` +16.runCmd() +``` +runCmd(){ + var child = process.runCmd('echo abc') + // killSignal can be a number or a string + var child = process.runCmd('echo abc;', {killSignal : 'SIGKILL'}); + var child = process.runCmd('sleep 5; echo abc;', {timeout : 1, killSignal : 9, maxBuffer : 2}) +} +``` +17.wait() +``` +wait() +{ + var child = process.runCmd('ls') + var status = child.wait(); + status.then(val => { + console.log(val); + }) +} +``` +18.getOutput() +``` +getOutput(){ + var child = process.runCmd('echo bcd;'); + var res = child.getOutput(); + child.wait(); + res.then(val => { + console.log(val); + }) +} +``` +19.getErrorOutput() +``` +getErrorOutput(){ + var child = process.runCmd('makdir 1.txt'); // execute an error command + var res = child.getErrorOutput(); + child.wait(); + res.then(val => { + console.log(val); + }) +} +``` +20.close() +``` +close(){ + var child = process.runCmd('ls; sleep 5s;') + var result = child.close() +} +``` +21.kill() +``` +kill(){ + var child = process.runCmd('ls; sleep 5s;') + var result = child.kill('SIGHUP'); + child.wait(); + var temp = child.killed; +} +``` +22.killed +``` +{ + var child = process.runCmd('ls; sleep 5;') + child.kill(3); + var killed_ = child.killed; + child.wait(); +} +``` +23.exitCode +``` +{ + var child = process.runCmd('ls; sleep 5;') + child.kill(9); + child.wait(); + var exitCode_ = child.exitCode; +} +``` +24.pid +``` +pid +{ + var child = process.runCmd('ls; sleep 5;') + var pid_ = child.pid; + child.wait(); +} +``` +25.ppid +``` +ppid +{ + var child = process.runCmd('ls; sleep 5;') + var ppid_ = child.ppid; + child.wait(); +} +``` +26.tid +``` +tid(){ + var ansu = Process.tid; +} +``` +27.isIsolatedProcess() +``` +isIsolatedProcess(){ + var ansu = Process.isIsolatedProcess()(); +} +``` +28.isAppUid() +``` +isAppUid(){ + var ansu = Process.isAppUid(10000); +} +``` +29.is64Bit() +``` +is64Bit(){ + var ansu = Process.is64Bit(); +} +``` +30.getUidForName() +``` +getUidForName(){ + var buf = "root"; + var ansu = Process.getUidForName(buf); +} +``` +31.getEnvironmentVar() +``` +getEnvironmentVar(){ + var ansu = Process.getEnvironmentVar('USER'); +} +``` +32.getAvailableCores() +``` +getAvailableCores(){ + var ansu = Process.getAvailableCores(); +} +``` +33.getThreadPriority() +``` +getThreadPriority(){ + var result = Process.getTid(); + var ansu = getThreadPriority(result); +} +``` +34.getStartRealtime() +``` +getStartRealtime(){ + var ansu = Process.getStartRealtime(); +} +``` +35.getPastCputime() +``` +getPastCputime(){ + var ansu = Process.getPastCputime(); +} +``` +36.getSystemConfig() +``` +getSystemConfig(){ + var _SC_ARG_MAX = 0; + var ansu = Process.getSystemConfig(_SC_ARG_MAX) +} +``` + +## 4.js_worker_module子模块 + +### 4.1.简介 + +worker能够让js拥有多线程的能力,通过postMessage完成worker线程与宿主线程通信。 + +### 4.2.接口说明 +接口实现详见:js_worker_module/jsapi/worker + +#### 4.2.1.Worker对象描述 + +宿主线程用于与worker线程通信的Object对象。 + +##### 4.2.1.1接口 + +1. + +- 接口名 + +|constructor(scriptURL:string, options? WorkerOptions) | 构造函数 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +``` + +2. + +- 接口名 + +| postMessage(message:Object, options?:PostMessageOptions) | 向worker线程发送消息 | +|---|---| +| postMessage(message:Object, transfer:ArrayBuffer[]) | 向worker线程发送消息 | + +- 使用示例 + +``` +// 示例一 +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// 示例二 +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +var buffer = new ArrayBuffer(8); +worker.postMessage(buffer, [buffer]); +``` + +3. + +- 接口名 + +| on(type:string, listener:EventListener) | 向worker添加一个事件监听 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.on("alert", (e)=>{ + console.log("worker on..."); +}) +``` + +4. + +- 接口名 + +| once(type:string, listener:EventListener) | 向worker添加一个事件监听, 事件监听只执行一次便自动删除 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.once("alert", (e)=>{ + console.log("worker on..."); +}) +``` + +5. + +- 接口名 + +| off(type:string, listener?:EventListener) | 删除worker的事件监听 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.off("alert"); +``` + +6. + +- 接口名 + +| terminate() | 关闭worker线程,终止worker发送消息 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.terminate(); +``` + +7. + +- 接口名 + +| removeEventListener(type:string, listener?:EventListener) | 删除worker的事件监听 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.removeEventListener("alert"); +``` + +8. + +- 接口名 + +| dispatchEvent(event: Event) | 分发定义在worker的事件 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.dispatchEvent({type:"alert"}); +``` + +9. + +- 接口名 + +| removeAllListener() | 删除worker的所有事件监听 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.removeAllListener(); +``` + +##### 4.2.1.2.属性 + +1. + +- 属性名 + +| onexit?:(code:number)=>void | worker退出时被调用的事件处理程序,处理程序在宿主线程中执行 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onexit = function(e) { + console.log("onexit..."); +} +``` + +2. + +- 属性名 + +| onerror?:(ev:ErrorEvent)=>void | worker在执行过程中发生异常被调用的事件处理程序,处理程序在宿主线程中执行 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onerror = function(e) { + console.log("onerror..."); +} +``` + +3. + +- 属性名 + +| onmessage?:(ev:MessageEvent)=>void | 宿主线程收到来自其创建的worker通过parentPort.postMessage接口发送的消息时被调用的事件处理程序, 处理程序在宿主线程中执行 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onmessage = function(e) { + console.log("onmessage..."); +} +``` + +4. + +- 属性名 + +| onmessageerror?:(event:MessageEvent)=>void | worker对象接收到一条无法序列化的消息时被调用的事件处理程序, 处理程序在宿主线程中执行 | +|---|---| + +- 使用示例 + +``` +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.onmessageerror = function(e) { + console.log("onmessageerror..."); +} +``` + +#### 4.2.2.parentPort对象描述 + +worker线程用于与宿主线程通信的Object对象。 + +##### 4.2.2.1.接口 + +1. + +- 接口名 + +| postMessage(message:Object, options?:PostMessageOptions) | 向宿主线程发送消息 | +|---|---| +| postMessage(message:Object, transfer:ArrayBuffer[]) | 向宿主线程发送消息 | + +- 使用示例 + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + parentPort.postMessage("hello world from worker.js"); +} +``` + +2. + +- 接口名 + +| close() | 关闭worker线程,终止worker接收消息 | +|---|---| + +- 使用示例 + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + parentPort.close(); +} +``` + +##### 4.2.2.2.属性 + +1. + +- 属性名 + +| onmessage?:(event:MessageEvent)=>void | 宿主线程收到来自其创建的worker通过worker.postMessage接口发送的消息时被调用的事件处理程序,处理程序在worker线程中执行 | +|---|---| + +- 使用示例 + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + console.log("receive main.js message"); +} +``` + +2. + +- 属性名 + +| onerror?:(ev: ErrorEvent)=>void | worker在执行过程中发生异常被调用的事件处理程序,处理程序在worker线程中执行 | +|---|---| + +- 使用示例 + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onerror = function(e) { + console.log("onerror..."); +} + +``` + +3. + +- 属性名 + +| onmessageerror?:(event: MessageEvent)=>void | worker对象接收到一条无法被反序列化的消息时被调用的事件处理程序, 处理程序在worker线程中执行 | +|---|---| + +- 使用示例 + +``` +// main.js +import worker from "@ohos.worker" +const worker = new worker.Worker("workers/worker.js"); +worker.postMessage("hello world"); + +// worker.js +import worker from "@ohos.worker" +const parentPort = worker.parentPort; +parentPort.onmessageerror = function(e) { + console.log("onmessageerror..."); +} +``` + +### 4.3涉及仓 + +- ace_ace_engine(foundation/arkui/ace_engine-readme_zh.md) +- ace_napi(foundation/arkui/napi-readme_zh.md) + + +### 相关仓 + +[ets_utils子系统](commonlibrary/ets_utils/README.md) + +### 许可证 + +Util在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_util_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony-sig/commonlibrary_ets_utils/blob/master/LICENSE) \ No newline at end of file diff --git a/bundle.json b/bundle.json new file mode 100644 index 0000000..705540a --- /dev/null +++ b/bundle.json @@ -0,0 +1,68 @@ +{ + "name": "@ohos/js_api_module", + "version": "", + "description": "commonlibrary_ets_utils, contains of 4 submodules:js_api_module,js_util_module,js_sys_module,js_worker_module", + "homePage": "https://gitee.com/openharmony", + "license": "Apache V2", + "repository": "https://gitee.com/openharmony/js_api_module", + "domain": "os", + "language": "", + "publishAs": "code-segment", + "private": false, + "scripts": {}, + "tags": [ + "js" + ], + "keywords": [ + "ets", + "utils" + ], + "envs": {}, + "dirs": {}, + "author": { + "name": "", + "email": "", + "url": "" + }, + "contributors": [ + { + "name": "", + "email": "", + "url": "" + } + ], + "segment": { + "destPath": "commonlibrary/ets_utils" + }, + "component": { + "name": "ets_utils", + "subsystem": "commonlibrary", + "syscap": [], + "features": [], + "adapted_system_type": [], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": [ + "//commonlibrary/ets_utils/js_api_module/uri:uri_packages", + "//commonlibrary/ets_utils/js_api_module/url:url_packages", + "//commonlibrary/ets_utils/js_api_module/convertxml:convertxml_packages", + "//commonlibrary/ets_utils/js_api_module/xml:xml_packages", + "//commonlibrary/ets_utils/js_sys_module/process:process_packages", + "//commonlibrary/ets_utils/js_sys_module/dfx:dfx_packages", + "//commonlibrary/ets_utils/js_util_module/util:util_packages", + "//commonlibrary/ets_utils/js_util_module/container:container_packages", + "//commonlibrary/ets_utils/js_worker_module:jsapi_packages" + ], + "inner_kits": [], + "test": [ + "//commonlibrary/ets_utils/js_api_module/test_uri/unittest:unittest", + "//commonlibrary/ets_utils/js_api_module/test_xml/unittest:unittest" + ] + } + } +} diff --git a/js_api_module/LICENSE b/js_api_module/LICENSE deleted file mode 100755 index 4a45986..0000000 --- a/js_api_module/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/js_api_module/README.md b/js_api_module/README.md deleted file mode 100755 index 24abd0a..0000000 --- a/js_api_module/README.md +++ /dev/null @@ -1,457 +0,0 @@ -# js_api_module Subsystem/Component - -- [Introduction](#Introduction) -- [Contents](#Contents) -- [Illustrate](#Illustrate) - - [Interface Description](#Interface Description) - - [Instructions for use](#Instructions for use) - -- [Related warehouse](#Related warehouse) - -## Introduction - -The interface of URL is used to parse, construct, normalize, and encode URLs. The constructor of URL creates a new URL object. In order to make changes to the resolved components of the URL or to the URL. The URLSearchParams interface defines some practical methods to process URL query strings. - -URI Represents a Uniform Resource Identifier (URI) reference. - -XML representation refers to extensible markup language. - -The XmlSerializer interface is used to generate an xml file. The constructor of XmlSerializer creates a new XmlSerializer object, and calls the method of the XmlSerializer object to generate an xml file. The XmlPullParser interface is used to parse the existing xml file. The constructor of XmlPullParser creates a new XmlPullParser object, and calls the method of the XmlPullParser object to parse the xml file. - -## Contents - -``` -base/compileruntime/js_api_module/ -├── Class:URL # URL class -│ ├── new URL(input[, base]) # Create URL object -│ ├── hash # hash attribute -│ ├── host # host attribute -│ ├── hostname # hostname attribute -│ ├── href # href attribute -│ ├── origin # origin attribute -│ ├── password # password attribute -│ ├── pathname # pathname attribute -│ ├── port # port attribute -│ ├── protocol # protocol attribute -│ ├── search # search attribute -│ ├── searchParams # searchParams attribute -│ ├── username # username attribute -│ ├── toString() # toString method -│ └── toJSON() # toJSON method -├── Class: URLSearchParams # URLSearchParams class -│ ├── new URLSearchParams() # Create URLSearchParams object -│ ├── new URLSearchParams(string) # Create URLSearchParams object -│ ├── new URLSearchParams(obj) # Create URLSearchParams object -│ ├── new URLSearchParams(iterable) # Create URLSearchParams object -│ ├── append(name, value) # append method -│ ├── delete(name) # delete method -│ ├── entries() # entries method -│ ├── forEach(fn[, thisArg]) # forEach method -│ ├── get(name) # get method -│ ├── getAll(name) # getAll method -│ ├── has(name) # has method -│ ├── keys() # keys method -│ ├── set(name, value) # set method -│ ├── sort() # sort method -│ ├── toString() # toString method -│ ├── values() # values method -│ └── urlSearchParams[Symbol.iterator]() # Create URLSearchParams object -├── Class:URI # URI class -│ ├── URI(str: string) # Create URI object -│ ├── scheme # scheme attribute -│ ├── authority # authority attribute -│ ├── ssp # ssp attribute -│ ├── userinfo # userinfo attribute -│ ├── host # host attribute -│ ├── port # port attribute -│ ├── query # query attribute -│ ├── fragment # fragment attribute -│ ├── path # path method -│ ├── equals(ob: Object) # equals method -│ ├── normalize() # normalize method -│ ├── checkIsAbsolute() # checkIsAbsolute method -│ ├── normalize() # normalize method -│ ├── toString() # toString method -├── Class:ConvertXml # ConvertXml class -│ ├── ConvertXml() # Create convertxml class object -│ └── convert(xml: string, options: Object) # convert method -├── Class:XmlSerializer # XmlSerializer class -│ ├── new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) # Create XmlSerializer class object -│ ├── setAttributes(name: string, value: string) # Set Attributes method -│ ├── addEmptyElement(name: string) # Add an empty element method -│ ├── setDeclaration() # Set the Declaration method -│ ├── startElement(name: string) # Set the start element method -│ ├── endElement() # Set the end element method -│ ├── setNamespace(prefix: string, namespace: string) # Namespace method -│ ├── setCommnet(text: string) # Set up Commnet method -│ ├── setCData(text: string) # Set the CData method -│ ├── setText(text: string) # Set the Text method -│ ├── setDocType(text: string) # Set DocType method -└── Class: XmlPullParser # XmlPullParser class - ├── new (buffer: ArrayBuffer | DataView, encoding?: string) # Create XmlPullParser object - └── parse(option: ParseOptions) # parse method -``` - -## Illustrate - -### Interface Description - - -| Interface name | Illustrate | -| -------- | -------- | -| new URL(url: string,base?:string \| URL) | Create and return a URL object that references the URL specified by the absolute URL string, the relative URL string, and the basic URL string. | -| tostring():string | The stringification method returns a USVString containing the complete URL. It is equivalent to the read-only URL.href. | -| toJSON():string | This method returns a USVString, which contains a serialized URL version. | -| new URLSearchParams() | The URLSearchParams() constructor has no parameters. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | -| new URLSearchParams(string) | The input parameter of URLSearchParams(string) constructor is string data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | -| new URLSearchParams(obj) | URLSearchParams(obj) The input parameter of the constructor is the obj data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | -| new URLSearchParams(iterable) | URLSearchParams(iterable) The input parameter of the constructor is the iterable data type. This method creates and returns a new URLSearchParams object. The beginning'?' character will be ignored. | -| has(name: string): boolean | Retrieve whether the searchParams object contains name. If yes, it returns true, otherwise it returns false. | -| set(name: string, value string): void | Retrieve whether the searchParams object contains a key-value pair whose key is name. If not, add the key-value pair, if any, modify the value corresponding to the first key in the object, and delete the remaining key-value pairs whose key is name. | -| sort(): void | According to the Unicode code point of the key, sort all key/value pairs contained in this object and return undefined. | -| toString(): string | According to the searchParams object, the query string applicable in the URL is returned. | -| keys(): iterableIterator\ | Return an iterator, which allows iterating through all the key values contained in the object. | -| values(): iterableIterator\ | Returns an iterator, which allows iterating over all the value values contained in the object. | -| append(name: string, value: string): void | Insert the name, value key-value pair in the searchParams object. | -| delete(name: string): void | Traverse the searchParams object, find all the names, and delete the corresponding key-value pairs. | -| get(name: string): string | Retrieve the first name in the searchParams object and return the value corresponding to the name key. | -| getAll(name: string): string[] | Retrieve all names in the searchParams object and return all the values corresponding to the name key. | -| entries(): iterableIterator<[string, string]> | Returns an iterator that allows iterating through all key/value pairs contained in the searchParams object. | -| forEach(): void | Through the callback function to traverse the key-value pairs on the URLSearchParams instance object. | -| urlSearchParams\[Symbol.iterator]() | Returns an ES6 iterator for each name-value pair in the query string. Each item of the iterator is a JavaScript array. | -| URI​(str: string) | Construct the URI by parsing the given input parameter (String str). This constructor parses the given string strictly in accordance with the grammatical provisions in RFC 2396 Appendix A. | -| getScheme​() | Return the scheme component of this URI, or null if the scheme is not defined. | -| getAuthority​() | Returns the decoded authority component of this URI, or null if authority is not defined. The string returned by this method is the same as the string returned by the getRawAuthority method, except that all escaped octet sequences are decoded. | -| getSchemeSpecificPart​() | Returns the decoding scheme-specific part of this URI. The string returned by this method is the same as the string returned by the getRawSchemeSpecificPart method, except that all escaped octet sequences are decoded. | -| getUserInfo​() | Returns the decoded userinfo component of this URI. The userinfo component of the URI (if defined) only contains characters in unreserved, punctuation, escape, and other categories. | -| getHost​() | Return the host component of this URI, or null if host is not defined. | -| getPort​() | Return the port of this URI, or -1 if the port is not defined. The port component of the URI (if defined) is a non-negative integer. | -| getQuery​() | Returns the decoded query component of this URI, or null if the query is not defined. The string returned by this method is the same as the string returned by the getRawQuery method, except that all escaped octet sequences are decoded. | -| getFragment​() | Returns the decoded fragment component of this URI, or null if the fragment is not defined. The string returned by this method is the same as the string returned by the getRawFragment method, except that all escaped octet sequences are decoded. | -| getPath​() | Returns the decoded path component of this URI, or null if path is not defined. The string returned by this method is the same as the string returned by the getRawPath method, except that all escaped octet sequences are decoded. | -| equals(ob: Object) | Test whether this URI is equal to another object. If the given object is not a URI, this method immediately returns false. | -| normalize​() | Normalize the path of this URI. If this URI is opaque, or its path is already in normal form, then this URI is returned. Otherwise, a new URI identical to this URI will be constructed. | -| checkIsAbsolute() | Determine whether this URI is absolute. If and only if it has a scheme component, the URI is absolute and the return value is true, otherwise the return value is false. | -| toString() | Return the content of this URI as a string. | -| ConvertXml() | The constructor used to construct the convertxml class object. This constructor does not need to pass in parameters. | -| convert(xml: string, options: Object) | Returns a JavaScript object that converts an XML string as required by the option. | -| XmlSerializer(buffer: ArrayBuffer \| DataView, encoding?: string) | Create and return an XmlSerializer object. The XmlSerializer object passes two parameters. The first parameter is ArrayBuffer or DataView, and the second parameter is the file format (UTF-8 by default). | -| setAttributes(name: string, value: string): void | Write the Attributes attribute to the xml file. | -| addEmptyElement(name: string): void | Write an empty element. | -| setDeclaration(): void | Set the Declaration to use the encoding to write the xml declaration. For example: | -| startElement(name: string): void | Write the elemnet start tag with the given name.| -| endElement(): void | Write the end tag of the element. | -| setNamespace(prefix: string, namespace: string): void | Write the namespace of the current element tag. | -| setCommnet(text: string): void | Write the comment attribute. | -| setCData(text: string): void | Write the CData attribute. | -| setText(text: string): void | Write the Text property. | -| setDocType(text: string): void | Write the DocType attribute. | -| XmlPullParser(buffer: ArrayBuffer \| DataView, encoding?: string) | Create and return an XmlPullParser object. The XmlPullParser object passes two parameters. The first parameter is ArrayBuffer or DataView, and the second parameter is the file format (default is UTF-8). | -| parse(option: ParseOptions): void | This interface is used to parse xml. The ParseOptions parameter is an interface containing five optional parameters {supportDoctype?: boolea ignoreNameSpace?: boolean tagValueCallbackFunction?: (name: string, value: string) => boolean attributeValueCallbackFunction?: (name: string, value: string) => boolean) tokenValueCallbackFunction?: (eventType: EventType, value: ParseInfo) => boolean }. The input parameter 1 of the tokenValueCallbackFunction callback function is the event type, and the input parameter 2 is the info interface containing get attributes such as getColumnNumber and getDepth. The user can obtain the depth and other information in the current parsing process through methods such as info.getDepth(). | -### Instructions for use - -The usage of each interface is as follows: - - -1、new URL(url: string,base?:string|URL) -``` -let b = new URL('https://developer.mozilla.org'); // => 'https://developer.mozilla.org/' - -let a = new URL( 'sca/./path/path/../scasa/text', 'http://www.example.com'); -// => 'http://www.example.com/sca/path/scasa/text' -``` -2、tostring():string -``` -const url = new URL('http://10.0xFF.O400.235:8080/directory/file?query#fragment'); -url.toString() // => 'http://10.0xff.o400.235:8080/directory/file?query#fragment' - -const url = new URL("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"); -url.toString() // => 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html' - -const url = new URL("http://username:password@host:8080/directory/file?query#fragment"); -url.toString() // => 'http://username:password@host:8080/directory/file?query#fragment' -``` -3、toJSON():string -``` -const url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/toString"); -url.toJSON(); // => 'https://developer.mozilla.org/en-US/docs/Web/API/URL/toString' -``` -4、new URLSearchParams() -``` -let params = new URLSearchParams('foo=1&bar=2'); -``` -5、new URLSearchParams(string) -``` -params = new URLSearchParams('user=abc&query=xyz'); -console.log(params.get('user')); -// Prints 'abc' -``` -6、new URLSearchParams(obj) -``` -const params = new URLSearchParams({ - user: 'abc', - query: ['first', 'second'] -}); -console.log(params.getAll('query')); -// Prints [ 'first,second' ] -``` -7、new URLSearchParams(iterable) -``` -let params; - -// Using an array -params = new URLSearchParams([ - ['user', 'abc'], - ['query', 'first'], - ['query', 'second'], -]); -console.log(params.toString()); -// Prints 'user = abc & query = first&query = second' -``` -8、has(name: string): boolean -``` -console.log(params.has('bar')); // =>true -``` -9、set(name: string, value string): void -``` -params.set('baz', 3); -``` -10、sort(): void -``` -params .sort(); -``` -11、toString(): string -``` -console.log(params .toString()); // =>bar=2&baz=3&foo=1' -``` -12、keys(): iterableIterator\ -``` -for(var key of params.keys()) { - console.log(key); -} // =>bar baz foo -``` -13、values(): iterableIterator\ -``` -for(var value of params.values()) { - console.log(value); -} // =>2 3 1 -``` -14、append(name: string, value: string): void -``` -params.append('foo', 3); // =>bar=2&baz=3&foo=1&foo=3 -``` -15、delete(name: string): void -``` -params.delete('baz'); // => bar=2&foo=1&foo=3 -``` -16、get(name: string): string -``` -params.get('foo'); // => 1 -``` -17、getAll(name: string): string[] -``` -params.getAll('foo'); // =>[ '1', '3' ] -``` -18、entries(): iterableIterator<[string, string]> -``` -for(var pair of searchParams.entries()) { - console.log(pair[0]+ ', '+ pair[1]); -} // => bar, 2 foo, 1 foo, 3 -``` -19、forEach(): void -``` -url.searchParams.forEach((value, name, searchParams) => { - console.log(name, value, url.searchParams === searchParams); -}); -// => foo 1 true -// => bar 2 true -``` -20、urlSearchParams[Symbol.iterator] () -``` -const params = new URLSearchParams('foo=bar&xyz=baz'); -for (const [name, value] of params) { - console.log(name, value); -} -// Prints: -// foo bar -// xyz bar -``` - - -21、URI​(String str) -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -``` -22、scheme -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.scheme // => "http"; -``` -23、authority -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.authority // => "gg:gaogao@www.baidu.com:99"; -``` -24、ssp -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.ssp " // => gg:gaogao@www.baidu.com:99/path/path?query"; -``` -25、userinfo -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.userinfo // => "gg:gaogao"; -``` -26、host -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.host // => "www.baidu.com"; -``` -27、port -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.port // => "99"; -``` -28、query -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.query // => "query"; -``` -29、fragment -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.fragment // => "fagment"; -``` -30、path -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.path // => "/path/path"; -``` -31、equals(Object ob) -``` -let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment'); -let gaogao1 = gaogao; -let res = gaogao.equals(gaogao1); -console.log(res); // => true; -``` -32、normalize​() -``` -let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment'); -let res = gaogao.normalize(); -console.log(res.path); // => "/path/path1" -console.log(res.toString()); // => "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment" -``` -33、checkIsAbsolute() -``` -let gaogao = new Uri.URI('f/tp://username:password@www.baidu.com:88/path?query#fagment'); -let res = gaogao.checkIsAbsolute(); -console.log(res); //=> false; -``` -34、toString() -``` -let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'); -let res = gaogao.toString(); -console.log(res.toString()); // => 'http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'; -``` - - -35、ConvertXml() -``` -var convertml = new convertXml.ConvertXml(); -``` -36、convert(xml: string, options: Object) -``` -var result = convertml.convert(xml, {compact: false, spaces: 4}); -``` -37、new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) -``` - -var arrayBuffer = new ArrayBuffer(1024); -var bufView = new DataView(arrayBuffer); -var thatSer = new xml.XmlSerializer(bufView); -``` -38、setDeclaration():void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setDeclaration() // => ; -``` -39、setCommnet(text: string):void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setCommnet("Hello, World!"); // => ; -``` -40、setCData(text: string) :void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); // => -``` -41、setDocType(text: string):void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setDocType("foo"); // => -``` -42、setNamespace(prefix: string, namespace: string): void -43、startElement(name: string): void -44、setAttributes(name: string, value: string): void -45、endElement(): void -46、setText(text: string): void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); -thatSer.startElement("table"); -thatSer.setAttributes("importance", "high"); -thatSer.setText("Happy"); -endElement(); // => Happy -``` -47、addEmptyElement(name: string): void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.addEmptyElement("b"); // => -``` -48、new (buffer: ArrayBuffer | DataView, encoding?: string) -``` -var strXml = - '' + - '' + - ' Happy' + - ''; -var arrayBuffer = new ArrayBuffer(strXml.length*2); -var bufView = new Uint8Array(arrayBuffer); -var strLen = strXml.length; -for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i);//设置arraybuffer 方式 -} -var that = new xml.XmlPullParser(arrayBuffer); - -``` -49、parse(option: ParseOptions): void -``` -var strXml = - '' + - '' + - ' Happy' + - ''; -var arrayBuffer = new ArrayBuffer(strXml.length*2); -var bufView = new Uint8Array(arrayBuffer); -var strLen = strXml.length; -for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i); -} -var that = new xml.XmlPullParser(arrayBuffer); -var arrTag = {}; -arrTag[0] = '132'; -var i = 1; -function func(key, value){ - arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); - i++; - return true; -} -var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}; -that.parse(options); -``` -## Related warehouse -[js_api_module Subsystem](base/compileruntime/js_api_module-readme.md) - -## License - -URL is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_api_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony/js_api_module/blob/master/LICENSE) for the full license text. \ No newline at end of file diff --git a/js_api_module/README_zh.md b/js_api_module/README_zh.md deleted file mode 100755 index e25ac52..0000000 --- a/js_api_module/README_zh.md +++ /dev/null @@ -1,456 +0,0 @@ -# js_api_module子系统/组件 - -- [简介](#简介) -- [目录](#目录) -- [说明](#说明) - - [接口说明](#接口说明) - - [使用说明](#使用说明) - -- [相关仓](#相关仓) - -## 简介 - -URL接口用于解析,构造,规范化和编码 URLs。 URL的构造函数创建新的URL对象。 以便对URL的已解析组成部分或对URL进行更改。URLSearchParams 接口定义了一些实用的方法来处理 URL 的查询字符串。 - -URI表示统一资源标识符引用。 - -xml表示指可扩展标记语言。 - -XmlSerializer接口用于生成一个xml文件。 XmlSerializer的构造函数创建新的XmlSerializer对象,调用XmlSerializer对象的方法生成一个xml文件。XmlPullParser 接口用于解析已有的xml文件,XmlPullParser的构造函数创建新的XmlPullParser对象,调用XmlPullParser对象的方法解析xml。 - -## 目录 - -``` -base/compileruntime/js_api_module/ -├── Class:URL # URL类 -│ ├── new URL(input[, base]) # 创建URL对象 -│ ├── hash # hash属性 -│ ├── host # host属性 -│ ├── hostname # hostname属性 -│ ├── href # href属性 -│ ├── origin # origin属性 -│ ├── password # password属性 -│ ├── pathname # pathname属性 -│ ├── port # port属性 -│ ├── protocol # protocol属性 -│ ├── search # search属性 -│ ├── searchParams # searchParams属性 -│ ├── username # username属性 -│ ├── toString() # toString方法 -│ └── toJSON() # toJSON方法 -├── Class: URLSearchParams # URLSearchParams类 -│ ├── new URLSearchParams() # 创建URLSearchParams对象 -│ ├── new URLSearchParams(string) # 创建URLSearchParams对象 -│ ├── new URLSearchParams(obj) # 创建URLSearchParams对象 -│ ├── new URLSearchParams(iterable) # 创建URLSearchParams对象 -│ ├── append(name, value) # append方法 -│ ├── delete(name) # delete方法 -│ ├── entries() # entries方法 -│ ├── forEach(fn[, thisArg]) # forEach方法 -│ ├── get(name) # get方法 -│ ├── getAll(name) # getAll方法 -│ ├── has(name) # has方法 -│ ├── keys() # keys方法 -│ ├── set(name, value) # set方法 -│ ├── sort() # sort方法 -│ ├── toString() # toString方法 -│ ├── values() # values方法 -│ └── urlSearchParams[Symbol.iterator]() # 创建URLSearchParams对象 -├── Class:URI # URI类 -│ ├── URI(str: string) # 创建URI对象 -│ ├── scheme # scheme属性 -│ ├── authority # authority属性 -│ ├── ssp # ssp属性 -│ ├── userinfo # userinfo属性 -│ ├── host # host属性 -│ ├── port # port属性 -│ ├── query # query属性 -│ ├── fragment # fragment属性 -│ ├── path # path属性 -│ ├── equals(ob: Object) # equals方法 -│ ├── normalize() # normalize方法 -│ ├── checkIsAbsolute() # checkIsAbsolute方法 -│ ├── normalize() # normalize方法 -│ └── toString() # toString方法 -├── Class:ConvertXml # ConvertXml类 -│ ├── ConvertXml() # 创建ConvertXml类对象 -│ └── convert(xml: string, options: Object) # convert方法 -├── Class:XmlSerializer # XmlSerializer类 -│ ├── new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) # 创建XmlSerializer类对象 -│ ├── setAttributes(name: string, value: string) # 设置Attributes方法 -│ ├── addEmptyElement(name: string) # 添加一个空元素方法 -│ ├── setDeclaration() # 设置Declaration方法 -│ ├── startElement(name: string) # 设置开始元素方法 -│ ├── endElement() # 设置结束元素方法 -│ ├── setNamespace(prefix: string, namespace: string) # 设置命名空间方法 -│ ├── setCommnet(text: string) # 设置Commnet方法 -│ ├── setCData(text: string) # 设置CData方法 -│ ├── setText(text: string) # 设置Text方法 -│ └── setDocType(text: string) # 设置DocType方法 -└── Class: XmlPullParser # XmlPullParser类 - ├── new (buffer: ArrayBuffer | DataView, encoding?: string) # 创建XmlPullParser对象 - └── parse(option: ParseOptions) # parse方法 -``` - -## 说明 - -### 接口说明 - - -| 接口名 | 说明 | -| -------- | -------- | -| URL(url: string,base?:string \| URL) | 创建并返回一个URL对象,该URL对象引用使用绝对URL字符串,相对URL字符串和基本URL字符串指定的URL。 | -| tostring():string | 该字符串化方法返回一个包含完整 URL 的 USVString。它的作用等同于只读的 URL.href。 | -| toJSON():string | 该方法返回一个USVString,其中包含一个序列化的URL版本。 | -| new URLSearchParams() | URLSearchParams() 构造器无入参,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | -| new URLSearchParams(string) | URLSearchParams(string) 构造器的入参为string数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | -| new URLSearchParams(obj) | URLSearchParams(obj) 构造器的入参为obj数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | -| new URLSearchParams(iterable) | URLSearchParams(iterable) 构造器的入参为iterable数据类型,该方法创建并返回一个新的URLSearchParams 对象。 开头的'?' 字符会被忽略。 | -| has(name: string): boolean | 检索searchParams对象中是否含有name。有则返回true,否则返回false。 | -| set(name: string, value string): void | 检索searchParams对象中是否含有key为name的键值对。没有的话则添加该键值对,有的话则修改对象中第一个key所对应的value,并删除键为name的其余键值对。 | -| sort(): void | 根据键的Unicode代码点,对包含在此对象中的所有键/值对进行排序,并返回undefined。 | -| toString(): string | 根据searchParams对象,返回适用在URL中的查询字符串。 | -| keys(): iterableIterator\ | 返回一个iterator,遍历器允许遍历对象中包含的所有key值。 | -| values(): iterableIterator\ | 返回一个iterator,遍历器允许遍历对象中包含的所有value值。 | -| append(name: string, value: string): void | 在searchParams对象中插入name, value键值对。 | -| delete(name: string): void | 遍历searchParams对象,查找所有的name,删除对应的键值对。 | -| get(name: string): string | 检索searchParams对象中第一个name,返回name键对应的值。 | -| getAll(name: string): string[] | 检索searchParams对象中所有name,返回name键对应的所有值。 | -| entries(): iterableIterator<[string, string]> | 返回一个iterator,允许遍历searchParams对象中包含的所有键/值对。 | -| forEach(): void | 通过回调函数来遍历URLSearchParams实例对象上的键值对。 | -| urlSearchParams\[Symbol.iterator]() | 返回查询字符串中每个名称-值对的ES6迭代器。迭代器的每个项都是一个JavaScript数组。 | -| URI​(str: string) | 通过解析给定入参(String str)来构造URI。此构造函数严格按照RFC 2396附录A中的语法规定解析给定字符串。 | -| scheme​ | 返回此 URI 的scheme部分,如果scheme未定义,则返回 null | -| authority​ | 返回此 URI 的解码authority部分,如果authority未定义,则返回 null。 | -| ssp​ | 返回此 URI 的解码scheme-specific部分。 | -| userinfo​ | 返回此 URI 的解码userinfo部分。包含passworld和username。 | -| host​ | 返回此 URI 的host部分,如果host未定义,则返回 null。 | -| port​ | 返回此 URI 的port部分,如果port未定义,则返回 -1。URI 的port组件(如果已定义)是一个非负整数。 | -| query​ | 返回此 URI 的query部分,如果query未定义,则返回 null。 | -| fragment​ | 返回此 URI 的解码fragment组件,如果fragment未定义,则返回 null。| -| path​ | 返回此 URI 的解码path组件,如果path未定义,则返回 null。 | -| equals(ob: Object) | 测试此 URI 是否与另一个对象相等。如果给定的对象不是 URI,则此方法立即返回 false。 | -| normalize​() | 规范化这个 URI 的路径。如果这个 URI 的path不规范,将规范后构造一个新 URI对象返回。 | -| checkIsAbsolute​() | 判断这个 URI 是否是绝对的。当且仅当它具有scheme部分时,URI 是绝对的,返回值为true,否则返回值为false。 | -| ConvertXml() | 用于构造ConvertXml类对象的构造函数。此构造函数无需传入参数。 | -| convert(xml: string, options: Object) | 返回按选项要求转化xml字符串的JavaScrip对象。 | -| XmlSerializer(buffer: ArrayBuffer \| DataView, encoding?: string) | 创建并返回一个XmlSerializer对象,该XmlSerializer对象传参两个第一参数是ArrayBuffer或DataView一段内存,第二个参数为文件格式(默认为UTF-8)。 | -| setAttributes(name: string, value: string): void | 给xml文件中写入属性Attributes属性。 | -| addEmptyElement(name: string): void | 写入一个空元素。 | -| setDeclaration(): void | 设置Declaration使用编码写入xml声明。例如:<?xml version=“1.0”encoding=“utf-8”> | -| startElement(name: string): void | 写入具有给定名称的elemnet开始标记。| -| endElement(): void | 写入元素的结束标记。 | -| setNamespace(prefix: string, namespace: string): void | 写入当前元素标记的命名空间。 | -| setCommnet(text: string): void | 写入comment属性。 | -| setCData(text: string): void | 写入CData属性。 | -| setText(text: string): void | 写入Text属性。 | -| setDocType(text: string): void | 写入DocType属性。 | -| XmlPullParser(buffer: ArrayBuffer \| DataView, encoding?: string) | 创建并返回一个XmlPullParser对象,该XmlPullParser对象传参两个第一参数是ArrayBuffer或DataView一段内存,第二个参数为文件格式(默认为UTF-8)。 | -| parse(option: ParseOptions): void | 该接口用于解析xml,ParseOptions参数为一个接口包含五个可选参{supportDoctype?: boolea ignoreNameSpace?: boolean tagValueCallbackFunction?: (name: string, value: string) => boolean attributeValueCallbackFunction?: (name: string, value: string) => boolean) tokenValueCallbackFunction?: (eventType: EventType, value: ParseInfo) => boolean }。其中tokenValueCallbackFunction回调函数的入参1是事件类型,入参2是包含getColumnNumber、getDepth等get属性的info接口,用户可通过info.getDepth()等方法来获取当前解析过程中的depth等信息。 | -### 使用说明 - -各接口使用方法如下: - - -1、new URL(url: string,base?:string|URL) -``` -let b = new URL('https://developer.mozilla.org'); // => 'https://developer.mozilla.org/' - -let a = new URL( 'sca/./path/path/../scasa/text', 'http://www.example.com'); -// => 'http://www.example.com/sca/path/scasa/text' -``` -2、tostring():string -``` -const url = new URL('http://10.0xFF.O400.235:8080/directory/file?query#fragment'); -url.toString() // => 'http://10.0xff.o400.235:8080/directory/file?query#fragment' - -const url = new URL("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"); -url.toString() // => 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html' - -const url = new URL("http://username:password@host:8080/directory/file?query#fragment"); -url.toString() // => 'http://username:password@host:8080/directory/file?query#fragment' -``` -3、toJSON():string -``` -const url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/toString"); -url.toJSON(); // => 'https://developer.mozilla.org/en-US/docs/Web/API/URL/toString' -``` -4、new URLSearchParams() -``` -let params = new URLSearchParams('foo=1&bar=2'); -``` -5、new URLSearchParams(string) -``` -params = new URLSearchParams('user=abc&query=xyz'); -console.log(params.get('user')); -// Prints 'abc' -``` -6、new URLSearchParams(obj) -``` -const params = new URLSearchParams({ - user: 'abc', - query: ['first', 'second'] -}); -console.log(params.getAll('query')); -// Prints [ 'first,second' ] -``` -7、new URLSearchParams(iterable) -``` -let params; - -// Using an array -params = new URLSearchParams([ - ['user', 'abc'], - ['query', 'first'], - ['query', 'second'], -]); -console.log(params.toString()); -// Prints 'user = abc & query = first&query = second' -``` -8、has(name: string): boolean -``` -console.log(params.has('bar')); // =>true -``` -9、set(name: string, value string): void -``` -params.set('baz', 3); -``` -10、sort(): void -``` -params .sort(); -``` -11、toString(): string -``` -console.log(params .toString()); // =>bar=2&baz=3&foo=1' -``` -12、keys(): iterableIterator\ -``` -for(var key of params.keys()) { - console.log(key); -} // =>bar baz foo -``` -13、values(): iterableIterator\ -``` -for(var value of params.values()) { - console.log(value); -} // =>2 3 1 -``` -14、append(name: string, value: string): void -``` -params.append('foo', 3); // =>bar=2&baz=3&foo=1&foo=3 -``` -15、delete(name: string): void -``` -params.delete('baz'); // => bar=2&foo=1&foo=3 -``` -16、get(name: string): string -``` -params.get('foo'); // => 1 -``` -17、getAll(name: string): string[] -``` -params.getAll('foo'); // =>[ '1', '3' ] -``` -18、entries(): iterableIterator<[string, string]> -``` -for(var pair of searchParams.entries()) { - console.log(pair[0]+ ', '+ pair[1]); -} // => bar, 2 foo, 1 foo, 3 -``` -19、forEach(): void -``` -url.searchParams.forEach((value, name, searchParams) => { - console.log(name, value, url.searchParams === searchParams); -}); -// => foo 1 true -// => bar 2 true -``` -20、urlSearchParams[Symbol.iterator] () -``` -const params = new URLSearchParams('foo=bar&xyz=baz'); -for (const [name, value] of params) { - console.log(name, value); -} -// Prints: -// foo bar -// xyz bar -``` - - -21、URI​(str: string) -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -``` -22、scheme -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.scheme // => "http"; -``` -23、authority -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.authority // => "gg:gaogao@www.baidu.com:99"; -``` -24、ssp -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.ssp " // => gg:gaogao@www.baidu.com:99/path/path?query"; -``` -25、userinfo -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.userinfo // => "gg:gaogao"; -``` -26、host -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.host // => "www.baidu.com"; -``` -27、port -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.port // => "99"; -``` -28、query -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.query // => "query"; -``` -29、fragment -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.fragment // => "fagment"; -``` -30、path -``` -let gaogao = new Uri.URI('http://gg:gaogao@www.baidu.com:99/path/path?query#fagment'); -gaogao.path // => "/path/path"; -``` -31、equals(ob: Object) -``` -let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment'); -let gaogao1 = gaogao; -let res = gaogao.equals(gaogao1); -console.log(res); // => true; -``` -32、normalize​() -``` -let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment'); -let res = gaogao.normalize(); -console.log(res.path); // => "/path/path1" -console.log(res.toString()); // => "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment" -``` -33、checkIsAbsolute​() -``` -let gaogao = new Uri.URI('f/tp://username:password@www.baidu.com:88/path?query#fagment'); -let res = gaogao.checkIsAbsolute(); -console.log(res); //=> false; -``` -34、toString() -``` -let gaogao = new Uri.URI('http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'); -let res = gaogao.toString(); -console.log(res.toString()); // => 'http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment'; -``` - - -35、ConvertXml() -``` -var convertml = new convertXml.ConvertXml(); -``` -36、convert(xml: string, options: Object) -``` -var result = convertml.convert(xml, {compact: false, spaces: 4}); -``` -37、new XmlSerializer(buffer: ArrayBuffer | DataView, encoding?: string) -``` - -var arrayBuffer = new ArrayBuffer(1024); -var bufView = new DataView(arrayBuffer); -var thatSer = new xml.XmlSerializer(bufView); -``` -38、setDeclaration():void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setDeclaration() // => ; -``` -39、setCommnet(text: string):void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setCommnet("Hello, World!"); // => ; -``` -40、setCData(text: string) :void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setDocType('root SYSTEM "http://www.test.org/test.dtd"'); // => -``` -41、setDocType(text: string):void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setDocType("foo"); // => -``` -42、setNamespace(prefix: string, namespace: string): void -43、startElement(name: string): void -44、setAttributes(name: string, value: string): void -45、endElement(): void -46、setText(text: string): void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); -thatSer.startElement("table"); -thatSer.setAttributes("importance", "high"); -thatSer.setText("Happy"); -endElement(); // => Happy -``` -47、addEmptyElement(name: string): void -``` -var thatSer = new xml.XmlSerializer(bufView); -thatSer.addEmptyElement("b"); // => -``` -48、new (buffer: ArrayBuffer | DataView, encoding?: string) -``` -var strXml = - '' + - '' + - ' Happy' + - ''; -var arrayBuffer = new ArrayBuffer(strXml.length*2); -var bufView = new Uint8Array(arrayBuffer); -var strLen = strXml.length; -for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i);//设置arraybuffer 方式 -} -var that = new xml.XmlPullParser(arrayBuffer); - -``` -49、parse(option: ParseOptions): void -``` -var strXml = - '' + - '' + - ' Happy' + - ''; -var arrayBuffer = new ArrayBuffer(strXml.length*2); -var bufView = new Uint8Array(arrayBuffer); -var strLen = strXml.length; -for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i); -} -var that = new xml.XmlPullParser(arrayBuffer); -var arrTag = {}; -arrTag[0] = '132'; -var i = 1; -function func(key, value){ - arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); - i++; - return true; -} -var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} -that.parse(options); -``` -## 相关仓 -[js_api_module子系统](base/compileruntime/js_api_module/readme.md) - -### 许可证 - -URL在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_api_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony/js_api_module/blob/master/LICENSE) \ No newline at end of file diff --git a/js_api_module/bundle.json b/js_api_module/bundle.json deleted file mode 100644 index f72b26f..0000000 --- a/js_api_module/bundle.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "name": "@ohos/js_api_module", - "version": "", - "description": "js_api_module, used to store the basic class library JSAPI, such as url, uri, etc.| 用于存放基础类库JSAPI,比如url、uri等", - "homePage": "https://gitee.com/openharmony", - "license": "Apache V2", - "repository": "https://gitee.com/openharmony/js_api_module", - "domain": "os", - "language": "", - "publishAs": "code-segment", - "private": false, - "scripts": {}, - "tags": [ - "js" - ], - "keywords": [ - "js", - "api", - "module" - ], - "envs": {}, - "dirs": {}, - "author": { - "name": "", - "email": "", - "url": "" - }, - "contributors": [ - { - "name": "", - "email": "", - "url": "" - } - ], - "segment": { - "destPath": "base/compileruntime/js_api_module" - }, - "component": { - "name": "jsapi_api", - "subsystem": "utils", - "syscap": [], - "features": [], - "adapted_system_type": [], - "rom": "", - "ram": "", - "deps": { - "components": [], - "third_party": [] - }, - "build": { - "sub_component": [ - "//base/compileruntime/js_api_module/uri:uri_packages", - "//base/compileruntime/js_api_module/url:url_packages", - "//base/compileruntime/js_api_module/convertxml:convertxml_packages", - "//base/compileruntime/js_api_module/xml:xml_packages" - ], - "inner_kits": [], - "test": [ - "//base/compileruntime/js_api_module/test_uri/unittest:unittest", - "//base/compileruntime/js_api_module/test_xml/unittest:unittest" - ] - } - } -} diff --git a/js_api_module/convertxml/BUILD.gn b/js_api_module/convertxml/BUILD.gn old mode 100755 new mode 100644 index 9196ea1..ab4f723 --- a/js_api_module/convertxml/BUILD.gn +++ b/js_api_module/convertxml/BUILD.gn @@ -18,12 +18,12 @@ import("//foundation/arkui/ace_engine/ace_config.gni") # compile .ts to .js. action("build_ts_js") { - script = "//base/compileruntime/js_api_module/build_ts_js.py" + script = "//commonlibrary/ets_utils/js_api_module/build_ts_js.py" args = [ "--dst-file", rebase_path(target_out_dir + "/js_convertxml.js"), "--module-path", - rebase_path("/base/compileruntime/js_api_module/convertxml"), + rebase_path("/commonlibrary/ets_utils/js_api_module/convertxml"), "--out-file", rebase_path("./out/js_convertxml.js"), "--relative-path", @@ -81,7 +81,7 @@ ohos_shared_library("convertxml") { "//third_party/node/src", "//third_party/libxml2/include", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_api_module/convertxml", + "//commonlibrary/ets_utils/js_api_module/convertxml", ] sources = [ @@ -92,7 +92,7 @@ ohos_shared_library("convertxml") { deps = [ ":convertxml_abc", ":js_convertxml", - "//base/compileruntime/js_api_module/convertxml/:js_convertxml", + "//commonlibrary/ets_utils/js_api_module/convertxml/:js_convertxml", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_quickjs", "//third_party/icu/icu4c:static_icuuc", @@ -105,8 +105,8 @@ ohos_shared_library("convertxml") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_api" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_api_module/convertxml/js_convertxml.cpp b/js_api_module/convertxml/js_convertxml.cpp old mode 100755 new mode 100644 diff --git a/js_api_module/convertxml/js_convertxml.h b/js_api_module/convertxml/js_convertxml.h old mode 100755 new mode 100644 diff --git a/js_api_module/convertxml/native_module_convertxml.cpp b/js_api_module/convertxml/native_module_convertxml.cpp old mode 100755 new mode 100644 diff --git a/js_api_module/test_uri/unittest/BUILD.gn b/js_api_module/test_uri/unittest/BUILD.gn old mode 100755 new mode 100644 index 5b934a6..3445793 --- a/js_api_module/test_uri/unittest/BUILD.gn +++ b/js_api_module/test_uri/unittest/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("test_uri_unittest") { configs = [ "//arkcompiler/ets_runtime:ark_jsruntime_public_config" ] include_dirs = [ - "//base/compileruntime/js_api_module/uri", + "//commonlibrary/ets_utils/js_api_module/uri", "//arkcompiler/ets_runtime", "//foundation/arkui/napi", "//foundation/arkui/napi/interfaces/kits", @@ -42,7 +42,7 @@ ohos_unittest("test_uri_unittest") { deps = [ "//arkcompiler/ets_runtime:libark_jsruntime", - "//base/compileruntime/js_api_module/uri:uri_packages", + "//commonlibrary/ets_utils/js_api_module/uri:uri_packages", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_ark", "//third_party/bounds_checking_function:libsec_static", diff --git a/js_api_module/test_uri/unittest/test.h b/js_api_module/test_uri/unittest/test.h old mode 100755 new mode 100644 diff --git a/js_api_module/test_uri/unittest/test_napi.cpp b/js_api_module/test_uri/unittest/test_napi.cpp old mode 100755 new mode 100644 diff --git a/js_api_module/test_xml/unittest/BUILD.gn b/js_api_module/test_xml/unittest/BUILD.gn index d5c364d..6ff0ac9 100644 --- a/js_api_module/test_xml/unittest/BUILD.gn +++ b/js_api_module/test_xml/unittest/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("test_xml_unittest") { configs = [ "//arkcompiler/ets_runtime:ark_jsruntime_public_config" ] include_dirs = [ - "//base/compileruntime/js_api_module/xml", + "//commonlibrary/ets_utils/js_api_module/xml", "//arkcompiler/ets_runtime", "//foundation/arkui/napi", "//foundation/arkui/napi/interfaces/kits", @@ -42,7 +42,7 @@ ohos_unittest("test_xml_unittest") { deps = [ "//arkcompiler/ets_runtime:libark_jsruntime", - "//base/compileruntime/js_api_module/xml:xml_packages", + "//commonlibrary/ets_utils/js_api_module/xml:xml_packages", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_ark", "//third_party/bounds_checking_function:libsec_static", diff --git a/js_api_module/uri/BUILD.gn b/js_api_module/uri/BUILD.gn old mode 100755 new mode 100644 index adafc28..2bf3415 --- a/js_api_module/uri/BUILD.gn +++ b/js_api_module/uri/BUILD.gn @@ -17,12 +17,12 @@ import("//foundation/arkui/ace_engine/ace_config.gni") # compile .ts to .js. action("build_ts_js") { - script = "//base/compileruntime/js_api_module/build_ts_js.py" + script = "//commonlibrary/ets_utils/js_api_module/build_ts_js.py" args = [ "--dst-file", rebase_path(target_out_dir + "/js_uri.js"), "--module-path", - rebase_path("/base/compileruntime/js_api_module/uri"), + rebase_path("/commonlibrary/ets_utils/js_api_module/uri"), "--out-file", rebase_path("./out/js_uri.js"), "--relative-path", @@ -79,7 +79,7 @@ ohos_shared_library("uri") { "//third_party/icu/icu4c/source/common", "//third_party/node/src", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_api_module/uri", + "//commonlibrary/ets_utils/js_api_module/uri", ] sources = [ @@ -90,7 +90,7 @@ ohos_shared_library("uri") { deps = [ ":js_uri", ":uri_abc", - "//base/compileruntime/js_api_module/uri/:js_uri", + "//commonlibrary/ets_utils/js_api_module/uri/:js_uri", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_quickjs", "//third_party/icu/icu4c:static_icuuc", @@ -102,8 +102,8 @@ ohos_shared_library("uri") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_api" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_api_module/uri/js_uri.cpp b/js_api_module/uri/js_uri.cpp old mode 100755 new mode 100644 diff --git a/js_api_module/uri/js_uri.h b/js_api_module/uri/js_uri.h old mode 100755 new mode 100644 diff --git a/js_api_module/uri/native_module_uri.cpp b/js_api_module/uri/native_module_uri.cpp old mode 100755 new mode 100644 diff --git a/js_api_module/url/BUILD.gn b/js_api_module/url/BUILD.gn old mode 100755 new mode 100644 index 56cdcaa..2368b06 --- a/js_api_module/url/BUILD.gn +++ b/js_api_module/url/BUILD.gn @@ -17,12 +17,12 @@ import("//foundation/arkui/ace_engine/ace_config.gni") # compile .ts to .js. action("build_ts_js") { - script = "//base/compileruntime/js_api_module/build_ts_js.py" + script = "//commonlibrary/ets_utils/js_api_module/build_ts_js.py" args = [ "--dst-file", rebase_path(target_out_dir + "/js_url.js"), "--module-path", - rebase_path("/base/compileruntime/js_api_module/url"), + rebase_path("/commonlibrary/ets_utils/js_api_module/url"), "--out-file", rebase_path("./out/js_url.js"), "--relative-path", @@ -79,7 +79,7 @@ ohos_shared_library("url") { "//third_party/icu/icu4c/source/common", "//third_party/node/src", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_api_module/url", + "//commonlibrary/ets_utils/js_api_module/url", ] sources = [ @@ -90,7 +90,7 @@ ohos_shared_library("url") { deps = [ ":js_url", ":url_abc", - "//base/compileruntime/js_api_module/url/:js_url", + "//commonlibrary/ets_utils/js_api_module/url/:js_url", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_quickjs", "//third_party/icu/icu4c:static_icuuc", @@ -102,8 +102,8 @@ ohos_shared_library("url") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_api" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_api_module/url/js_url.cpp b/js_api_module/url/js_url.cpp old mode 100755 new mode 100644 diff --git a/js_api_module/url/js_url.h b/js_api_module/url/js_url.h old mode 100755 new mode 100644 diff --git a/js_api_module/url/native_module_url.cpp b/js_api_module/url/native_module_url.cpp old mode 100755 new mode 100644 diff --git a/js_api_module/xml/BUILD.gn b/js_api_module/xml/BUILD.gn index 367182c..a1d4605 100644 --- a/js_api_module/xml/BUILD.gn +++ b/js_api_module/xml/BUILD.gn @@ -18,13 +18,13 @@ import("//foundation/arkui/ace_engine/ace_config.gni") # compile .ts to .js. action("build_ts_js") { - script = "//base/compileruntime/js_api_module/build_ts_js.py" + script = "//commonlibrary/ets_utils/js_api_module/build_ts_js.py" args = [ "--dst-file", rebase_path(target_out_dir + "/js_xml.js"), "--module-path", - rebase_path("/base/compileruntime/js_api_module/xml"), + rebase_path("/commonlibrary/ets_utils/js_api_module/xml"), "--out-file", rebase_path("./out/js_xml.js"), "--relative-path", @@ -82,7 +82,7 @@ ohos_shared_library("xml") { "//third_party/icu/icu4c/source/common", "//third_party/node/src", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_api_module/xml", + "//commonlibrary/ets_utils/js_api_module/xml", ] sources = [ @@ -93,7 +93,7 @@ ohos_shared_library("xml") { deps = [ ":js_xml", ":xml_abc", - "//base/compileruntime/js_api_module/xml/:js_xml", + "//commonlibrary/ets_utils/js_api_module/xml/:js_xml", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_quickjs", "//third_party/icu/icu4c:static_icuuc", @@ -105,8 +105,8 @@ ohos_shared_library("xml") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_api" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_sys_module/README.md b/js_sys_module/README.md deleted file mode 100755 index e2b84dc..0000000 --- a/js_sys_module/README.md +++ /dev/null @@ -1,365 +0,0 @@ -# js_sys_module Subsystems/Components - -- [Introduction](#Introduction) -- [Directory](#Directory) -- [Description](#Description) - - [Interface description](#Interface description) - - [Interface instructions](#Interface instructions) - -- [Related warehouse](#Related warehouse]) - -## Introduction -Process is mainly used to obtain the relevant ID of the process, obtain and modify the working directory of the process, exit and close the process. The childprocess object can be used to create a new process. The main process can obtain the standard input and output of the child process, send signals and close the child process. -## Directory - -``` -base/compileruntime/js_sys_module/ -├── Class:PROCESS # class of PROCESS -├── Uid # attribute of Uid -├── Gid # attribute of Gid -├── EUid # attribute of EUid -├── EGid # attribute of EGid -├── Groups # attribute of Groups -├── Pid # attribute of Pid -├── Ppid # attribute of Ppid -├── chdir() # method of chdir -├── uptime() # method of uptime -├── kill() # method of kill -├── abort() # method of abort -├── on() # method of on -├── tid # method of tid -├── getStartRealtime() # method of getStartRealtime -├── getAvailableCores() # method of getAvailableCores -├── getPastCputime() # method of getPastCputime -├── isIsolatedProcess() # method of isIsolatedProcess -├── is64Bit() # method of is64Bit -├── isAppUid() # method of isAppUid -├── getUidForName() # method of getUidForName -├── getThreadPriority() # method of getThreadPriority -├── getSystemConfig() # method of getSystemConfig -├── getEnvironmentVar() # method of getEnvironmentVar -├── exit() # method of exit -├── cwd() # method of cwd -├── off() # method of off -├── runCmd() # method of runCmd -└─── Class:CHILDPROCESS # class of CHILDPROCESS - ├── close() # method of close - ├── kill() # method of kill - ├── getOutput() # method of getOutput - ├── getErrorOutput() # method of getErrorOutput - ├── wait() # method of wait - ├── killed # attribute of killed - ├── pid # attribute of pid - ├── ppid # attribute of ppid - └── exitCode # attribute of exitCode -``` - -## Description - -### Interface description -| Interface name | description | -| -------- | -------- | -| const uid :number | returns the digital user ID of the process. | -| const gid :number | returns the numeric group ID of the process. | -| const euid :number | returns the numeric valid user identity of the process. | -| const egid :number | returns the numeric valid group ID of the node.js process. | -| const groups :number[] | returns an array with supplementary group ID. | -| const pid :number | returns the PID of the process. | -| const ppid :number | returns the PID of the parent process of the current process. | -| chdir(dir:string) :void | change the current working directory of the node.js process. | -| uptime() :number | returns the number of seconds the current system has been running. | -| Kill(pid:number, signal:number) :boolean | send the signal to the identified process PID, and true means the sending is successful. | -| abort() :void | cause the node.js process to exit immediately and generate a core file. | -| on(type:string ,listener:EventListener) :void | used to store events triggered by users. | -| exit(code:number):void | cause the node.js process to exit immediately. | -| cwd():string | returns the current working directory of the node.js process. | -| off(type: string): boolean | clear the events stored by the user. True means the clearing is successful. | -| runCmd(command: string, options?: { timeout : number, killSignal : number \| string, maxBuffer : number }): ChildProcess |through runcmd, you can fork a new process to run a shell and return the childprocess object. The first parameter command refers to the shell to be run, and the second parameter options refers to some running parameters of the child process. These parameters mainly refer to timeout, killsignal and maxbuffer. If timeout is set, the child process will send a signal killsignal after timeout is exceeded. Maxbuffer is used to limit the maximum stdout and stderr sizes that can be received. | -| wait(): Promise\ | is used to wait for the child process to run and return the promise object, whose value is the exit code of the child process. | -| getOutput(): Promise\ | used to get the standard output of the child process. | -| getErrorOutput(): Promise\ | used to get the standard error output of the child process. | -| const tid:number | Returns the TID of the process. | -| getStartRealtime() :number | Gets the real time elapsed (in milliseconds) from system startup to process startup. | -| getAvailableCores() :number[] | Gets the CPU kernel available to the current process on the multi-core device. | -| getPastCputime() :number | Gets the CPU time (in milliseconds) from the start of the process to the current time. | -| isIsolatedProcess(): boolean | Check if the process is quarantined. | -| is64Bit(): boolean | Check whether the process is running in a 64 bit environment. | -| isAppUid(v:number): boolean | Checks whether the specified uid belongs to a specific application. | -| getUidForName(v:string): number | Obtain the user group ID to which the user belongs according to the user name | -| getThreadPriority(v:number): number | Gets the thread priority based on the specified TID. | -| getSystemConfig(name:number): number | Gets the configuration of the system according to the specified system configuration name. | -| getEnvironmentVar(name:string): string | Obtain the corresponding value according to the name of the environment variable. | -| close(): void | used to close the running child process. | -| kill(signal: number \| string): void | used to send signals to child processes. | -| readonly killed: boolean | indicates whether the signal is sent successfully, and true indicates that the signal is sent successfully. | -| readonly exitCode: number | indicates the exit code of the child process. | -| readonly pid: number | represents the child process ID. | -| readonly ppid: number | represents the main process ID. | - -### Interface instructions - -Example of using interface: -1.uid() -``` -uid(){ - var res = Process.uid; -} -``` -2.gid() -``` -gid(){ - var result = Process.gid; -} -``` -3.euid() -``` -euid(){ - var and = Process.euid; -} -``` -4.egid() -``` -egid(){ - var resb = Process.egid; -} -``` -5.groups() -``` -groups(){ - var answer = Process.groups; -} -``` -6.pid() -``` -pid(){ - var result = Process.pid; -} -``` -7.ppid() -``` -ppid(){ - var result = Process.ppid; -} -``` -8.chdir() -``` -chdir(){ - Process.chdir("123456"); -} -``` -9.uptime() -``` -uptime(){ - var num = Process.uptime(); -} -``` -10.kill() -``` -kill(){ - var ansu = Process.kill(5,23); -} -``` -11.abort() -``` -abort(){ - Process.abort(); -} -``` -12.on() -``` -on(){ - function add(num){ - var value = num + 5; - return value; - } - Process.on("add",add); -} -``` -13.exit() -``` -exit(){ - Process.exit(15); -} -``` -14.Cwd() -``` -Cwd(){ - var result = Process.cwd(); -} -``` -15.off() - -``` -off(){ - var result = Process.off("add"); -} -``` -16.runCmd() -``` -runCmd(){ - var child = process.runCmd('echo abc') - // killSignal can be a number or a string - var child = process.runCmd('echo abc;', {killSignal : 'SIGKILL'}); - var child = process.runCmd('sleep 5; echo abc;', {timeout : 1, killSignal : 9, maxBuffer : 2}) -} -``` -17.wait() -``` -wait() -{ - var child = process.runCmd('ls') - var status = child.wait(); - status.then(val => { - console.log(val); - }) -} -``` -18.getOutput() -``` -getOutput(){ - var child = process.runCmd('echo bcd;'); - var res = child.getOutput(); - child.wait(); - res.then(val => { - console.log(val); - }) -} -``` -19.getErrorOutput() -``` -getErrorOutput(){ - var child = process.runCmd('makdir 1.txt'); // execute an error command - var res = child.getErrorOutput(); - child.wait(); - res.then(val => { - console.log(val); - }) -} -``` -20.close() -``` -close(){ - var child = process.runCmd('ls; sleep 5s;') - var result = child.close() -} -``` -21.kill() -``` -kill(){ - var child = process.runCmd('ls; sleep 5s;') - var result = child.kill('SIGHUP'); - child.wait(); - var temp = child.killed; -} -``` -22.killed -``` -{ - var child = process.runCmd('ls; sleep 5;') - child.kill(3); - var killed_ = child.killed; - child.wait(); -} -``` -23.exitCode -``` -{ - var child = process.runCmd('ls; sleep 5;') - child.kill(9); - child.wait(); - var exitCode_ = child.exitCode; -} -``` -24.pid -``` -pid -{ - var child = process.runCmd('ls; sleep 5;') - var pid_ = child.pid; - child.wait(); -} -``` -25.ppid -``` -ppid -{ - var child = process.runCmd('ls; sleep 5;') - var ppid_ = child.ppid; - child.wait(); -} -``` -26.tid -``` -tid(){ - var ansu = Process.tid; -} -``` -27.isIsolatedProcess() -``` -isIsolatedProcess(){ - var ansu = Process.isIsolatedProcess()(); -} -``` -28.isAppUid() -``` -isAppUid(){ - var ansu = Process.isAppUid(10000); -} -``` -29.is64Bit() -``` -is64Bit(){ - var ansu = Process.is64Bit(); -} -``` -30.getUidForName() -``` -getUidForName(){ - var buf = "root"; - var ansu = Process.getUidForName(buf); -} -``` -31.getEnvironmentVar() -``` -getEnvironmentVar(){ - var ansu = Process.getEnvironmentVar('USER'); -} -``` -32.getAvailableCores() -``` -getAvailableCores(){ - var ansu = Process.getAvailableCores(); -} -``` -33.getThreadPriority() -``` -getThreadPriority(){ - var result = Process.getTid(); - var ansu = getThreadPriority(result); -} -``` -34.getStartRealtime() -``` -getStartRealtime(){ - var ansu = Process.getStartRealtime(); -} -``` -35.getPastCputime() -``` -getPastCputime(){ - var ansu = Process.getPastCputime(); -} -``` -36.getSystemConfig() -``` -getSystemConfig(){ - var _SC_ARG_MAX = 0; - var ansu = Process.getSystemConfig(_SC_ARG_MAX) -} -``` -## Related warehouse -[js_sys_module](base/compileruntime/js_sys_module/readme.md) - -### License - -SYS is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_sys_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony/js_sys_module/blob/master/LICENSE) for the full license text. \ No newline at end of file diff --git a/js_sys_module/README_zh.md b/js_sys_module/README_zh.md deleted file mode 100755 index 0f178f3..0000000 --- a/js_sys_module/README_zh.md +++ /dev/null @@ -1,366 +0,0 @@ -# js_sys_module子系统/组件 - -- [简介](#简介) -- [目录](#目录) -- [说明](#说明) - - [接口说明](#接口说明) - - [使用说明](#使用说明) - -- [相关仓](#相关仓]) - -## 简介 -进程主要用于获取进程的相关ID,获取和修改进程的工作目录,退出和关闭进程。 childprocess 对象可用于创建新进程。 主进程可以获取子进程的标准输入输出,发送信号,关闭子进程。 -## 目录 - -``` -base/compileruntime/js_sys_module/ -├── Class:PROCESS # PROCESS类 -├── Uid # Uid属性 -├── Gid # Gid属性 -├── EUid # EUid属性 -├── EGid # EGid属性 -├── Groups # Groups属性 -├── Pid # Pid属性 -├── Ppid # Ppid属性 -├── chdir() # chdir方法 -├── uptime() # uptime方法 -├── kill() # kill方法 -├── abort() # abort方法 -├── on() # on方法 -├── tid # tid方法 -├── getStartRealtime() # getStartRealtime方法 -├── getAvailableCores() # getAvailableCores方法 -├── getPastCputime() # getPastCputime方法 -├── isIsolatedProcess() # isIsolatedProcess方法 -├── is64Bit() # is64Bit方法 -├── isAppUid() # isAppUid方法 -├── getUidForName() # getUidForName方法 -├── getThreadPriority() # getThreadPriority方法 -├── getSystemConfig() # getSystemConfig方法 -├── getEnvironmentVar() # getEnvironmentVar方法 -├── exit() # exit方法 -├── cwd() # cwd方法 -├── off() # off方法 -├── runCmd() # runCmd方法 -└─── Class:CHILDPROCESS # class of CHILDPROCESS类 - ├── close() # close方法 - ├── kill() # kill方法 - ├── getOutput() # getOutput方法 - ├── getErrorOutput() # getErrorOutput方法 - ├── wait() # wait方法 - ├── killed # killed属性 - ├── pid # pid属性 - ├── ppid # ppid属性 - └── exitCode # exitCode属性 -``` - -## 说明 - -### 接口说明 -| 接口名 | 说明 | -| -------- | -------- | -| const uid :number | 返回进程的数字用户 ID。 | -| const gid :number | 返回进程的数字组 ID。 | -| const euid :number | 返回进程的数字有效用户身份。 | -| const egid :number | 返回 node.js 进程的数字有效组 ID。 | -| const groups :number[] | 返回具有补充组 ID 的数组。 | -| const pid :number | 返回进程的PID。 | -| const ppid :number | 返回当前进程的父进程的PID。 | -| chdir(dir:string) :void | 更改 node.js 进程的当前工作目录。 | -| uptime() :number | 返回当前系统已经运行的秒数。 | -| Kill(pid:number, signal:number) :boolean | 将信号发送到识别的进程PID,true表示发送成功。 | -| abort() :void | 导致 node.js 进程立即退出并生成核心文件。 | -| on(type:string ,listener:EventListener) :void | 用于存储用户触发的事件。 | -| exit(code:number):void | 导致 node.js 进程立即退出。 | -| cwd():string | 返回 node.js 进程的当前工作目录。 | -| off(type: string): boolean | 清除用户存储的事件。 True 表示清算成功。 | -| runCmd(command: string, options?: { timeout : number, killSignal : number \| string, maxBuffer : number }): ChildProcess |通过runcmd,你可以fork一个新进程来运行一个shell并返回childprocess对象。 第一个参数command指的是要运行的shell,第二个参数options指的是子进程的一些运行参数。 这些参数主要是指 timeout、killsignal 和 maxbuffer。 如果设置了timeout,则子进程会在超时后发送killsignal信号。 Maxbuffer 用于限制可以接收的最大 stdout 和 stderr 大小。 | -| wait(): Promise\ | 用于等待子进程运行并返回promise对象,其值为子进程的退出码。 | -| getOutput(): Promise\ | 用于获取子进程的标准输出。 | -| getErrorOutput(): Promise\ | 用于获取子进程的标准错误输出。 | -| const tid:number | 返回进程的 TID。 | -| getStartRealtime() :number | 获取从系统启动到进程启动所经过的实时时间(以毫秒为单位)。 | -| getAvailableCores() :number[] | 获取多核设备上当前进程可用的 CPU 内核。 | -| getPastCputime() :number | 获取从进程开始到当前时间的 CPU 时间(以毫秒为单位)。 | -| isIsolatedProcess(): boolean | 检查进程是否被隔离。 | -| is64Bit(): boolean | 检查进程是否在 64 位环境中运行。 | -| isAppUid(v:number): boolean | 检查指定的 uid 是否属于特定应用程序。 | -| getUidForName(v:string): number | 根据用户名获取用户所属的用户组ID | -| getThreadPriority(v:number): number | 根据指定的 TID 获取线程优先级。 | -| getSystemConfig(name:number): number | 根据指定的系统配置名称获取系统的配置。 | -| getEnvironmentVar(name:string): string | 根据环境变量的名称获取对应的值。 | -| close(): void | 用于关闭正在运行的子进程。 | -| kill(signal: number \| string): void | 用于向子进程发送信号。 | -| readonly killed: boolean | 表示信号是否发送成功,true表示信号发送成功。 | -| readonly exitCode: number | 表示子进程的退出代码。 | -| readonly pid: number | 表示子进程ID。 | -| readonly ppid: number | 代表主进程ID。 | - -### 使用说明 - -各接口使用方法如下: -1.uid() -``` -uid(){ - var res = Process.uid; -} -``` -2.gid() -``` -gid(){ - var result = Process.gid; -} -``` -3.euid() -``` -euid(){ - var and = Process.euid; -} -``` -4.egid() -``` -egid(){ - var resb = Process.egid; -} -``` -5.groups() -``` -groups(){ - var answer = Process.groups; -} -``` -6.pid() -``` -pid(){ - var result = Process.pid; -} -``` -7.ppid() -``` -ppid(){ - var result = Process.ppid; -} -``` -8.chdir() -``` -chdir(){ - Process.chdir("123456"); -} -``` -9.uptime() -``` -uptime(){ - var num = Process.uptime(); -} -``` -10.kill() -``` -kill(){ - var ansu = Process.kill(5,23); -} -``` -11.abort() -``` -abort(){ - Process.abort(); -} -``` -12.on() -``` -on(){ - function add(num){ - var value = num + 5; - return value; - } - Process.on("add",add); -} -``` -13.exit() -``` -exit(){ - Process.exit(15); -} -``` -14.Cwd() -``` -Cwd(){ - var result = Process.cwd(); -} -``` -15.off() - -``` -off(){ - var result = Process.off("add"); -} -``` -16.runCmd() -``` -runCmd(){ - var child = process.runCmd('echo abc') - // killSignal can be a number or a string - var child = process.runCmd('echo abc;', {killSignal : 'SIGKILL'}); - var child = process.runCmd('sleep 5; echo abc;', {timeout : 1, killSignal : 9, maxBuffer : 2}) -} -``` -17.wait() -``` -wait() -{ - var child = process.runCmd('ls') - var status = child.wait(); - status.then(val => { - console.log(val); - }) -} -``` -18.getOutput() -``` -getOutput(){ - var child = process.runCmd('echo bcd;'); - var res = child.getOutput(); - child.wait(); - res.then(val => { - console.log(val); - }) -} -``` -19.getErrorOutput() -``` -getErrorOutput(){ - var child = process.runCmd('makdir 1.txt'); // execute an error command - var res = child.getErrorOutput(); - child.wait(); - res.then(val => { - console.log(val); - }) -} -``` -20.close() -``` -close(){ - var child = process.runCmd('ls; sleep 5s;') - var result = child.close() -} -``` -21.kill() -``` -kill(){ - var child = process.runCmd('ls; sleep 5s;') - var result = child.kill('SIGHUP'); - child.wait(); - var temp = child.killed; -} -``` -22.killed -``` -{ - var child = process.runCmd('ls; sleep 5;') - child.kill(3); - var killed_ = child.killed; - child.wait(); -} -``` -23.exitCode -``` -{ - var child = process.runCmd('ls; sleep 5;') - child.kill(9); - child.wait(); - var exitCode_ = child.exitCode; -} -``` -24.pid -``` -pid -{ - var child = process.runCmd('ls; sleep 5;') - var pid_ = child.pid; - child.wait(); -} -``` -25.ppid -``` -ppid -{ - var child = process.runCmd('ls; sleep 5;') - var ppid_ = child.ppid; - child.wait(); -} -``` -26.tid -``` -tid(){ - var ansu = Process.tid; -} -``` -27.isIsolatedProcess() -``` -isIsolatedProcess(){ - var ansu = Process.isIsolatedProcess()(); -} -``` -28.isAppUid() -``` -isAppUid(){ - var ansu = Process.isAppUid(10000); -} -``` -29.is64Bit() -``` -is64Bit(){ - var ansu = Process.is64Bit(); -} -``` -30.getUidForName() -``` -getUidForName(){ - var buf = "root"; - var ansu = Process.getUidForName(buf); -} -``` -31.getEnvironmentVar() -``` -getEnvironmentVar(){ - var ansu = Process.getEnvironmentVar('USER'); -} -``` -32.getAvailableCores() -``` -getAvailableCores(){ - var ansu = Process.getAvailableCores(); -} -``` -33.getThreadPriority() -``` -getThreadPriority(){ - var result = Process.getTid(); - var ansu = getThreadPriority(result); -} -``` -34.getStartRealtime() -``` -getStartRealtime(){ - var ansu = Process.getStartRealtime(); -} -``` -35.getPastCputime() -``` -getPastCputime(){ - var ansu = Process.getPastCputime(); -} -``` -36.getSystemConfig() -``` -getSystemConfig(){ - var _SC_ARG_MAX = 0; - var ansu = Process.getSystemConfig(_SC_ARG_MAX) -} -``` - -## 相关仓 -[js_sys_module](base/compileruntime/js_sys_module/readme.md) - -### 许可证 - -SYS在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_sys_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony/js_sys_module/blob/master/LICENSE) \ No newline at end of file diff --git a/js_sys_module/bundle.json b/js_sys_module/bundle.json deleted file mode 100644 index bb43b3e..0000000 --- a/js_sys_module/bundle.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "@ohos/js_sys_module", - "version": "", - "description": "Provide system basic ability query API, including process information, CPU load information, etc. | js_sys_module, 提供系统基础能力查询API,包括进程信息,CPU负载信息等", - "homePage": "https://gitee.com/openharmony", - "license": "Apache V2", - "repository": "https://gitee.com/openharmony/js_sys_module", - "domain": "os", - "language": "", - "publishAs": "code-segment", - "private": false, - "scripts": {}, - "tags": [ - "js" - ], - "keywords": [ - "js", - "sys", - "module" - ], - "envs": {}, - "dirs": {}, - "author": { - "name": "", - "email": "", - "url": "" - }, - "contributors": [ - { - "name": "", - "email": "", - "url": "" - } - ], - "segment": { - "destPath": "base/compileruntime/js_sys_module" - }, - "component": { - "name": "jsapi_sys", - "subsystem": "utils", - "syscap": [], - "features": [], - "adapted_system_type": [], - "rom": "", - "ram": "", - "deps": { - "components": [], - "third_party": [] - }, - "build": { - "sub_component": [ - "//base/compileruntime/js_sys_module/process:process_packages", - "//base/compileruntime/js_sys_module/dfx:dfx_packages" - ], - "inner_kits": [], - "test": [] - } - } -} diff --git a/js_sys_module/dfx/BUILD.gn b/js_sys_module/dfx/BUILD.gn index 5e58bfe..1781056 100644 --- a/js_sys_module/dfx/BUILD.gn +++ b/js_sys_module/dfx/BUILD.gn @@ -20,7 +20,7 @@ ohos_shared_library("dfx") { "//third_party/icu/icu4c/source/common", "//third_party/node/src", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_api_module/dfx", + "//commonlibrary/ets_utils/js_api_module/dfx", ] sources = [ "native_module_dfx.cpp" ] @@ -37,8 +37,8 @@ ohos_shared_library("dfx") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_sys" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_sys_module/process/BUILD.gn b/js_sys_module/process/BUILD.gn index 3b24d4b..e8f3ca0 100644 --- a/js_sys_module/process/BUILD.gn +++ b/js_sys_module/process/BUILD.gn @@ -18,7 +18,7 @@ ohos_shared_library("process") { "//third_party/icu/icu4c/source/common", "//third_party/node/src", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_sys_module/process", + "//commonlibrary/ets_utils/js_sys_module/process", ] sources = [ @@ -39,8 +39,8 @@ ohos_shared_library("process") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_sys" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_sys_module/test/unittest/BUILD.gn b/js_sys_module/test/unittest/BUILD.gn old mode 100755 new mode 100644 index 5b693a0..cee6278 --- a/js_sys_module/test/unittest/BUILD.gn +++ b/js_sys_module/test/unittest/BUILD.gn @@ -22,7 +22,7 @@ ohos_unittest("test_process_unittest") { configs = [ "//arkcompiler/ets_runtime:ark_jsruntime_public_config" ] include_dirs = [ - "//base/compileruntime/js_sys_module/process", + "//commonlibrary/ets_utils/js_sys_module/process", "//arkcompiler/ets_runtime", "//foundation/arkui/napi", "//foundation/arkui/napi/interfaces/kits", @@ -42,7 +42,7 @@ ohos_unittest("test_process_unittest") { deps = [ "//arkcompiler/ets_runtime:libark_jsruntime", - "//base/compileruntime/js_sys_module/process:process_packages", + "//commonlibrary/ets_utils/js_sys_module/process:process_packages", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_ark", "//third_party/bounds_checking_function:libsec_static", diff --git a/js_sys_module/test/unittest/test.h b/js_sys_module/test/unittest/test.h old mode 100755 new mode 100644 diff --git a/js_sys_module/test/unittest/test_process.cpp b/js_sys_module/test/unittest/test_process.cpp old mode 100755 new mode 100644 diff --git a/js_util_module/LICENSE b/js_util_module/LICENSE deleted file mode 100755 index f433b1a..0000000 --- a/js_util_module/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/js_util_module/README.md b/js_util_module/README.md deleted file mode 100755 index 62e74c5..0000000 --- a/js_util_module/README.md +++ /dev/null @@ -1,1031 +0,0 @@ -# js_util_module Subsystems / components - -- [Introduction](#Introduction) -- [Directory](#Directory) -- [Description](#Description) - - [Interface description](#Interface description) - - [Instruction for use](#Instruction for use) - -- [Related warehouse](#Related warehouse) - -## Introduction -The 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. -Encodes 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. -## 目录 - -``` -base/compileruntime/js_util_module/ -├── Class:TextEncoder # TextEncoder class -│ ├── new TextEncoder() # create textencoder object -│ ├── encode() # encode method -│ ├── encoding # encoding property -│ └── encodeInto() # encodeInto method -├── Class:TextDecoder # TextDecoder class -│ ├── new TextDecoder() # create TextDecoder object -│ ├── decode() # decode method -│ ├── encoding # encoding property -│ ├── fatal # fatal property -│ └── ignoreBOM # ignoreBOM property -├── printf() # printf method -├── getErrorString() # getErrorString method -├── callbackWrapper() # callbackWrapper method -├── promiseWrapper() # promiseWrapper method -├── Class:Base64 # Base64 class -│ ├── new Base64() # create Base64 object -│ ├── encodeSync() # encodeSync method -│ ├── encodeToStringSync() # encodeToStringSync method -│ ├── decodeSync() # decodeSync method -│ ├── encode() # encode method -│ ├── encodeToString() # encodeToString method -│ └── decode() # decode method -├── Class:RationalNumber # RationalNumber class -│ ├── new RationalNumber() # create RationalNumber object -│ ├── createRationalFromString() # creatRationalFromString method -│ ├── compareTo() # compareTo method -│ ├── equals() # equals method -│ ├── valueOf() # valueOf method -│ ├── getCommonDivisor() # getCommonDivisor method -│ ├── getDenominator() # getDenominator method -│ ├── getNumerator() # getNumerator method -│ ├── isFinite() # isFinite method -│ ├── isNaN() # isNaN method -│ ├── isZero() # isZero method -│ └── toString() # toString method -├── Class:LruBuffer # LruBuffer class -│ ├── new LruBuffer() # create RationalNumber object -│ ├── updateCapacity() # updateCapacity method -│ ├── toString() # toString method -│ ├── values() # values method -│ ├── length # attribute of length -│ ├── getCapacity() # getCapacity method -│ ├── clear() # clear method -│ ├── getCreateCount # getCreateCount method -│ ├── getMissCount() # getMissCount method -│ ├── getRemovalCount() # getRemovalCount method -│ ├── getMatchCount() # getMatchCount method -│ ├── getPutCount() # getPutCount method -│ ├── isEmpty() # isEmpty method -│ ├── get() # get method -│ ├── put() # put method -│ ├── keys() # keys method -│ ├── remove() # remove method -│ ├── afterRemoval() # afterRemoval method -│ ├── contains() # contains method -│ ├── createDefault() # createDefault method -│ ├── entries() # entries method -│ └── [Symbol.iterator]() # Symboliterator method -├── Class:Scope # Scope class -| ├── constructor() # create Scope object -| ├── toString() # toString method -| ├── intersect() # intersect method -| ├── intersect() # intersect method -| ├── getUpper() # getUpper method -| ├── getLower() # getLower method -| ├── expand() # expand method -| ├── expand() # expand method -| ├── expand() # expand method -| ├── contains() # contains method -| ├── contains() # contains method -| └── clamp() # clamp method -└── Class:Types # Types class - ├── isAnyArrayBuffer() # isAnyArrayBuffer method - ├── isArrayBufferView() # isArrayBufferView method - ├── isArgumentsObject() # isArgumentsObject method - ├── isArrayBuffer() # isArrayBuffer method - ├── isAsyncFunction() # isAsyncFunction method - ├── isBigInt64Array() # isBigInt64Array method - ├── isBigUint64Array() # isBigUint64Array method - ├── isBooleanObject() # isBooleanObject method - ├── isBoxedPrimitive() # isBoxedPrimitive method - ├── isDataView() # isDataView method - ├── isDate() # isDate method - ├── isExternal() # isExternal method - ├── isFloat32Array() # isFloat32Arraymethod - ├── isFloat64Array() # isFloat64Array method - ├── isGeneratorFunction() # isGeneratorFunction method - ├── isGeneratorObject() # isGeneratorObject method - ├── isInt8Array() # isInt8Array method - ├── isInt16Array() # isInt16Array method - ├── isInt32Array() # isInt32Array method - ├── isMap() # isMap method - ├── isMapIterator() # isMapIterator method - ├── isModuleNamespaceObject() # isModuleNamespaceObject method - ├── isNativeError() # isNativeError method - ├── isNumberObject() # isNumberObject method - ├── isPromise() # isPromise method - ├── isProxy() # isProxy method - ├── isRegExp() # isRegExp method - ├── isSet() # isSet method - ├── isSetIterator() # isSetIterator method - ├── isSharedArrayBuffer() # isSharedArrayBuffer method - ├── isStringObject() # isStringObject method - ├── isSymbolObject() # isSymbolObject method - ├── isTypedArray() # isTypedArray method - ├── isUint8Array() # isUint8Array method - ├── isUint8ClampedArray() # isUint8ClampedArray method - ├── isUint16Array() # isUint16Array method - ├── isUint32Array() # isUint32Array method - ├── isWeakMap() # isWeakMap method - └── isWeakSet() # isWeakSet method -``` - -## Description - -### Interface description -| Interface name | Description | -| -------- | -------- | -| constructor(encoding? : string) | Constructor, the parameter encoding indicates the format of encoding. Default utf-8, Support gb18030, gbk, gb2312. | -| readonly encoding : string | In the TextEncoder module, get the encoding format. | -| encode(input : string) : Uint8Array | Input string string, encoding according to encoding and output uint8 byte stream. | -| 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. | -| 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. | -| readonly encoding : string | In the TextDecoder module, get the set decoding format. | -| readonly fatal : boolean | Get the setting that throws the exception. | -| readonly ignoreBOM : boolean | Get whether to ignore the setting of the bom flag. | -| 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. | -| encodeSync(src: Uint8Array): Uint8Array; | Encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | -| encodeToStringSync(src: Uint8Array): string; | Encodes the specified byte array as a String using the Base64 encoding scheme. | -| 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. | -| encode(src: Uint8Array): Promise\; | Asynchronously encodes all bytes in the specified u8 array into the newly allocated u8 array using the Base64 encoding scheme. | -| encodeToString(src: Uint8Array): Promise\; | Asynchronously encodes the specified byte array into a String using the Base64 encoding scheme. | -| decode(src: Uint8Array \| string): Promise\; | Use the Base64 encoding scheme to asynchronously decode a Base64-encoded string or input u8 array into a newly allocated u8 array. | -| static createRationalFromString(rationalString: string): RationalNumber | Create a RationalNumber object based on the given string. | -| compareTo(another: RationalNumber): number | Compare the current RationalNumber object with the given object. | -| equals(obj: object): number | Check if the given object is the same as the current RationalNumber object.| -| valueOf(): number | Take the current RationalNumber object to an integer value or a floating point value. | -| static getCommonDivisor(number1: number, number2: number,): number | Obtain the greatest common divisor of two specified numbers. | -| getDenominator(): number | Get the denominator of the current RationalNumber object. | -| getNumerator(): number | Get the numerator of the current RationalNumber object. | -| isFinite(): boolean | Check that the current RationalNumber object is limited. | -| isNaN(): boolean | Check whether the current RationalNumber object represents a non-number (NaN) value. | -| isZero(): boolean | Check whether the current RationalNumber object represents a zero value. | -| toString(): string | Get the string representation of the current RationalNumber object. | -| constructor(capacity?: number) | The Create Default constructor is used to create a new LruBuffer instance with a default capacity of 64. | -| 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. | -| toString(): string | Returns the string representation of the object and outputs the string representation of the object. | -| 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. | -| length: number | represents the total number of values in the current buffer. The output returns the total number of values in the current buffer. | -| getCapacity(): number | Gets the capacity of the current buffer. The output returns the capacity of the current buffer. | -| 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. | -| getCreateCount(): number | Get the number of times the returned value of createdefault(), and output the number of times the returned value of createdefault(). | -| 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. | -| getRemovalCount(): number | Gets the number of evictions from the buffer, and outputs the number of evictions from the buffer. | -| getMatchCount​(): number | Obtain the number of successful matching of query values, and output the number of successful matching of query values. | -| 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. | -| isEmpty(): boolean | Checks whether the current buffer is empty and returns true if the current buffer does not contain any values. | -| 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. | -| 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. | -| 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. | -| remove​(key: K):V \| undefined | Deletes the specified key and its associated value from the current buffer. | -| afterRemoval(isEvict: boolean, key: K, value: V, newValue: V): void | Perform subsequent operations after deleting the value. | -| contains(key: K): boolean | Checks whether the current buffer contains the specified key, and returns true if the buffer contains the specified key. | -| 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. | -| 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. | -| \[Symbol.iterator\](): [K,V]| Returns a two-dimensional array in the form of key value pairs. | -| 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. | -| toString():string | The stringification method returns a string representation that contains the current range. | -| intersect(range: Scope): Scope | Gets the intersection of the given range and the current range. | -| intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope | Gets the intersection of the current range with a given lower and upper bound range. | -| getUpper(): ScopeType | Gets the upper bound of the current scope. | -| getLower(): ScopeType | Gets the lower bound of the current scope. | -| expand(lowerObj: ScopeType, upperObj: ScopeType): Scope | Creates and returns a union that includes the current range and a given lower and upper bound. | -| expand(range: Scope): Scope | Creates and returns a union that includes the current range and the given range. | -| expand(value: ScopeType): Scope | Creates and returns a union that includes the current range and the given value. | -| contains(value: ScopeType): boolean | Checks whether the given value is included in the current range. | -| contains(range: Scope): boolean | Checks whether the given range is within the current range. | -| clamp(value: ScopeType): ScopeType | Clips the specified value to the current range. | -| 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. | -| function getErrorString(errno: number): string | The geterrorstring () method uses a system error number as a parameter to return system error information. | -| 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. | -| 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. | -| isAnyArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer or sharedarraybuffer type. | -| 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. | -| isArgumentsObject(value: Object): boolean | Check whether the entered value is an arguments object type. | -| isArrayBuffer(value: Object): boolean | Check whether the entered value is of arraybuffer type. | -| isAsyncFunction(value: Object): boolean | Check whether the value entered is an asynchronous function type. | -| isBigInt64Array(value: Object): boolean | Check whether the entered value is of bigint64array array type. | -| isBigUint64Array(value: Object): boolean | Check whether the entered value is of biguint64array array array type. | -| isBooleanObject(value: Object): boolean | Check whether the entered value is a Boolean object type. | -| isBoxedPrimitive(value: Object): boolean | Check whether the entered value is a Boolean or number or string or symbol object type. | -| isDataView(value: Object): boolean | Check whether the entered value is of DataView type. | -| isDate(value: Object): boolean | Check whether the entered value is of type date. | -| isExternal(value: Object): boolean | Check whether the entered value is a native external value type. | -| isFloat32Array(value: Object): boolean | Check whether the entered value is of float32array array type. | -| isFloat64Array(value: Object): boolean | Check whether the entered value is of float64array array type. | -| isGeneratorFunction(value: Object): boolean | Check whether the input value is a generator function type. | -| isGeneratorObject(value: Object): boolean | Check whether the entered value is a generator object type. | -| isInt8Array(value: Object): boolean | Check whether the entered value is of int8array array type. | -| isInt16Array(value: Object): boolean | Check whether the entered value is the int16array type. | -| isInt32Array(value: Object): boolean | Check whether the entered value is the int32array array type. | -| isMap(value: Object): boolean | Check whether the entered value is of map type. | -| isMapIterator(value: Object): boolean | Check whether the entered value is the iterator type of map. | -| isModuleNamespaceObject(value: Object): boolean | Check whether the entered value is the module namespace object object type. | -| isNativeError(value: Object): boolean | Check whether the value entered is of type error. | -| isNumberObject(value: Object): boolean | Check whether the entered value is of the number object type. | -| isPromise(value: Object): boolean | Check whether the entered value is of promise type. | -| isProxy(value: Object): boolean | Check whether the value entered is of proxy type. | -| isRegExp(value: Object): boolean | Check whether the entered value is of type regexp. | -| isSet(value: Object): boolean | Check whether the entered value is of type set. | -| isSetIterator(value: Object): boolean | Check whether the entered value is the iterator type of set. | -| isSharedArrayBuffer(value: Object): boolean | Check whether the entered value is of type sharedarraybuffer. | -| isStringObject(value: Object): boolean | Check whether the entered value is a string object type. | -| isSymbolObject(value: Object): boolean | Check whether the entered value is a symbol object type. | -| isTypedArray(value: Object): boolean | Check whether the entered value is a type contained in typedarray. | -| isUint8Array(value: Object): boolean | Check whether the entered value is the uint8array array type. | -| isUint8ClampedArray(value: Object): boolean | Check whether the entered value is the uint8clapedarray array type. | -| isUint16Array(value: Object): boolean | Check whether the entered value is the uint16array array array type. | -| isUint32Array(value: Object): boolean | Check whether the entered value is the uint32array array type. | -| isWeakMap(value: Object): boolean | Check whether the entered value is of type weakmap. | -| isWeakSet(value: Object): boolean | Check whether the entered value is of type weakset. | - -Each specifier in printf is replaced with a converted value from the corresponding parameter. Supported specifiers are: -| Stylized character | Style requirements | -| -------- | -------- | -| %s: | String will be used to convert all values except BigInt, Object and -0. | -| %d: | Number will be used to convert all values except BigInt and Symbol. | -| %i: | parseInt(value, 10) is used for all values except BigInt and Symbol. | -| %f: | parseFloat(value) is used for all values expect Symbol. | -| %j: | JSON. Replaced with the string '[Circular]' if the argument contains circular references. | -| %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. | -| %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. | -| %c: | CSS. This specifier is ignored and will skip any CSS passed in. | -| %%: | single percent sign ('%'). This does not consume an argument. | - -### Instruction for use - - -The use methods of each interface are as follows: - -1.readonly encoding() - -``` -import util from '@ohos.util' -var textEncoder = new util.TextEncoder(); -var getEncoding = textEncoder.encoding(); -``` -2.encode() -``` -import util from '@ohos.util' -var textEncoder = new util.TextEncoder(); -var result = textEncoder.encode('abc'); -``` -3.encodeInto() -``` -import util from '@ohos.util' -var textEncoder = new util.TextEncoder(); -var obj = textEncoder.encodeInto('abc', dest); -``` -4.textDecoder() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -``` -5.readonly encoding() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var getEncoding = textDecoder.encoding(); -``` -6.readonly fatal() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var fatalStr = textDecoder.fatal(); -``` -7.readonly ignoreBOM() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var ignoreBom = textDecoder.ignoreBOM(); -``` -8.decode() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var result = textDecoder.decode(input, {stream : true}); -``` -9.printf() -``` -import util from '@ohos.util' -var format = "%%%o%%%i%s"; -var value = function aa(){}; -var value1 = 1.5; -var value2 = "qwer"; -var result = util.printf(format,value,value1,value2); -``` -10.getErrorString() -``` -import util from '@ohos.util' -var errnum = 13; -var result = util.getErrorString(errnum); -``` -11.callbackWrapper() -``` -import util from '@ohos.util' -async function promiseFn() { - return Promise.resolve('value'); -}; -var cb = util.callbackWrapper(promiseFn); -cb((err, ret) => { - expect(err).strictEqual(null); - expect(ret).strictEqual('value'); -}) -``` -12.promiseWrapper() -``` -import util from '@ohos.util' -function aysnFun(str1, str2, callback) { - if (typeof str1 === 'string' && typeof str1 === 'string') { - callback(null, str1 + str2); - } else { - callback('type err'); - } -} -let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); -newPromiseObj.then(res => { - expect(res).strictEqual('HelloWorld'); -}) -``` -13.encodeSync() -``` -import util from '@ohos.util' -var that = new util.Base64(); -var array = new Uint8Array([115,49,51]); -var result = that.encodeSync(array); -``` -14.encodeToStringSync() -``` -import util from '@ohos.util' -var that = new util.Base64(); -var array = new Uint8Array([115,49,51]); -var result = that.encodeToStringSync(array); -``` -15.decodeSync() -``` -import util from '@ohos.util' -var that = new util.Base64() -var buff = 'czEz'; -var result = that.decodeSync(buff); -``` -16.encode() -``` -import util from '@ohos.util' -var that = new util.Base64() -var array = new Uint8Array([115,49,51]); -await that.encode(array).then(val=>{ -}) -done() -``` -17.encodeToString() -``` -import util from '@ohos.util' -var that = new util.Base64() -var array = new Uint8Array([115,49,51]); -await that.encodeToString(array).then(val=>{ -}) -done() -``` -18.decode() -``` -import util from '@ohos.util' -var that = new util.Base64() -var buff = 'czEz'; -await that.decode(buff).then(val=>{ -}) -done() -``` -19.createRationalFromString() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(0, 0); -var res = pro.createRationalFromString("-1:2"); -var result1 = res.value(); -``` -20.compareTo() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var proc = new util.RationalNumber(3, 4); -var res = pro.compareTo(proc); -``` -21.equals() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var proc = new util.RationalNumber(3, 4); -var res = pro.equals(proc); -``` -22.valueOf() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var res = pro.value(); -``` -23.getCommonDivisor() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(0, 0); -var res = pro.getCommonDivisor(4, 8); -``` -24.getDenominator() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var res = pro.getDenominator(); -``` -25.getNumerator() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.getNumerator(); -``` -26.isFinite() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.isFinite(); -``` -27.isNaN() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.isNaN(); -``` -28.isZero() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.isZero(); - -``` -29.toString() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.toString(); - -``` -30.updateCapacity() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.updateCapacity(100); -``` -31.toString() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.get(2); -pro.remove(20); -var result = pro.toString(); -``` -32.values() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.put(2,"anhu"); -pro.put("afaf","grfb"); -var result = pro.values(); -``` -33.length -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.put(1,8); -var result = pro.length; -``` -34.getCapacity() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.getCapacity(); -``` -35.clear() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.clear(); -``` -36.getCreateCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(1,8); -var result = pro.getCreateCount(); -``` -37.getMissCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.get(2) -var result = pro.getMissCount(); -``` -38.getRemovalCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.updateCapacity(2); -pro.put(50,22); -var result = pro.getRemovalCount(); -``` -39.getMatchCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.get(2); -var result = pro.getMatchCount(); -``` -40.getPutCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.getPutCount(); -``` -41.isEmpty() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.isEmpty(); -``` -42.get() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.get(2); -``` -43.put() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.put(2,10); -``` -44.keys() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); - pro.put(2,10); -var result = pro.keys(); -``` -45.remove() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.remove(20); -``` -46.contains() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.contains(20); -``` -47.createDefault() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.createDefault(50); -``` -48.entries() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.entries(); -``` -49.\[Symbol.iterator\]() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro[symbol.iterator](); -``` -50.afterRemoval() -``` -import util from '@ohos.util' -var arr = []; -class ChildLruBuffer extends util.LruBuffer -{ - constructor() - { - super(); - } - static getInstance() - { - if(this.instance == null) - { - this.instance = new ChildLruBuffer(); - } - return this.instance; - } - afterRemoval(isEvict, key, value, newValue) - { - if (isEvict === false) - { - arr = [key, value, newValue]; - } - } -} -ChildLruBuffer.getInstance().afterRemoval(false,10,30,null) -``` -Construct a new class in the Scope interface to implement the compareTo method. - -``` -class Temperature { - constructor(value) { - this._temp = value; - } - compareTo(value) { - return this._temp >= value.getTemp(); - } - getTemp() { - return this._temp; - } - toString() { - return this._temp.toString(); - } -} -``` - -51.constructor() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -``` - -52.toString() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var result = range.toString() // => [30,40] -``` - -53.intersect() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var rangeFir = new Scope(tempMiDF, tempMidS); -var result = range.intersect(rangeFir) // => [35,39] -``` - -54.intersect() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var range = new Scope(tempLower, tempUpper); -var result = range.intersect(tempMiDF, tempMidS) // => [35,39] -``` - -55.getUpper() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var result = range.getUpper() // => 40 -``` - -56.getLower() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var result = range.getLower() // => 30 -``` - -57.expand() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var range = new Scope(tempLower, tempUpper); -var result = range.expand(tempMiDF, tempMidS) // => [30,40] -``` - -58.expand() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var range = new Scope(tempLower, tempUpper); -var rangeFir = new Scope(tempMiDF, tempMidS); -var result = range.expand(rangeFir) // => [30,40] -``` - -59.expand() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var range = new Scope(tempLower, tempUpper); -var result = range.expand(tempMiDF) // => [30,40] -``` - -60.contains() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var range = new Scope(tempLower, tempUpper); -var result = range.contains(tempMiDF) // => true -``` - -61.contains() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var tempLess = new Temperature(20); -var tempMore = new Temperature(45); -var rangeSec = new Scope(tempLess, tempMore); -var result = range.contains(rangeSec) // => true -``` - -62.clamp() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var range = new Scope(tempLower, tempUpper); -var result = range.clamp(tempMiDF) // => 35 -``` -63.isAnyArrayBuffer() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isAnyArrayBuffer(new ArrayBuffer([])) -``` -64.isArrayBufferView() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16))); -``` -65.isArgumentsObject() -``` -import util from '@ohos.util' -function foo() { - var result = proc.isArgumentsObject(arguments); - } -var f = foo(); -``` -66.isArrayBuffer() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isArrayBuffer(new ArrayBuffer([])); -``` -67.isAsyncFunction() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isAsyncFunction(async function foo() {}); -``` -68.isBigInt64Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBigInt64Array(new Int16Array([])); -``` -69.isBigUint64Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBigUint64Array(new Int16Array([])); -``` -70.isBooleanObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBooleanObject(new Boolean(false)); -``` -71.isBoxedPrimitive() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBoxedPrimitive(new Boolean(false)); -``` -72.isDataView() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const ab = new ArrayBuffer(20); -var result = proc.isDataView(new DataView(ab)); -``` -73.isDate() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isDate(new Date()); -``` -74.isExternal() -``` -import util from '@ohos.util' -const data = util.createExternalType(); -var reult13 = proc.isExternal(data); -``` -75.isFloat32Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isFloat32Array(new Float32Array([])); -``` -76.isFloat64Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isFloat64Array(new Float64Array([])); -``` -77.isGeneratorFunction() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isGeneratorFunction(function* foo() {}); -``` -78.isGeneratorObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -function* foo() {} -const generator = foo(); -var result = proc.isGeneratorObject(generator); -``` -79.isInt8Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isInt8Array(new Int8Array([])); -``` -80.isInt16Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isInt16Array(new Int16Array([])); -``` -81.isInt32Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isInt32Array(new Int32Array([])); -``` -82.isMap() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isMap(new Map()); -``` -83.isMapIterator() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isMapIterator(map.keys()); -``` -84.isModuleNamespaceObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isModuleNamespaceObject(util); -``` -85.isNativeError() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isNativeError(new TypeError()); -``` -86.isNumberObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isNumberObject(new Number(0)); -``` -87.isPromise() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isPromise(Promise.resolve(42)); -``` -88.isProxy() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const target = {}; -const proxy = new Proxy(target, {}); -var result = proc.isProxy(proxy); -``` -89.isRegExp() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isRegExp(new RegExp('abc')); -``` -90.isSet() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isSet(new Set()); -``` -91.isSetIterator() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const set = new Set(); -var result = proc.isSetIterator(set.keys()); -``` -92.isSharedArrayBuffer() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); -``` -93.isStringObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isStringObject(new String('foo')); -``` -94.isSymbolObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const symbols = Symbol('foo'); -var result = proc.isSymbolObject(Object(symbols)); -``` -95.isTypedArray() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isTypedArray(new Float64Array([])); -``` -96.isUint8Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint8Array(new Uint8Array([])); -``` -97.isUint8ClampedArray() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); -``` -98.isUint16Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint16Array(new Uint16Array([])); -``` -99.isUint32Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint32Array(new Uint32Array([])); -``` -100.isWeakMap() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isWeakMap(new WeakMap()); -``` -101.isWeakSet() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isWeakSet(new WeakSet()); -``` -## Related warehouse - -[js_util_module subsystem](base/compileruntime/js_util_module-readme.md) - -## License - -Util 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. \ No newline at end of file diff --git a/js_util_module/README_zh.md b/js_util_module/README_zh.md deleted file mode 100644 index 554f758..0000000 --- a/js_util_module/README_zh.md +++ /dev/null @@ -1,1032 +0,0 @@ -# js_util_module子系统/组件 - -- [简介](#简介) -- [目录](#目录) -- [说明](#说明) - - [接口说明](#接口说明) - - [使用说明](#使用说明) - -- [相关仓](#相关仓) - -## 简介 - -UTIL接口用于字符编码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实例的构造函数用于创建具有指定下限和上限的对象,并要求这些对象必须具有可比性。 -## 目录 - -``` -base/compileruntime/js_util_module/ -├── Class:TextEncoder # TextEncoder类 -│ ├── new TextEncoder() # 创建TextEncoder对象 -│ ├── encode() # encode方法 -│ ├── encoding # encoding属性 -│ └── encodeInto() # encodeInto方法 -├── Class:TextDecoder # TextDecoder类 -│ ├── new TextDecoder() # 创建TextDecoder对象 -│ ├── decode() # decode方法 -│ ├── encoding # encoding属性 -│ ├── fatal # fatal属性 -│ └── ignoreBOM # ignoreBOM属性 -├── printf() # printf方法 -├── getErrorString() # getErrorString方法 -├── callbackWrapper() # callbackWrapper方法 -├── promiseWrapper() # promiseWrapper方法 -├── Class:Base64 # Base64类 -│ ├── new Base64() # 创建Base64对象 -│ ├── encodeSync() # encodeSync方法 -│ ├── encodeToStringSync() # encodeToStringSync方法 -│ ├── decodeSync() # decodeSync方法 -│ ├── encode() # encode方法 -│ ├── encodeToString() # encodeToString方法 -│ └── decode() # decode方法 -├── Class:RationalNumber # RationalNumber类 -│ ├── new RationalNumber() # 创建RationalNumber对象 -│ ├── createRationalFromString() # createRationalFromString方法 -│ ├── compareTo() # compareTo方法 -│ ├── equals() # equals方法 -│ ├── valueOf() # valueOf方法 -│ ├── getCommonDivisor() # getCommonDivisor方法 -│ ├── getDenominator() # getDenominator方法 -│ ├── getNumerator() # getNumerator方法 -│ ├── isFinite() # isFinite方法 -│ ├── isNaN() # isNaN方法 -│ ├── isZero() # isZero方法 -│ └── toString() # toString方法 -├── Class:LruBuffer # LruBuffer类 -│ ├── new LruBuffer() # 创建LruBuffer对象 -│ ├── updateCapacity() # updateCapacity方法 -│ ├── toString() # toString方法 -│ ├── values() # values方法 -│ ├── length # length属性 -│ ├── getCapacity() # getCapacity方法 -│ ├── clear() # clear方法 -│ ├── getCreateCount() # getCreateCount方法 -│ ├── getMissCount() # getMissCount方法 -│ ├── getRemovalCount() # getRemovalCount方法 -│ ├── getMatchCount() # getMatchCount方法 -│ ├── getPutCount() # getPutCount方法 -│ ├── isEmpty() # isEmpty方法 -│ ├── get() # get方法 -│ ├── put() # put方法 -│ ├── keys() # keys方法 -│ ├── remove() # remove方法 -│ ├── afterRemoval() # afterRemoval方法 -│ ├── contains() # contains方法 -│ ├── createDefault() # createDefault方法 -│ ├── entries() # entries方法 -│ └── [Symbol.iterator]() # Symboliterator方法 -|—— Class:Scope # Scope类 -| ├── constructor() # 创建Scope对象 -| ├── toString() # toString方法 -| ├── intersect() # intersect方法 -| ├── intersect() # intersect方法 -| ├── getUpper() # getUpper方法 -| ├── getLower() # getLower方法 -| ├── expand() # expand方法 -| ├── expand() # expand方法 -| ├── expand() # expand法 -| ├── contains() # contains方法 -| ├── contains() # contains方法 -| └── clamp() # clamp方法 -└── Class:Types # Types类 - ├── isAnyArrayBuffer() # isAnyArrayBuffer方法 - ├── isArrayBufferView() # isArrayBufferView方法 - ├── isArgumentsObject() # isArgumentsObject方法 - ├── isArrayBuffer() # isArrayBuffer方法 - ├── isAsyncFunction() # isAsyncFunction方法 - ├── isBigInt64Array() # isBigInt64Array方法 - ├── isBigUint64Array() # isBigUint64Array方法 - ├── isBooleanObject() # isBooleanObject方法 - ├── isBoxedPrimitive() # isBoxedPrimitive方法 - ├── isDataView() # isDataView方法 - ├── isDate() # isDate方法 - ├── isExternal() # isExternal方法 - ├── isFloat32Array() # isFloat32Array方法 - ├── isFloat64Array() # isFloat64Array方法 - ├── isGeneratorFunction() # isGeneratorFunction方法 - ├── isGeneratorObject() # isGeneratorObject方法 - ├── isInt8Array() # isInt8Array方法 - ├── isInt16Array() # isInt16Array方法 - ├── isInt32Array() # isInt32Array方法 - ├── isMap() # isMap方法 - ├── isMapIterator() # isMapIterator方法 - ├── isModuleNamespaceObject() # isModuleNamespaceObject方法 - ├── isNativeError() # isNativeError方法 - ├── isNumberObject() # isNumberObject方法 - ├── isPromise() # isPromise方法 - ├── isProxy() # isProxy方法 - ├── isRegExp() # isRegExp方法 - ├── isSet() # isSet方法 - ├── isSetIterator() # isSetIterator方法 - ├── isSharedArrayBuffer() # isSharedArrayBuffer方法 - ├── isStringObject() # isStringObject方法 - ├── isSymbolObject() # isSymbolObject方法 - ├── isTypedArray() # isTypedArray方法 - ├── isUint8Array() # isUint8Array方法 - ├── isUint8ClampedArray() # isUint8ClampedArray方法 - ├── isUint16Array() # isUint16Array方法 - ├── isUint32Array() # isUint32Array方法 - ├── isWeakMap() # isWeakMap方法 - └── isWeakSet() # isWeakSet方法 -``` -## 说明 - -### 接口说明 - - -| 接口名 | 说明 | -| -------- | -------- | -| constructor(encoding? : string) | 构造函数,参数encoding表示编码的格式。默认utf-8, 支持gb18030, gbk, gb2312. | -| readonly encoding : string | 在TextEncoder类中,获取编码的格式,只支持UTF-8。 | -| encode(input : string) : Uint8Array | 输入stirng字符串,根据encodeing编码并输出uint8字节流。 | -| encodeInto(input : string, dest : Uint8Array) : {read : number, written : number} | 输入stirng字符串,dest表示编码后存放位置,返回一个对象,read表示已经编码的字符的个数,written表示已编码字符所占字节的大小。 | -| constructor(encoding? : string, options? : {fatal? : boolean, ignoreBOM? : boolean}) | 构造函数,第一个参数encoding表示解码的格式。第二个参数表示一些属性。属性中fatal表示是否抛出异常,ignoreBOM表示是否忽略bom标志。 | -| readonly encoding : string | 在TextDecoder类中,获取设置的解码格式。 | -| readonly fatal : boolean | 获取抛出异常的设置。 | -| readonly ignoreBOM : boolean | 获取是否忽略bom标志的设置。 | -| decode(input : Uint8Array, options?: { stream?: false }) : string | 输入要解码的数据,解出对应的string字符串。第一个参数input表示要解码的数据,第二个参数options表示一个bool标志,表示将跟随附加数据,默认为false。 | -| encodeSync(src: Uint8Array): Uint8Array; | 使用Base64编码方案将指定u8数组中的所有字节编码到新分配的u8数组中。 | -| encodeToStringSync(src: Uint8Array): string; | 使用Base64编码方案将指定的字节数组编码为String。 | -| decodeSync(src: Uint8Array \| string): Uint8Array; | 使用Base64编码方案将Base64编码的字符串或输入u8数组解码为新分配的u8数组。 | -| encode(src: Uint8Array): Promise\; | 使用Base64编码方案将指定u8数组中的所有字节异步编码到新分配的u8数组中。 | -| encodeToString(src: Uint8Array): Promise\; | 使用Base64编码方案将指定的字节数组异步编码为String。 | -| decode(src: Uint8Array \| string): Promise\; | 使用Base64编码方案将Base64编码的字符串或输入u8数组异步解码为新分配的u8数组。 | -| static createRationalFromString(rationalString: string): RationalNumber | 基于给定的字符串创建一个RationalNumber对象。 | -| compareTo(another: RationalNumber): number | 将当前的RationalNumber对象与给定的对象进行比较。 | -| equals(obj: object): number | 检查给定对象是否与当前 RationalNumber 对象相同。 | -| valueOf(): number | 将当前的RationalNumber对象进行取整数值或者浮点数值。 | -| static getCommonDivisor(number1: number, number2: number,): number | 获得两个指定数的最大公约数。 | -| getDenominator(): number | 获取当前的RationalNumber对象的分母。 | -| getNumerator(): number | 获取当前的RationalNumber对象的分子。 | -| isFinite(): boolean | 检查当前的RationalNumber对象是有限的。 | -| isNaN(): boolean | 检查当前RationalNumber对象是否表示非数字(NaN)值。 | -| isZero(): boolean | 检查当前RationalNumber对象是否表示零值。 | -| toString(): string | 获取当前RationalNumber对象的字符串表示形式。 | -| constructor(capacity?: number) | 创建默认构造函数用于创建一个新的LruBuffer实例,默认容量为64。 | -| updateCapacity(newCapacity: number): void | 将缓冲区容量更新为指定容量,如果 newCapacity 小于或等于 0,则抛出此异常。 | -| toString(): string | 返回对象的字符串表示形式,输出对象的字符串表示 | -| values(): V[] | 获取当前缓冲区中所有值的列表,输出按升序返回当前缓冲区中所有值的列表,从最近访问到最近最少访问。 | -| length: number | 代表当前缓冲区中值的总数,输出返回当前缓冲区中值的总数。 | -| getCapacity(): number | 获取当前缓冲区的容量,输出返回当前缓冲区的容量。 | -| clear(): void | 从当前缓冲区清除键值对,清除键值对后,调用afterRemoval()方法依次对其执行后续操作。 | -| getCreateCount(): number | 获取createDefault()返回值的次数,输出返回createDefault()返回值的次数。 | -| getMissCount(): number | 获取查询值不匹配的次数,输出返回查询值不匹配的次数。 | -| getRemovalCount(): number | 获取从缓冲区中逐出值的次数,输出从缓冲区中驱逐的次数。 | -| getMatchCount​(): number | 获取查询值匹配成功的次数,输出返回查询值匹配成功的次数。 | -| getPutCount(): number | 获取将值添加到缓冲区的次数,输出返回将值添加到缓冲区的次数。 | -| isEmpty(): boolean | 检查当前缓冲区是否为空,输出如果当前缓冲区不包含任何值,则返回 true 。 | -| get(key: K) : V \| undefined | 表示要查询的键,输出如果指定的键存在于缓冲区中,则返回与键关联的值;否则返回undefined。 | -| put(key: K , value: V): V | 将键值对添加到缓冲区,输出与添加的键关联的值;如果要添加的键已经存在,则返回原始值,如果键或值为空,则抛出此异常。 | -| keys(): K[ ] | 获取当前缓冲区中值的键列表,输出返回从最近访问到最近最少访问排序的键列表。 | -| remove​(key: K): V \| undefined | 从当前缓冲区中删除指定的键及其关联的值。 | -| afterRemoval(isEvict: boolean, key: K, value : V, newValue : V):void | 删除值后执行后续操作。 | -| contains(key: K): boolean | 检查当前缓冲区是否包含指定的键,输出如果缓冲区包含指定的键,则返回 true 。 | -| createDefault(key: K): V | 如果未计算特定键的值,则执行后续操作,参数表示丢失的键,输出返回与键关联的值。 | -| entries(): [K,V] | 允许迭代包含在这个对象中的所有键值对。每对的键和值都是对象。 | -| \[Symbol.iterator\](): [K,V] | 返回以键值对得形式得一个二维数组。 | -| constructor(lowerObj: ScopeType, upperObj : ScopeType) | 创建并返回一个Scope对象,用于创建指定下限和上限的作用域实例的构造函数。 | -| toString(): string | 该字符串化方法返回一个包含当前范围的字符串表示形式。 | -| intersect(range: Scope): Scope | 获取给定范围和当前范围的交集。 | -| intersect(lowerObj: ScopeType, upperObj: ScopeType): Scope | 获取当前范围与给定下限和上限范围的交集。 | -| getUpper(): ScopeType | 获取当前范围的上限。 | -| getLower(): ScopeType | 获取当前范围的下限。 | -| expand(lowerObj: ScopeType, upperObj: ScopeType): Scope | 创建并返回包括当前范围和给定下限和上限的并集。 | -| expand(range: Scope): Scope | 创建并返回包括当前范围和给定范围的并集。 | -| expand(value: ScopeType): Scope | 创建并返回包括当前范围和给定值的并集。 | -| contains(value: ScopeType): boolean | 检查给定value是否包含在当前范围内。 | -| contains(range: Scope): boolean | 检查给定range是否在当前范围内。 | -| clamp(value: ScopeType): ScopeType | 将给定value限定到当前范围内。 | -| function printf(format: string, ...args: Object[]): string | printf()方法使用第一个参数作为格式字符串(其可以包含零个或多个格式说明符)来返回格式化的字符串。 | -| function getErrorString(errno: number): string | getErrorString()方法使用一个系统的错误数字作为参数,用来返回系统的错误信息。 | -| function callbackWrapper(original: Function): (err: Object, value: Object) => void | 参数为一个采用 async 函数(或返回 Promise 的函数)并返回遵循错误优先回调风格的函数,即将 (err, value) => ... 回调作为最后一个参数。 在回调中,第一个参数将是拒绝原因(如果 Promise 已解决,则为 null),第二个参数将是已解决的值。 | -| function promiseWrapper(original: (err: Object, value: Object) => void): Object | 参数为采用遵循常见的错误优先的回调风格的函数(也就是将 (err, value) => ... 回调作为最后一个参数),并返回一个返回 promise 的版本。 | -| isAnyArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer或SharedArrayBuffer类型。 | -| 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类型。 | -| isArgumentsObject(value: Object): boolean | 检查输入的value是否是一个arguments对象类型。 | -| isArrayBuffer(value: Object): boolean | 检查输入的value是否是ArrayBuffer类型。 | -| isAsyncFunction(value: Object): boolean | 检查输入的value是否是异步函数类型。 | -| isBigInt64Array(value: Object): boolean | 检查输入的value是否是BigInt64Array数组类型。 | -| isBigUint64Array(value: Object): boolean | 检查输入的value是否是BigUint64Array数组类型。 | -| isBooleanObject(value: Object): boolean | 检查输入的value是否是一个布尔对象类型。 | -| isBoxedPrimitive(value: Object): boolean | 检查输入的value是否是Boolean或Number或String或Symbol对象类型。 | -| isDataView(value: Object): boolean | 检查输入的value是否是DataView类型。 | -| isDate(value: Object): boolean | 检查输入的value是否是Date类型。 | -| isExternal(value: Object): boolean | 检查输入的value是否是一个native External值类型。 | -| isFloat32Array(value: Object): boolean | 检查输入的value是否是Float32Array数组类型。 | -| isFloat64Array(value: Object): boolean | 检查输入的value是否是Float64Array数组类型。 | -| isGeneratorFunction(value: Object): boolean | 检查输入的value是否是一个generator函数类型。 | -| isGeneratorObject(value: Object): boolean | 检查输入的value是否是一个generator对象类型。 | -| isInt8Array(value: Object): boolean | 检查输入的value是否是Int8Array数组类型。 | -| isInt16Array(value: Object): boolean | 检查输入的value是否是Int16Array数组类型。 | -| isInt32Array(value: Object): boolean | 检查输入的value是否是Int32Array数组类型。 | -| isMap(value: Object): boolean | 检查输入的value是否是Map类型。 | -| isMapIterator(value: Object): boolean | 检查输入的value是否是Map的iterator类型。 | -| isModuleNamespaceObject(value: Object): boolean | 检查输入的value是否是Module Namespace Object对象类型。 | -| isNativeError(value: Object): boolean | 检查输入的value是否是Error类型。 | -| isNumberObject(value: Object): boolean | 检查输入的value是否是Number对象类型。 | -| isPromise(value: Object): boolean | 检查输入的value是否是Promise类型。 | -| isProxy(value: Object): boolean | 检查输入的value是否是Proxy类型。 | -| isRegExp(value: Object): boolean | 检查输入的value是否是RegExp类型。 | -| isSet(value: Object): boolean | 检查输入的value是否是Set类型。 | -| isSetIterator(value: Object): boolean | 检查输入的value是否是Set的iterator类型。 | -| isSharedArrayBuffer(value: Object): boolean | 检查输入的value是否是SharedArrayBuffer类型。 | -| isStringObject(value: Object): boolean | 检查输入的value是否是一个String对象类型。 | -| isSymbolObject(value: Object): boolean | 检查输入的value是否是一个Symbol对象类型。 | -| isTypedArray(value: Object): boolean | 检查输入的value是否是TypedArray包含的类型。 | -| isUint8Array(value: Object): boolean | 检查输入的value是否是Uint8Array数组类型。 | -| isUint8ClampedArray(value: Object): boolean | 检查输入的value是否是Uint8ClampedArray数组类型。 | -| isUint16Array(value: Object): boolean | 检查输入的value是否是Uint16Array数组类型。 | -| isUint32Array(value: Object): boolean | 检查输入的value是否是Uint32Array数组类型。 | -| isWeakMap(value: Object): boolean | 检查输入的value是否是WeakMap类型。 | -| isWeakSet(value: Object): boolean | 检查输入的value是否是WeakSet类型。 | - -printf中每个说明符都替换为来自相应参数的转换后的值。 支持的说明符有: -| 式样化字符 | 式样要求 | -| -------- | -------- | -| %s: | String 将用于转换除 BigInt、Object 和 -0 之外的所有值。| -| %d: | Number 将用于转换除 BigInt 和 Symbol 之外的所有值。| -| %i: | parseInt(value, 10) 用于除 BigInt 和 Symbol 之外的所有值。| -| %f: | parseFloat(value) 用于除 Symbol 之外的所有值。| -| %j: | JSON。 如果参数包含循环引用,则替换为字符串 '[Circular]'。| -| %o: | Object. 具有通用 JavaScript 对象格式的对象的字符串表示形式。类似于具有选项 { showHidden: true, showProxy: true } 的 util.inspect()。这将显示完整的对象,包括不可枚举的属性和代理。| -| %O: | Object. 具有通用 JavaScript 对象格式的对象的字符串表示形式。类似于没有选项的 util.inspect()。 这将显示完整的对象,但不包括不可枚举的属性和代理。| -| %c: | 此说明符被忽略,将跳过任何传入的 CSS 。| -| %%: | 单个百分号 ('%')。 这不消耗待式样化参数。| - -### 使用说明 -各接口使用方法如下: - -1.readonly encoding() - -``` -import util from '@ohos.util' -var textEncoder = new util.TextEncoder(); -var getEncoding = textEncoder.encoding(); -``` -2.encode() -``` -import util from '@ohos.util' -var textEncoder = new util.TextEncoder(); -var result = textEncoder.encode('abc'); -``` -3.encodeInto() -``` -import util from '@ohos.util' -var textEncoder = new util.TextEncoder(); -var obj = textEncoder.encodeInto('abc', dest); -``` -4.textDecoder() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -``` -5.readonly encoding() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var getEncoding = textDecoder.encoding(); -``` -6.readonly fatal() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var fatalStr = textDecoder.fatal(); -``` -7.readonly ignoreBOM() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var ignoreBom = textDecoder.ignoreBOM(); -``` -8.decode() -``` -import util from '@ohos.util' -var textDecoder = new util.textDecoder("utf-16be", {fatal : true, ignoreBOM : false}); -var result = textDecoder.decode(input, {stream : true}); -``` -9.printf() -``` -import util from '@ohos.util' -var format = "%%%o%%%i%s"; -var value = function aa(){}; -var value1 = 1.5; -var value2 = "qwer"; -var result = util.printf(format,value,value1,value2); -``` -10.getErrorString() -``` -import util from '@ohos.util' -var errnum = 13; -var result = util.getErrorString(errnum); -``` -11.callbackWrapper() -``` -import util from '@ohos.util' -async function promiseFn() { - return Promise.resolve('value'); -}; -var cb = util.callbackWrapper(promiseFn); -cb((err, ret) => { - expect(err).strictEqual(null); - expect(ret).strictEqual('value'); -}) -``` -12.promiseWrapper() -``` -import util from '@ohos.util' -function aysnFun(str1, str2, callback) { - if (typeof str1 === 'string' && typeof str1 === 'string') { - callback(null, str1 + str2); - } else { - callback('type err'); - } -} -let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); -newPromiseObj.then(res => { - expect(res).strictEqual('HelloWorld'); -}) -``` -13.encodeSync() -``` -import util from '@ohos.util' -var that = new util.Base64(); -var array = new Uint8Array([115,49,51]); -var result = that.encodeSync(array); -``` -14.encodeToStringSync() -``` -import util from '@ohos.util' -var that = new util.Base64(); -var array = new Uint8Array([115,49,51]); -var result = that.encodeToStringSync(array); -``` -15.decodeSync() -``` -import util from '@ohos.util' -var that = new util.Base64() -var buff = 'czEz'; -var result = that.decodeSync(buff); - -``` -16.encode() -``` -import util from '@ohos.util' -var that = new util.Base64() -var array = new Uint8Array([115,49,51]); -await that.encode(array).then(val=>{ -}) -done() -``` -17.encodeToString() -``` -import util from '@ohos.util' -var that = new util.Base64() -var array = new Uint8Array([115,49,51]); -await that.encodeToString(array).then(val=>{ -}) -done() -``` -18.decode() -``` -import util from '@ohos.util' -var that = new util.Base64() -var buff = 'czEz'; -await that.decode(buff).then(val=>{ -}) -done() -``` -19.createRationalFromString() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(0, 0); -var res = pro.createRationalFromString("-1:2"); -var result1 = res.valueOf(); -``` -20.compareTo() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var proc = new util.RationalNumber(3, 4); -var res = pro.compareTo(proc); -``` -21.equals() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var proc = new util.RationalNumber(3, 4); -var res = pro.equals(proc); -``` -22.valueOf() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var res = pro.valueOf(); -``` -23.getCommonDivisor() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(0, 0); -var res = pro.getCommonDivisor(4, 8); -``` -24.getDenominator() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(2, 1); -var res = pro.getDenominator(); -``` -25.getNumerator() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.getNumerator(); -``` -26.isFinite() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.isFinite(); -``` -27.isNaN() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.isNaN(); -``` -28.isZero() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.isZero(); -``` -29.toString() -``` -import util from '@ohos.util' -var pro = new util.RationalNumber(-2, 1); -var res = pro.toString(); -``` -30.updateCapacity() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.updateCapacity(100); -``` -31.toString() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.get(2); -pro.remove(20); -var result = pro.toString(); -``` -32.values() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.put(2,"anhu"); -pro.put("afaf","grfb"); -var result = pro.values(); -``` -33.length -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.put(1,8); -var result = pro.length; -``` -34.getCapacity() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.getCapacity(); -``` -35.clear() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.clear(); -``` -36.getCreateCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(1,8); -var result = pro.getCreateCount(); -``` -37.getMissCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.get(2) -var result = pro.getMissCount(); -``` -38.getRemovalCount() -``` - -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.updateCapacity(2); -pro.put(50,22); -var result = pro.getRemovalCount(); - -``` -39.getMatchCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -pro.get(2); -var result = pro.getMatchCount(); -``` -40.getPutCount() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.getPutCount(); -``` -41.isEmpty() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.isEmpty(); -``` -42.get() - -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.get(2); -``` -43.put() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.put(2,10); -``` -44.keys() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.keys(); -``` -45.remove() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.remove(20); -``` -46.contains() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.contains(20); -``` -47.createDefault() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -var result = pro.createDefault(50); -``` -48.entries() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro.put(2,10); -var result = pro.entries(); -``` -49.\[Symbol.iterator\]() -``` -import util from '@ohos.util' -var pro = new util.LruBuffer(); -pro .put(2,10); -var result = pro[symbol.iterator](); -``` -50.afterRemoval() -``` -import util from '@ohos.util' -var arr = [ ]; -class ChildLruBuffer extends util.LruBuffer -{ - constructor() - { - super(); - } - static getInstance() - { - if(this.instance == null) - { - this.instance = new ChildLruBuffer(); - } - return this.instance; - } - afterRemoval(isEvict, key, value, newValue) - { - if (isEvict === false) - { - arr = [key, value, newValue]; - } - } -} -ChildLruBuffer.getInstance().afterRemoval(false,10,30,null) -``` -Scope接口中构造新类,实现compareTo方法。 - -``` -class Temperature { - constructor(value) { - this._temp = value; - } - compareTo(value) { - return this._temp >= value.getTemp(); - } - getTemp() { - return this._temp; - } - toString() { - return this._temp.toString(); - } -} -``` - -51.constructor() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -``` - -52.toString() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var result = range.toString() // => [30,40] -``` - -53.intersect() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var rangeFir = new Scope(tempMiDF, tempMidS); -var result = range.intersect(rangeFir) // => [35,39] -``` - -54.intersect() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var range = new Scope(tempLower, tempUpper); -var result = range.intersect(tempMiDF, tempMidS) // => [35,39] -``` - -55.getUpper() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var result = range.getUpper() // => 40 -``` - -56.getLower() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var result = range.getLower() // => 30 -``` - -57.expand() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var range = new Scope(tempLower, tempUpper); -var result = range.expand(tempMiDF, tempMidS) // => [30,40] -``` - -58.expand() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var tempMidS = new Temperature(39); -var range = new Scope(tempLower, tempUpper); -var rangeFir = new Scope(tempMiDF, tempMidS); -var result = range.expand(rangeFir) // => [30,40] -``` - -59.expand() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var range = new Scope(tempLower, tempUpper); -var result = range.expand(tempMiDF) // => [30,40] -``` - -60.contains() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var range = new Scope(tempLower, tempUpper); -var result = range.contains(tempMiDF) // => true -``` - -61.contains() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var range = new Scope(tempLower, tempUpper); -var tempLess = new Temperature(20); -var tempMore = new Temperature(45); -var rangeSec = new Scope(tempLess, tempMore); -var result = range.contains(rangeSec) // => true -``` - -62.clamp() - -``` -var tempLower = new Temperature(30); -var tempUpper = new Temperature(40); -var tempMiDF = new Temperature(35); -var range = new Scope(tempLower, tempUpper); -var result = range.clamp(tempMiDF) // => 35 -``` -63.isAnyArrayBuffer() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isAnyArrayBuffer(new ArrayBuffer([])) -``` -64.isArrayBufferView() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isArrayBufferView(new DataView(new ArrayBuffer(16))); -``` -65.isArgumentsObject() -``` -import util from '@ohos.util' -function foo() { - var result = proc.isArgumentsObject(arguments); - } -var f = foo(); -``` -66.isArrayBuffer() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isArrayBuffer(new ArrayBuffer([])); -``` -67.isAsyncFunction() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isAsyncFunction(async function foo() {}); -``` -68.isBigInt64Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBigInt64Array(new Int16Array([])); -``` -69.isBigUint64Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBigUint64Array(new Int16Array([])); -``` -70.isBooleanObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBooleanObject(new Boolean(false)); -``` -71.isBoxedPrimitive() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isBoxedPrimitive(new Boolean(false)); -``` -72.isDataView() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const ab = new ArrayBuffer(20); -var result = proc.isDataView(new DataView(ab)); -``` -73.isDate() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isDate(new Date()); -``` -74.isExternal() -``` -import util from '@ohos.util' -const data = util.createExternalType(); -var reult13 = proc.isExternal(data); -``` -75.isFloat32Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isFloat32Array(new Float32Array([])); -``` -76.isFloat64Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isFloat64Array(new Float64Array([])); -``` -77.isGeneratorFunction() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isGeneratorFunction(function* foo() {}); -``` -78.isGeneratorObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -function* foo() {} -const generator = foo(); -var result = proc.isGeneratorObject(generator); -``` -79.isInt8Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isInt8Array(new Int8Array([])); -``` -80.isInt16Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isInt16Array(new Int16Array([])); -``` -81.isInt32Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isInt32Array(new Int32Array([])); -``` -82.isMap() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isMap(new Map()); -``` -83.isMapIterator() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isMapIterator(map.keys()); -``` -84.isModuleNamespaceObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isModuleNamespaceObject(util); -``` -85.isNativeError() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isNativeError(new TypeError()); -``` -86.isNumberObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isNumberObject(new Number(0)); -``` -87.isPromise() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isPromise(Promise.resolve(42)); -``` -88.isProxy() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const target = {}; -const proxy = new Proxy(target, {}); -var result = proc.isProxy(proxy); -``` -89.isRegExp() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isRegExp(new RegExp('abc')); -``` -90.isSet() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isSet(new Set()); -``` -91.isSetIterator() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const set = new Set(); -var result = proc.isSetIterator(set.keys()); -``` -92.isSharedArrayBuffer() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isSharedArrayBuffer(new ArrayBuffer([])); -``` -93.isStringObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isStringObject(new String('foo')); -``` -94.isSymbolObject() -``` -import util from '@ohos.util' -var proc = new util.Types(); -const symbols = Symbol('foo'); -var result = proc.isSymbolObject(Object(symbols)); -``` -95.isTypedArray() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isTypedArray(new Float64Array([])); -``` -96.isUint8Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint8Array(new Uint8Array([])); -``` -97.isUint8ClampedArray() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint8ClampedArray(new Uint8ClampedArray([])); -``` -98.isUint16Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint16Array(new Uint16Array([])); -``` -99.isUint32Array() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isUint32Array(new Uint32Array([])); -``` -100.isWeakMap() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isWeakMap(new WeakMap()); -``` -101.isWeakSet() -``` -import util from '@ohos.util' -var proc = new util.Types(); -var result = proc.isWeakSet(new WeakSet()); -``` -## 相关仓 - -[js_util_module子系统](base/compileruntime/js_util_module-readme_zh.md) - -## 许可证 - -Util在[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) \ No newline at end of file diff --git a/js_util_module/bundle.json b/js_util_module/bundle.json deleted file mode 100644 index 4500146..0000000 --- a/js_util_module/bundle.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "name": "@ohos/js_util_module", - "version": "", - "description": "js_util_module, used to store some helper functions, such as string encoding and decoding, function callback, promise, Base | js_util_module, 用于存放一些帮助类函数,比如字符串编解码,函数callback化、promise化,Base64编解码,Lru缓存等", - "homePage": "https://gitee.com/openharmony", - "license": "Apache V2", - "repository": "https://gitee.com/openharmony/js_util_module", - "domain": "os", - "language": "", - "publishAs": "code-segment", - "private": false, - "scripts": {}, - "tags": [ - "js" - ], - "keywords": [ - "js", - "util", - "module" - ], - "envs": {}, - "dirs": {}, - "author": { - "name": "", - "email": "", - "url": "" - }, - "contributors": [ - { - "name": "", - "email": "", - "url": "" - } - ], - "segment": { - "destPath": "base/compileruntime/js_util_module" - }, - "component": { - "name": "jsapi_util", - "subsystem": "utils", - "syscap": [], - "features": [], - "adapted_system_type": [], - "rom": "", - "ram": "", - "deps": { - "components": [], - "third_party": [] - }, - "build": { - "sub_component": [ - "//base/compileruntime/js_util_module/util:util_packages", - "//base/compileruntime/js_util_module/container:container_packages" - ], - "inner_kits": [], - "test": [] - } - } -} diff --git a/js_util_module/container/BUILD.gn b/js_util_module/container/BUILD.gn index 1807d3d..7dfd7fb 100644 --- a/js_util_module/container/BUILD.gn +++ b/js_util_module/container/BUILD.gn @@ -36,7 +36,7 @@ container_names = [ # compile .ts to .js. action("build_js_ts") { - script = "//base/compileruntime/js_util_module/container/build_ts_js.py" + script = "//commonlibrary/ets_utils/js_util_module/container/build_ts_js.py" args = [ "--dst-file", rebase_path(target_out_dir + "/"), @@ -104,7 +104,7 @@ template("container_lib") { include_dirs = [ "//third_party/node/src", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_util_module/container/" + name, + "//commonlibrary/ets_utils/js_util_module/container/" + name, ] sources = [ name + "/native_module_" + name + ".cpp" ] @@ -112,7 +112,7 @@ template("container_lib") { dep_abc = ":" + name + "_abc" dep_js = ":js_" + name deps = [ - "//base/compileruntime/js_util_module/container/:js_" + name, + "//commonlibrary/ets_utils/js_util_module/container/:js_" + name, "//foundation/arkui/napi/:ace_napi", "//utils/native/base:utils", ] @@ -124,8 +124,8 @@ template("container_lib") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_util" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module/util" } diff --git a/js_util_module/container/build_ts_js.py b/js_util_module/container/build_ts_js.py index 8200dc5..5077e41 100755 --- a/js_util_module/container/build_ts_js.py +++ b/js_util_module/container/build_ts_js.py @@ -35,7 +35,7 @@ if __name__ == '__main__': input_arguments = parser.parse_args() build_path = os.path.abspath(os.path.join(os.getcwd(), input_arguments.relative_path)) - os.chdir("%s/base/compileruntime/js_util_module/container/" % build_path) + os.chdir("%s/commonlibrary/ets_utils/js_util_module/container/" % build_path) NODE_PATH = '../../../../prebuilts/build-tools/common/nodejs/\ diff --git a/js_util_module/util/BUILD.gn b/js_util_module/util/BUILD.gn old mode 100755 new mode 100644 index dffba0e..a561780 --- a/js_util_module/util/BUILD.gn +++ b/js_util_module/util/BUILD.gn @@ -18,12 +18,12 @@ import("//foundation/arkui/ace_engine/ace_config.gni") # compile .ts to .js. action("build_ts_js") { - script = "//base/compileruntime/js_util_module/build_ts_js.py" + script = "//commonlibrary/ets_utils/js_util_module/build_ts_js.py" args = [ "--dst-file", rebase_path(target_out_dir + "/util_js.js"), "--module-path", - rebase_path("/base/compileruntime/js_util_module/util"), + rebase_path("/commonlibrary/ets_utils/js_util_module/util"), "--out-file", rebase_path("./out/util_js.js"), "--relative-path", @@ -83,7 +83,7 @@ ohos_shared_library("util") { "//third_party/icu/icu4c/source", "//third_party/node/src", "//foundation/arkui/napi/interfaces/kits", - "//base/compileruntime/js_util_module/util", + "//commonlibrary/ets_utils/js_util_module/util", ] sources = [ @@ -97,7 +97,7 @@ ohos_shared_library("util") { deps = [ ":util_abc", ":util_js", - "//base/compileruntime/js_util_module/util/:util_js", + "//commonlibrary/ets_utils/js_util_module/util/:util_js", "//foundation/arkui/napi/:ace_napi", "//foundation/arkui/napi/:ace_napi_quickjs", "//third_party/icu/icu4c:static_icuuc", @@ -109,8 +109,8 @@ ohos_shared_library("util") { } else { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_util" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_util_module/util/js_base64.cpp b/js_util_module/util/js_base64.cpp old mode 100755 new mode 100644 diff --git a/js_util_module/util/js_base64.h b/js_util_module/util/js_base64.h old mode 100755 new mode 100644 diff --git a/js_util_module/util/js_textdecoder.cpp b/js_util_module/util/js_textdecoder.cpp old mode 100755 new mode 100644 diff --git a/js_util_module/util/js_textdecoder.h b/js_util_module/util/js_textdecoder.h old mode 100755 new mode 100644 diff --git a/js_util_module/util/js_textencoder.cpp b/js_util_module/util/js_textencoder.cpp old mode 100755 new mode 100644 diff --git a/js_util_module/util/js_textencoder.h b/js_util_module/util/js_textencoder.h old mode 100755 new mode 100644 diff --git a/js_util_module/util/native_module_util.cpp b/js_util_module/util/native_module_util.cpp old mode 100755 new mode 100644 diff --git a/js_worker_module/BUILD.gn b/js_worker_module/BUILD.gn index b1ec3f8..bd04a87 100644 --- a/js_worker_module/BUILD.gn +++ b/js_worker_module/BUILD.gn @@ -15,9 +15,9 @@ import("//build/ohos.gni") ohos_shared_library("worker") { include_dirs = [ - "//base/compileruntime/js_worker_module/worker", - "//base/compileruntime/js_worker_module/helper", - "//base/compileruntime/js_worker_module/plugin", + "//commonlibrary/ets_utils/js_worker_module/worker", + "//commonlibrary/ets_utils/js_worker_module/helper", + "//commonlibrary/ets_utils/js_worker_module/plugin", ] sources = [ @@ -38,8 +38,8 @@ ohos_shared_library("worker") { external_deps = [ "hilog:libhilog" ] } - subsystem_name = "utils" - part_name = "jsapi_worker" + subsystem_name = "commonlibrary" + part_name = "ets_utils" relative_install_dir = "module" } diff --git a/js_worker_module/LICENSE b/js_worker_module/LICENSE deleted file mode 100644 index f433b1a..0000000 --- a/js_worker_module/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/js_worker_module/README.md b/js_worker_module/README.md deleted file mode 100644 index 523429d..0000000 --- a/js_worker_module/README.md +++ /dev/null @@ -1,367 +0,0 @@ -# js_worker_module - -### Introduction - -Worker enables JS to have the ability of multithreading, and completes the communication between worker thread and host thread through PostMessage. - -### Interface description -For interface implementation, see: js_worker_module/jsapi/worker - -#### Worker object description - -The object object used by the host thread to communicate with the worker thread. - -##### Interface - -1. - -- name - -|constructor(scriptURL:string, options? WorkerOptions) | worker constructor to Creates a worker instance | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -``` - -2. - -- name - -| postMessage(message:Object, options?:PostMessageOptions) | Sends a message to the worker thread | -|---|---| -| postMessage(message:Object, transfer:ArrayBuffer[]) | Sends a message to the worker thread | - -- example - -``` -// example 1 -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// example 2 -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -var buffer = new ArrayBuffer(8); -worker.postMessage(buffer, [buffer]); -``` - -3. - -- name - -| on(type:string, listener:EventListener) | Adds an event listener to the worker | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.on("alert", (e)=>{ - console.log("worker on..."); -}) -``` - -4. - -- name - -| once(type:string, listener:EventListener) | Adds an event listener to the worker and removes the event listener automically after it is invoked once | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.once("alert", (e)=>{ - console.log("worker on..."); -}) -``` - -5. - -- name - -| off(type:string, listener?:EventListener) | Removes an event listener to the worker | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.off("alert"); -``` - -6. - -- name - -| terminate() | Terminates the worker thread to stop the worker from receiving messages | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.terminate(); -``` - -7. - -- name - -| removeEventListener(type:string, listener?:EventListener) | Removes an event defined for the worker | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.removeEventListener("alert"); -``` - -8. - -- name - -| dispatchEvent(event: Event) | Dispatches the event defined for the worker | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.dispatchEvent({type:"alert"}); -``` - -9. - -- name - -| removeAllListener() | Removes all event listeners for the worker | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.removeAllListener(); -``` - -##### Attribute - -1. - -- name - -| onexit?:(code:number)=>void | The onexit attribute of the worker specifies the event handler to be called when the worker exits. The handler is executed in the host thread | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onexit = function(e) { - console.log("onexit..."); -} -``` - -2. - -- name - -| onerror?:(ev:ErrorEvent)=>void | The onerror attribute of the worker specifies the event handler to be called when an exception occurs during worker execution. The event handler is executed in the host thread | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onerror = function(e) { - console.log("onerror..."); -} -``` - -3. - -- name - -| onmessage?:(ev:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler to be called then the host thread receives a message created by itself and sent by the worker through the parentPort.postMessage. The event handler is executed in the host thread | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onmessage = function(e) { - console.log("onmessage..."); -} -``` - -4. - -- name - -| onmessageerror?:(event:MessageEvent)=>void | The onmessage attribute of the worker specifies the event handler when the worker receives a message that cannot be serialized. The event handler is executed in the host thread | -|---|---| - -- example - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onmessageerror = function(e) { - console.log("onmessageerror..."); -} -``` - -#### parentPort object description - -Object of the worker thread used to communicate with the host thread - -##### Interface - -1. - -- name - -| postMessage(message:Object, options?:PostMessageOptions) | Send a message to host thread | -|---|---| -| postMessage(message:Object, transfer:ArrayBuffer[]) | Send a message to host thread | - -- example - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessage = function(e) { - parentPort.postMessage("hello world from worker.js"); -} -``` - -2. - -- name - -| close() | Close the worker thread to stop the worker from receiving messages | -|---|---| - -- example - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessage = function(e) { - parentPort.close(); -} -``` - -##### Attribute - -1. - -- name - -| onmessage?:(event:MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called then the worker thread receives a message sent by the host thread through worker postMessage. The event handler is executed in the worker thread | -|---|---| - -- example - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessage = function(e) { - console.log("receive main.js message"); -} -``` - -2. - -- name - -| onerror?:(ev: ErrorEvent)=>void | The onerror attribute of parentPort specifies the event handler to be called when an exception occurs during worker execution. The event handler is executed in the worker thread | -|---|---| - -- example - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onerror = function(e) { - console.log("onerror..."); -} - -``` - -3. - -- name - -| onmessageerror?:(event: MessageEvent)=>void | The onmessage attribute of parentPort specifies the event handler to be called then the worker receives a message that cannot be deserialized. The event handler is executed in the worker thread. | -|---|---| - -- example - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessageerror = function(e) { - console.log("onmessageerror..."); -} -``` - -### Repositories Involved - -- ace_ace_engine(foundation/arkui/ace_engine-readme.md) -- ace_napi(foundation/arkui/napi-readme.md) - -## Related warehouse -[js_worker_module Subsystem](base/compileruntime/js_worker_module-readme.md) - -### License - -Worker is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_worker_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony/js_worker_module/blob/master/LICENSE) for the full license text. \ No newline at end of file diff --git a/js_worker_module/README.zh.md b/js_worker_module/README.zh.md deleted file mode 100644 index c51d497..0000000 --- a/js_worker_module/README.zh.md +++ /dev/null @@ -1,368 +0,0 @@ -# js_worker_module - -### 简介 - -worker能够让js拥有多线程的能力,通过postMessage完成worker线程与宿主线程通信。 - -### 接口说明 -接口实现详见:js_worker_module/jsapi/worker - -#### Worker对象描述 - -宿主线程用于与worker线程通信的Object对象。 - -##### 接口 - -1. - -- 接口名 - -|constructor(scriptURL:string, options? WorkerOptions) | 构造函数 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -``` - -2. - -- 接口名 - -| postMessage(message:Object, options?:PostMessageOptions) | 向worker线程发送消息 | -|---|---| -| postMessage(message:Object, transfer:ArrayBuffer[]) | 向worker线程发送消息 | - -- 使用示例 - -``` -// 示例一 -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// 示例二 -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -var buffer = new ArrayBuffer(8); -worker.postMessage(buffer, [buffer]); -``` - -3. - -- 接口名 - -| on(type:string, listener:EventListener) | 向worker添加一个事件监听 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.on("alert", (e)=>{ - console.log("worker on..."); -}) -``` - -4. - -- 接口名 - -| once(type:string, listener:EventListener) | 向worker添加一个事件监听, 事件监听只执行一次便自动删除 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.once("alert", (e)=>{ - console.log("worker on..."); -}) -``` - -5. - -- 接口名 - -| off(type:string, listener?:EventListener) | 删除worker的事件监听 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.off("alert"); -``` - -6. - -- 接口名 - -| terminate() | 关闭worker线程,终止worker发送消息 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.terminate(); -``` - -7. - -- 接口名 - -| removeEventListener(type:string, listener?:EventListener) | 删除worker的事件监听 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.removeEventListener("alert"); -``` - -8. - -- 接口名 - -| dispatchEvent(event: Event) | 分发定义在worker的事件 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.dispatchEvent({type:"alert"}); -``` - -9. - -- 接口名 - -| removeAllListener() | 删除worker的所有事件监听 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.removeAllListener(); -``` - -##### 属性 - -1. - -- 属性名 - -| onexit?:(code:number)=>void | worker退出时被调用的事件处理程序,处理程序在宿主线程中执行 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onexit = function(e) { - console.log("onexit..."); -} -``` - -2. - -- 属性名 - -| onerror?:(ev:ErrorEvent)=>void | worker在执行过程中发生异常被调用的事件处理程序,处理程序在宿主线程中执行 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onerror = function(e) { - console.log("onerror..."); -} -``` - -3. - -- 属性名 - -| onmessage?:(ev:MessageEvent)=>void | 宿主线程收到来自其创建的worker通过parentPort.postMessage接口发送的消息时被调用的事件处理程序, 处理程序在宿主线程中执行 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onmessage = function(e) { - console.log("onmessage..."); -} -``` - -4. - -- 属性名 - -| onmessageerror?:(event:MessageEvent)=>void | worker对象接收到一条无法序列化的消息时被调用的事件处理程序, 处理程序在宿主线程中执行 | -|---|---| - -- 使用示例 - -``` -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.onmessageerror = function(e) { - console.log("onmessageerror..."); -} -``` - -#### parentPort对象描述 - -worker线程用于与宿主线程通信的Object对象。 - -##### 接口 - -1. - -- 接口名 - -| postMessage(message:Object, options?:PostMessageOptions) | 向宿主线程发送消息 | -|---|---| -| postMessage(message:Object, transfer:ArrayBuffer[]) | 向宿主线程发送消息 | - -- 使用示例 - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessage = function(e) { - parentPort.postMessage("hello world from worker.js"); -} -``` - -2. - -- 接口名 - -| close() | 关闭worker线程,终止worker接收消息 | -|---|---| - -- 使用示例 - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessage = function(e) { - parentPort.close(); -} -``` - -##### 属性 - -1. - -- 属性名 - -| onmessage?:(event:MessageEvent)=>void | 宿主线程收到来自其创建的worker通过worker.postMessage接口发送的消息时被调用的事件处理程序,处理程序在worker线程中执行 | -|---|---| - -- 使用示例 - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessage = function(e) { - console.log("receive main.js message"); -} -``` - -2. - -- 属性名 - -| onerror?:(ev: ErrorEvent)=>void | worker在执行过程中发生异常被调用的事件处理程序,处理程序在worker线程中执行 | -|---|---| - -- 使用示例 - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onerror = function(e) { - console.log("onerror..."); -} - -``` - -3. - -- 属性名 - -| onmessageerror?:(event: MessageEvent)=>void | worker对象接收到一条无法被反序列化的消息时被调用的事件处理程序, 处理程序在worker线程中执行 | -|---|---| - -- 使用示例 - -``` -// main.js -import worker from "@ohos.worker" -const worker = new worker.Worker("workers/worker.js"); -worker.postMessage("hello world"); - -// worker.js -import worker from "@ohos.worker" -const parentPort = worker.parentPort; -parentPort.onmessageerror = function(e) { - console.log("onmessageerror..."); -} -``` - -### 涉及仓 - -- ace_ace_engine(foundation/arkui/ace_engine-readme_zh.md) -- ace_napi(foundation/arkui/napi-readme_zh.md) - -## 相关仓 -[js_worker_module 子系统](base/compileruntime/js_worker_module-readme_zh.md) - - -### 许可证 - -Worker在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_worker_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony/js_worker_module/blob/master/LICENSE) \ No newline at end of file diff --git a/js_worker_module/bundle.json b/js_worker_module/bundle.json deleted file mode 100644 index a225bf3..0000000 --- a/js_worker_module/bundle.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "name": "@ohos/js_worker_module", - "version": "", - "description": "Provide JS multi-threading capability | 提供JS多线程能力", - "homePage": "https://gitee.com/openharmony", - "license": "Apache V2", - "repository": "https://gitee.com/openharmony/js_worker_module", - "domain": "os", - "language": "", - "publishAs": "code-segment", - "private": false, - "scripts": {}, - "tags": [ - "js" - ], - "keywords": [ - "js", - "worker", - "module" - ], - "envs": {}, - "dirs": {}, - "author": { - "name": "", - "email": "", - "url": "" - }, - "contributors": [ - { - "name": "", - "email": "", - "url": "" - } - ], - "segment": { - "destPath": "base/compileruntime/js_worker_module" - }, - "component": { - "name": "jsapi_worker", - "subsystem": "utils", - "syscap": [], - "features": [], - "adapted_system_type": [], - "rom": "", - "ram": "", - "deps": { - "components": [], - "third_party": [] - }, - "build": { - "sub_component": [ - "//base/compileruntime/js_worker_module:jsapi_packages" - ], - "inner_kits": [], - "test": [] - } - } -} diff --git a/js_worker_module/helper/napi_helper.cpp b/js_worker_module/helper/napi_helper.cpp index 384ca95..a05c14f 100644 --- a/js_worker_module/helper/napi_helper.cpp +++ b/js_worker_module/helper/napi_helper.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "base/compileruntime/js_worker_module/helper/napi_helper.h" +#include "napi_helper.h" #include "native_engine/native_value.h" diff --git a/js_worker_module/plugin/timer.cpp b/js_worker_module/plugin/timer.cpp index 4cd59ad..871d476 100644 --- a/js_worker_module/plugin/timer.cpp +++ b/js_worker_module/plugin/timer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "base/compileruntime/js_worker_module/plugin/timer.h" +#include "timer.h" #include "utils/log.h" diff --git a/js_worker_module/plugin/timer.h b/js_worker_module/plugin/timer.h index 08a2cb5..36c4896 100644 --- a/js_worker_module/plugin/timer.h +++ b/js_worker_module/plugin/timer.h @@ -19,8 +19,8 @@ #include #include -#include "base/compileruntime/js_worker_module/helper/napi_helper.h" -#include "base/compileruntime/js_worker_module/helper/object_helper.h" +#include "../helper/napi_helper.h" +#include "../helper/object_helper.h" #include "napi/native_api.h" #include "napi/native_node_api.h" diff --git a/js_worker_module/worker/message_queue.cpp b/js_worker_module/worker/message_queue.cpp index 66301a2..ea4fb1b 100644 --- a/js_worker_module/worker/message_queue.cpp +++ b/js_worker_module/worker/message_queue.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "base/compileruntime/js_worker_module/worker/message_queue.h" +#include "message_queue.h" #include "utils/log.h" namespace CompilerRuntime::WorkerModule { diff --git a/js_worker_module/worker/native_module_worker.cpp b/js_worker_module/worker/native_module_worker.cpp index 327d215..26816f5 100644 --- a/js_worker_module/worker/native_module_worker.cpp +++ b/js_worker_module/worker/native_module_worker.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "base/compileruntime/js_worker_module/worker/worker.h" +#include "worker.h" /* * module define diff --git a/js_worker_module/worker/thread.cpp b/js_worker_module/worker/thread.cpp index 28432ac..c2103f1 100644 --- a/js_worker_module/worker/thread.cpp +++ b/js_worker_module/worker/thread.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "base/compileruntime/js_worker_module/worker/thread.h" +#include "thread.h" namespace CompilerRuntime::WorkerModule { Thread::Thread() : tId_() {} diff --git a/js_worker_module/worker/worker.cpp b/js_worker_module/worker/worker.cpp index 7265104..e63eec6 100644 --- a/js_worker_module/worker/worker.cpp +++ b/js_worker_module/worker/worker.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "base/compileruntime/js_worker_module/worker/worker.h" -#include "base/compileruntime/js_worker_module/plugin/timer.h" +#include "worker.h" +#include "../plugin/timer.h" namespace CompilerRuntime::WorkerModule { const static int MAXWORKERS = 8; diff --git a/js_worker_module/worker/worker.h b/js_worker_module/worker/worker.h index df28846..69cfb2e 100644 --- a/js_worker_module/worker/worker.h +++ b/js_worker_module/worker/worker.h @@ -19,10 +19,10 @@ #include #include #include -#include "base/compileruntime/js_worker_module/worker/message_queue.h" -#include "base/compileruntime/js_worker_module/helper/napi_helper.h" -#include "base/compileruntime/js_worker_module/helper/object_helper.h" -#include "base/compileruntime/js_worker_module/worker/worker_runner.h" +#include "message_queue.h" +#include "../helper/napi_helper.h" +#include "../helper/object_helper.h" +#include "worker_runner.h" #include "napi/native_api.h" #include "napi/native_node_api.h" #include "native_engine/native_engine.h" diff --git a/js_worker_module/worker/worker_runner.cpp b/js_worker_module/worker/worker_runner.cpp index 3b535fd..cc4e21d 100644 --- a/js_worker_module/worker/worker_runner.cpp +++ b/js_worker_module/worker/worker_runner.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ -#include "base/compileruntime/js_worker_module/worker/worker_runner.h" +#include "worker_runner.h" -#include "base/compileruntime/js_worker_module/helper/object_helper.h" +#include "../helper/object_helper.h" namespace CompilerRuntime::WorkerModule { WorkerRunner::WorkerRunner(WorkerStartCallback callback) : callback_(callback), selfThreadId_(uv_thread_self()) {} diff --git a/js_worker_module/worker/worker_runner.h b/js_worker_module/worker/worker_runner.h index ca3dbff..f48c6da 100644 --- a/js_worker_module/worker/worker_runner.h +++ b/js_worker_module/worker/worker_runner.h @@ -19,7 +19,7 @@ #include #include "native_engine/native_engine.h" -#include "base/compileruntime/js_worker_module/worker/thread.h" +#include "thread.h" namespace CompilerRuntime::WorkerModule { struct WorkerStartCallback {