Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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" } });
}
janpaul123-valle_tmp_4374095821764219776697402648626.web.val.run
July 15, 2024