Files
faunosteo/packages/anatomy/src/format.ts
T

31 lines
774 B
TypeScript

import { format } from 'prettier'
/**
* Prettier formatting of the generated artifacts with the repository
* options, so `prettier --check` accepts the committed files as generated
* (no exclusion needed). Shared by the legacy import and the draft.
*/
const PRETTIER_OPTIONS = {
semi: false,
singleQuote: true,
tabWidth: 2,
useTabs: false,
trailingComma: 'all',
printWidth: 80,
bracketSpacing: true,
arrowParens: 'always',
endOfLine: 'lf',
} as const
export function formatJson(value: unknown): Promise<string> {
return format(JSON.stringify(value, null, 2), {
...PRETTIER_OPTIONS,
parser: 'json',
})
}
export function formatMarkdown(text: string): Promise<string> {
return format(text, { ...PRETTIER_OPTIONS, parser: 'markdown' })
}