1.5.4 • Published 5 years ago

xconv v1.5.4

Weekly downloads
39
License
ISC
Repository
github
Last release
5 years ago

xconv

标记语言转换器

更新

  • 1.1.0 x-reader.read_attr$value内部参数错误修复。

NPM: https://www.npmjs.com/package/xconv

使用

npm i xconv
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(`
<text disabled a=1 b=2 data-city='{{util.cal("a", 1)}}'>
<!-- comment -->
fdasfasdadf{{couponInfo.parValue('abc', 1)}}<button disabled />
</text>
`, { format: true, indent: '    ' }
).root.toString());

输出:

{
    "a": 1,
    "b": [
        {
            "c": 1
        },
        null,
        1,
        2,
        "123",
        "{}}}([[[]]]]]])"
    ]
}
<root>
    <text disabled a="1" b="2" data-city='{{util.cal("a", 1)}}'>
        <!-- comment -->
        fdasfasdadf
        {{ couponInfo.parValue('abc', 1) }}
        <button disabled/>
    </text>
</root>

Generic-JSON

泛JSON类型,包含 JSONJSONPJS-Object 等多种标准嵌套封闭的文本格式。

QUOTE不敏感

对 双引号(")、单引号(')、撇号(`) 等可识别。

JSONP可识别

callback({
    a: 1,
    b: [
        { c: 1 }, null, 1, 2
        '123',
        "{}}}([[[]]]]]])",
    ],
});

转换结果

{
    "a": 1,
    "b": [
        {
            "c": 1
        },
        null,
        1,
        2,
        "123",
        "{}}}([[[]]]]]])"
    ]
}

Generic-XML

XML的标签识别,主要依赖对<>的成对标记解析。

松散的属性分析

标签内属性基本遵循HTML的松散原则,对引号("')和独立标记属性(disabledchecked 等等)可识别。

基于oop-node的DOM树构建

https://www.npmjs.com/package/oop-node

格式化输出

对缩进和换行的格式化

const { jsonx, xmlx } = require('./index');
console.log(xmlx.parse(`
<text disabled a=1 b=2 data-city='{{util.cal("a", 1)}}'>
<!-- comment -->
fdasfasdadf{{couponInfo.parValue('abc', 1)}}<button disabled />
</text>
`, { format: true, indent: '    ' }).root.toString());

输出结果

<root>
    <text disabled a="1" b="2" data-city='{{util.cal("a", 1)}}'>
        <!-- comment -->
        fdasfasdadf
        {{ couponInfo.parValue('abc', 1) }}
        <button disabled/>
    </text>
</root>

注意:当节点属性被识别为数据绑定时,会保留原始的属性包围引号。...data-city='{{util.cal("a", 1)}}'...

Readers

Readers是解析器的依赖。对应不同的文档。JReaderXReader继承自Reader

const {
    Reader,
    JReader,
    XReader
} = require('xconv');

Reader

读取一般的引号封闭与语法嵌套

JReader

对应jsonx,读取Generic-JSON文本。

XReader

对应xmlx,读取Generic-XML文本。

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.3.14

5 years ago

1.3.13

5 years ago

1.3.12

5 years ago

1.3.11

5 years ago

1.3.10

5 years ago

1.3.9

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.0

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago