本文整理汇总了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;未经允许,请勿转载。 |
请发表评论