當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript prettier.format函數代碼示例

本文整理匯總了TypeScript中prettier.format函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript format函數的具體用法?TypeScript format怎麽用?TypeScript format使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了format函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: generateEntry

 generateEntry () {
   try {
     const entryJS = String(fs.readFileSync(this.entryJSPath))
     const entryJSON = JSON.stringify(this.entryJSON)
     const entryDistJSPath = this.getDistFilePath(this.entryJSPath)
     const taroizeResult = taroize({
       json: entryJSON,
       script: entryJS,
       path: path.dirname(entryJS)
     })
     const { ast, scriptFiles } = this.parseAst({
       ast: taroizeResult.ast,
       sourceFilePath: this.entryJSPath,
       outputFilePath: entryDistJSPath,
       importStylePath: this.entryStyle ? this.entryStylePath.replace(path.extname(this.entryStylePath), OUTPUT_STYLE_EXTNAME) : null,
       isApp: true
     })
     const jsCode = generateMinimalEscapeCode(ast)
     this.writeFileToTaro(entryDistJSPath, prettier.format(jsCode, prettierJSConfig))
     printLog(processTypeEnum.GENERATE, '入口文件', this.generateShowPath(entryDistJSPath))
     if (this.entryStyle) {
       this.traverseStyle(this.entryStylePath, this.entryStyle)
     }
     this.generateScriptFiles(scriptFiles)
     if (this.entryJSON.tabBar) {
       this.generateTabBarIcon(this.entryJSON.tabBar)
     }
   } catch (err) {
     console.log(err)
   }
 }
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:31,代碼來源:index.ts

示例2: wxTransformer

 files.forEach(file => {
   if (!fs.existsSync(file) || this.hadBeenCopyedFiles.has(file)) {
     return
   }
   const code = fs.readFileSync(file).toString()
   let outputFilePath = file.replace(this.root, this.convertDir)
   const extname = path.extname(outputFilePath)
   if (/\.wxs/.test(extname)) {
     outputFilePath += '.js'
   }
   const transformResult = wxTransformer({
     code,
     sourcePath: file,
     outputPath: outputFilePath,
     isNormal: true,
     isTyped: REG_TYPESCRIPT.test(file)
   })
   const { ast, scriptFiles } = this.parseAst({
     ast: transformResult.ast,
     outputFilePath,
     sourceFilePath: file
   })
   const jsCode = generateMinimalEscapeCode(ast)
   this.writeFileToTaro(outputFilePath, prettier.format(jsCode, prettierJSConfig))
   printLog(processTypeEnum.COPY, 'JS 文件', this.generateShowPath(outputFilePath))
   this.hadBeenCopyedFiles.add(file)
   this.generateScriptFiles(scriptFiles)
 })
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:28,代碼來源:index.ts

示例3: runTest

    function runTest(text: string, expected: string) {
        if (options.commonPrefix != null)
            text = options.commonPrefix + text;

        const result = getTransformedText(text);
        if (!expected.endsWith("\n"))
            expected += "\n";
        assert.equal(prettier.format(result, { parser: "typescript" }), expected);
    }
開發者ID:dsherret,項目名稱:ts-nameof,代碼行數:9,代碼來源:runCommonTests.ts

示例4:

 f.saveFormat(generatedTypescriptFilename, (code) => {
     const options: prettier.Options = {
         bracketSpacing: true,
         insertPragma: true,
         parser: "typescript",
         printWidth: 120
     };
     return prettier.format(code, options);
 });
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:9,代碼來源:factory_code_generator.ts

示例5: prettifyResponse

  @action.bound
  prettifyResponse() {
    let options = {};

    if (this.contentType === "json") {
      options = { parser: "json" };
    }

    this.content = prettier.format(this.content, options);
  }
開發者ID:Raathigesh,項目名稱:Atmo,代碼行數:10,代碼來源:Response.ts

示例6: pascalCase

 imports.forEach(({ name, ast }) => {
   const importName = pascalCase(name)
   if (componentClassName === importName) {
     return
   }
   const importPath = path.join(self.importsDir, importName + '.js')
   if (!self.hadBeenBuiltImports.has(importPath)) {
     self.hadBeenBuiltImports.add(importPath)
     self.writeFileToTaro(importPath, prettier.format(generateMinimalEscapeCode(ast), prettierJSConfig))
   }
   lastImport.insertAfter(template(`import ${importName} from '${promoteRelativePath(path.relative(outputFilePath, importPath))}'`, babylonConfig)())
 })
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:12,代碼來源:index.ts

示例7: Promise

  new Promise((resolve, reject) => {
    try {
      const result = prettier.format(code, {
        parser: 'babylon',
        semi: false,
        singleQuote: true,
        trailingComma: 'all',
      })

      resolve(result)
    } catch (err) {
      logger.fatal(err)
      resolve(err)
    }
  })
開發者ID:leslieSie,項目名稱:docz,代碼行數:15,代碼來源:format.ts

示例8: format

    filePaths.map(async (filePath, index) => {
      const content = contents[index];
      let formattedContent;

      try {
        formattedContent = format(content, options);
      } catch (err) {
        error(`Couldn't format ${red(filePath)}.`);
        throw err;
      }

      if (content !== formattedContent) {
        fixedFiles.push(filePath);
        await writeFileAsync(filePath, formattedContent);
      }
    })
開發者ID:otbe,項目名稱:ws,代碼行數:16,代碼來源:prettier.ts

示例9: print

  public static print(element: AstElement, options: PrintOptions = {}): string {
    let code = Recast.print(element.node);

    options = Object.assign(
      { resolveFrom: process.cwd(), prettier: 'babylon' },
      options,
    );

    if (options.prettier) {
      code = prettier.format(code, {
        ...(options.prettierConfig || {}),
        parser: options.prettier,
      });
    }
    return code;
  }
開發者ID:vueneue,項目名稱:rquery,代碼行數:16,代碼來源:RQuery.ts

示例10: run_prettier_string

export async function run_prettier_string(
  path: string | undefined,
  str: string,
  options: any,
  logger: any
): Promise<string> {
  let pretty;
  logger.debug(`run_prettier options.parser: "${options.parser}"`);
  switch (options.parser) {
    case "latex":
      pretty = await latex_format(str, options);
      break;
    case "python":
      pretty = await python_format(str, options, logger);
      break;
    case "r":
      pretty = await r_format(str, options, logger);
      break;
    case "html-tidy":
    case "tidy":
      pretty = await html_format(str, options, logger);
      break;
    case "xml-tidy":
      pretty = await xml_format(str, options, logger);
      break;
    case "bib-biber":
      pretty = await bib_format(str, options, logger);
      break;
    case "clang-format":
      const ext = misc.filename_extension(path !== undefined ? path : "");
      pretty = await clang_format(str, options, ext, logger);
      break;
    case "gofmt":
      pretty = await gofmt(str, options, logger);
      break;
    default:
      pretty = prettier.format(str, options);
  }
  return pretty;
}
開發者ID:DrXyzzy,項目名稱:smc,代碼行數:40,代碼來源:prettier.ts


注:本文中的prettier.format函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。