https://github.com/dprint/js-formatter
JS formatter for dprint Wasm plugins.
https://github.com/dprint/js-formatter
Last synced: 11 months ago
JSON representation
JS formatter for dprint Wasm plugins.
- Host: GitHub
- URL: https://github.com/dprint/js-formatter
- Owner: dprint
- License: mit
- Created: 2021-06-13T20:27:35.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-01T02:43:30.000Z (about 2 years ago)
- Last Synced: 2025-08-08T15:44:52.522Z (12 months ago)
- Language: TypeScript
- Size: 131 KB
- Stars: 38
- Watchers: 2
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dprint - JS Formatter
[](https://github.com/dprint/js-formatter/actions?query=workflow%3ACI)
[](https://badge.fury.io/js/%40dprint%2Fformatter)
[](https://jsr.io/@dprint/formatter)
JS formatter for dprint Wasm plugins.
## Setup
Deno:
```sh
deno add @dprint/formatter
```
Node.js:
```sh
npm i @dprint/formatter
```
## Use
```ts
import { createStreaming, GlobalConfiguration } from "@dprint/formatter";
const globalConfig: GlobalConfiguration = {
indentWidth: 2,
lineWidth: 80,
};
const tsFormatter = await createStreaming(
// check https://plugins.dprint.dev/ for latest plugin versions
fetch("https://plugins.dprint.dev/typescript-0.57.0.wasm"),
);
tsFormatter.setConfig(globalConfig, {
semiColons: "asi",
});
// outputs: "const t = 5\n"
console.log(tsFormatter.formatText({
filePath: "file.ts",
fileText: "const t = 5;",
}));
```
Using with plugins on npm (ex. [@dprint/json](https://www.npmjs.com/package/@dprint/json)):
```ts
import { createFromBuffer } from "@dprint/formatter";
// You may have to use `getBuffer` on plugins that haven't updated yet.
// See the plugins README.md for details.
import { getPath } from "@dprint/json";
import * as fs from "node:fs";
const buffer = fs.readFileSync(getPath());
const formatter = createFromBuffer(buffer);
console.log(formatter.formatText({
filePath: "test.json",
fileText: "{test: 5}",
}));
```
### 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/ruff](https://www.npmjs.com/package/@dprint/ruff)