Attributes
Includes Deno configuration
Repository
Current version released
5 months ago
dprint - JS Formatter
JS formatter for dprint Wasm plugins.
Setup
Deno:
deno add @dprint/formatter
Node.js:
npm i @dprint/formatter
Use
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("file.ts", "const t = 5;"));
Using with plugins on npm (ex. @dprint/json):
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("test.json", "{test: 5}"));
Plugin NPM Packages
Note: In the future I will ensure plugins are published to JSR as well.