提交 92d95203 编写于 作者: G Gloria

Update docs against 14854+15143+14996

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 2db0ad1e
......@@ -47,21 +47,27 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
**Example**
```js
let xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let conv = new convertxml.ConvertXML()
let options = {trim : false, declarationKey:"_declaration",
instructionKey : "_instruction", attributesKey : "_attributes",
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
nameKey : "_name", elementsKey : "_elements"}
let result = JSON.stringify(conv.convertToJSObject(xml, options));
console.log(result);
try {
let xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let conv = new convertxml.ConvertXML()
let options = {
trim: false, declarationKey: "_declaration",
instructionKey: "_instruction", attributesKey: "_attributes",
textKey: "_text", cdataKey: "_cdata", doctypeKey: "_doctype",
commentKey: "_comment", parentKey: "_parent", typeKey: "_type",
nameKey: "_name", elementsKey: "_elements"
}
let result = JSON.stringify(conv.convertToJSObject(xml, options));
console.log(result);
} catch (e) {
console.log(e.toString());
}
// Output (non-compact)
// {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note","_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title","_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Play"}]}]}]}
```
......
# @ohos.reminderAgentManager (Reminder Agent Management)
# @ohos.reminderAgentManager (reminderAgentManager)
The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent.
......@@ -696,8 +696,8 @@ Sets the time information for a calendar reminder.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| year | number | Yes| Year.|
| month | number | Yes| Month.|
| day | number | Yes| Date.|
| hour | number | Yes| Hour.|
| minute | number | Yes| Minute.|
| second | number | No| Second.|
| month | number | Yes| Month. The value ranges from 1 to 12.|
| day | number | Yes| Day. The value ranges from 1 to 31.|
| hour | number | Yes| Hour. The value ranges from 0 to 23.|
| minute | number | Yes| Minute. The value ranges from 0 to 59.|
| second | number | No| Second. The value ranges from 0 to 59.|
......@@ -26,7 +26,7 @@ Formats the specified values and inserts them into the string by replacing the w
| Name | Type | Mandatory| Description |
| ------- | -------- | ---- | -------------- |
| format | string | Yes | String.|
| ...args | Object[] | No | Values to format. The formatted values will be replaced the wildcard in the string. |
| ...args | Object[] | No | Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
**Return value**
......@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum);
console.log("result = " + result);
```
**Some error code and message examples**
| Error Code| Message |
| ------ | -------------------------------- |
| -1 | operation not permitted |
| -2 | no such file or directory |
| -3 | no such process |
| -4 | interrupted system call |
| -5 | i/o error |
| -11 | resource temporarily unavailable |
| -12 | not enough memory |
| -13 | permission denied |
| -100 | network is down |
## util.callbackWrapper
callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void
......@@ -92,15 +106,14 @@ Calls back an asynchronous function. In the callback, the first parameter indica
**Example**
```js
async function promiseFn() {
return Promise.reject('value');
}
let err = "type err";
let cb = util.callbackWrapper(promiseFn);
cb((err, ret) => {
console.log(err);
console.log(ret);
}, err)
async function fn() {
return 'hello world';
}
let cb = util.callbackWrapper(fn);
cb((err, ret) => {
if (err) throw err;
console.log(ret);
});
```
## util.promisify<sup>9+</sup>
......@@ -126,24 +139,30 @@ Processes an asynchronous function and returns a promise.
**Example**
```js
function aysnFun(str1, str2) {
if (typeof str1 === 'object' && typeof str2 === 'object') {
return str2
} else {
return str1
}
}
let newPromiseObj = util.promisify(aysnFun);
newPromiseObj({ err: "type error" }, {value:'HelloWorld'}).then(res => {
console.log(res);
})
function fun(num, callback) {
if (typeof num === 'number') {
callback(null, num + 3);
} else {
callback("type err");
}
}
const addCall = util.promisify(fun);
(async () => {
try {
let res = await addCall(2);
console.log(res);
} catch (err) {
console.log(err);
}
})();
```
## util.randomUUID<sup>9+</sup>
## util.generateRandomUUID<sup>9+</sup>
randomUUID(entropyCache?: boolean): string
generateRandomUUID(entropyCache?: boolean): string
Uses a secure random number generator to generate a random universally unique identifier (UUID) of RFC 4122 version 4.
Uses a secure random number generator to generate a random universally unique identifier (UUID) of the string type in RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
......@@ -162,17 +181,17 @@ Uses a secure random number generator to generate a random universally unique id
**Example**
```js
let uuid = util.randomUUID(true);
let uuid = util.generateRandomUUID(true);
console.log("RFC 4122 Version 4 UUID:" + uuid);
// Output:
// RFC 4122 Version 4 UUID:88368f2a-d5db-47d8-a05f-534fab0a0045
```
## util.randomBinaryUUID<sup>9+</sup>
## util.generateRandomBinaryUUID<sup>9+</sup>
randomBinaryUUID(entropyCache?: boolean): Uint8Array
generateRandomBinaryUUID(entropyCache?: boolean): Uint8Array
Uses a secure random number generator to generate a random binary UUID of RFC 4122 version 4.
Uses a secure random number generator to generate a random UUID of the Uint8Array type in RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
......@@ -191,7 +210,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41
**Example**
```js
let uuid = util.randomBinaryUUID(true);
let uuid = util.generateRandomBinaryUUID(true);
console.log(JSON.stringify(uuid));
// Output:
// 138,188,43,243,62,254,70,119,130,20,235,222,199,164,140,150
......@@ -201,7 +220,7 @@ Uses a secure random number generator to generate a random binary UUID of RFC 41
parseUUID(uuid: string): Uint8Array
Parses a UUID from a string, as described in RFC 4122 version 4.
Converts the UUID of the string type generated by **generateRandomUUID** to the UUID of the **Uint8Array** type generated by **generateRandomBinaryUUID**, as described in RFC 4122 version 4.
**System capability**: SystemCapability.Utils.Lang
......@@ -243,7 +262,7 @@ Formats the specified values and inserts them into the string by replacing the w
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| format | string | Yes| String.|
| ...args | Object[] | No| Values to format. The formatted values will be replaced the wildcard in the string.|
| ...args | Object[] | No| Values to format. The formatted values will replace the wildcard in the string. If this parameter is not set, the first parameter is returned by default.|
**Return value**
......@@ -361,8 +380,8 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate
**Example**
```js
let textDecoder = new util.TextDecoder()
textDecoder.create('utf-8', { ignoreBOM : true });
let result = util.TextDecoder.create('utf-8', { ignoreBOM : true })
let retStr = result.encoding
```
### decodeWithStream<sup>9+</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册