source: node_modules/picocolors/picocolors.js

Last change on this file was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1let p = process || {}, argv = p.argv || [], env = p.env || {}
2let isColorSupported =
3 !(!!env.NO_COLOR || argv.includes("--no-color")) &&
4 (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || ((p.stdout || {}).isTTY && env.TERM !== "dumb") || !!env.CI)
5
6let formatter = (open, close, replace = open) =>
7 input => {
8 let string = "" + input, index = string.indexOf(close, open.length)
9 return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close
10 }
11
12let replaceClose = (string, close, replace, index) => {
13 let result = "", cursor = 0
14 do {
15 result += string.substring(cursor, index) + replace
16 cursor = index + close.length
17 index = string.indexOf(close, cursor)
18 } while (~index)
19 return result + string.substring(cursor)
20}
21
22let createColors = (enabled = isColorSupported) => {
23 let f = enabled ? formatter : () => String
24 return {
25 isColorSupported: enabled,
26 reset: f("\x1b[0m", "\x1b[0m"),
27 bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
28 dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
29 italic: f("\x1b[3m", "\x1b[23m"),
30 underline: f("\x1b[4m", "\x1b[24m"),
31 inverse: f("\x1b[7m", "\x1b[27m"),
32 hidden: f("\x1b[8m", "\x1b[28m"),
33 strikethrough: f("\x1b[9m", "\x1b[29m"),
34
35 black: f("\x1b[30m", "\x1b[39m"),
36 red: f("\x1b[31m", "\x1b[39m"),
37 green: f("\x1b[32m", "\x1b[39m"),
38 yellow: f("\x1b[33m", "\x1b[39m"),
39 blue: f("\x1b[34m", "\x1b[39m"),
40 magenta: f("\x1b[35m", "\x1b[39m"),
41 cyan: f("\x1b[36m", "\x1b[39m"),
42 white: f("\x1b[37m", "\x1b[39m"),
43 gray: f("\x1b[90m", "\x1b[39m"),
44
45 bgBlack: f("\x1b[40m", "\x1b[49m"),
46 bgRed: f("\x1b[41m", "\x1b[49m"),
47 bgGreen: f("\x1b[42m", "\x1b[49m"),
48 bgYellow: f("\x1b[43m", "\x1b[49m"),
49 bgBlue: f("\x1b[44m", "\x1b[49m"),
50 bgMagenta: f("\x1b[45m", "\x1b[49m"),
51 bgCyan: f("\x1b[46m", "\x1b[49m"),
52 bgWhite: f("\x1b[47m", "\x1b[49m"),
53
54 blackBright: f("\x1b[90m", "\x1b[39m"),
55 redBright: f("\x1b[91m", "\x1b[39m"),
56 greenBright: f("\x1b[92m", "\x1b[39m"),
57 yellowBright: f("\x1b[93m", "\x1b[39m"),
58 blueBright: f("\x1b[94m", "\x1b[39m"),
59 magentaBright: f("\x1b[95m", "\x1b[39m"),
60 cyanBright: f("\x1b[96m", "\x1b[39m"),
61 whiteBright: f("\x1b[97m", "\x1b[39m"),
62
63 bgBlackBright: f("\x1b[100m", "\x1b[49m"),
64 bgRedBright: f("\x1b[101m", "\x1b[49m"),
65 bgGreenBright: f("\x1b[102m", "\x1b[49m"),
66 bgYellowBright: f("\x1b[103m", "\x1b[49m"),
67 bgBlueBright: f("\x1b[104m", "\x1b[49m"),
68 bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
69 bgCyanBright: f("\x1b[106m", "\x1b[49m"),
70 bgWhiteBright: f("\x1b[107m", "\x1b[49m"),
71 }
72}
73
74module.exports = createColors()
75module.exports.createColors = createColors
Note: See TracBrowser for help on using the repository browser.