prettier-format

4.0.0 • Public • Published

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.

Related

Readme

Keywords

none

Package Sidebar

Install

npm i prettier-format

Weekly Downloads

978

Version

4.0.0

License

MIT

Unpacked Size

7.33 kB

Total Files

6

Last publish

Collaborators

  • fisker