UNPKG

@alexop/openapi-zod-client

Version:

[![Screenshot 2022-11-12 at 18 52 25](https://user-images.githubusercontent.com/47224540/201487856-ffc4c862-6f31-4de1-8ef1-3981fabf3416.png)](https://openapi-zod-client.vercel.app/)

13 lines (10 loc) 510 B
import prettier, { type Options } from "prettier"; import parserTypescript from "prettier/parser-typescript"; /** @see https://github.dev/stephenh/ts-poet/blob/5ea0dbb3c9f1f4b0ee51a54abb2d758102eda4a2/src/Code.ts#L231 */ export function maybePretty(input: string, options?: Options | null): string { try { return prettier.format(input.trim(), { parser: "typescript", plugins: [parserTypescript], ...options }); } catch { return input; // assume it's invalid syntax and ignore } }