@icebreakers/wxml

v1.0.2
wxml parser and serializer. fork form wxml and improve. thanks to vivaxy and roadupcc
wxml wxml-parser wxml-serializer parse-wxml serialize-wxml traverse-wxml stringify-wxml miniprogram parse and 6 more...

WXML

wxml parser and serializer.

Build Status NPM Version NPM Downloads MIT License Standard Version Codecov

Install

yarn add wxml or npm i wxml --save

Usage

import * as wxml from 'wxml';
const parsed = wxml.parse('<view></view>');
wxml.traverse(parsed, function visitor(node, parent) {
  const type = node.type;
  const parentNode = node.parentNode;

  if (type === wxml.NODE_TYPES.ELEMENT) {
    // handle element node
    const tagName = node.tagName;
    const attributes = node.attributes; // an object represents the attributes
    const childNodes = node.childNodes;
    const selfClosing = node.selfClosing; // if a node is self closing, like `<tag />`
  } else if (type === wxml.NODE_TYPES.TEXT) {
    // handle text node
    const textContent = node.textContent;
  } else if (type === wxml.NODE_TYPES.COMMENT) {
    // handle comment node
    const comment = node.comment;
  }
});
const serialized = wxml.serialize(parsed);

API

parse

(input: string) => AST

traverse

(node: Node, visitor: (node: Node, parent: Node) => void) => void

serialize

(node: Node) => string

npm i @icebreakers/wxml

Metadata

  • MIT
  • Whatever
  • SonOfMagic
  • released 5/10/2022

Downloads

Maintainers