# postsvg

> A tiny wrapper over posthml with the same API optimized for working with SVG

Latest version **2.2.7** (published 2019-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install postsvg
pnpm add postsvg
yarn add postsvg
bun add postsvg
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.7 |
| Published | 2019-02-08 |
| First published | 2016-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 174 |
| Author | JetBrains |
| Maintainers | kisenka |
| Keywords | posthtml, html, svg, transformations |

## Links

- npm: https://www.npmjs.com/package/postsvg
- Repository: https://github.com/JetBrains/svg-mixer
- Homepage: https://github.com/JetBrains/svg-mixer/tree/master/packages/postsvg
- Issues: https://github.com/JetBrains/svg-mixer/issues
- npm.io page: https://npm.io/package/postsvg

## Dependencies (6)

- [clone](https://npm.io/package/clone.md) ^1.0.4
- [posthtml](https://npm.io/package/posthtml.md) ^0.11.3
- [deepmerge](https://npm.io/package/deepmerge.md) ^2.1.0
- [posthtml-parser](https://npm.io/package/posthtml-parser.md) ^0.4.1
- [posthtml-render](https://npm.io/package/posthtml-render.md) ^1.1.2
- [posthtml-match-helper](https://npm.io/package/posthtml-match-helper.md) ^1.0.1

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 2.2.7 (latest) — 2019-02-08
- 2.1.2-alpha.0 (alpha) — 2018-04-09
- 2.2.0-alpha.10475b37 (canary) — 2018-04-09
- 2.2.6 — 2018-12-05
- 2.2.5 — 2018-10-29
- 2.2.4 — 2018-10-29
- 2.2.3 — 2018-06-13
- 2.2.2 — 2018-05-11
- 2.2.1 — 2018-04-28
- 2.2.0 — 2018-04-21
- 2.1.2 — 2018-04-13
- 2.1.0 — 2018-04-09
- 2.0.0 — 2017-10-22
- 0.0.3 — 2016-01-17
- 0.0.2 — 2016-01-15
- … 1 more at https://npm.io/package/postsvg/versions

## README

# PostSVG

A tiny wrapper over [posthtml](https://github.com/posthtml/posthtml) with the same 
API optimized for working with SVG.

## Differences from PostHTML

- Content is parsed in [xml mode](https://github.com/fb55/htmlparser2/wiki/Parser-options#option-xmlmode).
- Properly renders SVG self-closing tags (`<path />`, `<line />` etc).
- Processing result is instance of [Tree](https://github.com/kisenka/svg-mixer/blob/master/packages/postsvg/lib/tree.js) class which is wrapper 
  around Array and backward compatible with posthtml parser.

## Tree

PostSVG tree has several useful methods for work with AST:

```js
const { parse } = require('postsvg');

const tree = parse('<svg><path /><path class="qwe" /></svg>');

/**
 * `root` getter returns <svg> node
 * @return {Node}
 */ 
tree.root;

/**
 * Find all <path/> nodes
 * @return {Array<Node>}
 */
tree.select('path'); 

/**
 * Select only nodes with class="qwe"
 * @return {Array<Node>}
 */
tree.select('.qwe');

/**
 * Fill each <path/> node with red color 
 */
tree.each('path', node => node.attrs.fill = 'red');
```

Node has following structure:
```
Node<{
  tag: string,
  attrs?: Object,
  content?: Array<Node>
}>
```

## LICENSE

[MIT](https://github.com/JetBrains/svg-mixer/blob/master/LICENSE)

---
_Source: https://npm.io/package/postsvg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
