Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vivaxy/WXML
See https://github.com/oft/wxml.
https://github.com/vivaxy/WXML
miniprogram mp parse parse-wxml parser serialize serialize-wxml serializer stringify traverse traverse-wxml traverser weixin wxml wxml-parser wxml-serializer wxml-traverser wxmp
Last synced: 3 months ago
JSON representation
See https://github.com/oft/wxml.
- Host: GitHub
- URL: https://github.com/vivaxy/WXML
- Owner: vivaxy
- License: mit
- Archived: true
- Created: 2018-08-08T02:48:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-24T05:34:18.000Z (5 months ago)
- Last Synced: 2024-07-21T00:48:31.514Z (4 months ago)
- Topics: miniprogram, mp, parse, parse-wxml, parser, serialize, serialize-wxml, serializer, stringify, traverse, traverse-wxml, traverser, weixin, wxml, wxml-parser, wxml-serializer, wxml-traverser, wxmp
- Language: TypeScript
- Homepage: https://github.com/vivaxy/WXML
- Size: 1.37 MB
- Stars: 12
- Watchers: 4
- Forks: 6
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
- awesome-github-star - WXML
README
# WXML
đWXML parser and serializer.
[![Build Status][travis-image]][travis-url]
[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![MIT License][license-image]][license-url]
[![Standard Version][standard-version-image]][standard-version-url]
[![Codecov][codecov-image]][codecov-url]
[![DOI](https://zenodo.org/badge/143952530.svg)](https://zenodo.org/badge/latestdoi/143952530)# Install
`yarn add @vivaxy/wxml` or `npm i @vivaxy/wxml --save`
# Usage
```js
import * as wxml from '@vivaxy/wxml';
const parsed = wxml.parse('');
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 ``
} 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`
[travis-image]: https://img.shields.io/travis/vivaxy/WXML.svg?style=flat-square
[travis-url]: https://travis-ci.org/vivaxy/WXML
[npm-version-image]: https://img.shields.io/npm/v/@vivaxy/wxml.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@vivaxy/wxml
[npm-downloads-image]: https://img.shields.io/npm/dt/@vivaxy/wxml.svg?style=flat-square
[license-image]: https://img.shields.io/npm/l/@vivaxy/wxml.svg?style=flat-square
[license-url]: LICENSE
[standard-version-image]: https://img.shields.io/badge/release-standard%20version-brightgreen.svg?style=flat-square
[standard-version-url]: https://github.com/conventional-changelog/standard-version
[codecov-image]: https://img.shields.io/codecov/c/github/vivaxy/WXML.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/vivaxy/WXML