(ES Modules)prettier格式化typescript源码
1.安装prettier
npm i prettier
2. 引入
import {format} from 'prettier';
import parserTypeScript from 'prettier/plugins/typescript';
import parserEsTree from 'prettier/plugins/estree.mjs';
3.使用
const formattedTsDefinitions = await format('declare namespace Test{}', {
parser: "typescript",
plugins: [parserTypeScript, parserEsTree],
semi: true,
singleQuote: true,
printWidth: 100,
tabWidth: 2,
trailingComma: "all",
});