https://github.com/typpo/prettier-worker
A Cloudflare Worker that formats code using prettier
https://github.com/typpo/prettier-worker
Last synced: 5 months ago
JSON representation
A Cloudflare Worker that formats code using prettier
- Host: GitHub
- URL: https://github.com/typpo/prettier-worker
- Owner: typpo
- Created: 2022-02-27T17:02:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-27T18:06:23.000Z (over 4 years ago)
- Last Synced: 2025-04-14T14:59:06.331Z (about 1 year ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## prettier-worker
Prettier, hosted as a Cloudflare Worker.
# Usage
Send a POST request to https://prettier.ty.workers.dev. The POST request be `application/json` encoded and the payload must look like this:
```js
{
"code": "<...your javascript code...>",
"prettierOptions": {
// Optional prettier API params
}
}
```
The `prettierOptions` property is optional and will accept any API override parameter documented [here](https://prettier.io/docs/en/options.html).
The response will look like this:
```json
{
"code": "<...your formatted javascript code...>"
}
```
If an error was thrown, the response will have a non-200 HTTP status code and probably look like this:
```json
{
"error": "<...description of error...>"
}
```
# Examples
Here's an example JSON payload that specifies some options:
```json
{
"code": "foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());",
"prettierOptions": {
"singleQuote": true,
"semi": true,
"trailingComma": "all"
}
}
```
You can test things on your command line as well (see `examples/` directory):
```sh
curl -X POST -H 'content-type: application/json' https://prettier.ty.workers.dev -d '{
"code": "foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());"
}'
```
# Supported parsers
Only the `babel` parser is supported by default due to Cloudflare limitations on bundle size.