source: trip-planner-front/node_modules/colorette/index.cjs@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1const tty = require("tty")
2
3const env = process.env
4
5const isDisabled = "NO_COLOR" in env
6const isForced = "FORCE_COLOR" in env
7const isWindows = process.platform === "win32"
8
9const isCompatibleTerminal =
10 tty && tty.isatty(1) && env.TERM && env.TERM !== "dumb"
11
12const isCI =
13 "CI" in env &&
14 ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env)
15
16let enabled =
17 !isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI)
18
19const raw = (open, close, searchRegex, replaceValue) => (s) =>
20 enabled
21 ? open +
22 (~(s += "").indexOf(close, 4) // skip opening \x1b[
23 ? s.replace(searchRegex, replaceValue)
24 : s) +
25 close
26 : s
27
28const init = (open, close) => {
29 return raw(
30 `\x1b[${open}m`,
31 `\x1b[${close}m`,
32 new RegExp(`\\x1b\\[${close}m`, "g"),
33 `\x1b[${open}m`
34 )
35}
36
37exports.options = Object.defineProperty({}, "enabled", {
38 get: () => enabled,
39 set: (value) => (enabled = value),
40})
41
42exports.reset = init(0, 0)
43exports.bold = raw("\x1b[1m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[1m")
44exports.dim = raw("\x1b[2m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[2m")
45exports.italic = init(3, 23)
46exports.underline = init(4, 24)
47exports.inverse = init(7, 27)
48exports.hidden = init(8, 28)
49exports.strikethrough = init(9, 29)
50exports.black = init(30, 39)
51exports.red = init(31, 39)
52exports.green = init(32, 39)
53exports.yellow = init(33, 39)
54exports.blue = init(34, 39)
55exports.magenta = init(35, 39)
56exports.cyan = init(36, 39)
57exports.white = init(37, 39)
58exports.gray = init(90, 39)
59exports.bgBlack = init(40, 49)
60exports.bgRed = init(41, 49)
61exports.bgGreen = init(42, 49)
62exports.bgYellow = init(43, 49)
63exports.bgBlue = init(44, 49)
64exports.bgMagenta = init(45, 49)
65exports.bgCyan = init(46, 49)
66exports.bgWhite = init(47, 49)
67exports.blackBright = init(90, 39)
68exports.redBright = init(91, 39)
69exports.greenBright = init(92, 39)
70exports.yellowBright = init(93, 39)
71exports.blueBright = init(94, 39)
72exports.magentaBright = init(95, 39)
73exports.cyanBright = init(96, 39)
74exports.whiteBright = init(97, 39)
75exports.bgBlackBright = init(100, 49)
76exports.bgRedBright = init(101, 49)
77exports.bgGreenBright = init(102, 49)
78exports.bgYellowBright = init(103, 49)
79exports.bgBlueBright = init(104, 49)
80exports.bgMagentaBright = init(105, 49)
81exports.bgCyanBright = init(106, 49)
82exports.bgWhiteBright = init(107, 49)
Note: See TracBrowser for help on using the repository browser.