@prettier/sync

0.5.2 • Public • Published

@prettier/sync

Build Status Coverage Npm Version MIT License

Synchronous version of Prettier

Installation

yarn add prettier @prettier/sync

Usage

import synchronizedPrettier from "@prettier/sync";

synchronizedPrettier.format("foo( )", { parser: "babel" });
// => 'foo();\n'

This package is a simple wrapper of make-synchronized.

For more complex use cases, it more reasonable to extract functionality into a separate file, and run with make-synchronized, synckit, or make-synchronous etc.

Example:

import * as fs from "node:fs/promises";
import * as prettier from "prettier";
import makeSynchronized from "make-synchronized";

export default makeSynchronized(import.meta, async function formatFile(file) {
  const config = await prettier.resolveConfig(file);
  const content = await fs.readFile(file, "utf8");
  const formatted = await prettier.format(content, {
    ...config,
    filepath: file,
  });
  await fs.writeFile(file, formatted);
});

createSynchronizedPrettier(options)

options

Type: object

prettierEntry

Type: string | URL

Path or URL to prettier entry.

import { createSynchronizedPrettier } from "@prettier/sync";

const synchronizedPrettier = createSynchronizedPrettier({
  prettierEntry: "/path/to/prettier/index.js",
});

synchronizedPrettier.format("foo( )", { parser: "babel" });
// => 'foo();\n'

Readme

Keywords

none

Package Sidebar

Install

npm i @prettier/sync

Weekly Downloads

61,939

Version

0.5.2

License

MIT

Unpacked Size

6.66 kB

Total Files

5

Last publish

Collaborators

  • sosukesuzuki
  • fisker
  • suchipi
  • mgrip
  • czosel
  • patrick91
  • zimme
  • azz
  • vjeux
  • evilebottnawi
  • kddeisz
  • shinigami92
  • j-f
  • lydell