本文整理汇总了TypeScript中chalk.Chalk类的典型用法代码示例。如果您正苦于以下问题:TypeScript Chalk类的具体用法?TypeScript Chalk怎么用?TypeScript Chalk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Chalk类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: catch
ws.on('message', data => {
let msg;
try {
data = data.toString();
msg = JSON.parse(data);
} catch (e) {
process.stderr.write(`Error parsing JSON message from dev server: "${data}" ${chalk.red(e.stack ? e.stack : e)}\n`);
return;
}
if (!isDevServerMessage(msg)) {
const m = util.inspect(msg, { colors: chalk.enabled });
process.stderr.write(`Bad format in dev server message: ${m}\n`);
return;
}
if (msg.category === 'console') {
let status: Chalk | undefined; // unknown levels are normal color
if (msg.type === 'info' || msg.type === 'log') {
status = chalk.reset;
} else if (msg.type === 'error') {
status = chalk.red;
} else if (msg.type === 'warn') {
status = chalk.yellow;
}
if (status) {
process.stdout.write(`[${status('console.' + msg.type)}]: ${msg.data.join(' ')}\n`);
} else {
process.stdout.write(`[console]: ${msg.data.join(' ')}\n`);
}
}
});
示例2: highlightTrailingSpaces
const highlightLeadingTrailingSpaces = (line: string, bgColor: Chalk): string =>
// If line consists of ALL spaces: highlight all of them.
highlightTrailingSpaces(line, bgColor).replace(
// If line has an ODD length of leading spaces: highlight only the LAST.
/^(\s\s)*(\s)(?=[^\s])/,
'$1' + bgColor('$2'),
);
示例3: defaultErrorFormatter
/**
* The default error formatter.
*/
function defaultErrorFormatter(error: ErrorInfo, colors: Chalk) {
const messageColor =
error.severity === 'warning' ? colors.bold.yellow : colors.bold.red;
return (
colors.grey('[tsl] ') +
messageColor(error.severity.toUpperCase()) +
(error.file === ''
? ''
: messageColor(' in ') +
colors.bold.cyan(`${error.file}(${error.line},${error.character})`)) +
constants.EOL +
messageColor(` TS${error.code}: ${error.content}`)
);
}
示例4: bgColor
const highlightTrailingSpaces = (line: string, bgColor: Chalk): string =>
line.replace(/\s+$/, bgColor('$&'));
示例5: successfulTypeScriptInstance
function successfulTypeScriptInstance(
loaderOptions: LoaderOptions,
loader: Webpack,
log: logger.Logger,
colors: Chalk,
compiler: typeof typescript,
compilerCompatible: boolean,
compilerDetailsLogMessage: string
) {
const configFileAndPath = getConfigFile(
compiler,
colors,
loader,
loaderOptions,
compilerCompatible,
log,
compilerDetailsLogMessage!
);
if (configFileAndPath.configFileError !== undefined) {
const { message, file } = configFileAndPath.configFileError;
return {
error: makeError(
colors.red('error while reading tsconfig.json:' + EOL + message),
file
)
};
}
const { configFilePath, configFile } = configFileAndPath;
const basePath = loaderOptions.context || path.dirname(configFilePath || '');
const configParseResult = getConfigParseResult(
compiler,
configFile,
basePath
);
if (configParseResult.errors.length > 0 && !loaderOptions.happyPackMode) {
const errors = formatErrors(
configParseResult.errors,
loaderOptions,
colors,
compiler,
{ file: configFilePath },
loader.context
);
loader._module.errors.push(...errors);
return {
error: makeError(
colors.red('error while parsing tsconfig.json'),
configFilePath
)
};
}
const compilerOptions = getCompilerOptions(configParseResult);
const files: TSFiles = new Map<string, TSFile>();
const otherFiles: TSFiles = new Map<string, TSFile>();
// same strategy as https://github.com/s-panferov/awesome-typescript-loader/pull/531/files
let { getCustomTransformers: customerTransformers } = loaderOptions;
let getCustomTransformers = Function.prototype;
if (typeof customerTransformers === 'function') {
getCustomTransformers = customerTransformers;
} else if (typeof customerTransformers === 'string') {
try {
customerTransformers = require(customerTransformers);
} catch (err) {
throw new Error(
`Failed to load customTransformers from "${
loaderOptions.getCustomTransformers
}": ${err.message}`
);
}
if (typeof customerTransformers !== 'function') {
throw new Error(
`Custom transformers in "${
loaderOptions.getCustomTransformers
}" should export a function, got ${typeof getCustomTransformers}`
);
}
getCustomTransformers = customerTransformers;
}
if (loaderOptions.transpileOnly) {
// quick return for transpiling
// we do need to check for any issues with TS options though
const program =
configParseResult.projectReferences !== undefined
? compiler!.createProgram({
rootNames: configParseResult.fileNames,
options: configParseResult.options,
projectReferences: configParseResult.projectReferences
})
: compiler!.createProgram([], compilerOptions);
//.........这里部分代码省略.........
示例6: color
return content.replace(regex, (item, pos, originalText) => {
return color(this.applyBinding(item, model, 2));
});
示例7: logger
? (message: string) => logger(stderrConsole, yellow(message))