@autorest/common
Version:
Autorest common utilities
27 lines • 1.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.color = void 0;
const chalk_1 = __importDefault(require("chalk"));
const NOT_EMPTY_LINE_REGEXP = /^(?!$)/gm;
function color(text) {
return text
.replace(/(\[.*?\])/gm, (_, x) => chalk_1.default.yellow.bold(x))
.replace(/\*\*(.*?)\*\*/gm, (_, x) => chalk_1.default.bold(x))
.replace(/^# (.*)/gm, (_, x) => chalk_1.default.greenBright(x))
.replace(/^## (.*)/gm, (_, x) => chalk_1.default.green(x))
.replace(/^### (.*)/gm, (_, x) => chalk_1.default.cyanBright(x))
.replace(/(https?:\/\/\S*)/gm, (_, x) => chalk_1.default.blue.bold.underline(x))
.replace(/_(.*)_/gm, (_, x) => chalk_1.default.italic(x))
.replace(/^>(.*)/gm, (_, x) => chalk_1.default.cyan(` ${x}`))
.replace(/^!(.*)/gm, (_, x) => chalk_1.default.red.bold(` ${x}`))
.replace(/```(.*)```/gs, (_, x) => indentAllLines(x, ` ${chalk_1.default.gray("|")} `))
.replace(/`(.+?)`/gm, (_, x) => chalk_1.default.gray(x))
.replace(/(".*?")/gm, (_, x) => chalk_1.default.gray(x))
.replace(/('.*?')/gm, (_, x) => chalk_1.default.gray(x));
}
exports.color = color;
const indentAllLines = (lines, indent) => lines.replace(NOT_EMPTY_LINE_REGEXP, indent);
//# sourceMappingURL=coloring.js.map