move app to app/ subdir

This commit is contained in:
Kyle Corbitt
2023-08-05 10:00:10 -07:00
parent 7707d451e0
commit 21ef67ed4c
203 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import prettier from "prettier/standalone";
import parserTypescript from "prettier/plugins/typescript";
// @ts-expect-error for some reason missing from types
import parserEstree from "prettier/plugins/estree";
import * as babel from "@babel/standalone";
export function stripTypes(tsCode: string): string {
const options = {
presets: ["typescript"],
filename: "file.ts",
};
try {
const result = babel.transform(tsCode, options);
return result.code ?? tsCode;
} catch (error) {
// console.error("Error stripping types", error);
return tsCode;
}
}
export default async function formatPromptConstructor(code: string): Promise<string> {
return await prettier.format(stripTypes(code), {
parser: "typescript",
plugins: [parserTypescript, parserEstree],
// We're showing these in pretty narrow panes so let's keep the print width low
printWidth: 60,
});
}