本文整理汇总了TypeScript中chalk.greenColor类的典型用法代码示例。如果您正苦于以下问题:TypeScript greenColor类的具体用法?TypeScript greenColor怎么用?TypeScript greenColor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了greenColor类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
messages.map(function(message) {
let messageType;
// fixable
const fixableIcon = message.fix ? chalk[greenColor].bold("\u2713 ") : "";
if (message.fix) {
totalFixable++;
}
if ((message as any).fatal || message.severity === 2) {
messageType = fixableIcon + chalk.red("error");
summaryColor = "red";
errors++;
} else {
messageType = fixableIcon + chalk.yellow("warning");
warnings++;
}
return [
"",
message.line || 0,
message.column || 0,
messageType,
message.message.replace(/\.$/, ""),
chalk.gray(message.ruleId || "")
];
}),
示例2:
messages.map(function(message) {
// fixable
totalFixed++;
const messageType = chalk[greenColor].bold("\u2714 ");
return [
"",
message.line || 0,
message.column || 0,
messageType,
message.message.replace(/\.$/, ""),
chalk.gray(message.ruleId || "")
];
}),
示例3: prettyError
messages.forEach(function(message) {
// fixable
const fixableIcon = message.fix ? chalk[greenColor].bold("\u2713 ") : "";
if (message.fix) {
totalFixable++;
}
if ((message as any).fatal || message.severity === 2) {
errors++;
} else {
warnings++;
}
const r = fixableIcon + prettyError(code, result.filePath, message);
if (r) {
output += r + "\n";
}
});
示例4: formatter
function formatter(results: TextlintResult[]) {
let output = "\n";
let total = 0;
let totalFixable = 0;
let errors = 0;
let warnings = 0;
let summaryColor = "yellow";
let greenColor = "green";
results.forEach(function(result) {
const messages = result.messages;
if (messages.length === 0) {
return;
}
total += messages.length;
output += chalk.underline(result.filePath) + "\n";
output +=
table(
messages.map(function(message) {
let messageType;
// fixable
const fixableIcon = message.fix ? chalk[greenColor].bold("\u2713 ") : "";
if (message.fix) {
totalFixable++;
}
if ((message as any).fatal || message.severity === 2) {
messageType = fixableIcon + chalk.red("error");
summaryColor = "red";
errors++;
} else {
messageType = fixableIcon + chalk.yellow("warning");
warnings++;
}
return [
"",
message.line || 0,
message.column || 0,
messageType,
message.message.replace(/\.$/, ""),
chalk.gray(message.ruleId || "")
];
}),
{
align: ["", "r", "l"],
stringLength: function(str: string) {
const lines = chalk.stripColor(str).split("\n");
return Math.max.apply(
null,
lines.map(function(line: string) {
return widthOfString(line);
})
);
}
}
)
.split("\n")
.map(function(el: string) {
return el.replace(/(\d+)\s+(\d+)/, function(_, p1, p2) {
return chalk.gray(p1 + ":" + p2);
});
})
.join("\n") + "\n\n";
});
if (total > 0) {
output += chalk[summaryColor].bold(
[
"\u2716 ",
total,
pluralize(" problem", total),
" (",
errors,
pluralize(" error", errors),
", ",
warnings,
pluralize(" warning", warnings),
")\n"
].join("")
);
}
if (totalFixable > 0) {
output += chalk[greenColor].bold(
"✓ " + totalFixable + " fixable " + pluralize("problem", totalFixable) + ".\n"
);
output += "Try to run: $ " + chalk.underline("textlint --fix [file]") + "\n";
}
return total > 0 ? output : "";
}
示例5: function
export default function(results: TextlintFixResult[], options: any) {
// default: true
chalk.enabled = options.color !== undefined ? options.color : true;
let output = "\n";
let totalFixed = 0;
let errors = 0;
const summaryColor = "yellow";
const greenColor = "green";
results.forEach(function(result) {
const filePath = result.filePath;
const messages = result.applyingMessages;
// still error count
const remainingMessages = result.remainingMessages;
errors += remainingMessages.length;
totalFixed += messages.length;
if (messages.length === 0) {
return;
}
if (!isFile(filePath)) {
return;
}
output += `${chalk.underline(result.filePath)}\n`;
const originalContent = fs.readFileSync(filePath, "utf-8");
const diff = jsdiff.diffLines(originalContent, result.output);
diff.forEach(function(part: any, index: number) {
const prevLine = diff[index - 1];
const nextLine = diff[index + 1];
if (!isModified(part) && part.count > 1) {
const greyColor = "grey";
/*
<MODIFIED>
first line
....
*/
if (isModified(prevLine)) {
const lines = part.value.split("\n");
output += `${chalk[greyColor](lines[0])}\n`;
}
output += chalk[greyColor]("...");
if (isModified(nextLine)) {
const lines = part.value.split("\n");
output += `${chalk[greyColor](lines[lines.length - 1])}\n`;
}
/*
...
last line
<MODIFIED>
*/
return;
}
// green for additions, red for deletions
// grey for common parts
let lineColor;
let diffMark = "";
if (part.added) {
lineColor = "green";
diffMark = "+ ";
} else if (part.removed) {
lineColor = "red";
diffMark = "- ";
} else {
lineColor = "grey";
diffMark = "";
}
output += chalk[lineColor](addMarkEachLine(diffMark, part.value));
});
output += "\n\n";
});
if (totalFixed > 0) {
output += chalk[greenColor].bold(
[
// http://www.fileformat.info/info/unicode/char/2714/index.htm
"✔ Fixed ",
totalFixed,
pluralize(" problem", totalFixed),
"\n"
].join("")
);
}
if (errors > 0) {
output += chalk[summaryColor].bold(
[
// http://www.fileformat.info/info/unicode/char/2716/index.htm
"✖ Remaining ",
errors,
pluralize(" problem", errors),
"\n"
].join("")
);
}
return totalFixed > 0 ? output : "";
}
示例6: function
export default function(results: TextlintFixResult[], options: any) {
// default: true
chalk.enabled = options.color !== undefined ? options.color : true;
let output = "\n";
let totalFixed = 0;
let errors = 0;
const summaryColor = "yellow";
const greenColor = "green";
results.forEach(function(result) {
if (!result.applyingMessages || !result.remainingMessages) {
return;
}
const messages = result.applyingMessages;
// still error count
const remainingMessages = result.remainingMessages;
errors += remainingMessages.length;
if (messages.length === 0) {
return;
}
output += `${chalk.underline(result.filePath)}\n`;
output += `${table(
messages.map(function(message) {
// fixable
totalFixed++;
const messageType = chalk[greenColor].bold("\u2714 ");
return [
"",
message.line || 0,
message.column || 0,
messageType,
message.message.replace(/\.$/, ""),
chalk.gray(message.ruleId || "")
];
}),
{
align: ["", "r", "l"],
stringLength: (str: string) => {
const lines = chalk.stripColor(str).split("\n");
return Math.max.apply(
null,
lines.map(function(line: string) {
return widthOfString(line);
})
);
}
}
)
.split("\n")
.map(function(el: string) {
return el.replace(/(\d+)\s+(\d+)/, function(_m, p1, p2) {
return chalk.gray(`${p1}:${p2}`);
});
})
.join("\n")}\n\n`;
});
if (totalFixed > 0) {
output += chalk[greenColor].bold(
[
// http://www.fileformat.info/info/unicode/char/2714/index.htm
"\u2714 Fixed ",
totalFixed,
pluralize(" problem", totalFixed),
"\n"
].join("")
);
}
if (errors > 0) {
output += chalk[summaryColor].bold(
[
// http://www.fileformat.info/info/unicode/char/2716/index.htm
"\u2716 Remaining ",
errors,
pluralize(" problem", errors),
"\n"
].join("")
);
}
return totalFixed > 0 ? output : "";
}
示例7: formatter
/**
*
* @param {TextLintResult[]} results
* @param {TextLintFormatterOption} options
* @returns {string}
*/
function formatter(results: TextlintResult[], options: TextLintFormatterOption) {
// default: true
const useColor = options.color !== undefined ? options.color : true;
let output = "";
let total = 0;
let errors = 0;
let warnings = 0;
let totalFixable = 0;
results.forEach(function(result) {
const code = require("fs").readFileSync(result.filePath, "utf-8");
const messages = result.messages;
if (messages.length === 0) {
return;
}
total += messages.length;
messages.forEach(function(message) {
// fixable
const fixableIcon = message.fix ? chalk[greenColor].bold("\u2713 ") : "";
if (message.fix) {
totalFixable++;
}
if ((message as any).fatal || message.severity === 2) {
errors++;
} else {
warnings++;
}
const r = fixableIcon + prettyError(code, result.filePath, message);
if (r) {
output += r + "\n";
}
});
});
if (total > 0) {
output += chalk[summaryColor].bold(
[
"\u2716 ",
total,
pluralize(" problem", total),
" (",
errors,
pluralize(" error", errors),
", ",
warnings,
pluralize(" warning", warnings),
")\n"
].join("")
);
}
if (totalFixable > 0) {
output += chalk[greenColor].bold(
"✓ " + totalFixable + " fixable " + pluralize("problem", totalFixable) + ".\n"
);
output += "Try to run: $ " + chalk.underline("textlint --fix [file]") + "\n";
}
if (!useColor) {
return stripAnsi(output);
}
return output;
}