oop-node

1.7.1 • Public • Published

oop-node

OOP模式的结构化节点

安装

npm i oop-node

继承结构

BaseNode
    - NamedNode
        - Attribute
        - ElementAbstract
            - ElementBase
                + AttributeList :: attributes
                - ElementComment
                - ElementText
                - Element
                    + NodeList<ElementAbstract> :: childNodes
        - Document
            + NodeList<ElementAbstract> :: childNodes
    - TreeNode
BaseList
    - TypedList<T>
        - NodeList<T>
            - AttributeList<Attribute>

使用

代码

const { Document } = require('oop-element');
 
let document = new Document();
let div = doc.appendChild(doc.createElement('view'));
div.setAttribute('class', 'user-name').setAttribute('date', '2019-04-07');
div.appendChild(doc.createComment('User Name'));
div.appendChild(doc.createElement('h1')).appendChild(doc.createText('Hello~'));
div.appendChild(doc.createText('Marvin'));
div.appendChild(doc.createElement('image')).setAttribute('src', 'http://asdfsadfsa.asfdfa.com');
div.appendChild(doc.createComment('User Name End'));
console.log(doc.toString());

输出

<view class="user-name" date="2019-04-07"><!-- User Name -->Marvin<!-- User Name End --></view>

带缩进

let document = new Document({
    format: true,   // 带格式
    indent: '    ', // 缩进字符串(默认2空格)
});
 

输出

<view class="user-name" date="2019-04-07">
    <!-- User Name -->
    Marvin
    <!-- User Name End -->
</view>

Readme

Keywords

Package Sidebar

Install

npm i oop-node

Weekly Downloads

1

Version

1.7.1

License

ISC

Unpacked Size

25.8 kB

Total Files

24

Last publish

Collaborators

  • imnull