@prm-programmer/safe-chalk 1.0.0 → 2.4.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/index.d.ts +66 -0
- package/index.js +56 -23
- package/package.json +19 -5
package/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Описываем структуру одной функции в цепочке
|
|
2
|
+
interface ChalkInstance {
|
|
3
|
+
(text?: string): ChalkInstance | string;
|
|
4
|
+
|
|
5
|
+
// Системные стили
|
|
6
|
+
reset(): ChalkInstance;
|
|
7
|
+
bold(): ChalkInstance;
|
|
8
|
+
dim(): ChalkInstance;
|
|
9
|
+
italic(): ChalkInstance;
|
|
10
|
+
underline(): ChalkInstance;
|
|
11
|
+
inverse(): ChalkInstance;
|
|
12
|
+
hidden(): ChalkInstance;
|
|
13
|
+
strikethrough(): ChalkInstance;
|
|
14
|
+
|
|
15
|
+
// Базовые системные фоны
|
|
16
|
+
bgRed(): ChalkInstance;
|
|
17
|
+
bgGreen(): ChalkInstance;
|
|
18
|
+
bgYellow(): ChalkInstance;
|
|
19
|
+
bgBlue(): ChalkInstance;
|
|
20
|
+
|
|
21
|
+
// --- ВАША ПАЛИТРА ЦВЕТОВ ТЕКСТА ---
|
|
22
|
+
Red(): ChalkInstance;
|
|
23
|
+
Blue(): ChalkInstance;
|
|
24
|
+
Tomato(): ChalkInstance;
|
|
25
|
+
Orange(): ChalkInstance;
|
|
26
|
+
Gold(): ChalkInstance;
|
|
27
|
+
Yellow(): ChalkInstance;
|
|
28
|
+
Lime(): ChalkInstance;
|
|
29
|
+
Green(): ChalkInstance;
|
|
30
|
+
Cyan(): ChalkInstance;
|
|
31
|
+
Teal(): ChalkInstance;
|
|
32
|
+
Navy(): ChalkInstance;
|
|
33
|
+
MidnightBlue(): ChalkInstance;
|
|
34
|
+
Magenta(): ChalkInstance;
|
|
35
|
+
Purple(): ChalkInstance;
|
|
36
|
+
White(): ChalkInstance;
|
|
37
|
+
Gray(): ChalkInstance;
|
|
38
|
+
Black(): ChalkInstance;
|
|
39
|
+
// Добавьте сюда остальные редкие цвета (IndianRed, Khaki и т.д.) через двоеточие (): ChalkInstance;
|
|
40
|
+
|
|
41
|
+
// --- ВАША ПАЛИТРА ЦВЕТОВ ФОНА ---
|
|
42
|
+
bgTomato(): ChalkInstance;
|
|
43
|
+
bgOrange(): ChalkInstance;
|
|
44
|
+
bgGold(): ChalkInstance;
|
|
45
|
+
bgYellow(): ChalkInstance;
|
|
46
|
+
bgLime(): ChalkInstance;
|
|
47
|
+
bgGreen(): ChalkInstance;
|
|
48
|
+
bgCyan(): ChalkInstance;
|
|
49
|
+
bgTeal(): ChalkInstance;
|
|
50
|
+
bgMidnightBlue(): ChalkInstance;
|
|
51
|
+
bgMagenta(): ChalkInstance;
|
|
52
|
+
bgPurple(): ChalkInstance;
|
|
53
|
+
bgWhite(): ChalkInstance;
|
|
54
|
+
bgBlack(): ChalkInstance;
|
|
55
|
+
// Добавьте сюда остальные фоны (bgIndianRed и т.д.) через двоеточие (): ChalkInstance;
|
|
56
|
+
|
|
57
|
+
/** Динамический пользовательский цвет, заданный через setCustomColor */
|
|
58
|
+
custom(): ChalkInstance;
|
|
59
|
+
|
|
60
|
+
/** Устанавливает кастомные RGB компоненты (0-255) для метода .custom() */
|
|
61
|
+
setCustomColor(red: number, green: number, blue: number): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Объявляем, что модуль экспортирует этот объект
|
|
65
|
+
declare const myChalk: ChalkInstance;
|
|
66
|
+
export = myChalk;
|
package/index.js
CHANGED
|
@@ -1,33 +1,66 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
underline: '\x1b[4m',
|
|
5
|
-
red: '\x1b[31m',
|
|
6
|
-
green: '\x1b[32m',
|
|
7
|
-
yellow: '\x1b[33m',
|
|
8
|
-
blue: '\x1b[34m',
|
|
9
|
-
magenta: '\x1b[35m',
|
|
10
|
-
cyan: '\x1b[36m',
|
|
11
|
-
bgRed: '\x1b[41m',
|
|
12
|
-
bgGreen: '\x1b[42m',
|
|
13
|
-
bgYellow: '\x1b[43m',
|
|
14
|
-
bgBlue: '\x1b[44m'
|
|
15
|
-
};
|
|
1
|
+
const RGB_COLORS = {"Red":[255,0,0],"Blue":[0,0,255],"IndianRed":[205,92,92],"LightCoral":[240,128,128],"Salmon":[250,128,114],"DarkSalmon":[233,150,122],"LightSalmon":[255,160,122],"Crimson":[220,20,60],"FireBrick":[178,34,34],"DarkRed":[139,0,0],"Pink":[255,192,203],"LightPink":[255,182,193],"HotPink":[255,105,180],"DeepPink":[255,20,147],"MediumVioletRed":[199,21,133],"PaleVioletRed":[219,112,147],"Coral":[255,127,80],"Tomato":[255,99,71],"OrangeRed":[255,69,0],"DarkOrange":[255,140,0],"Orange":[255,165,0],"Gold":[255,215,0],"Yellow":[255,255,0],"LightYellow":[255,255,224],"LemonChiffon":[255,250,205],"LightGoldenrodYellow":[250,250,210],"PapayaWhip":[255,239,213],"Moccasin":[255,228,181],"PeachPuff":[255,218,185],"PaleGoldenrod":[238,232,170],"Khaki":[240,230,140],"DarkKhaki":[189,183,107],"GreenYellow":[173,255,47],"Chartreuse":[127,255,0],"LawnGreen":[124,252,0],"Lime":[0,255,0],"LimeGreen":[50,205,50],"PaleGreen":[152,251,152],"LightGreen":[144,238,144],"MediumSpringGreen":[0,250,154],"SpringGreen":[0,255,127],"SeaGreen":[46,139,87],"ForestGreen":[34,139,34],"Green":[0,128,0],"DarkGreen":[0,100,0],"YellowGreen":[154,205,50],"OliveDrab":[107,142,35],"Olive":[128,128,0],"DarkOliveGreen":[85,107,47],"MediumAquamarine":[102,205,170],"DarkSeaGreen":[143,188,143],"LightSeaGreen":[32,178,170],"DarkCyan":[0,139,139],"Teal":[0,128,128],"Aqua":[0,255,255],"Cyan":[0,255,255],"LightCyan":[224,255,255],"PaleTurquoise":[175,238,238],"Aquamarine":[127,255,212],"Turquoise":[64,224,208],"MediumTurquoise":[72,209,204],"DarkTurquoise":[0,206,209],"CadetBlue":[95,158,160],"SteelBlue":[70,130,180],"LightSteelBlue":[176,196,222],"PowderBlue":[176,224,230],"LightBlue":[173,216,230],"SkyBlue":[135,206,235],"LightSkyBlue":[135,206,250],"DeepSkyBlue":[0,191,255],"DodgerBlue":[30,144,255],"CornflowerBlue":[100,149,237],"RoyalBlue":[65,105,225],"MediumBlue":[0,0,205],"DarkBlue":[0,0,139],"Navy":[0,0,128],"MidnightBlue":[25,25,112],"Lavender":[230,230,250],"Thistle":[216,191,216],"Plum":[221,160,221],"Violet":[238,130,238],"Orchid":[218,112,214],"Fuchsia":[255,0,255],"Magenta":[255,0,255],"MediumOrchid":[186,85,211],"MediumPurple":[147,112,219],"Amethyst":[153,102,204],"BlueViolet":[138,43,226],"DarkViolet":[148,0,211],"DarkOrchid":[153,50,204],"DarkMagenta":[139,0,139],"Purple":[128,0,128],"Indigo":[75,0,130],"SlateBlue":[106,90,205],"DarkSlateBlue":[72,61,139],"MediumSlateBlue":[123,104,238],"Cornsilk":[255,248,220],"BlanchedAlmond":[255,235,205],"Bisque":[255,228,196],"NavajoWhite":[255,222,173],"Wheat":[245,222,179],"BurlyWood":[222,184,135],"Tan":[210,180,140],"RosyBrown":[188,143,143],"SandyBrown":[244,164,96],"Goldenrod":[218,165,32],"DarkGoldenrod":[184,134,11],"Peru":[205,133,63],"Chocolate":[210,105,30],"SaddleBrown":[139,69,19],"Sienna":[160,82,45],"Brown":[165,42,42],"Maroon":[128,0,0],"White":[255,255,255],"Snow":[255,250,250],"Honeydew":[240,255,240],"MintCream":[245,255,250],"Azure":[240,255,240],"AliceBlue":[240,248,255],"GhostWhite":[248,248,255],"WhiteSmoke":[245,245,245],"Seashell":[255,245,238],"Beige":[245,245,220],"OldLace":[253,245,230],"FloralWhite":[255,250,240],"Ivory":[255,255,240],"AntiqueWhite":[250,235,215],"Linen":[250,240,230],"LavenderBlush":[255,240,245],"MistyRose":[255,228,225],"Gainsboro":[220,220,220],"LightGray":[211,211,211],"Silver":[192,192,192],"DarkGray":[169,169,169],"Gray":[128,128,128],"DimGray":[105,105,105],"LightSlateGray":[119,136,153],"SlateGray":[112,128,144],"DarkSlateGray":[47,79,79],"Black":[0,0,0]};
|
|
2
|
+
const ANSI_STYLES = {"reset":"\u001b[0m","bold":"\u001b[1m","dim":"\u001b[2m","italic":"\u001b[3m","underline":"\u001b[4m","inverse":"\u001b[7m","hidden":"\u001b[8m","strikethrough":"\u001b[9m","bgRed":"\u001b[41m","bgGreen":"\u001b[42m","bgYellow":"\u001b[43m","bgBlue":"\u001b[44m"};
|
|
3
|
+
let customColor = [0,0,0];
|
|
16
4
|
|
|
17
5
|
function createChalk(activeCodes = []) {
|
|
18
|
-
const builder = (text)
|
|
19
|
-
return
|
|
6
|
+
const builder = function(text) {
|
|
7
|
+
if (text === undefined) return createChalk(activeCodes);
|
|
8
|
+
return activeCodes.join("") + text + ANSI_STYLES.reset;
|
|
20
9
|
};
|
|
21
10
|
|
|
22
|
-
|
|
11
|
+
builder.setCustomColor = function(red, green, blue) {
|
|
12
|
+
if ([red, green, blue].some(c => typeof c !== "number" || c < 0 || c > 255)) {
|
|
13
|
+
throw new Error("Color components must be between 0 and 255.");
|
|
14
|
+
}
|
|
15
|
+
customColor = [red, green, blue];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return new Proxy(builder, {
|
|
23
19
|
get(target, prop) {
|
|
24
|
-
if (prop
|
|
25
|
-
|
|
20
|
+
if (typeof prop !== "string") return target[prop];
|
|
21
|
+
|
|
22
|
+
let nextCode = "";
|
|
23
|
+
|
|
24
|
+
// 1. Проверяем системные стили (bold, bgRed и т.д.)
|
|
25
|
+
if (prop in ANSI_STYLES) {
|
|
26
|
+
nextCode = ANSI_STYLES[prop];
|
|
27
|
+
}
|
|
28
|
+
// 2. Проверяем динамический фон (bgTomato и т.д.)
|
|
29
|
+
else if (prop.startsWith("bg") && prop.slice(2) in RGB_COLORS) {
|
|
30
|
+
const [r, g, b] = RGB_COLORS[prop.slice(2)];
|
|
31
|
+
nextCode = `\x1b[48;2;${r};${g};${b}m`;
|
|
32
|
+
}
|
|
33
|
+
// 3. Проверяем цвета текста (Tomato, Red и т.д.)
|
|
34
|
+
else if (prop in RGB_COLORS) {
|
|
35
|
+
const [r, g, b] = RGB_COLORS[prop];
|
|
36
|
+
nextCode = `\x1b[38;2;${r};${g};${b}m`;
|
|
37
|
+
}
|
|
38
|
+
// 4. Проверяем метод кастомного цвета
|
|
39
|
+
else if (prop === "custom") {
|
|
40
|
+
const [r, g, b] = customColor;
|
|
41
|
+
nextCode = `\x1b[38;2;${r};${g};${b}m`;
|
|
42
|
+
}
|
|
43
|
+
// Если это другое свойство (например, setCustomColor)
|
|
44
|
+
else {
|
|
45
|
+
return target[prop];
|
|
26
46
|
}
|
|
27
|
-
|
|
47
|
+
|
|
48
|
+
// ИСПРАВЛЕНИЕ: Возвращаем функцию, которая умеет обрабатывать и текст, и пустые скобки
|
|
49
|
+
return function(text) {
|
|
50
|
+
const updatedCodes = [...activeCodes, nextCode];
|
|
51
|
+
|
|
52
|
+
// Если текст НЕ передали (например: myChalk.bgTomato() ),
|
|
53
|
+
// возвращаем новый прокси для продолжения цепочки
|
|
54
|
+
if (text === undefined) {
|
|
55
|
+
return createChalk(updatedCodes);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Если текст передали (например: .White('Привет!') ),
|
|
59
|
+
// мгновенно склеиваем и возвращаем готовую раскрашенную строку
|
|
60
|
+
return updatedCodes.join("") + text + ANSI_STYLES.reset;
|
|
61
|
+
};
|
|
28
62
|
}
|
|
29
63
|
});
|
|
30
64
|
}
|
|
31
65
|
|
|
32
|
-
|
|
33
|
-
export default myChalk;
|
|
66
|
+
module.exports = createChalk();
|
package/package.json
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prm-programmer/safe-chalk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"require": "./index.js",
|
|
10
|
+
"import": "./index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"description": "A secure and lightweight alternative to chalk with 140+ colors and autocomplete support",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"chalk",
|
|
16
|
+
"ansi",
|
|
17
|
+
"color",
|
|
18
|
+
"terminal",
|
|
19
|
+
"safe",
|
|
20
|
+
"types"
|
|
21
|
+
],
|
|
8
22
|
"author": "prm-programmer",
|
|
9
23
|
"license": "MIT"
|
|
10
24
|
}
|