colorino 0.10.1 → 0.11.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 +354 -351
- package/dist/browser.bundle.cjs +127 -116
- package/dist/browser.bundle.mjs +128 -116
- package/dist/browser.cjs +13 -14
- package/dist/browser.d.cts +5 -5
- package/dist/browser.d.mts +5 -5
- package/dist/browser.d.ts +5 -5
- package/dist/browser.mjs +5 -5
- package/dist/node.cjs +58 -125
- package/dist/node.d.cts +3 -6
- package/dist/node.d.mts +3 -6
- package/dist/node.d.ts +3 -6
- package/dist/node.mjs +40 -106
- package/dist/shared/{colorino.BnDovC2X.mjs → colorino.BPD_4Zhq.mjs} +125 -120
- package/dist/shared/{colorino.B4p-EEl9.cjs → colorino.D9xuyiJg.cjs} +124 -122
- package/dist/shared/{colorino.DjY5jpGa.d.ts → colorino.bX_hrCT6.d.cts} +2 -3
- package/dist/shared/{colorino.DjY5jpGa.d.cts → colorino.bX_hrCT6.d.mts} +2 -3
- package/dist/shared/{colorino.DjY5jpGa.d.mts → colorino.bX_hrCT6.d.ts} +2 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,351 +1,354 @@
|
|
|
1
|
-
# <a id="0"></a>🎨 Colorino
|
|
2
|
-
|
|
3
|
-
**The zero‑configuration, context‑aware `console` logger for Node.js and the browser—with smart theming and graceful color degradation.**
|
|
4
|
-
|
|
5
|
-
Colorino automatically adapts its palette to your terminal or browser DevTools theme, and degrades colors gracefully so your logs stay readable and on‑brand even in limited environments
|
|
6
|
-
|
|
7
|
-
# <a id="0"></a><a id="0"></a>
|
|
8
|
-
|
|
9
|
-
- [Why use Colorino?](#1)
|
|
10
|
-
- [Features](#2)
|
|
11
|
-
- [Installation](#3)
|
|
12
|
-
- [Browser via CDN (unpkg)](#4)
|
|
13
|
-
- [Usage](#5)
|
|
14
|
-
- [Quick Start](#5-1)
|
|
15
|
-
- [Creating a Custom Logger](#5-2)
|
|
16
|
-
- [Options & Theme Overrides](#5-3)
|
|
17
|
-
- [Available Theme Presets](#5-3-1)
|
|
18
|
-
- [Examples](#5-3-2)
|
|
19
|
-
- [Customization](#5-4)
|
|
20
|
-
- [Supported Environment Variables](#5-5)
|
|
21
|
-
- [Colorino vs. Chalk](#6)
|
|
22
|
-
- [API Reference](#7)
|
|
23
|
-
- [1. `colorino` (default instance)](#7-1)
|
|
24
|
-
- [2. `createColorino(palette?, options?)` (factory)](#7-2)
|
|
25
|
-
- [Extending Colorino](#8)
|
|
26
|
-
- [Use case: automatic file/context info](#8-1)
|
|
27
|
-
- [Internals & Dependencies](#9)
|
|
28
|
-
- [Why This Pattern?](#9-1)
|
|
29
|
-
- [License](#10)
|
|
30
|
-
|
|
31
|
-
<!-- Table of contents is made with https://github.com/eugene-khyst/md-toc-cli -->
|
|
32
|
-
|
|
33
|
-
## <a id="1"></a>Why use Colorino?
|
|
34
|
-
|
|
35
|
-
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.
|
|
36
|
-
|
|
37
|
-
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.
|
|
38
|
-
|
|
39
|
-
## <a id="2"></a>Features
|
|
40
|
-
|
|
41
|
-
- 🎨 **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.
|
|
42
|
-
- 🤘 **Graceful Color Degradation**: Accepts rich colors (hex/RGB) and automatically down‑samples to the best ANSI‑16/ANSI‑256/Truecolor match for the current environment.
|
|
43
|
-
- 🤝 **Familiar API:** If you know `console.log`, you already know Colorino: all standard log levels are supported.
|
|
44
|
-
- 🔀 **Environment-Aware:** Works in **Node.js** (ANSI color and truecolor) and all major **Browsers** (CSS styles).
|
|
45
|
-
- ⚡️ **Fast, Lightweight:** Minimal dependencies, works great in modern frameworks and CLIs.
|
|
46
|
-
- 🔒 **Robust:** Handles bad inputs and weird environments safely.
|
|
47
|
-
- 🛠️ **Customizable:** Override individual log colors for your own branding.
|
|
48
|
-
|
|
49
|
-
## <a id="3"></a>Installation
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
npm install colorino
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## <a id="4"></a>Browser via CDN (unpkg)
|
|
56
|
-
|
|
57
|
-
You can use Colorino directly in the browser without any build step.
|
|
58
|
-
|
|
59
|
-
**ESM (recommended):**
|
|
60
|
-
|
|
61
|
-
```html
|
|
62
|
-
<!DOCTYPE html>
|
|
63
|
-
<html>
|
|
64
|
-
<head>
|
|
65
|
-
<script type="module">
|
|
66
|
-
import { colorino } from 'https://unpkg.com/colorino/dist/browser.bundle.mjs';
|
|
67
|
-
|
|
68
|
-
colorino.info('Hello from the browser!');
|
|
69
|
-
colorino.error('Something went wrong');
|
|
70
|
-
</script>
|
|
71
|
-
</head>
|
|
72
|
-
<body></body>
|
|
73
|
-
</html>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
CommonJS-style bundle:
|
|
77
|
-
|
|
78
|
-
```HTML
|
|
79
|
-
<!DOCTYPE html>
|
|
80
|
-
<html>
|
|
81
|
-
<head>
|
|
82
|
-
<script src="https://unpkg.com/colorino/dist/browser.bundle.cjs"></script>
|
|
83
|
-
<script>
|
|
84
|
-
// `colorino` is exposed as a global
|
|
85
|
-
colorino.info('Hello from the CJS bundle!');
|
|
86
|
-
</script>
|
|
87
|
-
</head>
|
|
88
|
-
<body></body>
|
|
89
|
-
</html>
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## <a id="5"></a>Usage
|
|
93
|
-
|
|
94
|
-
### <a id="5-1"></a>Quick Start
|
|
95
|
-
|
|
96
|
-
Just import the default instance and log away!
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
import { colorino } from 'colorino'
|
|
100
|
-
|
|
101
|
-
// All log levels automatically themed
|
|
102
|
-
colorino.error('A critical error!')
|
|
103
|
-
colorino.warn('A warning message.')
|
|
104
|
-
colorino.info('Useful info logging.')
|
|
105
|
-
colorino.log('A plain log.')
|
|
106
|
-
colorino.debug('Debug with objects:', { x: 5, y: 9 })
|
|
107
|
-
colorino.trace('Tracing app start...')
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### <a id="5-2"></a>Creating a Custom Logger
|
|
111
|
-
|
|
112
|
-
Need your own colors or different settings?
|
|
113
|
-
Use the factory to create as many loggers as you want (each with its own palette and options):
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
import { createColorino } from 'colorino'
|
|
117
|
-
|
|
118
|
-
const myLogger = createColorino(
|
|
119
|
-
{ // Palette (partial)
|
|
120
|
-
error: '#ff007b',
|
|
121
|
-
info: '#3498db'
|
|
122
|
-
},
|
|
123
|
-
{ disableWarnings: true } // Options (see below)
|
|
124
|
-
)
|
|
125
|
-
myLogger.error('Critical!')
|
|
126
|
-
myLogger.info('Rebranded info!')
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### <a id="5-3"></a>Options & Theme Overrides
|
|
130
|
-
|
|
131
|
-
`createColorino(palette?, options?)` accepts:
|
|
132
|
-
|
|
133
|
-
| Option | Type
|
|
134
|
-
|
|
135
|
-
| `disableWarnings` | `boolean`
|
|
136
|
-
| `theme` | `ThemeOption` (see below)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
myLogger
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
|
236
|
-
|
|
237
|
-
| `
|
|
238
|
-
| `
|
|
239
|
-
| `
|
|
240
|
-
| `
|
|
241
|
-
| `
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
|
249
|
-
|
|
250
|
-
|
|
|
251
|
-
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
-
|
|
263
|
-
|
|
264
|
-
- `.
|
|
265
|
-
- `.
|
|
266
|
-
- `.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
//
|
|
318
|
-
Object.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
base.
|
|
324
|
-
},
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
- **
|
|
347
|
-
- **
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
1
|
+
# <a id="0"></a>🎨 Colorino
|
|
2
|
+
|
|
3
|
+
**The zero‑configuration, context‑aware `console` logger for Node.js and the browser—with smart theming and graceful color degradation.**
|
|
4
|
+
|
|
5
|
+
Colorino automatically adapts its palette to your terminal or browser DevTools theme, and degrades colors gracefully so your logs stay readable and on‑brand even in limited environments
|
|
6
|
+
|
|
7
|
+
# <a id="0"></a><a id="0"></a>
|
|
8
|
+
|
|
9
|
+
- [Why use Colorino?](#1)
|
|
10
|
+
- [Features](#2)
|
|
11
|
+
- [Installation](#3)
|
|
12
|
+
- [Browser via CDN (unpkg)](#4)
|
|
13
|
+
- [Usage](#5)
|
|
14
|
+
- [Quick Start](#5-1)
|
|
15
|
+
- [Creating a Custom Logger](#5-2)
|
|
16
|
+
- [Options & Theme Overrides](#5-3)
|
|
17
|
+
- [Available Theme Presets](#5-3-1)
|
|
18
|
+
- [Examples](#5-3-2)
|
|
19
|
+
- [Customization](#5-4)
|
|
20
|
+
- [Supported Environment Variables](#5-5)
|
|
21
|
+
- [Colorino vs. Chalk](#6)
|
|
22
|
+
- [API Reference](#7)
|
|
23
|
+
- [1. `colorino` (default instance)](#7-1)
|
|
24
|
+
- [2. `createColorino(palette?, options?)` (factory)](#7-2)
|
|
25
|
+
- [Extending Colorino](#8)
|
|
26
|
+
- [Use case: automatic file/context info](#8-1)
|
|
27
|
+
- [Internals & Dependencies](#9)
|
|
28
|
+
- [Why This Pattern?](#9-1)
|
|
29
|
+
- [License](#10)
|
|
30
|
+
|
|
31
|
+
<!-- Table of contents is made with https://github.com/eugene-khyst/md-toc-cli -->
|
|
32
|
+
|
|
33
|
+
## <a id="1"></a>Why use Colorino?
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
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.
|
|
38
|
+
|
|
39
|
+
## <a id="2"></a>Features
|
|
40
|
+
|
|
41
|
+
- 🎨 **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.
|
|
42
|
+
- 🤘 **Graceful Color Degradation**: Accepts rich colors (hex/RGB) and automatically down‑samples to the best ANSI‑16/ANSI‑256/Truecolor match for the current environment.
|
|
43
|
+
- 🤝 **Familiar API:** If you know `console.log`, you already know Colorino: all standard log levels are supported.
|
|
44
|
+
- 🔀 **Environment-Aware:** Works in **Node.js** (ANSI color and truecolor) and all major **Browsers** (CSS styles).
|
|
45
|
+
- ⚡️ **Fast, Lightweight:** Minimal dependencies, works great in modern frameworks and CLIs.
|
|
46
|
+
- 🔒 **Robust:** Handles bad inputs and weird environments safely.
|
|
47
|
+
- 🛠️ **Customizable:** Override individual log colors for your own branding.
|
|
48
|
+
|
|
49
|
+
## <a id="3"></a>Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install colorino
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## <a id="4"></a>Browser via CDN (unpkg)
|
|
56
|
+
|
|
57
|
+
You can use Colorino directly in the browser without any build step.
|
|
58
|
+
|
|
59
|
+
**ESM (recommended):**
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<!DOCTYPE html>
|
|
63
|
+
<html>
|
|
64
|
+
<head>
|
|
65
|
+
<script type="module">
|
|
66
|
+
import { colorino } from 'https://unpkg.com/colorino/dist/browser.bundle.mjs';
|
|
67
|
+
|
|
68
|
+
colorino.info('Hello from the browser!');
|
|
69
|
+
colorino.error('Something went wrong');
|
|
70
|
+
</script>
|
|
71
|
+
</head>
|
|
72
|
+
<body></body>
|
|
73
|
+
</html>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
CommonJS-style bundle:
|
|
77
|
+
|
|
78
|
+
```HTML
|
|
79
|
+
<!DOCTYPE html>
|
|
80
|
+
<html>
|
|
81
|
+
<head>
|
|
82
|
+
<script src="https://unpkg.com/colorino/dist/browser.bundle.cjs"></script>
|
|
83
|
+
<script>
|
|
84
|
+
// `colorino` is exposed as a global
|
|
85
|
+
colorino.info('Hello from the CJS bundle!');
|
|
86
|
+
</script>
|
|
87
|
+
</head>
|
|
88
|
+
<body></body>
|
|
89
|
+
</html>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## <a id="5"></a>Usage
|
|
93
|
+
|
|
94
|
+
### <a id="5-1"></a>Quick Start
|
|
95
|
+
|
|
96
|
+
Just import the default instance and log away!
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { colorino } from 'colorino'
|
|
100
|
+
|
|
101
|
+
// All log levels automatically themed
|
|
102
|
+
colorino.error('A critical error!')
|
|
103
|
+
colorino.warn('A warning message.')
|
|
104
|
+
colorino.info('Useful info logging.')
|
|
105
|
+
colorino.log('A plain log.')
|
|
106
|
+
colorino.debug('Debug with objects:', { x: 5, y: 9 })
|
|
107
|
+
colorino.trace('Tracing app start...')
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### <a id="5-2"></a>Creating a Custom Logger
|
|
111
|
+
|
|
112
|
+
Need your own colors or different settings?
|
|
113
|
+
Use the factory to create as many loggers as you want (each with its own palette and options):
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { createColorino } from 'colorino'
|
|
117
|
+
|
|
118
|
+
const myLogger = createColorino(
|
|
119
|
+
{ // Palette (partial)
|
|
120
|
+
error: '#ff007b',
|
|
121
|
+
info: '#3498db'
|
|
122
|
+
},
|
|
123
|
+
{ disableWarnings: true } // Options (see below)
|
|
124
|
+
)
|
|
125
|
+
myLogger.error('Critical!')
|
|
126
|
+
myLogger.info('Rebranded info!')
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### <a id="5-3"></a>Options & Theme Overrides
|
|
130
|
+
|
|
131
|
+
`createColorino(palette?, options?)` accepts:
|
|
132
|
+
|
|
133
|
+
| Option | Type | Default | Description |
|
|
134
|
+
|-------------------|--------------------------------------|---------|-----------------------------------------------------------------------------|
|
|
135
|
+
| `disableWarnings` | `boolean` | `false` | Suppress warnings when color support can't be detected or is disabled. |
|
|
136
|
+
| `theme` | `ThemeOption` (see below) | `'auto'`| Control the active color theme or force a specific mode. |
|
|
137
|
+
| `disableOscProbe` | `boolean` | `false` | Disable OSC 11 terminal theme probing (use only env heuristics for theme). |
|
|
138
|
+
| `maxDepth` | `number` | `5` | Maximum depth when pretty-printing objects in log output. |
|
|
139
|
+
|
|
140
|
+
**`theme` accepts three types of values:**
|
|
141
|
+
|
|
142
|
+
1. **`'auto'`** (Default): Automatically detects your terminal or browser theme (dark/light) and applies the matching default preset.
|
|
143
|
+
When combined with `disableOscProbe: true`, only environment variables are used for theme detection (no OSC 11 probe).
|
|
144
|
+
2. **`'dark' | 'light'`**: Forces the logger into a specific mode using the default preset for that mode.
|
|
145
|
+
3. **`ThemeName`**: Forces a specific built-in palette (e.g., `'dracula'`).
|
|
146
|
+
|
|
147
|
+
#### <a id="5-3-1"></a>Available Theme Presets
|
|
148
|
+
|
|
149
|
+
Pass any of these names to the `theme` option to use a specific palette:
|
|
150
|
+
|
|
151
|
+
| Theme Name | Type | Description |
|
|
152
|
+
|----------------------|-----------------|--------------------------------------------------|
|
|
153
|
+
| `'dracula'` | **Dark** (High) | Vibrant pinks, purples, and cyans. |
|
|
154
|
+
| `'catppuccin-mocha'` | **Dark** (Low) | Soothing pastel colors. |
|
|
155
|
+
| `'minimal-dark'` | **Dark** | *Default Dark (auto).* Minimal, high-contrast. |
|
|
156
|
+
| `'minimal-light'` | **Light** | *Default Light (auto).* Minimal, high-contrast. |
|
|
157
|
+
| `'github-light'` | **Light** (High)| Clean, sharp, high-contrast. |
|
|
158
|
+
| `'catppuccin-latte'` | **Light** (Low) | Warm, cozy light mode with soft colors. |
|
|
159
|
+
|
|
160
|
+
#### <a id="5-3-2"></a>Examples
|
|
161
|
+
|
|
162
|
+
**1. Minimal defaults with custom branding:**
|
|
163
|
+
Set only the colors you care about; everything else stays maximally readable.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// Only customize error and warn
|
|
167
|
+
const myLogger = createColorino({
|
|
168
|
+
error: '#ff007b',
|
|
169
|
+
warn: '#ffa500'
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
// Detected dark terminal:
|
|
173
|
+
// - error: #ff007b (your custom red)
|
|
174
|
+
// - warn: #ffa500 (your custom orange)
|
|
175
|
+
// - info, log, debug, trace: #ffffff (white - safe on dark)
|
|
176
|
+
|
|
177
|
+
// Detected light terminal:
|
|
178
|
+
// - error: #ff007b (your custom red)
|
|
179
|
+
// - warn: #ffa500 (your custom orange)
|
|
180
|
+
// - info, log, debug, trace: #000000 (black - safe on light)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**2. Use a specific preset:**
|
|
184
|
+
Instant branding with zero configuration.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
// Forces the Dracula palette
|
|
188
|
+
const draculaLogger = createColorino({}, { theme: 'dracula' })
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**3. Customize a preset:**
|
|
192
|
+
Overlay your own colors on top of a built-in theme.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// Use GitHub Light but with a custom error color
|
|
196
|
+
const myLogger = createColorino(
|
|
197
|
+
{ error: '#ff007b' },
|
|
198
|
+
{ theme: 'github-light' }
|
|
199
|
+
)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**4. Force a specific mode (uses defaults):**
|
|
203
|
+
Useful for CI/CD or environments where detection fails.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
// Forces dark mode using the default minimal palette (minimal-dark)
|
|
207
|
+
const darkLogger = createColorino({}, { theme: 'dark' })
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
> **Tip:**
|
|
211
|
+
> 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).
|
|
212
|
+
|
|
213
|
+
### <a id="5-4"></a>Customization
|
|
214
|
+
|
|
215
|
+
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.
|
|
216
|
+
|
|
217
|
+
Colorino always targets the highest color fidelity supported by the environment. If your palette uses hex colors but only ANSI‑16 is available, Colorino computes the nearest ANSI color so your branding stays recognizable, even on limited terminals.
|
|
218
|
+
|
|
219
|
+
If you pass an invalid color value (e.g. malformed hex) in a custom palette, Colorino throws an InputValidationError at creation time so broken palettes fail fast.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { createColorino } from 'colorino'
|
|
223
|
+
|
|
224
|
+
// Custom error color; others use theme defaults
|
|
225
|
+
const myLogger = createColorino({ error: '#ff007b' })
|
|
226
|
+
|
|
227
|
+
myLogger.error('Oh no!') // Uses your custom color
|
|
228
|
+
myLogger.info('Still styled by theme.') // Uses the default theme color
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### <a id="5-5"></a>Supported Environment Variables
|
|
232
|
+
|
|
233
|
+
Colorino auto-detects your environment and color support, but you can override behavior using these standard environment variables (compatible with Chalk):
|
|
234
|
+
|
|
235
|
+
| Variable | Effect | Example |
|
|
236
|
+
|-----------------|------------------------------------------------------------------------------------------|--------------------------------------|
|
|
237
|
+
| `NO_COLOR` | Forces no color output | `NO_COLOR=1 node app.js` |
|
|
238
|
+
| `FORCE_COLOR` | Forces color level: `0`=off, `1`=ANSI‑16, `2`=ANSI‑256, `3`=Truecolor | `FORCE_COLOR=3 node app.js` |
|
|
239
|
+
| `CLICOLOR` | `"0"` disables color | `CLICOLOR=0 node app.js` |
|
|
240
|
+
| `CLICOLOR_FORCE`| Non‑`"0"` value enables color even if not a TTY | `CLICOLOR_FORCE=1 node app.js` |
|
|
241
|
+
| `TERM` | Terminal type; may influence color support | `TERM=xterm-256color` |
|
|
242
|
+
| `COLORTERM` | `'truecolor'` or `'24bit'` enables truecolor | `COLORTERM=truecolor` |
|
|
243
|
+
| `WT_SESSION` | Enables color detection for Windows Terminal | |
|
|
244
|
+
| `CI` | Many CI platforms default to no color | `CI=1 node app.js` |
|
|
245
|
+
|
|
246
|
+
## <a id="6"></a>Colorino vs. Chalk
|
|
247
|
+
|
|
248
|
+
| Feature | 🎨 **Colorino** | 🖍️ **Chalk** |
|
|
249
|
+
|--------------------------|----------------------------|-----------------|
|
|
250
|
+
| Out-of-box logs | ✔ themed, all log levels | ✘ string styling|
|
|
251
|
+
| Zero-config | ✔ | ✘ manual, per-use|
|
|
252
|
+
| Node + browser | ✔ | ✘ (Node only) |
|
|
253
|
+
| CSS console logs | ✔ | ✘ |
|
|
254
|
+
| Extensible / Composable | ✔ (via factory) | ✘ |
|
|
255
|
+
|
|
256
|
+
## <a id="7"></a>API Reference
|
|
257
|
+
|
|
258
|
+
The `colorino` package exports two main items:
|
|
259
|
+
|
|
260
|
+
### <a id="7-1"></a>1. `colorino` (default instance)
|
|
261
|
+
|
|
262
|
+
A pre-configured, zero-setup logger instance. Just import and use.
|
|
263
|
+
|
|
264
|
+
- `.log(...args)`
|
|
265
|
+
- `.info(...args)`
|
|
266
|
+
- `.warn(...args)`
|
|
267
|
+
- `.error(...args)`
|
|
268
|
+
- `.debug(...args)`
|
|
269
|
+
- `.trace(...args)`
|
|
270
|
+
|
|
271
|
+
### <a id="7-2"></a>2. `createColorino(palette?, options?)` (factory)
|
|
272
|
+
|
|
273
|
+
A factory function to create your own customized logger instances.
|
|
274
|
+
|
|
275
|
+
- `palette` (`Partial<Palette>`): An object to override default colors for specific log levels (e.g., `{ error: '#ff007b' }`).
|
|
276
|
+
- `options` (`ColorinoOptions`): An object to control behavior:
|
|
277
|
+
- `disableWarnings: boolean` (default `false`): Suppress warnings on environments with no color support.
|
|
278
|
+
- `theme: 'dark' | 'light'` (default `auto`): Force a specific theme instead of auto-detecting.
|
|
279
|
+
|
|
280
|
+
## <a id="8"></a>Extending Colorino
|
|
281
|
+
|
|
282
|
+
Colorino is designed for composition: create a base logger via `createColorino()`, then extend it by inheriting from the base and overriding only the methods you need.
|
|
283
|
+
|
|
284
|
+
### <a id="8-1"></a>Use case: automatic file/context info
|
|
285
|
+
|
|
286
|
+
This example prefixes every `.info()` and `.error()` call with best‑effort caller context (file/line) derived from a synthetic `Error` stack.
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
import { createColorino, type Colorino, type ColorinoOptions, type Palette } from 'colorino'
|
|
290
|
+
|
|
291
|
+
function getCallerContext(): string {
|
|
292
|
+
const err = new Error()
|
|
293
|
+
if (!err.stack) return 'unknown'
|
|
294
|
+
|
|
295
|
+
const lines = err.stack.split('\n').slice(2) // skip "Error" + current frame
|
|
296
|
+
const frame = lines[0] ?? ''
|
|
297
|
+
|
|
298
|
+
const match =
|
|
299
|
+
frame.match(/at (.+?) \((.+?):(\d+):\d+\)/) ??
|
|
300
|
+
frame.match(/at (.+?):(\d+):\d+/)
|
|
301
|
+
|
|
302
|
+
if (!match) return frame.trim() || 'unknown'
|
|
303
|
+
|
|
304
|
+
const [_, maybeFn, fileOrLine, maybeLine] = match
|
|
305
|
+
const file = maybeLine ? fileOrLine : maybeFn
|
|
306
|
+
const line = maybeLine ?? fileOrLine
|
|
307
|
+
|
|
308
|
+
return `${file}:${line}`
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function createContextLogger(
|
|
312
|
+
palette?: Partial<Palette>,
|
|
313
|
+
options?: ColorinoOptions,
|
|
314
|
+
): Colorino {
|
|
315
|
+
const base = createColorino(palette, options)
|
|
316
|
+
|
|
317
|
+
// Inherit all default methods from the base logger...
|
|
318
|
+
const logger = Object.create(base) as Colorino // Object.create uses `base` as the prototype.
|
|
319
|
+
|
|
320
|
+
// ...and override only what you need.
|
|
321
|
+
Object.assign(logger, { // Object.assign copies these methods onto `logger`. [web:346]
|
|
322
|
+
info(...args: unknown[]) {
|
|
323
|
+
base.info(`[${getCallerContext()}]`, ...args)
|
|
324
|
+
},
|
|
325
|
+
error(...args: unknown[]) {
|
|
326
|
+
base.error(`[${getCallerContext()}]`, ...args)
|
|
327
|
+
},
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
return logger
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Usage
|
|
334
|
+
const logger = createContextLogger({}, { theme: 'dracula' })
|
|
335
|
+
logger.info('User created', { id: 123 })
|
|
336
|
+
logger.error('Failed to load user', { id: 456 })
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## <a id="9"></a>Internals & Dependencies
|
|
340
|
+
|
|
341
|
+
- Colorino’s runtime logic depends on a single bundled library, `neverthrow`, which is MIT‑licensed and used for type‑safe Result handling.
|
|
342
|
+
- `neverthrow` is bundled into the published artifacts, so you do not need to install it separately; your application sees a single runtime dependency: Colorino itself.
|
|
343
|
+
|
|
344
|
+
### <a id="9-1"></a>Why This Pattern?
|
|
345
|
+
|
|
346
|
+
- **Composition > Inheritance**: No fragile base class problems
|
|
347
|
+
- **Type Safe**: TypeScript infers the return type correctly
|
|
348
|
+
- **Future Proof**: Works even if colorino's internal implementation changes
|
|
349
|
+
- **Clean**: No messing with `super()` or constructor parameters
|
|
350
|
+
- **Composable**: You can layer multiple extensions
|
|
351
|
+
|
|
352
|
+
## <a id="10"></a>License
|
|
353
|
+
|
|
354
|
+
[MIT](LICENSE.md)
|