debug-web 1.0.1 → 2.1.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/CHANGELOG.md +11 -0
- package/LICENSE +1 -1
- package/README.de.md +115 -92
- package/README.es.md +120 -98
- package/README.md +115 -94
- package/README.ru.md +108 -86
- package/README.zh.md +115 -94
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +111 -118
- package/dist/index.mjs +1 -1
- package/package.json +22 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.0] - 2026-03-11
|
|
4
|
+
- Add function `createDebug`
|
|
5
|
+
- Add method `dump`
|
|
6
|
+
- Add option `native`
|
|
7
|
+
- Add option `local`
|
|
8
|
+
- Removed singleton
|
|
9
|
+
- Target ES version (`ES2018`)
|
|
10
|
+
|
|
11
|
+
## [1.0.1] - 2026-01-06
|
|
12
|
+
- Updated README.md
|
|
13
|
+
|
|
3
14
|
## [1.0.0] - 2026-01-04
|
|
4
15
|
- Initial release of debug-web library
|
|
5
16
|
- Console logging with CSS styling, global data storage, and TypeScript support
|
package/LICENSE
CHANGED
package/README.de.md
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
# Debug Web
|
|
2
|
-
Leichtgewichtige Bibliothek für Browser-Debugging.
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
3
|
+
NPM-Paket für das Debugging im Browser mit anpassbaren Protokollierungsebenen (log, warn, error, debug).\
|
|
4
|
+
Leichtgewichtig und einfach zu bedienen.
|
|
5
|
+
|
|
6
|
+
**Eigenschaften**:
|
|
7
|
+
- 🚀 **Keine Abhängigkeiten** — reines TypeScript;
|
|
8
|
+
- 📦 **Größe ~3.4 kB** — minimaler Einfluss auf Ihr Bundle;
|
|
9
|
+
- 🏅 **SonarQube `A` Bewertung** — höchstes Maß an Codequalität und Zuverlässigkeit;
|
|
10
|
+
- 🎨 **Konsolen-Styling** — farbliche Formatierung zur schnellen Identifikation;
|
|
11
|
+
- 💾 **Globaler Speicher** — Zugriff auf Debug-Daten über `window`;
|
|
12
|
+
- 🔧 **Flexible Konfiguration** — Protokollierungsebenen, Stile, Aliase, Unterstützung von Vererbung.
|
|
9
13
|
|
|
10
14
|
---
|
|
11
15
|
|
|
12
16
|
## Inhaltsverzeichnis 📑
|
|
13
17
|
|
|
14
18
|
- [Installation](#installation-)
|
|
15
|
-
- [
|
|
19
|
+
- [Protokollierungsebenen](#protokollierungsebenen-)
|
|
16
20
|
- [Optionen](#optionen-)
|
|
17
21
|
- [Standardstile](#standardstile-)
|
|
18
|
-
- [Verwendung](#verwendung-)
|
|
19
|
-
- [Stilanpassung](#stilanpassung-)
|
|
20
22
|
- [API](#api-)
|
|
21
|
-
- [
|
|
23
|
+
- [createDebug](#funktion-createdebug)
|
|
24
|
+
- [Protokollierungsmethoden](#protokollierungsmethoden)
|
|
25
|
+
- [Datenverarbeitung](#datenverarbeitung)
|
|
26
|
+
- [Ebenenverwaltung](#ebenenverwaltung)
|
|
27
|
+
- [Debug-Daten](#debug-daten)
|
|
28
|
+
- [Unterstützung](#unterstützung-)
|
|
29
|
+
- [Lizenz](#lizenz)
|
|
22
30
|
|
|
23
|
-
##
|
|
31
|
+
## Übersetzungen
|
|
24
32
|
|
|
25
33
|
[English](README.md), [Español](README.es.md), [Deutsch](README.de.md), [中文](README.zh.md), [Русский](README.ru.md)
|
|
26
34
|
|
|
@@ -35,7 +43,7 @@ npm install debug-web
|
|
|
35
43
|
yarn add debug-web
|
|
36
44
|
```
|
|
37
45
|
|
|
38
|
-
##
|
|
46
|
+
## Protokollierungsebenen 🔧
|
|
39
47
|
|
|
40
48
|
Priorität (niedrig nach hoch):
|
|
41
49
|
|
|
@@ -45,17 +53,21 @@ Priorität (niedrig nach hoch):
|
|
|
45
53
|
4. `warn` (3) — Warnungen (`console.warn`);
|
|
46
54
|
5. `error` (4) — Fehler (`console.error`).
|
|
47
55
|
|
|
48
|
-
ℹ️ Benutzerdefinierte
|
|
56
|
+
ℹ️ Benutzerdefinierte Ebenen: beliebige Zeichenfolgen (z.B. `success`, `focus`) werden als `info`-Ebene verarbeitet
|
|
57
|
+
und können eigene Stile haben.
|
|
49
58
|
|
|
50
59
|
## Optionen ⚙️
|
|
51
60
|
|
|
52
|
-
| Parameter | Typ |
|
|
53
|
-
|
|
54
|
-
| `app` | `string` \| `null` | `'
|
|
55
|
-
| `level` | `DebugLogLevel` | `'log'` |
|
|
56
|
-
| `prop` | `string` \| `null` | `'info'` |
|
|
57
|
-
| `data` | `Record<string, unknown>` | — | Initiale Debug-Daten
|
|
58
|
-
| `
|
|
61
|
+
| Parameter | Typ | Standard | Beschreibung |
|
|
62
|
+
|-----------|---------------------------------|--------------------------------|------------------------------------------------------------------------------|
|
|
63
|
+
| `app` | `string` \| `null` | `'_debug_web'` | Eindeutiger App-Name zur Trennung von Daten |
|
|
64
|
+
| `level` | `DebugLogLevel` | `'log'` | Minimale Protokollierungsebene (Nachrichten darunter werden nicht angezeigt) |
|
|
65
|
+
| `prop` | `string` \| `null` | `'info'` | Globaler Variablenname für Datenzugriff (`null` — nicht erstellen) |
|
|
66
|
+
| `data` | `Record<string, unknown>` | — | Initiale Debug-Daten |
|
|
67
|
+
| `local` | `boolean` | `false` | Ebene in `localStorage` speichern (sonst `sessionStorage`) |
|
|
68
|
+
| `native` | `boolean` | `false` | Native Konsolenmethoden (ohne Stile) verwenden |
|
|
69
|
+
| `aliases` | `Record<string, DebugLogLevel>` | '{}' | Benutzerdefinierte Aliase für `createDebug` |
|
|
70
|
+
| `style` | `Record<DebugLogLevel, string>` | siehe [unten](#standardstile-) | CSS-Stile für die Protokollierungsebenen |
|
|
59
71
|
|
|
60
72
|
```typescript
|
|
61
73
|
type DebugLogLevel = 'debug' | 'log' | 'info' | 'success' | 'warn' | 'error' | string;
|
|
@@ -63,110 +75,121 @@ type DebugLogLevel = 'debug' | 'log' | 'info' | 'success' | 'warn' | 'error' | s
|
|
|
63
75
|
|
|
64
76
|
### Standardstile 🎨
|
|
65
77
|
|
|
66
|
-
|
|
|
78
|
+
| Ebene | Stil (CSS) |
|
|
67
79
|
|-----------|----------------------------------------------------------------------------|
|
|
68
80
|
| `info` | `background-color: #155adc; color: #fff; padding: 2px; border-radius: 3px` |
|
|
81
|
+
| `mark` | `background-color: #695aff; color: #fff; padding: 2px; border-radius: 3px` |
|
|
69
82
|
| `success` | `background-color: #13a10e; color: #fff; padding: 2px; border-radius: 3px` |
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
83
|
+
| `focus` | `background-color: #881798; color: #fff; padding: 2px; border-radius: 3px` |
|
|
84
|
+
| `alert` | `background-color: #ffa500; color: #fff; padding: 2px; border-radius: 3px` |
|
|
85
|
+
| `danger` | `background-color: #dc143c; color: #fff; padding: 2px; border-radius: 3px` |
|
|
72
86
|
|
|
73
87
|
## Verwendung 💡
|
|
74
88
|
|
|
75
|
-
###
|
|
76
|
-
|
|
77
|
-
Einmalig am Einstiegspunkt der Anwendung aufrufen (`main.js` / `app.js`):
|
|
78
|
-
|
|
79
|
-
```javascript
|
|
80
|
-
import { debugInit } from 'debug-web';
|
|
89
|
+
### Erstellen einer Instanz
|
|
81
90
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
```typescript
|
|
92
|
+
// debug.ts
|
|
93
|
+
import { DebugWeb } from 'debug-web';
|
|
94
|
+
|
|
95
|
+
export const debug = new DebugWeb({
|
|
96
|
+
app: 'my-app',
|
|
97
|
+
level: process.env.NODE_ENV === 'development' ? 'log' : 'error',
|
|
98
|
+
data: { version: APP_VERSION },
|
|
99
|
+
aliases: { s: 'success', f: 'focus' },
|
|
100
|
+
local: true,
|
|
85
101
|
});
|
|
86
102
|
```
|
|
87
103
|
|
|
88
|
-
###
|
|
89
|
-
|
|
90
|
-
Überall in der Anwendung verwenden, um Nachrichten auszugeben:
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
import { debug, log, info, success, warn, error } from 'debug-web';
|
|
94
|
-
|
|
95
|
-
debug('Debug-Nachricht');
|
|
96
|
-
log('Reguläre Nachricht');
|
|
97
|
-
info('Informationelle Nachricht');
|
|
98
|
-
success('Erfolg!');
|
|
99
|
-
warn('Warnung!');
|
|
100
|
-
error(new Error());
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### Debug-Daten
|
|
104
|
+
### API 📚
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
#### Funktion `createDebug`
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
import { debugData } from 'debug-web';
|
|
108
|
+
Erstellt einen Proxy mit Aliasen und Unterstützung für benutzerdefinierte Ebenen.
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
```typescript
|
|
111
|
+
<T extends typeof DebugWeb>( options?: CreateDebugOptions, DebugClass?: T ) => CustomLogLevels & InstanceType<T>;
|
|
111
112
|
```
|
|
112
|
-
💡 Tipp: Gib in DevTools `info` (oder einen anderen `prop`-Wert) ein, um alle gespeicherten Daten zu erhalten.
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
Standard-Aliase: `d` → `debug`, `l` → `log`, `i` → `info`, `w` → `warn`, `e` → `error`
|
|
115
|
+
|
|
116
|
+
#### Protokollierungsmethoden
|
|
117
|
+
|
|
118
|
+
| Ebene | Typ |
|
|
119
|
+
|--------------|------------------------------------------------------------------------|
|
|
120
|
+
| `debug` | `(message?: unknown, ...attrs: unknown[]) => void` |
|
|
121
|
+
| `log` | `(...attrs: unknown[]) => void` |
|
|
122
|
+
| `info` | `(...attrs: unknown[]) => void` |
|
|
123
|
+
| `warn` | `(...attrs: unknown[]) => void` |
|
|
124
|
+
| `error` | `(...attrs: unknown[]) => void` |
|
|
125
|
+
| `group` | `(open?: boolean, level?: DebugLogLevel, ...attrs: unknown[]) => void` |
|
|
126
|
+
| `groupEnd` | `(level?: DebugLogLevel) => void` |
|
|
127
|
+
| `dir` | `(value: unknown, options?: unknown) => void` |
|
|
128
|
+
| `dirxml` | `(...attrs: unknown[]) => void` |
|
|
129
|
+
| `trace` | `(...attrs: unknown[]) => void` |
|
|
130
|
+
| `table` | `(data: unknown, properties?: string[]) => void` |
|
|
131
|
+
| `count` | `(label?: string) => void` |
|
|
132
|
+
| `countReset` | `(label?: string) => void` |
|
|
133
|
+
| `time` | `(label?: string) => void` |
|
|
134
|
+
| `timeLog` | `(label?: string, ...attrs: unknown[]) => void` |
|
|
135
|
+
| `timeEnd` | `(label?: string) => void` |
|
|
136
|
+
|
|
137
|
+
#### Datenverarbeitung
|
|
138
|
+
|
|
139
|
+
| Methode | Typ | Kommentar |
|
|
140
|
+
|---------|---------------------------------------------------|---------------------------------------------------------------------------------|
|
|
141
|
+
| `set` | `(data: DebugWebData) => void` | Speichert Debug-Daten (zusammenführen) |
|
|
142
|
+
| `get` | `(api?: boolean) => DebugWebData \| undefined` | Gibt eine Kopie aller Daten zurück. Bei `true` werden Hilfsmethoden hinzugefügt |
|
|
143
|
+
| `dump` | `(keys: string[], options?: DumpOptions) => void` | Gibt Daten als Tabelle aus (ignoriert Protokollierungsebenen) |
|
|
115
144
|
|
|
116
|
-
```javascript
|
|
117
|
-
import { debugSetStyle } from 'debug-web';
|
|
118
145
|
|
|
119
|
-
|
|
120
|
-
|
|
146
|
+
```typescript
|
|
147
|
+
type DebugWebData = Record<string, unknown>
|
|
121
148
|
|
|
122
|
-
|
|
123
|
-
|
|
149
|
+
type DumpOptions = {
|
|
150
|
+
level?: DebugLogLevel;
|
|
151
|
+
title?: string | ((data: DebugWebData) => string);
|
|
152
|
+
open?: boolean;
|
|
153
|
+
}
|
|
124
154
|
```
|
|
125
155
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
### Protokollierungsmethoden
|
|
156
|
+
#### Ebenenverwaltung
|
|
129
157
|
|
|
130
|
-
|
|
158
|
+
| Methode | Typ | Kommentar |
|
|
159
|
+
|------------------|-----------------|------------------------------------------|
|
|
160
|
+
| `level` (getter) | `DebugLogLevel` | Aktuelle Protokollierungsebene abrufen |
|
|
161
|
+
| `level` (setter) | `DebugLogLevel` | Aktuelle Protokollierungsebene festlegen |
|
|
131
162
|
|
|
132
|
-
|
|
133
|
-
- `group` (`groupCollapsed`), `groupEnd`;
|
|
134
|
-
- `trace`, `count`, `countReset`;
|
|
135
|
-
- `time`, `timeLog`, `timeEnd`;
|
|
136
|
-
- `dir`, `dirxml`, `table`.
|
|
163
|
+
#### Styling
|
|
137
164
|
|
|
138
|
-
|
|
165
|
+
| Methode | Typ | Kommentar |
|
|
166
|
+
|------------------|-----------------------------------|----------------------------------------------------|
|
|
167
|
+
| `style` (getter) | `() => DebugWebStyle` | Aktuelle Stilzuordnung abrufen |
|
|
168
|
+
| `style` (setter) | `(styles: DebugWebStyle) => void` | Stilzuordnung aktualisieren (wird zusammengeführt) |
|
|
139
169
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- `debugReset`.
|
|
170
|
+
```typescript
|
|
171
|
+
type DebugWebStyle = Record<DebugLogLevel, string | undefined>
|
|
172
|
+
```
|
|
144
173
|
|
|
145
|
-
|
|
174
|
+
### Debug-Daten
|
|
146
175
|
|
|
147
|
-
Sie
|
|
176
|
+
Speichern Sie beliebige Daten und betrachten Sie sie in der Konsole:
|
|
148
177
|
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
// Neuen Stil für benutzerdefiniertes Level hinzufügen
|
|
153
|
-
CustomDebug.setStyle({ ...WebDebug._style, 'customEvent': 'color: #00ff00' });
|
|
154
|
-
}
|
|
178
|
+
```javascript
|
|
179
|
+
debug.set({ error: null, user: { id: 1, name: 'John' } });
|
|
180
|
+
```
|
|
155
181
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// Prüfen, ob 'info'-Level (dem benutzerdefinierte Level gleichgesetzt werden) erlaubt ist
|
|
159
|
-
if (!CustomDebug.can('info')) return;
|
|
182
|
+
Daten sind über `window[prop]` (Standard ist `info`) zugänglich.
|
|
183
|
+
Geben Sie in der Browserkonsole ein:
|
|
160
184
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
185
|
+
```javascript
|
|
186
|
+
info // { error: null, user: {...}, setLevel: f }
|
|
187
|
+
info.setLevel() // Protokollierungsebene ändern
|
|
165
188
|
```
|
|
166
189
|
|
|
167
|
-
## Unterstützung
|
|
190
|
+
## Unterstützung ❤️
|
|
168
191
|
|
|
169
|
-
Wenn
|
|
192
|
+
Wenn diese Bibliothek für Sie nützlich ist, ziehen Sie bitte in Betracht, ihre Entwicklung zu unterstützen:
|
|
170
193
|
|
|
171
194
|
- [Patreon](https://www.patreon.com/collection/1924882)
|
|
172
195
|
- [Boosty](https://boosty.to/karlen/donate)
|
package/README.es.md
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
# Debug Web
|
|
2
|
-
Librería ligera para depuración en el navegador.
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Paquete NPM para depuración en el navegador con niveles de registro personalizables (log, warn, error, debug).\
|
|
4
|
+
Ligero y fácil de usar.
|
|
5
|
+
|
|
6
|
+
**Características**:
|
|
5
7
|
- 🚀 **Sin dependencias** — solo TypeScript puro;
|
|
6
|
-
- 📦 **Peso ~3.
|
|
7
|
-
-
|
|
8
|
-
-
|
|
8
|
+
- 📦 **Peso ~3.4 kB** — impacto mínimo en tu bundle;
|
|
9
|
+
- 🏅 **Calificación SonarQube `A`** — el nivel más alto de calidad y confiabilidad de código;
|
|
10
|
+
- 🎨 **Estilización de consola** — formato de colores para una identificación rápida;
|
|
11
|
+
- 💾 **Almacenamiento global** — acceso a los datos de depuración a través de `window`;
|
|
12
|
+
- 🔧 **Configuración flexible** — niveles de registro, estilos, alias, soporte para herencia.
|
|
9
13
|
|
|
10
14
|
---
|
|
11
15
|
|
|
12
|
-
## Tabla de
|
|
16
|
+
## Tabla de contenidos 📑
|
|
13
17
|
|
|
14
18
|
- [Instalación](#instalación-)
|
|
15
|
-
- [Niveles de
|
|
19
|
+
- [Niveles de registro](#niveles-de-registro-)
|
|
16
20
|
- [Opciones](#opciones-)
|
|
17
|
-
- [Estilos por
|
|
18
|
-
- [Cómo Usar](#cómo-usar-)
|
|
19
|
-
- [Personalización de Estilos](#personalización-de-estilos-)
|
|
21
|
+
- [Estilos por defecto](#estilos-por-defecto-)
|
|
20
22
|
- [API](#api-)
|
|
21
|
-
- [
|
|
23
|
+
- [createDebug](#función-createdebug)
|
|
24
|
+
- [Métodos de registro](#métodos-de-registro)
|
|
25
|
+
- [Manejo de datos](#manejo-de-datos)
|
|
26
|
+
- [Gestión de niveles](#gestión-de-niveles)
|
|
27
|
+
- [Datos de depuración](#datos-de-depuración)
|
|
28
|
+
- [Soporte](#soporte-)
|
|
29
|
+
- [Licencia](#licencia)
|
|
22
30
|
|
|
23
|
-
##
|
|
31
|
+
## Traducciones
|
|
24
32
|
|
|
25
33
|
[English](README.md), [Español](README.es.md), [Deutsch](README.de.md), [中文](README.zh.md), [Русский](README.ru.md)
|
|
26
34
|
|
|
@@ -35,7 +43,7 @@ npm install debug-web
|
|
|
35
43
|
yarn add debug-web
|
|
36
44
|
```
|
|
37
45
|
|
|
38
|
-
## Niveles de
|
|
46
|
+
## Niveles de registro 🔧
|
|
39
47
|
|
|
40
48
|
Prioridad (de menor a mayor):
|
|
41
49
|
|
|
@@ -45,129 +53,143 @@ Prioridad (de menor a mayor):
|
|
|
45
53
|
4. `warn` (3) — advertencias (`console.warn`)
|
|
46
54
|
5. `error` (4) — errores (`console.error`)
|
|
47
55
|
|
|
48
|
-
ℹ️ Niveles personalizados: cualquier valor de cadena (
|
|
56
|
+
ℹ️ Niveles personalizados: cualquier valor de cadena (por ejemplo, `success`, `focus`) será procesado como nivel `info`
|
|
57
|
+
y puede tener sus propios estilos.
|
|
49
58
|
|
|
50
59
|
## Opciones ⚙️
|
|
51
60
|
|
|
52
|
-
| Parámetro | Tipo | Por
|
|
53
|
-
|
|
54
|
-
| `app` | `string` \| `null` | `'
|
|
55
|
-
| `level` | `DebugLogLevel` | `'log'` | Nivel mínimo de registro (mensajes por debajo
|
|
56
|
-
| `prop` | `string` \| `null` | `'info'` | Nombre de
|
|
57
|
-
| `data` | `Record<string, unknown>` | — | Datos de depuración
|
|
58
|
-
| `
|
|
61
|
+
| Parámetro | Tipo | Por defecto | Descripción |
|
|
62
|
+
|-----------|---------------------------------|------------------------------------|-----------------------------------------------------------------------------|
|
|
63
|
+
| `app` | `string` \| `null` | `'_debug_web'` | Nombre único de la aplicación para separar datos |
|
|
64
|
+
| `level` | `DebugLogLevel` | `'log'` | Nivel mínimo de registro (no se muestran mensajes por debajo de este nivel) |
|
|
65
|
+
| `prop` | `string` \| `null` | `'info'` | Nombre de variable global para acceder a datos (`null` — no crear) |
|
|
66
|
+
| `data` | `Record<string, unknown>` | — | Datos iniciales de depuración |
|
|
67
|
+
| `local` | `boolean` | `false` | Guardar el nivel en `localStorage` (de lo contrario en `sessionStorage`) |
|
|
68
|
+
| `native` | `boolean` | `false` | Usar métodos nativos de la consola (sin estilos) |
|
|
69
|
+
| `aliases` | `Record<string, DebugLogLevel>` | '{}' | Alias personalizados para `createDebug` |
|
|
70
|
+
| `style` | `Record<DebugLogLevel, string>` | ver [abajo](#estilos-por-defecto-) | Estilos CSS para los niveles de registro |
|
|
59
71
|
|
|
60
72
|
```typescript
|
|
61
73
|
type DebugLogLevel = 'debug' | 'log' | 'info' | 'success' | 'warn' | 'error' | string;
|
|
62
74
|
```
|
|
63
75
|
|
|
64
|
-
### Estilos por
|
|
76
|
+
### Estilos por defecto 🎨
|
|
65
77
|
|
|
66
78
|
| Nivel | Estilo (CSS) |
|
|
67
79
|
|-----------|----------------------------------------------------------------------------|
|
|
68
80
|
| `info` | `background-color: #155adc; color: #fff; padding: 2px; border-radius: 3px` |
|
|
81
|
+
| `mark` | `background-color: #695aff; color: #fff; padding: 2px; border-radius: 3px` |
|
|
69
82
|
| `success` | `background-color: #13a10e; color: #fff; padding: 2px; border-radius: 3px` |
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
|
|
73
|
-
## Cómo Usar 💡
|
|
74
|
-
|
|
75
|
-
### Inicialización
|
|
83
|
+
| `focus` | `background-color: #881798; color: #fff; padding: 2px; border-radius: 3px` |
|
|
84
|
+
| `alert` | `background-color: #ffa500; color: #fff; padding: 2px; border-radius: 3px` |
|
|
85
|
+
| `danger` | `background-color: #dc143c; color: #fff; padding: 2px; border-radius: 3px` |
|
|
76
86
|
|
|
77
|
-
|
|
87
|
+
## Cómo usar 💡
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
import { debugInit } from 'debug-web';
|
|
89
|
+
### Crear una instancia
|
|
81
90
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
```typescript
|
|
92
|
+
// debug.ts
|
|
93
|
+
import { DebugWeb } from 'debug-web';
|
|
94
|
+
|
|
95
|
+
export const debug = new DebugWeb({
|
|
96
|
+
app: 'my-app',
|
|
97
|
+
level: process.env.NODE_ENV === 'development' ? 'log' : 'error',
|
|
98
|
+
data: { version: APP_VERSION },
|
|
99
|
+
aliases: { s: 'success', f: 'focus' },
|
|
100
|
+
local: true,
|
|
85
101
|
});
|
|
86
102
|
```
|
|
87
103
|
|
|
88
|
-
###
|
|
89
|
-
|
|
90
|
-
Usa en cualquier parte de la aplicación para mostrar mensajes:
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
import { debug, log, info, success, warn, error } from 'debug-web';
|
|
94
|
-
|
|
95
|
-
debug('Mensaje de depuración');
|
|
96
|
-
log('Mensaje regular');
|
|
97
|
-
info('Mensaje informativo');
|
|
98
|
-
success('¡Éxito!');
|
|
99
|
-
warn('¡Advertencia!');
|
|
100
|
-
error(new Error());
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### Datos de Depuración
|
|
104
|
+
### API 📚
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
#### Función `createDebug`
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
import { debugData } from 'debug-web';
|
|
108
|
+
Crea un proxy con alias y soporte para niveles personalizados.
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
```typescript
|
|
111
|
+
<T extends typeof DebugWeb>( options?: CreateDebugOptions, DebugClass?: T ) => CustomLogLevels & InstanceType<T>;
|
|
111
112
|
```
|
|
112
113
|
|
|
113
|
-
|
|
114
|
+
Alias por defecto: `d` → `debug`, `l` → `log`, `i` → `info`, `w` → `warn`, `e` → `error`
|
|
115
|
+
|
|
116
|
+
#### Métodos de registro
|
|
117
|
+
|
|
118
|
+
| Nivel | Tipo |
|
|
119
|
+
|--------------|------------------------------------------------------------------------|
|
|
120
|
+
| `debug` | `(message?: unknown, ...attrs: unknown[]) => void` |
|
|
121
|
+
| `log` | `(...attrs: unknown[]) => void` |
|
|
122
|
+
| `info` | `(...attrs: unknown[]) => void` |
|
|
123
|
+
| `warn` | `(...attrs: unknown[]) => void` |
|
|
124
|
+
| `error` | `(...attrs: unknown[]) => void` |
|
|
125
|
+
| `group` | `(open?: boolean, level?: DebugLogLevel, ...attrs: unknown[]) => void` |
|
|
126
|
+
| `groupEnd` | `(level?: DebugLogLevel) => void` |
|
|
127
|
+
| `dir` | `(value: unknown, options?: unknown) => void` |
|
|
128
|
+
| `dirxml` | `(...attrs: unknown[]) => void` |
|
|
129
|
+
| `trace` | `(...attrs: unknown[]) => void` |
|
|
130
|
+
| `table` | `(data: unknown, properties?: string[]) => void` |
|
|
131
|
+
| `count` | `(label?: string) => void` |
|
|
132
|
+
| `countReset` | `(label?: string) => void` |
|
|
133
|
+
| `time` | `(label?: string) => void` |
|
|
134
|
+
| `timeLog` | `(label?: string, ...attrs: unknown[]) => void` |
|
|
135
|
+
| `timeEnd` | `(label?: string) => void` |
|
|
136
|
+
|
|
137
|
+
#### Manejo de datos
|
|
138
|
+
|
|
139
|
+
| Método | Tipo | Comentario |
|
|
140
|
+
|--------|---------------------------------------------------|-----------------------------------------------------------------------------|
|
|
141
|
+
| `set` | `(data: DebugWebData) => void` | Guarda los datos de depuración (los fusiona) |
|
|
142
|
+
| `get` | `(api?: boolean) => DebugWebData \| undefined` | Devuelve una copia de todos los datos. Si es `true`, añade métodos de ayuda |
|
|
143
|
+
| `dump` | `(keys: string[], options?: DumpOptions) => void` | Imprime los datos en formato tabla (ignora niveles de registro) |
|
|
114
144
|
|
|
115
|
-
## Personalización de Estilos 🖌️
|
|
116
145
|
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// Cambiar estilo para un nivel específico
|
|
121
|
-
debugSetStyle('info', 'color: purple; font-weight: bold;');
|
|
146
|
+
```typescript
|
|
147
|
+
type DebugWebData = Record<string, unknown>
|
|
122
148
|
|
|
123
|
-
|
|
124
|
-
|
|
149
|
+
type DumpOptions = {
|
|
150
|
+
level?: DebugLogLevel;
|
|
151
|
+
title?: string | ((data: DebugWebData) => string);
|
|
152
|
+
open?: boolean;
|
|
153
|
+
}
|
|
125
154
|
```
|
|
126
155
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
### Métodos de Registro
|
|
156
|
+
#### Gestión de niveles
|
|
130
157
|
|
|
131
|
-
|
|
158
|
+
| Método | Tipo | Comentario |
|
|
159
|
+
|------------------|-----------------|----------------------------------------|
|
|
160
|
+
| `level` (getter) | `DebugLogLevel` | Obtener el nivel de registro actual |
|
|
161
|
+
| `level` (setter) | `DebugLogLevel` | Establecer el nivel de registro actual |
|
|
132
162
|
|
|
133
|
-
|
|
134
|
-
- `group` (`groupCollapsed`), `groupEnd`;
|
|
135
|
-
- `trace`, `count`, `countReset`;
|
|
136
|
-
- `time`, `timeLog`, `timeEnd`;
|
|
137
|
-
- `dir`, `dirxml`, `table`.
|
|
163
|
+
#### Estilización
|
|
138
164
|
|
|
139
|
-
|
|
165
|
+
| Método | Tipo | Comentario |
|
|
166
|
+
|------------------|-----------------------------------|----------------------------------------------|
|
|
167
|
+
| `style` (getter) | `() => DebugWebStyle` | Obtener el mapa de estilos actual |
|
|
168
|
+
| `style` (setter) | `(styles: DebugWebStyle) => void` | Actualizar el mapa de estilos (se fusionará) |
|
|
140
169
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
- `debugReset`.
|
|
170
|
+
```typescript
|
|
171
|
+
type DebugWebStyle = Record<DebugLogLevel, string | undefined>
|
|
172
|
+
```
|
|
145
173
|
|
|
146
|
-
|
|
174
|
+
### Datos de depuración
|
|
147
175
|
|
|
148
|
-
|
|
176
|
+
Guarde cualquier dato y véalo en la consola:
|
|
149
177
|
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// Agregar nuevo estilo para nivel personalizado
|
|
154
|
-
CustomDebug.setStyle({ ...WebDebug._style, 'customEvent': 'color: #00ff00' });
|
|
155
|
-
}
|
|
178
|
+
```javascript
|
|
179
|
+
debug.set({ error: null, user: { id: 1, name: 'John' } });
|
|
180
|
+
```
|
|
156
181
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// Verificar si el nivel 'info' (al que se equiparan niveles personalizados) está permitido
|
|
160
|
-
if (!CustomDebug.can('info')) return;
|
|
182
|
+
Los datos son accesibles a través de `window[prop]` (por defecto es `info`).
|
|
183
|
+
Escriba en la consola del navegador:
|
|
161
184
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
185
|
+
```javascript
|
|
186
|
+
info // { error: null, user: {...}, setLevel: f }
|
|
187
|
+
info.setLevel() // cambiar el nivel de registro
|
|
166
188
|
```
|
|
167
189
|
|
|
168
|
-
##
|
|
190
|
+
## Soporte ❤️
|
|
169
191
|
|
|
170
|
-
Si
|
|
192
|
+
Si esta biblioteca te resulta útil, considera apoyar su desarrollo:
|
|
171
193
|
|
|
172
194
|
- [Patreon](https://www.patreon.com/collection/1924882)
|
|
173
195
|
- [Boosty](https://boosty.to/karlen/donate)
|
|
@@ -177,7 +199,7 @@ Si encuentras útil esta librería, considera apoyar su desarrollo:
|
|
|
177
199
|
MIT © [Karlen Pireverdiev](https://github.com/Karlen-ll)
|
|
178
200
|
|
|
179
201
|
## Enlaces
|
|
180
|
-
- [📝 Historial de
|
|
181
|
-
- [💻 Código
|
|
182
|
-
- [🐛
|
|
202
|
+
- [📝 Historial de cambios](CHANGELOG.md)
|
|
203
|
+
- [💻 Código fuente](https://github.com/Karlen-ll/debug-web)
|
|
204
|
+
- [🐛 Reportes de errores](https://github.com/Karlen-ll/debug-web/issues)
|
|
183
205
|
- [📦 Paquete NPM](https://www.npmjs.com/package/debug-web)
|