prettier-format
v4.0.0
Published
auto load config and run prettier on code
Downloads
5,358
Readme
prettier-format
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
- write-prettier-file write formatted code to file.