# @dprint/formatter

> Wasm formatter for dprint plugins.

Latest version **0.5.1** (published 2026-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dprint/formatter
pnpm add @dprint/formatter
yarn add @dprint/formatter
bun add @dprint/formatter
```

## Health

**Score 65/100 (B)** — status: stable.

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2026-01-06 |
| First published | 2021-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 109.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 41 |
| Author | David Sherret |
| Maintainers | dsherret |
| Keywords | dprint, formatter, wasm |

## Links

- npm: https://www.npmjs.com/package/@dprint/formatter
- Repository: https://github.com/dprint/js-formatter
- Homepage: https://github.com/dprint/js-formatter#readme
- Issues: https://github.com/dprint/js-formatter/issues
- npm.io page: https://npm.io/package/@dprint/formatter

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.5.1 (latest) — 2026-01-06
- 0.4.1 — 2024-06-30
- 0.4.0 — 2024-06-30
- 0.3.0 — 2024-05-04
- 0.2.1 — 2023-12-26
- 0.2.0 — 2022-01-08
- 0.1.5 — 2021-10-19
- 0.1.4 — 2021-06-13
- 0.1.3 — 2021-06-13
- 0.1.2 — 2021-06-13

## README

# dprint - JS Formatter

[![CI](https://github.com/dprint/js-formatter/workflows/CI/badge.svg)](https://github.com/dprint/js-formatter/actions?query=workflow%3ACI)
[![npm version](https://badge.fury.io/js/%40dprint%2Fformatter.svg)](https://badge.fury.io/js/%40dprint%2Fformatter)
[![JSR](https://jsr.io/badges/@dprint/formatter)](https://jsr.io/@dprint/formatter)

JS formatter for dprint Wasm plugins.

## Setup

Deno:

```sh
deno add npm:@dprint/formatter
```

Node.js:

```sh
npm i @dprint/formatter
```

## Use

The context API allows you to manage multiple plugins with shared configuration and automatic plugin selection based on file type:

```ts
import { createContext } from "@dprint/formatter";
import * as json from "@dprint/json";
import * as markdown from "@dprint/markdown";
import * as typescript from "@dprint/typescript";
import fs from "node:fs";

const context = createContext({
  // global config
  indentWidth: 2,
  lineWidth: 80,
});

// note: some plugins might have a getBuffer() export instead
context.addPlugin(fs.readFileSync(typescript.getPath()), {
  semiColons: "asi",
});
context.addPlugin(fs.readFileSync(json.getPath()));
context.addPlugin(fs.readFileSync(markdown.getPath()));

console.log(context.formatText({
  filePath: "config.json",
  fileText: "{\"a\":1}",
}));

console.log(context.formatText({
  filePath: "app.ts",
  fileText: "const x=1",
}));
```

The context also handles host formatting automatically, so embedded code blocks (like JSON in Markdown) will be formatted by the appropriate plugin.

### Plugin NPM Packages

Note: In the future I will ensure plugins are published to JSR as well.

- [@dprint/json](https://www.npmjs.com/package/@dprint/json)
- [@dprint/typescript](https://www.npmjs.com/package/@dprint/typescript)
- [@dprint/markdown](https://www.npmjs.com/package/@dprint/markdown)
- [@dprint/toml](https://www.npmjs.com/package/@dprint/toml)
- [@dprint/dockerfile](https://www.npmjs.com/package/@dprint/dockerfile)
- [@dprint/biome](https://www.npmjs.com/package/@dprint/biome)
- [@dprint/oxc](https://www.npmjs.com/package/@dprint/oxc)
- [@dprint/mago](https://www.npmjs.com/package/@dprint/mago)
- [@dprint/ruff](https://www.npmjs.com/package/@dprint/ruff)

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