提交 21775e9b 编写于 作者: J jiangkai43

Modify the code and function descriptions

Signed-off-by: Njiangkai43 <jiangkai43@huawei.com>
上级 f96b7aef
...@@ -47,21 +47,27 @@ convertToJSObject(xml: string, options?: ConvertOptions) : Object ...@@ -47,21 +47,27 @@ convertToJSObject(xml: string, options?: ConvertOptions) : Object
**示例:** **示例:**
```js ```js
let xml = try {
'<?xml version="1.0" encoding="utf-8"?>' + let xml =
'<note importance="high" logged="true">' + '<?xml version="1.0" encoding="utf-8"?>' +
' <title>Happy</title>' + '<note importance="high" logged="true">' +
' <todo>Work</todo>' + ' <title>Happy</title>' +
' <todo>Play</todo>' + ' <todo>Work</todo>' +
'</note>'; ' <todo>Play</todo>' +
let conv = new convertxml.ConvertXML() '</note>';
let options = {trim : false, declarationKey:"_declaration", let conv = new convertxml.ConvertXML()
instructionKey : "_instruction", attributesKey : "_attributes", let options = {
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype", trim: false, declarationKey: "_declaration",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type", instructionKey: "_instruction", attributesKey: "_attributes",
nameKey : "_name", elementsKey : "_elements"} textKey: "_text", cdataKey: "_cdata", doctypeKey: "_doctype",
let result = JSON.stringify(conv.convertToJSObject(xml, options)); commentKey: "_comment", parentKey: "_parent", typeKey: "_type",
console.log(result); 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"}]}]}]} // {"_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 ...@@ -26,7 +26,7 @@ format(format: string, ...args: Object[]): string
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | -------- | ---- | -------------- | | ------- | -------- | ---- | -------------- |
| format | string | 是 | 式样化字符串。 | | format | string | 是 | 式样化字符串。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据 | | ...args | Object[] | 否 | 替换式样化字符串通配符的数据,此参数缺失时,默认返回第一个参数。 |
**返回值:** **返回值:**
...@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum); ...@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum);
console.log("result = " + result); 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 ## util.callbackWrapper
callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void callbackWrapper(original: Function): (err: Object, value: Object )=&gt;void
...@@ -126,17 +140,23 @@ promisify(original: (err: Object, value: Object) =&gt; void): Function ...@@ -126,17 +140,23 @@ promisify(original: (err: Object, value: Object) =&gt; void): Function
**示例:** **示例:**
```js ```js
function aysnFun(str1, str2) { function fun(num, callback) {
if (typeof str1 === 'object' && typeof str2 === 'object') { if (typeof num === 'number') {
return str2 callback(null, num + 3);
} else { } else {
return str1 callback("type err");
} }
} }
let newPromiseObj = util.promisify(aysnFun);
newPromiseObj({ err: "type error" }, {value:'HelloWorld'}).then(res => { const addCall = util.promisify(fun);
console.log(res); (async () => {
}) try {
let res = await addCall(2);
console.log(res);
} catch (err) {
console.log(err);
}
})();
``` ```
## util.randomUUID<sup>9+</sup> ## util.randomUUID<sup>9+</sup>
...@@ -243,7 +263,7 @@ printf(format: string, ...args: Object[]): string ...@@ -243,7 +263,7 @@ printf(format: string, ...args: Object[]): string
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| format | string | 是 | 式样化字符串。 | | format | string | 是 | 式样化字符串。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据。 | | ...args | Object[] | 否 | 替换式样化字符串通配符的数据,此参数缺失时,默认返回第一个参数。 |
**返回值:** **返回值:**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册