@validatem/core
Version:
The last validation library you'll ever need.
33 lines (25 loc) • 972 B
JavaScript
;
const supportsColor = require("supports-color");
// NOTE: We do some manual ANSI escape code stuff here for now, because using `chalk` would significantly inflate the bundle size of the core.
// TODO: Find a better solution for this.
let openHighlight, openDim, openHighlightBold, openDimBold, closeColor;
if (supportsColor.stderr) {
openHighlight = `\u001b[32m`; // green
openDim = `\u001b[90m`; // gray
openHighlightBold = `\u001b[32;1m`; // green bold
openDimBold = `\u001b[90;1m`; // gray bold
// closeColor = `\u001b[39m`; // Does not reset bold!
closeColor = `\u001b[0m`;
} else {
openHighlight = "";
openDim = "";
openHighlightBold = "";
openDimBold = "";
closeColor = "";
}
module.exports = {
dim: (string) => openDim + string + closeColor,
highlight: (string) => openHighlight + string + closeColor,
dimBold: (string) => openDimBold + string + closeColor,
highlightBold: (string) => openHighlightBold + string + closeColor,
};