# mdast-util-compact

> mdast utility to make a tree compact

Latest version **5.0.0** (published 2023-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install mdast-util-compact
pnpm add mdast-util-compact
yarn add mdast-util-compact
bun add mdast-util-compact
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2023-07-07 |
| First published | 2016-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 3 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Titus Wormer |
| Maintainers | wooorm, kmck |
| Keywords | unist, mdast, mdast-util, util, utility, tree, compact, node |

## Links

- npm: https://www.npmjs.com/package/mdast-util-compact
- Repository: https://github.com/syntax-tree/mdast-util-compact
- Homepage: https://github.com/syntax-tree/mdast-util-compact#readme
- Issues: https://github.com/syntax-tree/mdast-util-compact/issues
- Funding: https://opencollective.com/unified
- npm.io page: https://npm.io/package/mdast-util-compact

## Dependencies (3)

- [devlop](https://npm.io/package/devlop.md) ^1.0.0
- [@types/mdast](https://npm.io/package/@types/mdast.md) ^4.0.0
- [unist-util-visit](https://npm.io/package/unist-util-visit.md) ^5.0.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2023-07-07
- 4.1.1 — 2023-01-25
- 4.1.0 — 2021-07-30
- 4.0.0 — 2021-04-23
- 3.0.0 — 2020-10-03
- 2.0.1 — 2020-02-22
- 2.0.0 — 2019-11-10
- 1.0.4 — 2019-11-10
- 1.0.3 — 2019-05-24
- 1.0.2 — 2018-08-20
- 1.0.1 — 2017-06-13
- 1.0.0 — 2016-07-16

## README

# mdast-util-compact

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

[mdast][] utility to make trees compact by collapsing adjacent text nodes and
blockquotes.

## Contents

*   [What is this?](#what-is-this)
*   [When should I use this?](#when-should-i-use-this)
*   [Install](#install)
*   [Use](#use)
*   [API](#api)
    *   [`compact(tree)`](#compacttree)
*   [Types](#types)
*   [Compatibility](#compatibility)
*   [Security](#security)
*   [Related](#related)
*   [Contribute](#contribute)
*   [License](#license)

## What is this?

This package is a utility that lets you make a tree, after changes, more similar
to how it would be parsed.

## When should I use this?

Probably never!
You should try and keep your trees clean yourself.

## Install

This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

```sh
npm install mdast-util-compact
```

In Deno with [`esm.sh`][esmsh]:

```js
import {compact} from 'https://esm.sh/mdast-util-compact@5'
```

In browsers with [`esm.sh`][esmsh]:

```html
<script type="module">
  import {compact} from 'https://esm.sh/mdast-util-compact@5?bundle'
</script>
```

## Use

```js
import {u} from 'unist-builder'
import {compact} from 'mdast-util-compact'

const tree = u('strong', [u('text', 'alpha'), u('text', ' '), u('text', 'bravo')])

compact(tree)

console.log(tree)
```

Yields:

```js
{
  type: 'strong',
  children: [ { type: 'text', value: 'alpha bravo' } ]
}
```

## API

This package exports the identifier [`compact`][api-compact].
There is no default export.

### `compact(tree)`

Make an mdast tree compact by merging adjacent text nodes and block quotes.

###### Parameters

*   `tree` ([`Node`][node])
    — tree to change

###### Returns

Nothing (`undefined`).

## Types

This package is fully typed with [TypeScript][].
It exports no additional types.

## Compatibility

Projects maintained by the unified collective are compatible with maintained
versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `mdast-util-compact@^5`,
compatible with Node.js 16.

## Security

Use of `mdast-util-compact` does not involve **[hast][]** or user content so
there are no openings for [cross-site scripting (XSS)][xss] attacks.

## Related

*   [`mdast-squeeze-paragraphs`](https://github.com/syntax-tree/mdast-squeeze-paragraphs)
    — remove empty paragraphs

## Contribute

See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.

This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

## License

[MIT][license] © [Titus Wormer][author]

<!-- Definitions -->

[build-badge]: https://github.com/syntax-tree/mdast-util-compact/workflows/main/badge.svg

[build]: https://github.com/syntax-tree/mdast-util-compact/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-compact.svg

[coverage]: https://codecov.io/github/syntax-tree/mdast-util-compact

[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-compact.svg

[downloads]: https://www.npmjs.com/package/mdast-util-compact

[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-compact

[size]: https://bundlejs.com/?q=mdast-util-compact

[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[backers-badge]: https://opencollective.com/unified/backers/badge.svg

[collective]: https://opencollective.com/unified

[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

[chat]: https://github.com/syntax-tree/unist/discussions

[npm]: https://docs.npmjs.com/cli/install

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[esmsh]: https://esm.sh

[typescript]: https://www.typescriptlang.org

[license]: license

[author]: https://wooorm.com

[health]: https://github.com/syntax-tree/.github

[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md

[support]: https://github.com/syntax-tree/.github/blob/main/support.md

[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md

[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting

[mdast]: https://github.com/syntax-tree/mdast

[node]: https://github.com/syntax-tree/mdast#node

[hast]: https://github.com/syntax-tree/hast

[api-compact]: #compacttree

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