colorino 0.7.4 → 0.9.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/README.md +285 -262
- package/dist/browser.cjs +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.mts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.mjs +1 -1
- package/dist/node.cjs +10 -4
- package/dist/node.d.cts +2 -2
- package/dist/node.d.mts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.mjs +10 -4
- package/dist/shared/{colorino.BKNhSLFs.mjs → colorino.B23laVKA.mjs} +84 -30
- package/dist/shared/{colorino.D5epIHWO.d.cts → colorino.DVUvKR4R.d.cts} +8 -1
- package/dist/shared/{colorino.D5epIHWO.d.mts → colorino.DVUvKR4R.d.mts} +8 -1
- package/dist/shared/{colorino.D5epIHWO.d.ts → colorino.DVUvKR4R.d.ts} +8 -1
- package/dist/shared/{colorino.Di3ygmIx.cjs → colorino.Y3oJ89MM.cjs} +84 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,262 +1,285 @@
|
|
|
1
|
-
# <a id="0"></a>🎨 Colorino
|
|
2
|
-
|
|
3
|
-
**The zero-configuration, context-aware `console` logger for Node.js and the browser.**
|
|
4
|
-
|
|
5
|
-
Colorino automatically adapts its palette to your terminal or browser DevTools theme.
|
|
6
|
-
|
|
7
|
-
# <a id="0"></a><a id="0"></a>
|
|
8
|
-
|
|
9
|
-
- [Why use Colorino?](#1)
|
|
10
|
-
- [Features](#2)
|
|
11
|
-
- [Installation](#3)
|
|
12
|
-
- [Usage](#4)
|
|
13
|
-
- [Quick Start](#4-1)
|
|
14
|
-
- [Creating a Custom Logger](#4-2)
|
|
15
|
-
- [Options & Theme Overrides](#4-3)
|
|
16
|
-
- [Available Theme Presets](#4-3-1)
|
|
17
|
-
- [Examples](#4-3-2)
|
|
18
|
-
- [Customization](#4-4)
|
|
19
|
-
- [Supported Environment Variables](#4-5)
|
|
20
|
-
- [Colorino vs. Chalk](#5)
|
|
21
|
-
- [API Reference](#6)
|
|
22
|
-
- [1. `colorino` (default instance)](#6-1)
|
|
23
|
-
- [2. `createColorino(palette?, options?)` (factory)](#6-2)
|
|
24
|
-
- [Extending Colorino](#7)
|
|
25
|
-
- [Why This Pattern?](#7-1)
|
|
26
|
-
- [License](#8)
|
|
27
|
-
|
|
28
|
-
<!-- Table of contents is made with https://github.com/eugene-khyst/md-toc-cli -->
|
|
29
|
-
|
|
30
|
-
## <a id="1"></a>Why use Colorino?
|
|
31
|
-
|
|
32
|
-
Plain `console.log` is colorless and inconsistent. Libraries like `chalk` let you style strings, but you have to decorate every message and manually manage color choices.
|
|
33
|
-
|
|
34
|
-
Colorino is different: it’s a "batteries-included" logging facade with beautiful, theme-aware colors and a familiar API—no learning curve, no configuration. Instantly upgrade your logs everywhere.
|
|
35
|
-
|
|
36
|
-
## <a id="2"></a>Features
|
|
37
|
-
|
|
38
|
-
- 🎨 **Smart Theming:** Automatically detects *dark/light* mode and
|
|
39
|
-
- 🤝 **Familiar API:** If you know `console.log`, you already know Colorino: all standard log levels are supported.
|
|
40
|
-
- 🔀 **Environment-Aware:** Works in **Node.js** (ANSI color and truecolor) and all major **Browsers** (CSS styles).
|
|
41
|
-
- ⚡️ **Fast, Lightweight:** Minimal dependencies, works great in modern frameworks and CLIs.
|
|
42
|
-
- 🔒 **Robust:** Handles bad inputs and weird environments safely.
|
|
43
|
-
- 🛠️ **Customizable:** Override individual log colors for your own branding.
|
|
44
|
-
|
|
45
|
-
## <a id="3"></a>Installation
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
npm install colorino
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## <a id="4"></a>Usage
|
|
52
|
-
|
|
53
|
-
### <a id="4-1"></a>Quick Start
|
|
54
|
-
|
|
55
|
-
Just import the default instance and log away!
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
import { colorino } from 'colorino'
|
|
59
|
-
|
|
60
|
-
// All log levels automatically themed
|
|
61
|
-
colorino.error('A critical error!')
|
|
62
|
-
colorino.warn('A warning message.')
|
|
63
|
-
colorino.info('Useful info logging.')
|
|
64
|
-
colorino.log('A plain log.')
|
|
65
|
-
colorino.debug('Debug with objects:', { x: 5, y: 9 })
|
|
66
|
-
colorino.trace('Tracing app start...')
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### <a id="4-2"></a>Creating a Custom Logger
|
|
70
|
-
|
|
71
|
-
Need your own colors or different settings?
|
|
72
|
-
Use the factory to create as many loggers as you want (each with its own palette and options):
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
import { createColorino } from 'colorino'
|
|
76
|
-
|
|
77
|
-
const myLogger = createColorino(
|
|
78
|
-
{ // Palette (partial)
|
|
79
|
-
error: '#ff007b',
|
|
80
|
-
info: '#3498db'
|
|
81
|
-
},
|
|
82
|
-
{ disableWarnings: true } // Options (see below)
|
|
83
|
-
)
|
|
84
|
-
myLogger.error('Critical!')
|
|
85
|
-
myLogger.info('Rebranded info!')
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### <a id="4-3"></a>Options & Theme Overrides
|
|
89
|
-
|
|
90
|
-
`createColorino(palette?, options?)` accepts:
|
|
91
|
-
|
|
92
|
-
| Option | Type | Default | Description |
|
|
93
|
-
|-------------------|--------------------------------|---------|--------------------------------------------------------------------------------|
|
|
94
|
-
| `disableWarnings` | `boolean` | `false` | Suppress warnings when color support can't be detected or is disabled. |
|
|
95
|
-
| `theme` | `ThemeOption` (see below) | `'auto'`| Control the active color theme or force a specific mode. |
|
|
96
|
-
|
|
97
|
-
**`theme` accepts three types of values:**
|
|
98
|
-
|
|
99
|
-
1. **`'auto'`** (Default): Automatically detects your terminal or browser theme (dark/light) and applies the matching default preset.
|
|
100
|
-
2. **`'dark' | 'light'`**: Forces the logger into a specific mode using the default preset for that mode.
|
|
101
|
-
3. **`ThemeName`**: Forces a specific built-in palette (e.g., `'dracula'`).
|
|
102
|
-
|
|
103
|
-
#### <a id="4-3-1"></a>Available Theme Presets
|
|
104
|
-
|
|
105
|
-
Pass any of these names to the `theme` option to use a specific palette:
|
|
106
|
-
|
|
107
|
-
| Theme Name | Type | Description |
|
|
108
|
-
|----------------------|-----------------|--------------------------------------------------|
|
|
109
|
-
| `'dracula'` | **Dark** (High) | Vibrant pinks, purples, and cyans. |
|
|
110
|
-
| `'catppuccin-mocha'` | **Dark** (Low) |
|
|
111
|
-
| `'
|
|
112
|
-
| `'
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
```typescript
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
logger
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
1
|
+
# <a id="0"></a>🎨 Colorino
|
|
2
|
+
|
|
3
|
+
**The zero-configuration, context-aware `console` logger for Node.js and the browser.**
|
|
4
|
+
|
|
5
|
+
Colorino automatically adapts its palette to your terminal or browser DevTools theme, and defaults to **minimal, high-contrast** colors unless you opt into a specific theme preset.
|
|
6
|
+
|
|
7
|
+
# <a id="0"></a><a id="0"></a>
|
|
8
|
+
|
|
9
|
+
- [Why use Colorino?](#1)
|
|
10
|
+
- [Features](#2)
|
|
11
|
+
- [Installation](#3)
|
|
12
|
+
- [Usage](#4)
|
|
13
|
+
- [Quick Start](#4-1)
|
|
14
|
+
- [Creating a Custom Logger](#4-2)
|
|
15
|
+
- [Options & Theme Overrides](#4-3)
|
|
16
|
+
- [Available Theme Presets](#4-3-1)
|
|
17
|
+
- [Examples](#4-3-2)
|
|
18
|
+
- [Customization](#4-4)
|
|
19
|
+
- [Supported Environment Variables](#4-5)
|
|
20
|
+
- [Colorino vs. Chalk](#5)
|
|
21
|
+
- [API Reference](#6)
|
|
22
|
+
- [1. `colorino` (default instance)](#6-1)
|
|
23
|
+
- [2. `createColorino(palette?, options?)` (factory)](#6-2)
|
|
24
|
+
- [Extending Colorino](#7)
|
|
25
|
+
- [Why This Pattern?](#7-1)
|
|
26
|
+
- [License](#8)
|
|
27
|
+
|
|
28
|
+
<!-- Table of contents is made with https://github.com/eugene-khyst/md-toc-cli -->
|
|
29
|
+
|
|
30
|
+
## <a id="1"></a>Why use Colorino?
|
|
31
|
+
|
|
32
|
+
Plain `console.log` is colorless and inconsistent. Libraries like `chalk` let you style strings, but you have to decorate every message and manually manage color choices.
|
|
33
|
+
|
|
34
|
+
Colorino is different: it’s a "batteries-included" logging facade with beautiful, theme-aware colors and a familiar API—no learning curve, no configuration. Instantly upgrade your logs everywhere.
|
|
35
|
+
|
|
36
|
+
## <a id="2"></a>Features
|
|
37
|
+
|
|
38
|
+
- 🎨 **Smart Theming:** Automatically detects *dark/light* mode and applies a **minimal** high-contrast base palette by default; opt into a coordinated theme preset when you want richer colors.
|
|
39
|
+
- 🤝 **Familiar API:** If you know `console.log`, you already know Colorino: all standard log levels are supported.
|
|
40
|
+
- 🔀 **Environment-Aware:** Works in **Node.js** (ANSI color and truecolor) and all major **Browsers** (CSS styles).
|
|
41
|
+
- ⚡️ **Fast, Lightweight:** Minimal dependencies, works great in modern frameworks and CLIs.
|
|
42
|
+
- 🔒 **Robust:** Handles bad inputs and weird environments safely.
|
|
43
|
+
- 🛠️ **Customizable:** Override individual log colors for your own branding.
|
|
44
|
+
|
|
45
|
+
## <a id="3"></a>Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install colorino
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## <a id="4"></a>Usage
|
|
52
|
+
|
|
53
|
+
### <a id="4-1"></a>Quick Start
|
|
54
|
+
|
|
55
|
+
Just import the default instance and log away!
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { colorino } from 'colorino'
|
|
59
|
+
|
|
60
|
+
// All log levels automatically themed
|
|
61
|
+
colorino.error('A critical error!')
|
|
62
|
+
colorino.warn('A warning message.')
|
|
63
|
+
colorino.info('Useful info logging.')
|
|
64
|
+
colorino.log('A plain log.')
|
|
65
|
+
colorino.debug('Debug with objects:', { x: 5, y: 9 })
|
|
66
|
+
colorino.trace('Tracing app start...')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### <a id="4-2"></a>Creating a Custom Logger
|
|
70
|
+
|
|
71
|
+
Need your own colors or different settings?
|
|
72
|
+
Use the factory to create as many loggers as you want (each with its own palette and options):
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { createColorino } from 'colorino'
|
|
76
|
+
|
|
77
|
+
const myLogger = createColorino(
|
|
78
|
+
{ // Palette (partial)
|
|
79
|
+
error: '#ff007b',
|
|
80
|
+
info: '#3498db'
|
|
81
|
+
},
|
|
82
|
+
{ disableWarnings: true } // Options (see below)
|
|
83
|
+
)
|
|
84
|
+
myLogger.error('Critical!')
|
|
85
|
+
myLogger.info('Rebranded info!')
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### <a id="4-3"></a>Options & Theme Overrides
|
|
89
|
+
|
|
90
|
+
`createColorino(palette?, options?)` accepts:
|
|
91
|
+
|
|
92
|
+
| Option | Type | Default | Description |
|
|
93
|
+
|-------------------|--------------------------------|---------|--------------------------------------------------------------------------------|
|
|
94
|
+
| `disableWarnings` | `boolean` | `false` | Suppress warnings when color support can't be detected or is disabled. |
|
|
95
|
+
| `theme` | `ThemeOption` (see below) | `'auto'`| Control the active color theme or force a specific mode. |
|
|
96
|
+
|
|
97
|
+
**`theme` accepts three types of values:**
|
|
98
|
+
|
|
99
|
+
1. **`'auto'`** (Default): Automatically detects your terminal or browser theme (dark/light) and applies the matching default preset.
|
|
100
|
+
2. **`'dark' | 'light'`**: Forces the logger into a specific mode using the default preset for that mode.
|
|
101
|
+
3. **`ThemeName`**: Forces a specific built-in palette (e.g., `'dracula'`).
|
|
102
|
+
|
|
103
|
+
#### <a id="4-3-1"></a>Available Theme Presets
|
|
104
|
+
|
|
105
|
+
Pass any of these names to the `theme` option to use a specific palette:
|
|
106
|
+
|
|
107
|
+
| Theme Name | Type | Description |
|
|
108
|
+
|----------------------|-----------------|--------------------------------------------------|
|
|
109
|
+
| `'dracula'` | **Dark** (High) | Vibrant pinks, purples, and cyans. |
|
|
110
|
+
| `'catppuccin-mocha'` | **Dark** (Low) | Soothing pastel colors. |
|
|
111
|
+
| `'minimal-dark'` | **Dark** | *Default Dark (auto).* Minimal, high-contrast. |
|
|
112
|
+
| `'minimal-light'` | **Light** | *Default Light (auto).* Minimal, high-contrast. |
|
|
113
|
+
| `'github-light'` | **Light** (High)| Clean, sharp, high-contrast. |
|
|
114
|
+
| `'catppuccin-latte'` | **Light** (Low) | Warm, cozy light mode with soft colors. |
|
|
115
|
+
|
|
116
|
+
#### <a id="4-3-2"></a>Examples
|
|
117
|
+
|
|
118
|
+
**1. Minimal defaults with custom branding (recommended):**
|
|
119
|
+
Set only the colors you care about; everything else stays maximally readable.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Only customize error and warn
|
|
123
|
+
const myLogger = createColorino({
|
|
124
|
+
error: '#ff007b',
|
|
125
|
+
warn: '#ffa500'
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
// Detected dark terminal:
|
|
129
|
+
// - error: #ff007b (your custom red)
|
|
130
|
+
// - warn: #ffa500 (your custom orange)
|
|
131
|
+
// - info, log, debug, trace: #ffffff (white - safe on dark)
|
|
132
|
+
|
|
133
|
+
// Detected light terminal:
|
|
134
|
+
// - error: #ff007b (your custom red)
|
|
135
|
+
// - warn: #ffa500 (your custom orange)
|
|
136
|
+
// - info, log, debug, trace: #000000 (black - safe on light)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**2. Force a specific mode (uses defaults):**
|
|
140
|
+
Useful for CI/CD or environments where detection fails.
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// Forces dark mode using the default minimal palette (minimal-dark)
|
|
144
|
+
const darkLogger = createColorino({}, { theme: 'dark' })
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**3. Use a specific preset:**
|
|
148
|
+
Instant branding with zero configuration.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// Forces the Dracula palette
|
|
152
|
+
const draculaLogger = createColorino({}, { theme: 'dracula' })
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**4. Customize a preset:**
|
|
156
|
+
Overlay your own colors on top of a built-in theme.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Use GitHub Light but with a custom error color
|
|
160
|
+
const myLogger = createColorino(
|
|
161
|
+
{ error: '#ff007b' },
|
|
162
|
+
{ theme: 'github-light' }
|
|
163
|
+
)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
> **Tip:**
|
|
167
|
+
> Forcing `'dark'` or `'light'` bypasses automatic theming, ensuring predictable colors in environments with unknown or unsupported theme detection (like some CI pipelines, dumb terminals, or minimal browsers).
|
|
168
|
+
|
|
169
|
+
### <a id="4-4"></a>Customization
|
|
170
|
+
|
|
171
|
+
Use your brand colors by passing a partial palette to the `createColorino` factory. Any log levels you don't specify will use the detected **minimal** defaults (`minimal-dark` / `minimal-light`) unless you explicitly select a theme preset.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { createColorino } from 'colorino'
|
|
175
|
+
|
|
176
|
+
// Custom error color; others use theme defaults
|
|
177
|
+
const myLogger = createColorino({ error: '#ff007b' })
|
|
178
|
+
|
|
179
|
+
myLogger.error('Oh no!') // Uses your custom color
|
|
180
|
+
myLogger.info('Still styled by theme.') // Uses the default theme color
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### <a id="4-5"></a>Supported Environment Variables
|
|
184
|
+
|
|
185
|
+
Colorino auto-detects your environment and color support, but you can override behavior using these standard environment variables (compatible with Chalk):
|
|
186
|
+
|
|
187
|
+
| Variable | Effect | Example |
|
|
188
|
+
|------------------|---------------------------------------------------|--------------------------|
|
|
189
|
+
| `NO_COLOR` | Forces *no color* output | `NO_COLOR=1 node app.js` |
|
|
190
|
+
| `FORCE_COLOR` | Forces color (`1`=ANSI, `2`=256, `3`=truecolor) | `FORCE_COLOR=3 node app.js` |
|
|
191
|
+
| `CLICOLOR` | `"0"` disables color | `CLICOLOR=0 node app.js` |
|
|
192
|
+
| `CLICOLOR_FORCE` | Non-`"0"` value enables color even if not a TTY | `CLICOLOR_FORCE=1 node app.js` |
|
|
193
|
+
| `TERM` | Terminal type, can increase/decrease support | `TERM=xterm-256color` |
|
|
194
|
+
| `COLORTERM` | `'truecolor'` or `'24bit'` enables truecolor | `COLORTERM=truecolor` |
|
|
195
|
+
| `WT_SESSION` | Detected for Windows Terminal (enables color) | |
|
|
196
|
+
| `CI` | Many CI platforms default to *no color* | `CI=1 node app.js` |
|
|
197
|
+
|
|
198
|
+
## <a id="5"></a>Colorino vs. Chalk
|
|
199
|
+
|
|
200
|
+
| Feature | 🎨 **Colorino** | 🖍️ **Chalk** |
|
|
201
|
+
|--------------------------|----------------------------|-----------------|
|
|
202
|
+
| Out-of-box logs | ✔ themed, all log levels | ✘ string styling|
|
|
203
|
+
| Zero-config | ✔ | ✘ manual, per-use|
|
|
204
|
+
| Node + browser | ✔ | ✘ (Node only) |
|
|
205
|
+
| CSS console logs | ✔ | ✘ |
|
|
206
|
+
| Extensible / Composable | ✔ (via factory) | ✘ |
|
|
207
|
+
|
|
208
|
+
## <a id="6"></a>API Reference
|
|
209
|
+
|
|
210
|
+
The `colorino` package exports two main items:
|
|
211
|
+
|
|
212
|
+
### <a id="6-1"></a>1. `colorino` (default instance)
|
|
213
|
+
|
|
214
|
+
A pre-configured, zero-setup logger instance. Just import and use.
|
|
215
|
+
|
|
216
|
+
- `.log(...args)`
|
|
217
|
+
- `.info(...args)`
|
|
218
|
+
- `.warn(...args)`
|
|
219
|
+
- `.error(...args)`
|
|
220
|
+
- `.debug(...args)`
|
|
221
|
+
- `.trace(...args)`
|
|
222
|
+
|
|
223
|
+
### <a id="6-2"></a>2. `createColorino(palette?, options?)` (factory)
|
|
224
|
+
|
|
225
|
+
A factory function to create your own customized logger instances.
|
|
226
|
+
|
|
227
|
+
- `palette` (`Partial<Palette>`): An object to override default colors for specific log levels (e.g., `{ error: '#ff007b' }`).
|
|
228
|
+
- `options` (`ColorinoOptions`): An object to control behavior:
|
|
229
|
+
- `disableWarnings: boolean` (default `false`): Suppress warnings on environments with no color support.
|
|
230
|
+
- `theme: 'dark' | 'light'` (default `auto`): Force a specific theme instead of auto-detecting.
|
|
231
|
+
|
|
232
|
+
## <a id="7"></a>Extending Colorino
|
|
233
|
+
|
|
234
|
+
Example: Add a `fatal()` logger for critical errors.
|
|
235
|
+
|
|
236
|
+
Since colorino uses a factory pattern, extend it by creating your own factory that composes the base logger with additional methods:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { createColorino, type ColorinoOptions, type Palette } from 'colorino'
|
|
240
|
+
|
|
241
|
+
// Create a factory for your custom logger
|
|
242
|
+
export function createMyLogger(palette?: Partial<Palette>, options?: ColorinoOptions) {
|
|
243
|
+
// Get the base logger instance
|
|
244
|
+
const baseLogger = createColorino(palette, options)
|
|
245
|
+
|
|
246
|
+
// Define your custom method
|
|
247
|
+
function fatal(...args: unknown[]): void {
|
|
248
|
+
// Reuse the base logger's error method
|
|
249
|
+
baseLogger.error(...args)
|
|
250
|
+
|
|
251
|
+
// Add your custom behavior
|
|
252
|
+
if (typeof process !== 'undefined' && process.exit) {
|
|
253
|
+
process.exit(1)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Return a new object with all base methods + your custom ones
|
|
258
|
+
// This preserves type safety and the original API
|
|
259
|
+
return {
|
|
260
|
+
...baseLogger,
|
|
261
|
+
fatal,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Usage:
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const logger = createMyLogger({ error: '#d92626' })
|
|
270
|
+
|
|
271
|
+
logger.info('Starting!')
|
|
272
|
+
logger.fatal('Missing config: Exiting')
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### <a id="7-1"></a>Why This Pattern?
|
|
276
|
+
|
|
277
|
+
- **Composition > Inheritance**: No fragile base class problems
|
|
278
|
+
- **Type Safe**: TypeScript infers the return type correctly
|
|
279
|
+
- **Future Proof**: Works even if colorino's internal implementation changes
|
|
280
|
+
- **Clean**: No messing with `super()` or constructor parameters
|
|
281
|
+
- **Composable**: You can layer multiple extensions
|
|
282
|
+
|
|
283
|
+
## <a id="8"></a>License
|
|
284
|
+
|
|
285
|
+
[MIT](LICENSE.md)
|
package/dist/browser.cjs
CHANGED
package/dist/browser.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DVUvKR4R.cjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DVUvKR4R.cjs';
|
|
3
3
|
|
|
4
4
|
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
5
|
|
package/dist/browser.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DVUvKR4R.mjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DVUvKR4R.mjs';
|
|
3
3
|
|
|
4
4
|
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
5
|
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DVUvKR4R.js';
|
|
2
|
+
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DVUvKR4R.js';
|
|
3
3
|
|
|
4
4
|
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
5
|
|
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ColorLevel, t as themePalettes, a as Colorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.
|
|
1
|
+
import { C as ColorLevel, t as themePalettes, a as Colorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.B23laVKA.mjs';
|
|
2
2
|
|
|
3
3
|
class BrowserColorSupportDetector {
|
|
4
4
|
constructor(_window, _navigator, _overrideTheme) {
|
package/dist/node.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const determineBaseTheme = require('./shared/colorino.
|
|
3
|
+
const determineBaseTheme = require('./shared/colorino.Y3oJ89MM.cjs');
|
|
4
|
+
const node_child_process = require('node:child_process');
|
|
4
5
|
|
|
5
6
|
class OscThemeQuerier {
|
|
6
7
|
constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
|
|
@@ -54,9 +55,14 @@ class OscThemeQuerier {
|
|
|
54
55
|
this._stdin.pause();
|
|
55
56
|
}
|
|
56
57
|
_sleepSync(ms) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (process.platform === "win32") {
|
|
59
|
+
node_child_process.spawnSync("timeout", ["/T", String(Math.ceil(ms / 1e3)), "/NOBREAK"], {
|
|
60
|
+
stdio: "ignore",
|
|
61
|
+
shell: true
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
node_child_process.spawnSync("sleep", [String(ms / 1e3)], { stdio: "ignore" });
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
67
|
_parseResponse(response) {
|
|
62
68
|
const rgbMatch = response.match(
|
package/dist/node.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DVUvKR4R.cjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DVUvKR4R.cjs';
|
|
3
3
|
|
|
4
4
|
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
5
|
|
package/dist/node.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DVUvKR4R.mjs';
|
|
2
|
+
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DVUvKR4R.mjs';
|
|
3
3
|
|
|
4
4
|
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
5
|
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.
|
|
2
|
-
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.
|
|
1
|
+
import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.DVUvKR4R.js';
|
|
2
|
+
export { L as LogLevel, T as ThemeName, t as themePalettes } from './shared/colorino.DVUvKR4R.js';
|
|
3
3
|
|
|
4
4
|
declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
|
|
5
5
|
|
package/dist/node.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { e as err, O as OscQueryError, o as ok, C as ColorLevel, d as determineBaseTheme, t as themePalettes, a as Colorino, I as InputValidator } from './shared/colorino.
|
|
1
|
+
import { e as err, O as OscQueryError, o as ok, C as ColorLevel, d as determineBaseTheme, t as themePalettes, a as Colorino, I as InputValidator } from './shared/colorino.B23laVKA.mjs';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
2
3
|
|
|
3
4
|
class OscThemeQuerier {
|
|
4
5
|
constructor(_stdin, _stdout, _timeout = 300, _cacheTtl = 36e5) {
|
|
@@ -52,9 +53,14 @@ class OscThemeQuerier {
|
|
|
52
53
|
this._stdin.pause();
|
|
53
54
|
}
|
|
54
55
|
_sleepSync(ms) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
if (process.platform === "win32") {
|
|
57
|
+
spawnSync("timeout", ["/T", String(Math.ceil(ms / 1e3)), "/NOBREAK"], {
|
|
58
|
+
stdio: "ignore",
|
|
59
|
+
shell: true
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
spawnSync("sleep", [String(ms / 1e3)], { stdio: "ignore" });
|
|
63
|
+
}
|
|
58
64
|
}
|
|
59
65
|
_parseResponse(response) {
|
|
60
66
|
const rgbMatch = response.match(
|
|
@@ -125,24 +125,27 @@ class Colorino {
|
|
|
125
125
|
}
|
|
126
126
|
const result = {};
|
|
127
127
|
for (const key in val) {
|
|
128
|
-
result[key] = sanitize(
|
|
128
|
+
result[key] = sanitize(
|
|
129
|
+
val[key],
|
|
130
|
+
currentDepth + 1
|
|
131
|
+
);
|
|
129
132
|
}
|
|
130
133
|
return result;
|
|
131
134
|
};
|
|
132
135
|
return JSON.stringify(sanitize(value, 0), null, 2);
|
|
133
136
|
}
|
|
134
|
-
|
|
135
|
-
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
137
|
+
_processArgs(args) {
|
|
136
138
|
const processedArgs = [];
|
|
137
139
|
let previousWasObject = false;
|
|
138
140
|
for (const arg of args) {
|
|
139
141
|
const isFormattableObject = arg !== null && typeof arg === "object" && typeof arg !== "string" && !(arg instanceof Error);
|
|
140
142
|
const isError = arg instanceof Error;
|
|
141
143
|
if (isFormattableObject) {
|
|
142
|
-
processedArgs.push(
|
|
144
|
+
processedArgs.push(`
|
|
145
|
+
${this._formatValue(arg)}`);
|
|
143
146
|
previousWasObject = true;
|
|
144
147
|
} else if (isError) {
|
|
145
|
-
processedArgs.push("\n", arg);
|
|
148
|
+
processedArgs.push("\n", this._cleanErrorStack(arg));
|
|
146
149
|
previousWasObject = true;
|
|
147
150
|
} else {
|
|
148
151
|
if (typeof arg === "string" && previousWasObject) {
|
|
@@ -154,25 +157,17 @@ ${arg}`);
|
|
|
154
157
|
previousWasObject = false;
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const hex2 = this._palette[level];
|
|
164
|
-
if (typeof processedArgs[0] === "string") {
|
|
165
|
-
console[consoleMethod](
|
|
166
|
-
`%c${processedArgs[0]}`,
|
|
167
|
-
`color:${hex2}`,
|
|
168
|
-
...processedArgs.slice(1)
|
|
169
|
-
);
|
|
170
|
-
} else {
|
|
171
|
-
console[consoleMethod](...processedArgs);
|
|
172
|
-
}
|
|
173
|
-
return;
|
|
160
|
+
return processedArgs;
|
|
161
|
+
}
|
|
162
|
+
_applyBrowserColors(consoleMethod, args) {
|
|
163
|
+
const hex = this._palette[consoleMethod];
|
|
164
|
+
if (typeof args[0] === "string") {
|
|
165
|
+
return [`%c${args[0]}`, `color:${hex}`, ...args.slice(1)];
|
|
174
166
|
}
|
|
175
|
-
|
|
167
|
+
return args;
|
|
168
|
+
}
|
|
169
|
+
_applyNodeColors(consoleMethod, args) {
|
|
170
|
+
const hex = this._palette[consoleMethod];
|
|
176
171
|
let ansiCode;
|
|
177
172
|
switch (this._colorLevel) {
|
|
178
173
|
case ColorLevel.TRUECOLOR: {
|
|
@@ -192,17 +187,58 @@ ${arg}`);
|
|
|
192
187
|
break;
|
|
193
188
|
}
|
|
194
189
|
}
|
|
195
|
-
const coloredArgs = [...
|
|
190
|
+
const coloredArgs = [...args];
|
|
196
191
|
const firstStringIndex = coloredArgs.findIndex(
|
|
197
192
|
(arg) => typeof arg === "string"
|
|
198
193
|
);
|
|
199
194
|
if (firstStringIndex !== -1) {
|
|
200
195
|
coloredArgs[firstStringIndex] = `${ansiCode}${coloredArgs[firstStringIndex]}\x1B[0m`;
|
|
201
196
|
}
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
return coloredArgs;
|
|
198
|
+
}
|
|
199
|
+
_output(consoleMethod, args) {
|
|
200
|
+
if (consoleMethod === "trace") {
|
|
201
|
+
this._printCleanTrace(args, consoleMethod);
|
|
202
|
+
} else {
|
|
203
|
+
console[consoleMethod](...args);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
_out(level, args) {
|
|
207
|
+
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
208
|
+
const processedArgs = this._processArgs(args);
|
|
209
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
210
|
+
this._output(consoleMethod, processedArgs);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (this.isBrowser) {
|
|
214
|
+
const coloredArgs2 = this._applyBrowserColors(consoleMethod, processedArgs);
|
|
215
|
+
this._output(consoleMethod, coloredArgs2);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const coloredArgs = this._applyNodeColors(consoleMethod, processedArgs);
|
|
219
|
+
this._output(consoleMethod, coloredArgs);
|
|
220
|
+
}
|
|
221
|
+
_filterStack(stack) {
|
|
222
|
+
return stack.split("\n").filter(
|
|
223
|
+
(line) => !line.includes("colorino.js") && !line.includes("Colorino._out") && !line.includes("Colorino.error") && !line.includes("Colorino.warn") && !line.includes("Colorino.debug") && !line.includes("Colorino.info") && !line.includes("Colorino.log") && !line.includes("Colorino.trace") && !line.includes("Colorino._cleanErrorStack") && !line.includes("Colorino._printCleanTrace") && !line.includes("Colorino._filterStack")
|
|
224
|
+
).join("\n");
|
|
225
|
+
}
|
|
226
|
+
_cleanErrorStack(error) {
|
|
227
|
+
if (!error.stack) return error;
|
|
228
|
+
const cleanStack = this._filterStack(error.stack);
|
|
229
|
+
const cloned = Object.create(Object.getPrototypeOf(error));
|
|
230
|
+
Object.assign(cloned, error);
|
|
231
|
+
cloned.stack = cleanStack;
|
|
232
|
+
return cloned;
|
|
233
|
+
}
|
|
234
|
+
_printCleanTrace(args, method) {
|
|
235
|
+
const error = new Error();
|
|
236
|
+
if (error.stack) {
|
|
237
|
+
const cleanStack = this._filterStack(error.stack);
|
|
238
|
+
console[method](...args, `
|
|
239
|
+
${cleanStack}`);
|
|
204
240
|
} else {
|
|
205
|
-
console[
|
|
241
|
+
console[method](...args);
|
|
206
242
|
}
|
|
207
243
|
}
|
|
208
244
|
}
|
|
@@ -781,15 +817,33 @@ const githubLightPalette = {
|
|
|
781
817
|
trace: "#6a737d"
|
|
782
818
|
// Gray-light
|
|
783
819
|
};
|
|
820
|
+
const minimalDarkPalette = {
|
|
821
|
+
log: "#ffffff",
|
|
822
|
+
info: "#ffffff",
|
|
823
|
+
warn: "#ffffff",
|
|
824
|
+
error: "#ffffff",
|
|
825
|
+
debug: "#ffffff",
|
|
826
|
+
trace: "#ffffff"
|
|
827
|
+
};
|
|
828
|
+
const minimalLightPalette = {
|
|
829
|
+
log: "#000000",
|
|
830
|
+
info: "#000000",
|
|
831
|
+
warn: "#000000",
|
|
832
|
+
error: "#000000",
|
|
833
|
+
debug: "#000000",
|
|
834
|
+
trace: "#000000"
|
|
835
|
+
};
|
|
784
836
|
|
|
785
837
|
const themePalettes = {
|
|
786
838
|
"catppuccin-mocha": catppuccinMochaPalette,
|
|
787
839
|
"catppuccin-latte": catppuccinLattePalette,
|
|
788
840
|
dracula: draculaPalette,
|
|
789
|
-
"github-light": githubLightPalette
|
|
841
|
+
"github-light": githubLightPalette,
|
|
842
|
+
"minimal-dark": minimalDarkPalette,
|
|
843
|
+
"minimal-light": minimalLightPalette
|
|
790
844
|
};
|
|
791
|
-
const defaultDarkTheme = "
|
|
792
|
-
const defaultLightTheme = "
|
|
845
|
+
const defaultDarkTheme = "minimal-dark";
|
|
846
|
+
const defaultLightTheme = "minimal-light";
|
|
793
847
|
function isThemeName(theme) {
|
|
794
848
|
return theme in themePalettes;
|
|
795
849
|
}
|
|
@@ -2,7 +2,7 @@ type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
|
2
2
|
type LogLevel = ConsoleMethod & string;
|
|
3
3
|
type Palette = Record<LogLevel, string>;
|
|
4
4
|
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
5
|
-
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light';
|
|
5
|
+
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light' | 'minimal-dark' | 'minimal-light';
|
|
6
6
|
interface ColorinoOptions {
|
|
7
7
|
disableWarnings?: boolean;
|
|
8
8
|
theme?: TerminalTheme | ThemeName | 'auto';
|
|
@@ -449,7 +449,14 @@ declare class Colorino {
|
|
|
449
449
|
private _detectColorSupport;
|
|
450
450
|
private _maybeWarnUser;
|
|
451
451
|
private _formatValue;
|
|
452
|
+
private _processArgs;
|
|
453
|
+
private _applyBrowserColors;
|
|
454
|
+
private _applyNodeColors;
|
|
455
|
+
private _output;
|
|
452
456
|
private _out;
|
|
457
|
+
private _filterStack;
|
|
458
|
+
private _cleanErrorStack;
|
|
459
|
+
private _printCleanTrace;
|
|
453
460
|
}
|
|
454
461
|
|
|
455
462
|
declare const themePalettes: Record<ThemeName, Palette>;
|
|
@@ -2,7 +2,7 @@ type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
|
2
2
|
type LogLevel = ConsoleMethod & string;
|
|
3
3
|
type Palette = Record<LogLevel, string>;
|
|
4
4
|
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
5
|
-
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light';
|
|
5
|
+
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light' | 'minimal-dark' | 'minimal-light';
|
|
6
6
|
interface ColorinoOptions {
|
|
7
7
|
disableWarnings?: boolean;
|
|
8
8
|
theme?: TerminalTheme | ThemeName | 'auto';
|
|
@@ -449,7 +449,14 @@ declare class Colorino {
|
|
|
449
449
|
private _detectColorSupport;
|
|
450
450
|
private _maybeWarnUser;
|
|
451
451
|
private _formatValue;
|
|
452
|
+
private _processArgs;
|
|
453
|
+
private _applyBrowserColors;
|
|
454
|
+
private _applyNodeColors;
|
|
455
|
+
private _output;
|
|
452
456
|
private _out;
|
|
457
|
+
private _filterStack;
|
|
458
|
+
private _cleanErrorStack;
|
|
459
|
+
private _printCleanTrace;
|
|
453
460
|
}
|
|
454
461
|
|
|
455
462
|
declare const themePalettes: Record<ThemeName, Palette>;
|
|
@@ -2,7 +2,7 @@ type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'trace' | 'debug';
|
|
|
2
2
|
type LogLevel = ConsoleMethod & string;
|
|
3
3
|
type Palette = Record<LogLevel, string>;
|
|
4
4
|
type TerminalTheme = 'dark' | 'light' | 'unknown';
|
|
5
|
-
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light';
|
|
5
|
+
type ThemeName = 'catppuccin-mocha' | 'catppuccin-latte' | 'dracula' | 'github-light' | 'minimal-dark' | 'minimal-light';
|
|
6
6
|
interface ColorinoOptions {
|
|
7
7
|
disableWarnings?: boolean;
|
|
8
8
|
theme?: TerminalTheme | ThemeName | 'auto';
|
|
@@ -449,7 +449,14 @@ declare class Colorino {
|
|
|
449
449
|
private _detectColorSupport;
|
|
450
450
|
private _maybeWarnUser;
|
|
451
451
|
private _formatValue;
|
|
452
|
+
private _processArgs;
|
|
453
|
+
private _applyBrowserColors;
|
|
454
|
+
private _applyNodeColors;
|
|
455
|
+
private _output;
|
|
452
456
|
private _out;
|
|
457
|
+
private _filterStack;
|
|
458
|
+
private _cleanErrorStack;
|
|
459
|
+
private _printCleanTrace;
|
|
453
460
|
}
|
|
454
461
|
|
|
455
462
|
declare const themePalettes: Record<ThemeName, Palette>;
|
|
@@ -127,24 +127,27 @@ class Colorino {
|
|
|
127
127
|
}
|
|
128
128
|
const result = {};
|
|
129
129
|
for (const key in val) {
|
|
130
|
-
result[key] = sanitize(
|
|
130
|
+
result[key] = sanitize(
|
|
131
|
+
val[key],
|
|
132
|
+
currentDepth + 1
|
|
133
|
+
);
|
|
131
134
|
}
|
|
132
135
|
return result;
|
|
133
136
|
};
|
|
134
137
|
return JSON.stringify(sanitize(value, 0), null, 2);
|
|
135
138
|
}
|
|
136
|
-
|
|
137
|
-
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
139
|
+
_processArgs(args) {
|
|
138
140
|
const processedArgs = [];
|
|
139
141
|
let previousWasObject = false;
|
|
140
142
|
for (const arg of args) {
|
|
141
143
|
const isFormattableObject = arg !== null && typeof arg === "object" && typeof arg !== "string" && !(arg instanceof Error);
|
|
142
144
|
const isError = arg instanceof Error;
|
|
143
145
|
if (isFormattableObject) {
|
|
144
|
-
processedArgs.push(
|
|
146
|
+
processedArgs.push(`
|
|
147
|
+
${this._formatValue(arg)}`);
|
|
145
148
|
previousWasObject = true;
|
|
146
149
|
} else if (isError) {
|
|
147
|
-
processedArgs.push("\n", arg);
|
|
150
|
+
processedArgs.push("\n", this._cleanErrorStack(arg));
|
|
148
151
|
previousWasObject = true;
|
|
149
152
|
} else {
|
|
150
153
|
if (typeof arg === "string" && previousWasObject) {
|
|
@@ -156,25 +159,17 @@ ${arg}`);
|
|
|
156
159
|
previousWasObject = false;
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const hex2 = this._palette[level];
|
|
166
|
-
if (typeof processedArgs[0] === "string") {
|
|
167
|
-
console[consoleMethod](
|
|
168
|
-
`%c${processedArgs[0]}`,
|
|
169
|
-
`color:${hex2}`,
|
|
170
|
-
...processedArgs.slice(1)
|
|
171
|
-
);
|
|
172
|
-
} else {
|
|
173
|
-
console[consoleMethod](...processedArgs);
|
|
174
|
-
}
|
|
175
|
-
return;
|
|
162
|
+
return processedArgs;
|
|
163
|
+
}
|
|
164
|
+
_applyBrowserColors(consoleMethod, args) {
|
|
165
|
+
const hex = this._palette[consoleMethod];
|
|
166
|
+
if (typeof args[0] === "string") {
|
|
167
|
+
return [`%c${args[0]}`, `color:${hex}`, ...args.slice(1)];
|
|
176
168
|
}
|
|
177
|
-
|
|
169
|
+
return args;
|
|
170
|
+
}
|
|
171
|
+
_applyNodeColors(consoleMethod, args) {
|
|
172
|
+
const hex = this._palette[consoleMethod];
|
|
178
173
|
let ansiCode;
|
|
179
174
|
switch (this._colorLevel) {
|
|
180
175
|
case ColorLevel.TRUECOLOR: {
|
|
@@ -194,17 +189,58 @@ ${arg}`);
|
|
|
194
189
|
break;
|
|
195
190
|
}
|
|
196
191
|
}
|
|
197
|
-
const coloredArgs = [...
|
|
192
|
+
const coloredArgs = [...args];
|
|
198
193
|
const firstStringIndex = coloredArgs.findIndex(
|
|
199
194
|
(arg) => typeof arg === "string"
|
|
200
195
|
);
|
|
201
196
|
if (firstStringIndex !== -1) {
|
|
202
197
|
coloredArgs[firstStringIndex] = `${ansiCode}${coloredArgs[firstStringIndex]}\x1B[0m`;
|
|
203
198
|
}
|
|
204
|
-
|
|
205
|
-
|
|
199
|
+
return coloredArgs;
|
|
200
|
+
}
|
|
201
|
+
_output(consoleMethod, args) {
|
|
202
|
+
if (consoleMethod === "trace") {
|
|
203
|
+
this._printCleanTrace(args, consoleMethod);
|
|
204
|
+
} else {
|
|
205
|
+
console[consoleMethod](...args);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
_out(level, args) {
|
|
209
|
+
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
210
|
+
const processedArgs = this._processArgs(args);
|
|
211
|
+
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
212
|
+
this._output(consoleMethod, processedArgs);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (this.isBrowser) {
|
|
216
|
+
const coloredArgs2 = this._applyBrowserColors(consoleMethod, processedArgs);
|
|
217
|
+
this._output(consoleMethod, coloredArgs2);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const coloredArgs = this._applyNodeColors(consoleMethod, processedArgs);
|
|
221
|
+
this._output(consoleMethod, coloredArgs);
|
|
222
|
+
}
|
|
223
|
+
_filterStack(stack) {
|
|
224
|
+
return stack.split("\n").filter(
|
|
225
|
+
(line) => !line.includes("colorino.js") && !line.includes("Colorino._out") && !line.includes("Colorino.error") && !line.includes("Colorino.warn") && !line.includes("Colorino.debug") && !line.includes("Colorino.info") && !line.includes("Colorino.log") && !line.includes("Colorino.trace") && !line.includes("Colorino._cleanErrorStack") && !line.includes("Colorino._printCleanTrace") && !line.includes("Colorino._filterStack")
|
|
226
|
+
).join("\n");
|
|
227
|
+
}
|
|
228
|
+
_cleanErrorStack(error) {
|
|
229
|
+
if (!error.stack) return error;
|
|
230
|
+
const cleanStack = this._filterStack(error.stack);
|
|
231
|
+
const cloned = Object.create(Object.getPrototypeOf(error));
|
|
232
|
+
Object.assign(cloned, error);
|
|
233
|
+
cloned.stack = cleanStack;
|
|
234
|
+
return cloned;
|
|
235
|
+
}
|
|
236
|
+
_printCleanTrace(args, method) {
|
|
237
|
+
const error = new Error();
|
|
238
|
+
if (error.stack) {
|
|
239
|
+
const cleanStack = this._filterStack(error.stack);
|
|
240
|
+
console[method](...args, `
|
|
241
|
+
${cleanStack}`);
|
|
206
242
|
} else {
|
|
207
|
-
console[
|
|
243
|
+
console[method](...args);
|
|
208
244
|
}
|
|
209
245
|
}
|
|
210
246
|
}
|
|
@@ -783,15 +819,33 @@ const githubLightPalette = {
|
|
|
783
819
|
trace: "#6a737d"
|
|
784
820
|
// Gray-light
|
|
785
821
|
};
|
|
822
|
+
const minimalDarkPalette = {
|
|
823
|
+
log: "#ffffff",
|
|
824
|
+
info: "#ffffff",
|
|
825
|
+
warn: "#ffffff",
|
|
826
|
+
error: "#ffffff",
|
|
827
|
+
debug: "#ffffff",
|
|
828
|
+
trace: "#ffffff"
|
|
829
|
+
};
|
|
830
|
+
const minimalLightPalette = {
|
|
831
|
+
log: "#000000",
|
|
832
|
+
info: "#000000",
|
|
833
|
+
warn: "#000000",
|
|
834
|
+
error: "#000000",
|
|
835
|
+
debug: "#000000",
|
|
836
|
+
trace: "#000000"
|
|
837
|
+
};
|
|
786
838
|
|
|
787
839
|
const themePalettes = {
|
|
788
840
|
"catppuccin-mocha": catppuccinMochaPalette,
|
|
789
841
|
"catppuccin-latte": catppuccinLattePalette,
|
|
790
842
|
dracula: draculaPalette,
|
|
791
|
-
"github-light": githubLightPalette
|
|
843
|
+
"github-light": githubLightPalette,
|
|
844
|
+
"minimal-dark": minimalDarkPalette,
|
|
845
|
+
"minimal-light": minimalLightPalette
|
|
792
846
|
};
|
|
793
|
-
const defaultDarkTheme = "
|
|
794
|
-
const defaultLightTheme = "
|
|
847
|
+
const defaultDarkTheme = "minimal-dark";
|
|
848
|
+
const defaultLightTheme = "minimal-light";
|
|
795
849
|
function isThemeName(theme) {
|
|
796
850
|
return theme in themePalettes;
|
|
797
851
|
}
|