1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// To create a simple JavaScript formatter, we can utilize the Prettier library available in Deno.
// Prettier helps format and beautify JavaScript code.
// This val will take JavaScript code as input and format it using Prettier.
import { format } from "npm:prettier/standalone";
import parserBabel from "npm:prettier/parser-babel";
export default async function(req: Request): Promise<Response> {
const { code } = await req.json();
const formattedCode = format(code, {
parser: "babel",
plugins: [parserBabel],
});
return new Response(formattedCode, { headers: { "Content-Type": "text/plain" } });
}