本文整理汇总了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)
}
}
示例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)
})
示例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);
}
示例4:
f.saveFormat(generatedTypescriptFilename, (code) => {
const options: prettier.Options = {
bracketSpacing: true,
insertPragma: true,
parser: "typescript",
printWidth: 120
};
return prettier.format(code, options);
});
示例5: prettifyResponse
@action.bound
prettifyResponse() {
let options = {};
if (this.contentType === "json") {
options = { parser: "json" };
}
this.content = prettier.format(this.content, options);
}
示例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)())
})
示例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)
}
})
示例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);
}
})
示例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;
}
示例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;
}