@breadc/color 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 XLor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @breadc/color
2
+
3
+ [![version](https://img.shields.io/npm/v/@breadc/color?color=rgb%2850%2C203%2C86%29&label=@breadc/color)](https://www.npmjs.com/package/@breadc/color) [![CI](https://github.com/yjl9903/Breadc/actions/workflows/ci.yml/badge.svg)](https://github.com/yjl9903/Breadc/actions/workflows/ci.yml)
4
+
5
+ ![example](../../images/color.png)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm i @breadc/color
11
+ ```
12
+
13
+ ## License
14
+
15
+ MIT License © 2023 [XLor](https://github.com/yjl9903)
package/dist/index.cjs ADDED
@@ -0,0 +1,156 @@
1
+ 'use strict';
2
+
3
+ var SupportLevel = /* @__PURE__ */ ((SupportLevel2) => {
4
+ SupportLevel2[SupportLevel2["none"] = 0] = "none";
5
+ SupportLevel2[SupportLevel2["ansi"] = 1] = "ansi";
6
+ SupportLevel2[SupportLevel2["ansi256"] = 2] = "ansi256";
7
+ return SupportLevel2;
8
+ })(SupportLevel || {});
9
+ const options = {
10
+ enabled: true,
11
+ supportLevel: 0 /* none */
12
+ };
13
+ const globalVar = (
14
+ // @ts-ignore
15
+ typeof self !== "undefined" ? (
16
+ // @ts-ignore
17
+ self
18
+ ) : (
19
+ // @ts-ignore
20
+ typeof window !== "undefined" ? (
21
+ // @ts-ignore
22
+ window
23
+ ) : typeof global !== "undefined" ? global : {}
24
+ )
25
+ );
26
+ if (globalVar.process && globalVar.process.env && globalVar.process.stdout) {
27
+ const { FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = globalVar.process.env;
28
+ if (NODE_DISABLE_COLORS || NO_COLOR || FORCE_COLOR === "0") {
29
+ options.enabled = false;
30
+ } else if (FORCE_COLOR === "1" || FORCE_COLOR === "2" || FORCE_COLOR === "3") {
31
+ options.enabled = true;
32
+ } else if (TERM === "dumb") {
33
+ options.enabled = false;
34
+ } else if ("CI" in globalVar.process.env && [
35
+ "TRAVIS",
36
+ "CIRCLECI",
37
+ "APPVEYOR",
38
+ "GITLAB_CI",
39
+ "GITHUB_ACTIONS",
40
+ "BUILDKITE",
41
+ "DRONE"
42
+ ].some((vendor) => vendor in globalVar.process.env)) {
43
+ options.enabled = true;
44
+ } else {
45
+ options.enabled = process.stdout.isTTY;
46
+ }
47
+ if (options.enabled) {
48
+ options.supportLevel = TERM && TERM.endsWith("-256color") ? 2 /* ansi256 */ : 1 /* ansi */;
49
+ }
50
+ }
51
+ function kolorist(start, end, level = 1 /* ansi */) {
52
+ const open = `\x1B[${start}m`;
53
+ const close = `\x1B[${end}m`;
54
+ const regex = new RegExp(`\\x1b\\[${end}m`, "g");
55
+ return (str) => {
56
+ return options.enabled && options.supportLevel >= level ? open + ("" + str).replace(regex, open) + close : "" + str;
57
+ };
58
+ }
59
+ function stripColors(str) {
60
+ return ("" + str).replace(/\x1b\[[0-9;]+m/g, "").replace(/\x1b\]8;;.*?\x07(.*?)\x1b\]8;;\x07/g, (_, group) => group);
61
+ }
62
+ const reset = kolorist(0, 0);
63
+ const bold = kolorist(1, 22);
64
+ const dim = kolorist(2, 22);
65
+ const italic = kolorist(3, 23);
66
+ const underline = kolorist(4, 24);
67
+ const inverse = kolorist(7, 27);
68
+ const hidden = kolorist(8, 28);
69
+ const strikethrough = kolorist(9, 29);
70
+ const black = kolorist(30, 39);
71
+ const red = kolorist(31, 39);
72
+ const green = kolorist(32, 39);
73
+ const yellow = kolorist(33, 39);
74
+ const blue = kolorist(34, 39);
75
+ const magenta = kolorist(35, 39);
76
+ const cyan = kolorist(36, 39);
77
+ const white = kolorist(97, 39);
78
+ const gray = kolorist(90, 39);
79
+ const lightRed = kolorist(91, 39);
80
+ const lightGreen = kolorist(92, 39);
81
+ const lightYellow = kolorist(93, 39);
82
+ const lightBlue = kolorist(94, 39);
83
+ const lightMagenta = kolorist(95, 39);
84
+ const lightCyan = kolorist(96, 39);
85
+ const lightGray = kolorist(37, 39);
86
+ const bgBlack = kolorist(40, 49);
87
+ const bgRed = kolorist(41, 49);
88
+ const bgGreen = kolorist(42, 49);
89
+ const bgYellow = kolorist(43, 49);
90
+ const bgBlue = kolorist(44, 49);
91
+ const bgMagenta = kolorist(45, 49);
92
+ const bgCyan = kolorist(46, 49);
93
+ const bgWhite = kolorist(107, 49);
94
+ const bgGray = kolorist(100, 49);
95
+ const bgLightRed = kolorist(101, 49);
96
+ const bgLightGreen = kolorist(102, 49);
97
+ const bgLightYellow = kolorist(103, 49);
98
+ const bgLightBlue = kolorist(104, 49);
99
+ const bgLightMagenta = kolorist(105, 49);
100
+ const bgLightCyan = kolorist(106, 49);
101
+ const bgLightGray = kolorist(47, 49);
102
+ const ansi256 = (n) => kolorist("38;5;" + n, 0, 2 /* ansi256 */);
103
+ const ansi256Bg = (n) => kolorist("48;5;" + n, 0, 2 /* ansi256 */);
104
+ const OSC = "\x1B]";
105
+ const BEL = "\x07";
106
+ const SEP = ";";
107
+ function link(text, url) {
108
+ return options.enabled ? OSC + "8" + SEP + SEP + url + BEL + text + OSC + "8" + SEP + SEP + BEL : `${text} (\u200B${url}\u200B)`;
109
+ }
110
+
111
+ exports.SupportLevel = SupportLevel;
112
+ exports.ansi256 = ansi256;
113
+ exports.ansi256Bg = ansi256Bg;
114
+ exports.bgBlack = bgBlack;
115
+ exports.bgBlue = bgBlue;
116
+ exports.bgCyan = bgCyan;
117
+ exports.bgGray = bgGray;
118
+ exports.bgGreen = bgGreen;
119
+ exports.bgLightBlue = bgLightBlue;
120
+ exports.bgLightCyan = bgLightCyan;
121
+ exports.bgLightGray = bgLightGray;
122
+ exports.bgLightGreen = bgLightGreen;
123
+ exports.bgLightMagenta = bgLightMagenta;
124
+ exports.bgLightRed = bgLightRed;
125
+ exports.bgLightYellow = bgLightYellow;
126
+ exports.bgMagenta = bgMagenta;
127
+ exports.bgRed = bgRed;
128
+ exports.bgWhite = bgWhite;
129
+ exports.bgYellow = bgYellow;
130
+ exports.black = black;
131
+ exports.blue = blue;
132
+ exports.bold = bold;
133
+ exports.cyan = cyan;
134
+ exports.dim = dim;
135
+ exports.gray = gray;
136
+ exports.green = green;
137
+ exports.hidden = hidden;
138
+ exports.inverse = inverse;
139
+ exports.italic = italic;
140
+ exports.lightBlue = lightBlue;
141
+ exports.lightCyan = lightCyan;
142
+ exports.lightGray = lightGray;
143
+ exports.lightGreen = lightGreen;
144
+ exports.lightMagenta = lightMagenta;
145
+ exports.lightRed = lightRed;
146
+ exports.lightYellow = lightYellow;
147
+ exports.link = link;
148
+ exports.magenta = magenta;
149
+ exports.options = options;
150
+ exports.red = red;
151
+ exports.reset = reset;
152
+ exports.strikethrough = strikethrough;
153
+ exports.stripColors = stripColors;
154
+ exports.underline = underline;
155
+ exports.white = white;
156
+ exports.yellow = yellow;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Detect how much colors the current terminal supports
3
+ */
4
+ declare const enum SupportLevel {
5
+ none = 0,
6
+ ansi = 1,
7
+ ansi256 = 2
8
+ }
9
+ /**
10
+ * Config whether enable color output
11
+ */
12
+ declare const options: {
13
+ enabled: boolean;
14
+ supportLevel: SupportLevel;
15
+ };
16
+ declare function stripColors(str: string | number): string;
17
+ declare const reset: (str: string | number) => string;
18
+ declare const bold: (str: string | number) => string;
19
+ declare const dim: (str: string | number) => string;
20
+ declare const italic: (str: string | number) => string;
21
+ declare const underline: (str: string | number) => string;
22
+ declare const inverse: (str: string | number) => string;
23
+ declare const hidden: (str: string | number) => string;
24
+ declare const strikethrough: (str: string | number) => string;
25
+ declare const black: (str: string | number) => string;
26
+ declare const red: (str: string | number) => string;
27
+ declare const green: (str: string | number) => string;
28
+ declare const yellow: (str: string | number) => string;
29
+ declare const blue: (str: string | number) => string;
30
+ declare const magenta: (str: string | number) => string;
31
+ declare const cyan: (str: string | number) => string;
32
+ declare const white: (str: string | number) => string;
33
+ declare const gray: (str: string | number) => string;
34
+ declare const lightRed: (str: string | number) => string;
35
+ declare const lightGreen: (str: string | number) => string;
36
+ declare const lightYellow: (str: string | number) => string;
37
+ declare const lightBlue: (str: string | number) => string;
38
+ declare const lightMagenta: (str: string | number) => string;
39
+ declare const lightCyan: (str: string | number) => string;
40
+ declare const lightGray: (str: string | number) => string;
41
+ declare const bgBlack: (str: string | number) => string;
42
+ declare const bgRed: (str: string | number) => string;
43
+ declare const bgGreen: (str: string | number) => string;
44
+ declare const bgYellow: (str: string | number) => string;
45
+ declare const bgBlue: (str: string | number) => string;
46
+ declare const bgMagenta: (str: string | number) => string;
47
+ declare const bgCyan: (str: string | number) => string;
48
+ declare const bgWhite: (str: string | number) => string;
49
+ declare const bgGray: (str: string | number) => string;
50
+ declare const bgLightRed: (str: string | number) => string;
51
+ declare const bgLightGreen: (str: string | number) => string;
52
+ declare const bgLightYellow: (str: string | number) => string;
53
+ declare const bgLightBlue: (str: string | number) => string;
54
+ declare const bgLightMagenta: (str: string | number) => string;
55
+ declare const bgLightCyan: (str: string | number) => string;
56
+ declare const bgLightGray: (str: string | number) => string;
57
+ declare const ansi256: (n: number) => (str: string | number) => string;
58
+ declare const ansi256Bg: (n: number) => (str: string | number) => string;
59
+ declare function link(text: string, url: string): string;
60
+
61
+ export { SupportLevel, ansi256, ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, options, red, reset, strikethrough, stripColors, underline, white, yellow };
package/dist/index.mjs ADDED
@@ -0,0 +1,109 @@
1
+ var SupportLevel = /* @__PURE__ */ ((SupportLevel2) => {
2
+ SupportLevel2[SupportLevel2["none"] = 0] = "none";
3
+ SupportLevel2[SupportLevel2["ansi"] = 1] = "ansi";
4
+ SupportLevel2[SupportLevel2["ansi256"] = 2] = "ansi256";
5
+ return SupportLevel2;
6
+ })(SupportLevel || {});
7
+ const options = {
8
+ enabled: true,
9
+ supportLevel: 0 /* none */
10
+ };
11
+ const globalVar = (
12
+ // @ts-ignore
13
+ typeof self !== "undefined" ? (
14
+ // @ts-ignore
15
+ self
16
+ ) : (
17
+ // @ts-ignore
18
+ typeof window !== "undefined" ? (
19
+ // @ts-ignore
20
+ window
21
+ ) : typeof global !== "undefined" ? global : {}
22
+ )
23
+ );
24
+ if (globalVar.process && globalVar.process.env && globalVar.process.stdout) {
25
+ const { FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = globalVar.process.env;
26
+ if (NODE_DISABLE_COLORS || NO_COLOR || FORCE_COLOR === "0") {
27
+ options.enabled = false;
28
+ } else if (FORCE_COLOR === "1" || FORCE_COLOR === "2" || FORCE_COLOR === "3") {
29
+ options.enabled = true;
30
+ } else if (TERM === "dumb") {
31
+ options.enabled = false;
32
+ } else if ("CI" in globalVar.process.env && [
33
+ "TRAVIS",
34
+ "CIRCLECI",
35
+ "APPVEYOR",
36
+ "GITLAB_CI",
37
+ "GITHUB_ACTIONS",
38
+ "BUILDKITE",
39
+ "DRONE"
40
+ ].some((vendor) => vendor in globalVar.process.env)) {
41
+ options.enabled = true;
42
+ } else {
43
+ options.enabled = process.stdout.isTTY;
44
+ }
45
+ if (options.enabled) {
46
+ options.supportLevel = TERM && TERM.endsWith("-256color") ? 2 /* ansi256 */ : 1 /* ansi */;
47
+ }
48
+ }
49
+ function kolorist(start, end, level = 1 /* ansi */) {
50
+ const open = `\x1B[${start}m`;
51
+ const close = `\x1B[${end}m`;
52
+ const regex = new RegExp(`\\x1b\\[${end}m`, "g");
53
+ return (str) => {
54
+ return options.enabled && options.supportLevel >= level ? open + ("" + str).replace(regex, open) + close : "" + str;
55
+ };
56
+ }
57
+ function stripColors(str) {
58
+ return ("" + str).replace(/\x1b\[[0-9;]+m/g, "").replace(/\x1b\]8;;.*?\x07(.*?)\x1b\]8;;\x07/g, (_, group) => group);
59
+ }
60
+ const reset = kolorist(0, 0);
61
+ const bold = kolorist(1, 22);
62
+ const dim = kolorist(2, 22);
63
+ const italic = kolorist(3, 23);
64
+ const underline = kolorist(4, 24);
65
+ const inverse = kolorist(7, 27);
66
+ const hidden = kolorist(8, 28);
67
+ const strikethrough = kolorist(9, 29);
68
+ const black = kolorist(30, 39);
69
+ const red = kolorist(31, 39);
70
+ const green = kolorist(32, 39);
71
+ const yellow = kolorist(33, 39);
72
+ const blue = kolorist(34, 39);
73
+ const magenta = kolorist(35, 39);
74
+ const cyan = kolorist(36, 39);
75
+ const white = kolorist(97, 39);
76
+ const gray = kolorist(90, 39);
77
+ const lightRed = kolorist(91, 39);
78
+ const lightGreen = kolorist(92, 39);
79
+ const lightYellow = kolorist(93, 39);
80
+ const lightBlue = kolorist(94, 39);
81
+ const lightMagenta = kolorist(95, 39);
82
+ const lightCyan = kolorist(96, 39);
83
+ const lightGray = kolorist(37, 39);
84
+ const bgBlack = kolorist(40, 49);
85
+ const bgRed = kolorist(41, 49);
86
+ const bgGreen = kolorist(42, 49);
87
+ const bgYellow = kolorist(43, 49);
88
+ const bgBlue = kolorist(44, 49);
89
+ const bgMagenta = kolorist(45, 49);
90
+ const bgCyan = kolorist(46, 49);
91
+ const bgWhite = kolorist(107, 49);
92
+ const bgGray = kolorist(100, 49);
93
+ const bgLightRed = kolorist(101, 49);
94
+ const bgLightGreen = kolorist(102, 49);
95
+ const bgLightYellow = kolorist(103, 49);
96
+ const bgLightBlue = kolorist(104, 49);
97
+ const bgLightMagenta = kolorist(105, 49);
98
+ const bgLightCyan = kolorist(106, 49);
99
+ const bgLightGray = kolorist(47, 49);
100
+ const ansi256 = (n) => kolorist("38;5;" + n, 0, 2 /* ansi256 */);
101
+ const ansi256Bg = (n) => kolorist("48;5;" + n, 0, 2 /* ansi256 */);
102
+ const OSC = "\x1B]";
103
+ const BEL = "\x07";
104
+ const SEP = ";";
105
+ function link(text, url) {
106
+ return options.enabled ? OSC + "8" + SEP + SEP + url + BEL + text + OSC + "8" + SEP + SEP + BEL : `${text} (\u200B${url}\u200B)`;
107
+ }
108
+
109
+ export { SupportLevel, ansi256, ansi256Bg, bgBlack, bgBlue, bgCyan, bgGray, bgGreen, bgLightBlue, bgLightCyan, bgLightGray, bgLightGreen, bgLightMagenta, bgLightRed, bgLightYellow, bgMagenta, bgRed, bgWhite, bgYellow, black, blue, bold, cyan, dim, gray, green, hidden, inverse, italic, lightBlue, lightCyan, lightGray, lightGreen, lightMagenta, lightRed, lightYellow, link, magenta, options, red, reset, strikethrough, stripColors, underline, white, yellow };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@breadc/color",
3
+ "version": "0.8.0",
4
+ "description": "Terminal color for Breadc",
5
+ "keywords": [
6
+ "breadc",
7
+ "progress",
8
+ "cli",
9
+ "command-line"
10
+ ],
11
+ "homepage": "https://github.com/yjl9903/Breadc#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/yjl9903/Breadc/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/yjl9903/Breadc.git"
18
+ },
19
+ "license": "MIT",
20
+ "author": "XLor",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "require": "./dist/index.cjs",
25
+ "import": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts"
27
+ }
28
+ },
29
+ "main": "./dist/index.cjs",
30
+ "module": "./dist/index.mjs",
31
+ "types": "./dist/index.d.ts",
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "devDependencies": {
36
+ "@types/node": "^18.11.18",
37
+ "vitest": "^0.28.3"
38
+ },
39
+ "scripts": {
40
+ "build": "unbuild",
41
+ "format": "prettier --write src/**/*.ts test/*.ts",
42
+ "test": "vitest",
43
+ "test:ci": "vitest --run",
44
+ "typecheck": "tsc --noEmit"
45
+ }
46
+ }