@dprint/formatter
Wasm formatter for dprint plugins.
Last updated 5 years ago by dsherret .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @dprint/formatter 
SYNC missed versions from official npm registry.

dprint - JS Formatter

CI npm version JSR

JS formatter for dprint Wasm plugins.

Setup

Deno:

deno add npm:@dprint/formatter

Node.js:

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:

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.

Current Tags

  • 0.5.1                                ...           latest (3 months ago)

10 Versions

  • 0.5.1                                ...           3 months ago
  • 0.4.1                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.5                                ...           4 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None

Copyright 2013 - present © cnpmjs.org | Home |