Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@vivaxy/wxml

vivaxy850MIT2.1.0TypeScript support: included

🌇WXML parser and serializer.

wxml, vivaxy, wxml-parser, wxml-serializer, wxml-traverser, wxml-stringifier, parse-wxml, serialize-wxml, traverse-wxml, stringify-wxml, weixin, mp, wxmp, miniprogram, parse, traverse, serialize, parser, traverser, serializer

readme

WXML

🌇WXML parser and serializer.

Build Status NPM Version NPM Downloads MIT License Standard Version Codecov

Install

yarn add @vivaxy/wxml or npm i @vivaxy/wxml --save

Usage

import * as wxml from '@vivaxy/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

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.1.0 (2020-05-20)

Features

  • index: :sparkles: exports NODE_TYPES enum (98b4805)

2.0.3 (2020-05-20)

Bug Fixes

  • serialize: :bug: fix the wrong result when serializing double quotes in attributes (cc29f0f)

2.0.2 (2020-05-19)

Bug Fixes

  • project: :bug: fix typings (8b13436)

2.0.1 (2020-05-05)

Bug Fixes

  • parse: :bug: Fix Unexpected node error (4bb1217)

2.0.0 (2020-01-23)

⚠ BREAKING CHANGES

  • element-node: rename attrs to attributes; rename text to textContent; rename node type from string to number; enforce attributes, childNodes and selfClosing attributes exists on json object

  • element-node: :recycle: rename attrs to attributes (d7e5781)

1.0.0 (2019-12-15)

0.2.3 (2019-08-16)

0.2.2 (2018-09-08)

0.2.1 (2018-09-08)

0.2.0 (2018-09-08)

Features

  • parse: :sparkles:Refactor output data structure (2390d16)

0.1.2 (2018-09-08)

Bug Fixes

0.1.1 (2018-09-08)

Bug Fixes

0.1.0 (2018-08-16)

Features