Files
angular/adev/shared-docs/pipeline/api-gen/rendering/transforms/format-code.mts
T
Matthieu Riegler ca700e1def docs(docs-infra): Improve formatting of functions (#61154)
The commit introduce prettier to format some API entries.
For now we'll do only functions are other are a bit more complex because of the support of deprecation.

fixes #59211

PR Close #61154
2025-05-16 13:58:35 +00:00

25 lines
783 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import parserTypescript from 'prettier/plugins/typescript';
import prettierPluginEstree from 'prettier/plugins/estree';
import prettier from 'prettier/standalone';
export async function formatJs(code: string): Promise<string> {
return (
prettier
.format(code, {
parser: 'typescript',
plugins: [parserTypescript, prettierPluginEstree],
singleQuote: true,
})
// Make sure to trim the formatted code as shiki will add a new line if there are some remaining trailing spaces
.then((formattedCode) => formattedCode.trim())
);
}