Socket
Socket
Sign inDemoInstall

prettier-format

Package Overview
Dependencies
3
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    prettier-format

auto load config and run prettier on code


Version published
Weekly downloads
609
decreased by-16.12%
Maintainers
1
Install size
8.18 MB
Created
Weekly downloads
 

Readme

Source

prettier-format

Build Status Coverage Npm Version MIT License

auto load config and run prettier on code

Motivation

To load config and format code with prettier, you have to do

const config = await prettier.resolveConfig('path/to/file', {useCache: false})

const formatted = await prettier.format(source, {...config, semi: false})

I want it simple

const formatted = await format(source, {
  filepath: 'path/to/file',
  useCache: false,
  semi: false,
})

Install

yarn add prettier-format

Usage

import format from 'prettier-format'

await format(`hello (  'world' )`)
// => hello("world");\n

API

format(source, options?)

Returns promise resolves with formatted code.

source

Type: string

Source code you want to format.

options

Type: object

any value prettier.resolveConfig takes

any value prettier.format takes

options.filepath

Type: string

The filepath of source code, if filepath is not empty, config will load automaticly.

FAQs

Last updated on 08 Sep 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc