mirror of
https://github.com/angular/angular.git
synced 2026-11-23 07:05:14 -05:00
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
25 lines
783 B
TypeScript
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())
|
|
);
|
|
}
|