prettier

prettier

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)
          }
          }
上一篇:阶段9反射


下一篇:2022年前端React的100道面试题的第7题:组件的constructor