# xformatting

> Formats XML into a more readable format by inserting linebreaks and indents. Supports all element types (e.g. processing instructions) and also the xml:space attribute

Latest version **2.2.0** (published 2023-03-17) · MIT license · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2023-03-17 |
| First published | 2018-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 84.4 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Xpublisher GmbH |
| Maintainers | xpublisher |
| Keywords | xml, pretty, pretty-print, indent, parser, formatter, xml-formatter, xml:space, preserve, libxmljs |

## Links

- npm: https://www.npmjs.com/package/xformatting
- Repository: https://github.com/xpublisher/xformatting
- Homepage: https://github.com/xpublisher/xformatting#readme
- Issues: https://github.com/xpublisher/xformatting/issues
- npm.io page: https://npm.io/package/xformatting

## Dependencies (1)

- [libxmljs2](https://npm.io/package/libxmljs2.md) ^0.31.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2023-03-17
- 2.1.1 — 2022-01-12
- 2.1.0 — 2021-12-17
- 2.0.1 — 2021-12-16
- 2.0.0 — 2021-12-16
- 1.5.1 — 2021-12-14
- 1.5.0 — 2021-05-27
- 1.4.0 — 2021-05-27
- 1.3.0 — 2020-06-19
- 1.2.0 — 2019-01-24
- 1.1.2 — 2018-09-24
- 1.1.1 — 2018-09-05
- 1.1.0 — 2018-08-22
- 1.0.4 — 2018-06-19
- 1.0.3 — 2018-06-19
- … 2 more at https://npm.io/package/xformatting/versions

## README

<div align="center">
	<h2 style="font-size: 30px">
		&lt;xformatting/&gt;
	</h2>
	<p>
		<a href="https://github.com/xpublisher/xformatting/issues">
			<img src="https://img.shields.io/github/issues/xpublisher/xformatting.svg" alt="Issues"/>
		</a>
		<a href="https://travis-ci.org/xpublisher/xformatting">
			<img src="https://api.travis-ci.org/xpublisher/xformatting.svg" alt="Travis"/>
		</a>
		<a href="https://github.com/xpublisher/xformatting/blob/master/LICENSE" alt="License">
			<img src="https://img.shields.io/github/license/xpublisher/xformatting.svg"/>
		</a>
	</p>
	<hr>
	<p>
		Formats XML into a more readable format by inserting linebreaks and indents. Supports all element types (e.g. processing instructions) and also the xml:space attribute
	</p>
</div>

## Installation

```
$ npm install -S xformatting
```

## Usage

### Synchronous

```js
const { formatSync } = require('xformatting');

const xml = '<xformatting><code xml:space="preserve">var hello = "world"</code></xformatting>';
const formattedXml = formatSync(xml);
console.log(formattedXml);
```

### Asynchronous

```js
const { format } = require('xformatting');

const xml = '<xformatting><code xml:space="preserve">var hello = "world"</code></xformatting>';
format(xml).then((formattedXml) => {
	console.log(formattedXml);
});
```

## Options

You can pass an options object to the methods as a second argument. In this table you will find all setting options:

| Name                   | Type     | Default     | Description
|------------------------|----------|-------------|-------------
| linebreak              | string   | "\r\n"      | New line characters
| indentation            | string   | "\t"        | Characters for indentation
| preserveSpaceAttribute | string   | "xml:space" | Attribute name for preserve space
| preserveSpaceFn        | Function |             | Function to check if preserve space is active

## License

MIT

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