其他分享
首页 > 其他分享> > prettier

prettier

作者:互联网

prettier

prettier官方

Prettier is an opinionated code formatter with support for:

调用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)
          }
          }

标签:strClass,return,prettier,constructor,ApiService,httpClient
来源: https://blog.csdn.net/m0_56028305/article/details/121590133