@roboplay/sage
Version:
Codemod for Robo.js
119 lines (117 loc) • 4.17 kB
JavaScript
import tty from 'node:tty';
const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
const isWindows = platform === "win32";
const isDumbTerminal = env.TERM === "dumb";
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === void 0) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
const hexToRgb = (hex2) => {
const match = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex2);
if (!match) {
return null;
} else {
return {
r: parseInt(match[1], 16),
g: parseInt(match[2], 16),
b: parseInt(match[3], 16)
};
}
};
const init = (open, close, replace) => {
const openStr = typeof open === "object" ? `\x1B[38;2;${open.r};${open.g};${open.b}m` : `\x1B[${open}m`;
const closeStr = typeof close === "object" ? `\x1B[38;2;${close.r};${close.g};${close.b}m` : `\x1B[${close}m`;
return filterEmpty(openStr, closeStr, replace);
};
const color = {
reset: init(0, 0),
bold: init(1, 22, "\x1B[22m\x1B[1m"),
dim: init(2, 22, "\x1B[22m\x1B[2m"),
italic: init(3, 23),
underline: init(4, 24),
inverse: init(7, 27),
hidden: init(8, 28),
strikethrough: init(9, 29),
black: init(30, 39),
red: init(31, 39),
green: init(32, 39),
yellow: init(33, 39),
blue: init(34, 39),
magenta: init(35, 39),
cyan: init(36, 39),
white: init(37, 39),
gray: init(90, 39),
bgBlack: init(40, 49),
bgRed: init(41, 49),
bgGreen: init(42, 49),
bgYellow: init(43, 49),
bgBlue: init(44, 49),
bgMagenta: init(45, 49),
bgCyan: init(46, 49),
bgWhite: init(47, 49),
blackBright: init(90, 39),
redBright: init(91, 39),
greenBright: init(92, 39),
yellowBright: init(93, 39),
blueBright: init(94, 39),
magentaBright: init(95, 39),
cyanBright: init(96, 39),
whiteBright: init(97, 39),
bgBlackBright: init(100, 49),
bgRedBright: init(101, 49),
bgGreenBright: init(102, 49),
bgYellowBright: init(103, 49),
bgBlueBright: init(104, 49),
bgMagentaBright: init(105, 49),
bgCyanBright: init(106, 49),
bgWhiteBright: init(107, 49)
};
function composeColors(...fns) {
return (s) => fns.reduce((acc, fn) => fn(acc), s);
}
const hex = (hex2) => {
const rgb = hexToRgb(hex2);
return rgb ? init(rgb, { r: 255, g: 255, b: 255 }) : init(37, 39);
};
const createColors = ({ useColor = isColorSupported } = {}) => useColor ? color : Object.keys(color).reduce((colors, key) => ({ ...colors, [key]: String }), {});
const {
reset,
bold,
dim,
italic,
underline,
inverse,
hidden,
strikethrough,
black,
red,
green,
yellow,
blue,
magenta,
cyan,
white,
gray,
bgBlack,
bgRed,
bgGreen,
bgYellow,
bgBlue,
bgMagenta,
bgCyan,
bgWhite,
blackBright,
redBright,
greenBright,
yellowBright,
blueBright,
magentaBright,
cyanBright
} = createColors();
export { bgBlack, bgBlue, bgCyan, bgGreen, bgMagenta, bgRed, bgWhite, bgYellow, black, blackBright, blue, blueBright, bold, color, composeColors, createColors, cyan, cyanBright, dim, gray, green, greenBright, hex, hidden, inverse, isColorSupported, italic, magenta, magentaBright, red, redBright, reset, strikethrough, underline, white, yellow, yellowBright };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=color.js.map