未验证 提交 b4ccb36e 编写于 作者: O openharmony_ci 提交者: Gitee

!15175 修改promisify示例代码,uuid函数描述,增加convertToJSObject接口的错误码捕获【OpenHarmony-3.2-Beta5】

Merge pull request !15175 from jwx1068251/OpenHarmony-3.2-Beta5
......@@ -47,21 +47,27 @@ convertToJSObject(xml: string, options?: ConvertOptions) : Object
**示例:**
```js
let xml =
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);
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());
}
// 输出(宽泛型)
// {"_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"}]}]}]}
```
......
......@@ -26,7 +26,7 @@ format(format: string, ...args: Object[]): string
| 参数名 | 类型 | 必填 | 说明 |
| ------- | -------- | ---- | -------------- |
| format | string | 是 | 式样化字符串。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据,此参数缺失时,默认返回第一个参数。 |
**返回值:**
......@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum);
console.log("result = " + result);
```
**部分错误码及信息示例:**
| 错误码 | 信息 |
| ------ | -------------------------------- |
| -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
......@@ -126,17 +140,23 @@ promisify(original: (err: Object, value: Object) =&gt; void): Function
**示例:**
```js
function aysnFun(str1, str2) {
if (typeof str1 === 'object' && typeof str2 === 'object') {
return str2
function fun(num, callback) {
if (typeof num === 'number') {
callback(null, num + 3);
} else {
return str1
callback("type err");
}
}
let newPromiseObj = util.promisify(aysnFun);
newPromiseObj({ err: "type error" }, {value:'HelloWorld'}).then(res => {
}
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>
......@@ -243,7 +263,7 @@ printf(format: string, ...args: Object[]): string
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| format | string | 是 | 式样化字符串。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据,此参数缺失时,默认返回第一个参数。 |
**返回值:**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册