README
prettier-format
auto load config and run prettier on code
Motivation
To load config and format code with prettier, you have to do
;(async () => {
const config = await prettier.resolveConfig('path/to/file', {
useCache: false,
})
// there is also a sync version of `prettier.resolveConfig`
// called `prettier.resolveConfig.sync`
const formatted = prettier.format(source, {
...config,
semi: false,
})
})()
I want it simple
;(async () => {
const formatted = format(source, {
filePath: 'path/to/file',
useCache: false,
semi: false,
})
})()
Install
yarn add prettier-format
Ustage
import format from 'prettier-format'
format.sync(`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.
format.sync(source, options?)
Sync version.
Related
- write-prettier-file write formatted code to file.