tool-log 0.0.3 → 0.0.4
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/README.md +132 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# tool-log
|
|
2
|
+
|
|
3
|
+
> Цветная консоль для логирования
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
## Особенности
|
|
9
|
+
|
|
10
|
+
- 🎨 **Цветной вывод** — 9 цветов текста + 9 цветов фона
|
|
11
|
+
- ⚡ **Шорткоты** — методы `red()`, `green()`, `cyan()` и др.
|
|
12
|
+
- 🏷️ **Опциональные цвета** — переопределение цветов для отдельного вызова
|
|
13
|
+
- 📦 **Любые типы** — строки, числа, булевы, объекты, массивы, `null`, `undefined`
|
|
14
|
+
- 🚫 **Dev-only** — автоматическая блокировка логов в продакшене
|
|
15
|
+
- 📐 **Деструктуризация** — безопасное извлечение методов
|
|
16
|
+
|
|
17
|
+
## Установка
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install tool-log
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Быстрый старт
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { ClassLog } from 'tool-log';
|
|
27
|
+
|
|
28
|
+
const log = new ClassLog({ textColor: 'green', bgColor: 'bgBlack' });
|
|
29
|
+
|
|
30
|
+
log.red('Ошибка подключения');
|
|
31
|
+
log.green({ status: 'ok', users: 42 });
|
|
32
|
+
log.cyan('Готово', 123, true);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### Конструктор
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
new ClassLog(config?: ColorOptions)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Options:**
|
|
44
|
+
|
|
45
|
+
| Параметр | Тип | По умолчанию | Описание |
|
|
46
|
+
|----------|-----|--------------|----------|
|
|
47
|
+
| `textColor` | `TextColor` | `'white'` | Цвет текста по умолчанию |
|
|
48
|
+
| `bgColor` | `BgColor` | `null` | Цвет фона по умолчанию |
|
|
49
|
+
|
|
50
|
+
### Методы
|
|
51
|
+
|
|
52
|
+
#### `color(...args: LogValue[], options?: ColorOptions): void`
|
|
53
|
+
|
|
54
|
+
Базовый метод для цветного вывода.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
log.color('С фоном', { textColor: 'red', bgColor: 'bgWhite' });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Шорткоты
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
log.red('Ошибка');
|
|
64
|
+
log.blue('Информация');
|
|
65
|
+
log.yellow('Предупреждение');
|
|
66
|
+
log.green('Успех');
|
|
67
|
+
log.cyan('Данные');
|
|
68
|
+
log.magenta('Декор');
|
|
69
|
+
log.gray('Отладка');
|
|
70
|
+
log.black('Текст');
|
|
71
|
+
log.white('Текст');
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Деструктуризация
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const { red, green, cyan } = log;
|
|
78
|
+
red('ошибка');
|
|
79
|
+
green({ ok: true });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Типы
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
type LogValue = string | number | boolean | null | undefined | object | Function;
|
|
86
|
+
|
|
87
|
+
type TextColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';
|
|
88
|
+
type BgColor = 'bgBlack' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite';
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Примеры
|
|
92
|
+
|
|
93
|
+
### Несколько значений
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
log.green('Юзер', { id: 1, name: 'Иван' }, [1, 2, 3]);
|
|
97
|
+
log.cyan('флаг:', false, 'счётчик:', 42, 'null:', null);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Объекты и массивы
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
log.green({ status: 'ok', users: 42 });
|
|
104
|
+
log.yellow([1, 2, 3, { nested: true }]);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Несколько логгеров
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const infoLog = new ClassLog({ textColor: 'cyan' });
|
|
111
|
+
const errorLog = new ClassLog({ textColor: 'white', bgColor: 'bgRed' });
|
|
112
|
+
|
|
113
|
+
infoLog.cyan({ status: 'ok' });
|
|
114
|
+
errorLog.red('Критическая ошибка');
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Разработка
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Запуск dev-сервера
|
|
121
|
+
npm run dev
|
|
122
|
+
|
|
123
|
+
# Сборка
|
|
124
|
+
npm run build
|
|
125
|
+
|
|
126
|
+
# Публикация
|
|
127
|
+
npm run release:patch # или minor/major
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
[MIT](LICENSE) © [Vladimir Kurguzov](mailto:kurguzov74@gmail.com)
|