Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prettier/sync

Package Overview
Dependencies
Maintainers
14
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prettier/sync

Synchronous version of Prettier

  • 0.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
115K
decreased by-3.62%
Maintainers
14
Weekly downloads
 
Created
Source

@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'

FAQs

Package last updated on 17 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc