prettier
Prettier is an opinionated code formatter with support for:
- JavaScript (including experimental features)
- JSX
- Angular
- Vue
- Flow
- TypeScript
- CSS, Less, and SCSS
- HTML
- JSON
- GraphQL
- Markdown, including GFM and MDX
- YAML
调用prettier的方法
let apiModule = (apiJSON) => {
let strClass = `export class ApiService {
constructor(httpClient) {
this.httpClient = httpClient
}
${transferApi(apiJSON)}}`
return prettier.format(strClass, { parser: "babel" })
}
输出
export class ApiService {
constructor(httpClient) {
this.httpClient = httpClient;
}
async postDomains(data) {
const pathname = prefixUrl("/domains");
return await this.httpClient.post(pathname, data);
}
}
不调用prettier的方法
let apiModule = (apiJSON) => {
let strClass = `export class ApiService {
constructor(httpClient) {
this.httpClient = httpClient
}
${transferApi(apiJSON)}}`
return strClass
}
export class ApiService {
constructor(httpClient) {
this.httpClient = httpClient
}
async postDomains(data) {
const pathname = prefixUrl('/domains')
return await this.httpClient.post(pathname, data)
}
}