Structured text resolver
npm install xconv1.1.0 x-reader.read_attr$value内部参数错误修复。NPM: https://www.npmjs.com/package/xconv
``js
const { jsonx, xmlx } = require('xconv');
console.log(JSON.stringify(jsonx.parse(callback({
a: 1,
b: [
{ c: 1 }, null, 1, 2
'123',
"{}}}([[[]]]]]])",
],
});), null, ' '))
console.log(
xmlx.parse(
fdasfasdadf{{couponInfo.parValue('abc', 1)}}, { format: true, indent: ' ' }`
).root.toString());
输出:
`js`
{
"a": 1,
"b": [
{
"c": 1
},
null,
1,
2,
"123",
"{}}}([[[]]]]]])"
]
}`html`
fdasfasdadf
{{ couponInfo.parValue('abc', 1) }}
、JSONP、JS-Object 等多种标准嵌套封闭的文本格式。$3
对 双引号(")、单引号(')、撇号() 等可识别。```
callback({
a: 1,
b: [
{ c: 1 }, null, 1, 2
'123',
"{}}}([[[]]]]]])",
],
});
转换结果
`js`
{
"a": 1,
"b": [
{
"c": 1
},
null,
1,
2,
"123",
"{}}}([[[]]]]]])"
]
}
的标签识别,主要依赖对<和>的成对标记解析。$3
标签内属性基本遵循HTML的松散原则,对引号("')和独立标记属性(disabled、checked 等等)可识别。$3
https://www.npmjs.com/package/oop-node$3
对缩进和换行的格式化`js
const { jsonx, xmlx } = require('./index');
console.log(xmlx.parse(, { format: true, indent: ' ' }).root.toString());
`输出结果
`html
fdasfasdadf
{{ couponInfo.parValue('abc', 1) }}
`注意:当节点属性被识别为数据绑定时,会保留原始的属性包围引号。
...data-city='{{util.cal("a", 1)}}'...Readers
Readers是解析器的依赖。对应不同的文档。JReader和XReader继承自Reader。`js
const {
Reader,
JReader,
XReader
} = require('xconv');
`
$3
读取一般的引号封闭与语法嵌套$3
对应jsonx,读取Generic-JSON文本。$3
对应xmlx,读取Generic-XML`文本。