colorino 0.3.3 โ†’ 0.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/README.md CHANGED
@@ -1,39 +1,40 @@
1
- # ๐ŸŽจ Colorino
1
+ # <a id="0"></a>๐ŸŽจ Colorino
2
2
 
3
3
  **The zero-configuration, context-aware `console` logger for Node.js and the browser.**
4
4
 
5
5
  Colorino automatically adapts its palette to your terminal or browser DevTools theme.
6
6
 
7
- ---
8
-
9
- ## Table of Contents
10
-
11
- - [Why use Colorino?](#why-use-colorino)
12
- - [Features](#features)
13
- - [Installation](#installation)
14
- - [Usage](#usage)
15
- - [Quick Start](#quick-start)
16
- - [Creating a Custom Logger](#creating-a-custom-logger)
17
- - [Options & Theme Overrides](#options--theme-overrides)
18
- - [Customization](#customization)
19
- - [Supported Environment Variables](#supported-environment-variables)
20
- - [Colorino vs. Chalk](#colorino-vs-chalk)
21
- - [API Reference](#api-reference)
22
- - [Extending Colorino](#extending-colorino)
23
- - [Contributing](#contributing)
24
- - [License](#license)
25
-
26
- ---
27
-
28
- ## Why use Colorino?
7
+ # <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
+ - [Contributing](#8)
27
+ - [License](#9)
28
+
29
+ <!-- Table of contents is made with https://github.com/eugene-khyst/md-toc-cli -->
30
+
31
+ ## <a id="1"></a>Why use Colorino?
29
32
 
30
33
  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.
31
34
 
32
35
  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.
33
36
 
34
- ---
35
-
36
- ## Features
37
+ ## <a id="2"></a>Features
37
38
 
38
39
  - ๐ŸŽจ **Smart Theming:** Automatically detects *dark/light* mode and uses a coordinated color palette.
39
40
  - ๐Ÿค **Familiar API:** If you know `console.log`, you already know Colorino: all standard log levels are supported.
@@ -42,21 +43,15 @@ Colorino is different: itโ€™s a "batteries-included" logging facade with beautif
42
43
  - ๐Ÿ”’ **Robust:** Handles bad inputs and weird environments safely.
43
44
  - ๐Ÿ› ๏ธ **Customizable:** Override individual log colors for your own branding.
44
45
 
45
- ---
46
-
47
- ## Installation
46
+ ## <a id="3"></a>Installation
48
47
 
49
- ```sh
48
+ ```bash
50
49
  npm install colorino
51
- # or
52
- yarn add colorino
53
50
  ```
54
51
 
55
- ---
56
-
57
- ## Usage
52
+ ## <a id="4"></a>Usage
58
53
 
59
- ### Quick Start
54
+ ### <a id="4-1"></a>Quick Start
60
55
 
61
56
  Just import the default instance and log away!
62
57
 
@@ -72,9 +67,7 @@ colorino.debug('Debug with objects:', { x: 5, y: 9 })
72
67
  colorino.trace('Tracing app start...')
73
68
  ```
74
69
 
75
- ---
76
-
77
- ### Creating a Custom Logger
70
+ ### <a id="4-2"></a>Creating a Custom Logger
78
71
 
79
72
  Need your own colors or different settings?
80
73
  Use the factory to create as many loggers as you want (each with its own palette and options):
@@ -93,36 +86,65 @@ myLogger.error('Critical!')
93
86
  myLogger.info('Rebranded info!')
94
87
  ```
95
88
 
96
- ---
97
-
98
- ### Options & Theme Overrides
89
+ ### <a id="4-3"></a>Options & Theme Overrides
99
90
 
100
91
  `createColorino(palette?, options?)` accepts:
101
92
 
102
- | Option | Type | Default | Description |
103
- |-------------------|------------------------------|---------|--------------------------------------------------------------------------------|
104
- | `disableWarnings` | `boolean` | `false` | Suppress warnings when color support can't be detected or is disabled |
105
- | `theme` | `'dark' \| 'light' \| 'unknown'` | *(auto)*| Override auto-theme detection: force `'dark'` or `'light'` for palette selection |
93
+ | Option | Type | Default | Description |
94
+ |-------------------|--------------------------------|---------|--------------------------------------------------------------------------------|
95
+ | `disableWarnings` | `boolean` | `false` | Suppress warnings when color support can't be detected or is disabled. |
96
+ | `theme` | `ThemeOption` (see below) | `'auto'`| Control the active color theme or force a specific mode. |
97
+
98
+ **`theme` accepts three types of values:**
99
+
100
+ 1. **`'auto'`** (Default): Automatically detects your terminal or browser theme (dark/light) and applies the matching default preset.
101
+ 2. **`'dark' | 'light'`**: Forces the logger into a specific mode using the default preset for that mode.
102
+ 3. **`ThemeName`**: Forces a specific built-in palette (e.g., `'dracula'`).
103
+
104
+ #### <a id="4-3-1"></a>Available Theme Presets
105
+
106
+ Pass any of these names to the `theme` option to use a specific palette:
107
+
108
+ | Theme Name | Type | Description |
109
+ |----------------------|-----------------|--------------------------------------------------|
110
+ | `'dracula'` | **Dark** (High) | Vibrant pinks, purples, and cyans. |
111
+ | `'catppuccin-mocha'` | **Dark** (Low) | *Default Dark.* Soothing pastel colors. |
112
+ | `'github-light'` | **Light** (High)| *Default Light.* Clean, sharp, high-contrast. |
113
+ | `'catppuccin-latte'` | **Light** (Low) | Warm, cozy light mode with soft colors. |
106
114
 
107
- #### Example: Forcing a theme
115
+ #### <a id="4-3-2"></a>Examples
108
116
 
109
- If the auto-contrast and theme detection doesn't work (e.g., in some CI/CD, headless, or basic terminals), **force the color scheme**:
117
+ **1. Force a specific mode (uses defaults):**
118
+ Useful for CI/CD or environments where detection fails.
110
119
 
111
120
  ```typescript
112
- import { createColorino } from 'colorino'
121
+ // Forces the default dark theme (Catppuccin Mocha)
122
+ const darkLogger = createColorino({}, { theme: 'dark' })
123
+ ```
124
+
125
+ **2. Use a specific preset:**
126
+ Instant branding with zero configuration.
127
+
128
+ ```typescript
129
+ // Forces the Dracula palette
130
+ const draculaLogger = createColorino({}, { theme: 'dracula' })
131
+ ```
113
132
 
114
- // Force dark palette regardless of environment
115
- const forcedDarkLogger = createColorino({}, { theme: 'dark' })
133
+ **3. Customize a preset:**
134
+ Overlay your own colors on top of a built-in theme.
116
135
 
117
- forcedDarkLogger.info('This will always use dark-friendly colors.')
136
+ ```typescript
137
+ // Use GitHub Light but with a custom error color
138
+ const myLogger = createColorino(
139
+ { error: '#ff007b' },
140
+ { theme: 'github-light' }
141
+ )
118
142
  ```
119
143
 
120
144
  > **Tip:**
121
145
  > 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).
122
146
 
123
- ---
124
-
125
- ### Customization
147
+ ### <a id="4-4"></a>Customization
126
148
 
127
149
  Use your brand colors by passing a partial palette to the `createColorino` factory. Any log levels you don't specify will use the smart theme defaults.
128
150
 
@@ -136,9 +158,7 @@ myLogger.error('Oh no!') // Uses your custom color
136
158
  myLogger.info('Still styled by theme.') // Uses the default theme color
137
159
  ```
138
160
 
139
- ---
140
-
141
- ### Supported Environment Variables
161
+ ### <a id="4-5"></a>Supported Environment Variables
142
162
 
143
163
  Colorino auto-detects your environment and color support, but you can override behavior using these standard environment variables (compatible with Chalk):
144
164
 
@@ -153,9 +173,7 @@ Colorino auto-detects your environment and color support, but you can override b
153
173
  | `WT_SESSION` | Detected for Windows Terminal (enables color) | |
154
174
  | `CI` | Many CI platforms default to *no color* | `CI=1 node app.js` |
155
175
 
156
- ---
157
-
158
- ## Colorino vs. Chalk
176
+ ## <a id="5"></a>Colorino vs. Chalk
159
177
 
160
178
  | Feature | ๐ŸŽจ **Colorino** | ๐Ÿ–๏ธ **Chalk** |
161
179
  |--------------------------|----------------------------|-----------------|
@@ -165,13 +183,11 @@ Colorino auto-detects your environment and color support, but you can override b
165
183
  | CSS console logs | โœ” | โœ˜ |
166
184
  | Extensible / Composable | โœ” (via factory) | โœ˜ |
167
185
 
168
- ---
169
-
170
- ## API Reference
186
+ ## <a id="6"></a>API Reference
171
187
 
172
188
  The `colorino` package exports two main items:
173
189
 
174
- ### 1. `colorino` (default instance)
190
+ ### <a id="6-1"></a>1. `colorino` (default instance)
175
191
 
176
192
  A pre-configured, zero-setup logger instance. Just import and use.
177
193
 
@@ -182,7 +198,7 @@ A pre-configured, zero-setup logger instance. Just import and use.
182
198
  - `.debug(...args)`
183
199
  - `.trace(...args)`
184
200
 
185
- ### 2. `createColorino(palette?, options?)` (factory)
201
+ ### <a id="6-2"></a>2. `createColorino(palette?, options?)` (factory)
186
202
 
187
203
  A factory function to create your own customized logger instances.
188
204
 
@@ -191,9 +207,7 @@ A factory function to create your own customized logger instances.
191
207
  - `disableWarnings: boolean` (default `false`): Suppress warnings on environments with no color support.
192
208
  - `theme: 'dark' | 'light'` (default `auto`): Force a specific theme instead of auto-detecting.
193
209
 
194
- ---
195
-
196
- ## Extending Colorino
210
+ ## <a id="7"></a>Extending Colorino
197
211
 
198
212
  Example: Add a `fatal()` logger for critical errors.
199
213
 
@@ -236,7 +250,7 @@ logger.info('Starting!')
236
250
  logger.fatal('Missing config: Exiting')
237
251
  ```
238
252
 
239
- ### Why This Pattern?
253
+ ### <a id="7-1"></a>Why This Pattern?
240
254
 
241
255
  - **Composition > Inheritance**: No fragile base class problems
242
256
  - **Type Safe**: TypeScript infers the return type correctly
@@ -244,23 +258,76 @@ logger.fatal('Missing config: Exiting')
244
258
  - **Clean**: No messing with `super()` or constructor parameters
245
259
  - **Composable**: You can layer multiple extensions
246
260
 
247
- ---
261
+ ## <a id="8"></a>Contributing
248
262
 
249
- ## Contributing
263
+ We welcome contributions! Here's exactly how to get started:
250
264
 
251
- PRs and issues welcome!
265
+ 1. **Setup**
266
+ Fork the repo and install dependencies. This will also set up Git hooks via `husky`.
252
267
 
253
- 1. Fork the repo.
254
- 2. Make a branch (`git checkout -b feat/my-feature`)
255
- 3. Add your change, with tests.
256
- 4. Run `npm test:all` to ensure all tests pass in both Node and browser.
257
- 5. Open a Pull Request.
268
+ ```bash
269
+ git clone https://github.com/simwai/colorino.git
270
+ cd colorino
271
+ npm install
272
+ ```
258
273
 
259
- ---
274
+ 2. **Development Workflow**
275
+ Create a branch for your feature or fix.
276
+
277
+ ```bash
278
+ git checkout -b feat/my-cool-feature
279
+ ```
280
+
281
+ 3. **Running Tests**
282
+ We use **Vitest** for testing. Please run the full suite to ensure compatibility with both Node.js and Browsers.
283
+
284
+ ```bash
285
+ # Run all tests (Node + Browser)
286
+ npm run test:all
287
+
288
+ # Run only Node.js tests
289
+ npm run test:node
290
+
291
+ # Run only Browser tests (JSDOM)
292
+ npm run test:browser
293
+
294
+ # Watch mode with UI (great for dev!)
295
+ npm run test:ui
296
+ ```
297
+
298
+ 4. **Linting & Formatting**
299
+ We use **Oxlint** and **Oxfmt** for fast, robust linting.
300
+
301
+ ```bash
302
+ # Fix lint issues and format code
303
+ npm run format
304
+ ```
305
+
306
+ 5. **Commit Changes**
307
+ Commit your work. This triggers our `lint-staged` hooks to automatically lint, format, and run related tests on your staged files.
308
+
309
+ ```bash
310
+ git add .
311
+ git commit -m "feat: โœจ Add amazing new feature"
312
+ ```
313
+
314
+ 6. **Building**
315
+ To verify the build output (using `unbuild`):
316
+
317
+ ```bash
318
+ npm run build
319
+ ```
320
+
321
+ 7. **Submission**
322
+ Push your branch and open a Pull Request.
323
+
324
+ ```bash
325
+ git push origin feat/my-cool-feature
326
+ ```
260
327
 
261
- ## License
328
+ ## <a id="9"></a>License
262
329
 
263
- MIT
330
+ [MIT](LICENSE.md)
264
331
 
265
332
  ---
266
333
 
package/dist/browser.cjs CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const theme = require('./shared/colorino.gkk2eRGY.cjs');
4
- require('neverthrow');
3
+ const determineBaseTheme = require('./shared/colorino.B9WUj1qg.cjs');
5
4
 
6
5
  class BrowserColorSupportDetector {
7
6
  constructor(_window, _navigator, _overrideTheme) {
@@ -14,18 +13,18 @@ class BrowserColorSupportDetector {
14
13
  }
15
14
  getColorLevel() {
16
15
  if (!this.isBrowserEnv()) {
17
- return theme.ColorLevel.NO_COLOR;
16
+ return determineBaseTheme.ColorLevel.NO_COLOR;
18
17
  }
19
18
  const userAgent = this._navigator.userAgent.toLowerCase();
20
- if (userAgent.includes("chrome")) return theme.ColorLevel.ANSI256;
21
- if (userAgent.includes("firefox")) return theme.ColorLevel.ANSI256;
22
- return theme.ColorLevel.ANSI256;
19
+ if (userAgent.includes("chrome")) return determineBaseTheme.ColorLevel.ANSI256;
20
+ if (userAgent.includes("firefox")) return determineBaseTheme.ColorLevel.ANSI256;
21
+ return determineBaseTheme.ColorLevel.ANSI256;
23
22
  }
24
23
  getTheme() {
25
24
  if (this._overrideTheme) {
26
25
  return this._overrideTheme;
27
26
  }
28
- if (!this.isBrowserEnv()) {
27
+ if (!this.isBrowserEnv() || typeof this._window.matchMedia !== "function") {
29
28
  return "unknown";
30
29
  }
31
30
  if (this._window.matchMedia("(prefers-color-scheme: dark)").matches) {
@@ -38,15 +37,26 @@ class BrowserColorSupportDetector {
38
37
  }
39
38
  }
40
39
 
41
- function createColorino(palette, options = {}) {
42
- const validator = new theme.InputValidator();
40
+ function createColorino(palette = {}, options = {}) {
41
+ const validator = new determineBaseTheme.InputValidator();
42
+ let detectorThemeOverride;
43
+ if (options.theme === "dark" || options.theme === "light") {
44
+ detectorThemeOverride = options.theme;
45
+ }
43
46
  const browserDetector = new BrowserColorSupportDetector(
44
47
  window,
45
48
  navigator,
46
- options.theme
49
+ detectorThemeOverride
50
+ );
51
+ const detectedBrowserTheme = browserDetector.getTheme();
52
+ const themeOpt = options.theme ?? "auto";
53
+ const baseThemeName = determineBaseTheme.determineBaseTheme(
54
+ themeOpt,
55
+ detectedBrowserTheme
47
56
  );
48
- const finalPalette = { ...theme.darkDraculaPalette, ...palette };
49
- return new theme.Colorino(
57
+ const basePalette = determineBaseTheme.themePalettes[baseThemeName];
58
+ const finalPalette = { ...basePalette, ...palette };
59
+ return new determineBaseTheme.Colorino(
50
60
  finalPalette,
51
61
  validator,
52
62
  browserDetector,
@@ -56,7 +66,7 @@ function createColorino(palette, options = {}) {
56
66
  options
57
67
  );
58
68
  }
59
- const colorino = createColorino(theme.darkDraculaPalette);
69
+ const colorino = createColorino();
60
70
 
61
71
  exports.colorino = colorino;
62
72
  exports.createColorino = createColorino;
@@ -1,8 +1,7 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.Ddpe9uIB.cjs';
2
- export { L as LogLevel, T as TerminalTheme } from './shared/colorino.Ddpe9uIB.cjs';
3
- import 'neverthrow';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.B1MNcUze.cjs';
2
+ export { L as LogLevel, T as ThemeName } from './shared/colorino.B1MNcUze.cjs';
4
3
 
5
- declare function createColorino(palette: Partial<Palette>, options?: ColorinoOptions): Colorino;
4
+ declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
6
5
 
7
6
  declare const colorino: Colorino;
8
7
 
@@ -1,8 +1,7 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.Ddpe9uIB.mjs';
2
- export { L as LogLevel, T as TerminalTheme } from './shared/colorino.Ddpe9uIB.mjs';
3
- import 'neverthrow';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.B1MNcUze.mjs';
2
+ export { L as LogLevel, T as ThemeName } from './shared/colorino.B1MNcUze.mjs';
4
3
 
5
- declare function createColorino(palette: Partial<Palette>, options?: ColorinoOptions): Colorino;
4
+ declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
6
5
 
7
6
  declare const colorino: Colorino;
8
7
 
package/dist/browser.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.Ddpe9uIB.js';
2
- export { L as LogLevel, T as TerminalTheme } from './shared/colorino.Ddpe9uIB.js';
3
- import 'neverthrow';
1
+ import { P as Palette, C as ColorinoOptions, a as Colorino } from './shared/colorino.B1MNcUze.js';
2
+ export { L as LogLevel, T as ThemeName } from './shared/colorino.B1MNcUze.js';
4
3
 
5
- declare function createColorino(palette: Partial<Palette>, options?: ColorinoOptions): Colorino;
4
+ declare function createColorino(palette?: Partial<Palette>, options?: ColorinoOptions): Colorino;
6
5
 
7
6
  declare const colorino: Colorino;
8
7
 
package/dist/browser.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { C as ColorLevel, a as Colorino, d as darkDraculaPalette, I as InputValidator } from './shared/colorino.iQv4mlpl.mjs';
2
- import 'neverthrow';
1
+ import { C as ColorLevel, t as themePalettes, a as Colorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.CsFoITs1.mjs';
3
2
 
4
3
  class BrowserColorSupportDetector {
5
4
  constructor(_window, _navigator, _overrideTheme) {
@@ -23,7 +22,7 @@ class BrowserColorSupportDetector {
23
22
  if (this._overrideTheme) {
24
23
  return this._overrideTheme;
25
24
  }
26
- if (!this.isBrowserEnv()) {
25
+ if (!this.isBrowserEnv() || typeof this._window.matchMedia !== "function") {
27
26
  return "unknown";
28
27
  }
29
28
  if (this._window.matchMedia("(prefers-color-scheme: dark)").matches) {
@@ -36,14 +35,25 @@ class BrowserColorSupportDetector {
36
35
  }
37
36
  }
38
37
 
39
- function createColorino(palette, options = {}) {
38
+ function createColorino(palette = {}, options = {}) {
40
39
  const validator = new InputValidator();
40
+ let detectorThemeOverride;
41
+ if (options.theme === "dark" || options.theme === "light") {
42
+ detectorThemeOverride = options.theme;
43
+ }
41
44
  const browserDetector = new BrowserColorSupportDetector(
42
45
  window,
43
46
  navigator,
44
- options.theme
47
+ detectorThemeOverride
48
+ );
49
+ const detectedBrowserTheme = browserDetector.getTheme();
50
+ const themeOpt = options.theme ?? "auto";
51
+ const baseThemeName = determineBaseTheme(
52
+ themeOpt,
53
+ detectedBrowserTheme
45
54
  );
46
- const finalPalette = { ...darkDraculaPalette, ...palette };
55
+ const basePalette = themePalettes[baseThemeName];
56
+ const finalPalette = { ...basePalette, ...palette };
47
57
  return new Colorino(
48
58
  finalPalette,
49
59
  validator,
@@ -54,6 +64,6 @@ function createColorino(palette, options = {}) {
54
64
  options
55
65
  );
56
66
  }
57
- const colorino = createColorino(darkDraculaPalette);
67
+ const colorino = createColorino();
58
68
 
59
69
  export { colorino, createColorino };