@prm-programmer/safe-chalk 1.0.0 → 2.5.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 +21 -0
- package/README.md +50 -0
- package/index.d.ts +66 -0
- package/index.js +56 -23
- package/package.json +19 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rpm-programmer
|
|
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,50 @@
|
|
|
1
|
+
### 🎨 @rpm-programmer/safe-chalk
|
|
2
|
+
|
|
3
|
+
Безопасное и удобное форматирование текста в консоли Node.js. Это аналог популярного модуля в npm - ***chalk***. В этом коде добавлена поддержка CommonJS (В оригинальном ***chalk*** новых версиях полностью перешли на export/import).
|
|
4
|
+
|
|
5
|
+
### 🚀 Установка
|
|
6
|
+
|
|
7
|
+
Установите пакет в ваш проект с помощью одной команды:
|
|
8
|
+
|
|
9
|
+
* npm install @rpm-programmer/safe-chalk
|
|
10
|
+
|
|
11
|
+
### 💻 Быстрый старт
|
|
12
|
+
|
|
13
|
+
Просто импортируйте модуль и начните раскрашивать вывод в консоли:
|
|
14
|
+
|
|
15
|
+
* // Подключение пакета (CommonJS)
|
|
16
|
+
* const safeChalk = require('@rpm-programmer/safe-chalk');
|
|
17
|
+
* // Или для ES Modules:
|
|
18
|
+
* // import safeChalk from '@rpm-programmer/safe-chalk';
|
|
19
|
+
|
|
20
|
+
* // Простые примеры
|
|
21
|
+
* console.log(safeChalk.green('✓ Операция успешно завершена!'));
|
|
22
|
+
* console.log(safeChalk.red('𐄂 Произошла критическая ошибка!'));
|
|
23
|
+
|
|
24
|
+
### 🛠 API Reference
|
|
25
|
+
|
|
26
|
+
### safeChalk.green(text)
|
|
27
|
+
|
|
28
|
+
Окрашивает переданный текст в зеленый цвет.
|
|
29
|
+
|
|
30
|
+
* **Параметры:** text (string) — текст для форматирования.
|
|
31
|
+
* **Возвращает:** string — строку с ANSI-кодами.
|
|
32
|
+
|
|
33
|
+
### safeChalk.rgBlue(text)
|
|
34
|
+
|
|
35
|
+
Окрашивает фон переданного текста в синий.
|
|
36
|
+
|
|
37
|
+
* **Параметры:** text (string) — текст для форматирования.
|
|
38
|
+
* **Возвращает:** string — строку с ANSI-кодами.
|
|
39
|
+
|
|
40
|
+
### safeChalk.rgBlue().red(text)
|
|
41
|
+
|
|
42
|
+
Окрашивает фон переданного текста в синий и его цвет в красный
|
|
43
|
+
|
|
44
|
+
* **Параметры:** text (string) — текст для форматирования.
|
|
45
|
+
* **Возвращает:** string — строку с ANSI-кодами.
|
|
46
|
+
|
|
47
|
+
### 📄 Лицензия
|
|
48
|
+
|
|
49
|
+
Данный проект распространяется под лицензией [MIT](LICENSE).
|
|
50
|
+
Copyright © 2026 **rpm-programmer**.
|
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.5.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
|
}
|