Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fisker/prettier-format
auto load config and run prettier on code
https://github.com/fisker/prettier-format
Last synced: 6 days ago
JSON representation
auto load config and run prettier on code
- Host: GitHub
- URL: https://github.com/fisker/prettier-format
- Owner: fisker
- License: mit
- Created: 2019-07-09T11:42:46.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-04T01:03:50.000Z (8 months ago)
- Last Synced: 2024-04-04T02:25:39.992Z (8 months ago)
- Language: JavaScript
- Size: 384 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# prettier-format
[![Build Status][github_actions_badge]][github_actions_link]
[![Coverage][coveralls_badge]][coveralls_link]
[![Npm Version][package_version_badge]][package_link]
[![MIT License][license_badge]][license_link][github_actions_badge]: https://img.shields.io/github/workflow/status/fisker/prettier-format/CI/master?style=flat-square
[github_actions_link]: https://github.com/fisker/prettier-format/actions?query=branch%3Amaster
[coveralls_badge]: https://img.shields.io/coveralls/github/fisker/prettier-format/master?style=flat-square
[coveralls_link]: https://coveralls.io/github/fisker/prettier-format?branch=master
[license_badge]: https://img.shields.io/npm/l/prettier-format.svg?style=flat-square
[license_link]: https://github.com/fisker/prettier-format/blob/master/license
[package_version_badge]: https://img.shields.io/npm/v/prettier-format.svg?style=flat-square
[package_link]: https://www.npmjs.com/package/prettier-format> auto load config and run prettier on code
## Motivation
To load config and format code with prettier, you have to do
```js
const config = await prettier.resolveConfig('path/to/file', {useCache: false})const formatted = await prettier.format(source, {...config, semi: false})
```I want it simple
```js
const formatted = await format(source, {
filepath: 'path/to/file',
useCache: false,
semi: false,
})
```## Install
```sh
yarn add prettier-format
```## Usage
```js
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`](https://prettier.io/docs/en/api.html#prettierresolveconfigfilepath-options) takes
any value [`prettier.format`](https://prettier.io/docs/en/api.html#prettierformatsource-options) takes
#### options.filepath
Type: `string`
The filepath of source code, if filepath is not empty, config will load automaticly.
## Related
- [write-prettier-file](https://github.com/fisker/write-prettier-file) write formatted code to file.