chromalogger 1.1.0 → 1.1.2

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.fr.md ADDED
@@ -0,0 +1,360 @@
1
+ # ChromaLogger
2
+
3
+ [![npm version](https://img.shields.io/npm/v/chromalogger.svg?style=flat)](https://www.npmjs.com/package/chromalogger)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![GitHub stars](https://img.shields.io/github/stars/OrssiMp/chromalogger.svg?style=social)](https://github.com/OrssiMp/chromalogger/stargazers)
6
+
7
+ [🇬🇧 English](README.md) | [🇫🇷 Français](README.fr.md)
8
+
9
+ ChromaLogger est une bibliothèque Node.js puissante et flexible pour la journalisation de console avec un support avancé des couleurs, des styles et des fonctionnalités de débogage. Parfaite pour le développement et le débogage d'applications Node.js.
10
+
11
+ ## 🚀 Fonctionnalités
12
+
13
+ - 🌈 Support avancé des couleurs et styles (16+ couleurs, formatage de texte)
14
+ - 📊 Niveaux de log intégrés (DEBUG, INFO, WARN, ERROR)
15
+ - 🔄 Détection des références circulaires
16
+ - 📝 Support des templates avec placeholders
17
+ - 🛠️ Création de loggers personnalisés
18
+ - 💻 Utilisation en ligne de commande avec `clog`
19
+ - 🔌 Architecture extensible et API simple
20
+
21
+ ## 📦 Installation
22
+
23
+ ```bash
24
+ # Avec npm
25
+ npm install chromalogger
26
+
27
+ # Ou avec Yarn
28
+ yarn add chromalogger
29
+ ```
30
+
31
+ ## 💡 Démarrage Rapide
32
+
33
+ ```javascript
34
+ import { log, info, warn, error, createLogger } from 'chromalogger';
35
+
36
+ // Utilisation de base
37
+ log('Ceci est un message de log');
38
+ info('Message informatif');
39
+ warn('Message d\'avertissement');
40
+ error('Message d\'erreur');
41
+
42
+ // Avec styles
43
+ const success = createLogger('green', 'bold');
44
+ success('Opération réussie !');
45
+
46
+ // Templates avec placeholders
47
+ const utilisateur = { nom: 'Alice', age: 30 };
48
+ info('L\'utilisateur {0} a {1} ans', utilisateur.nom, utilisateur.age);
49
+
50
+ // Styles en ligne
51
+ import { red, bgYellow, bold } from 'chromalogger';
52
+ console.log(red('Texte en rouge') + ' et ' + bgYellow('fond jaune'));
53
+ ```
54
+
55
+ ## 📚 Documentation
56
+
57
+ ### Niveaux de Log
58
+
59
+ ChromaLogger définit 5 niveaux de log, du plus bas au plus élevé :
60
+
61
+ | Niveau | Valeur | Description |
62
+ | ------- | ------ | -------------------------------------------------------- |
63
+ | `DEBUG` | 0 | Messages détaillés pour le débogage |
64
+ | `INFO` | 1 | Informations générales sur le déroulement du programme |
65
+ | `WARN` | 2 | Situations potentiellement problématiques |
66
+ | `ERROR` | 3 | Erreurs qui n'empêchent pas l'application de fonctionner |
67
+ | `NONE` | 4 | Aucun log ne sera affiché |
68
+
69
+ ### Fonctions Principales
70
+
71
+ #### `createLogger(...styles)`
72
+
73
+ Crée un nouveau logger personnalisé avec les styles spécifiés.
74
+
75
+ ```javascript
76
+ const header = createLogger('bgBlue', 'white', 'bold');
77
+ header('En-tête important');
78
+ ```
79
+
80
+ #### `setLogLevel(level)`
81
+
82
+ Définit le niveau de log minimum à afficher.
83
+
84
+ ```javascript
85
+ setLogLevel('DEBUG'); // Affiche tout
86
+ setLogLevel('WARN'); // Affiche uniquement WARN et ERROR
87
+ ```
88
+
89
+ ### Styles Disponibles
90
+
91
+ #### Couleurs de texte
92
+ - `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
93
+
94
+ #### Arrière-plans
95
+ - `bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite`
96
+
97
+ #### Styles de texte
98
+ - `bright` - Texte en gras
99
+ - `dim` - Texte atténué
100
+ - `italic` - Texte en italique
101
+ - `underline` - Texte souligné
102
+ - `blink` - Texte clignotant
103
+ - `reverse` - Inverse les couleurs
104
+ - `hidden` - Texte caché
105
+ - `strikethrough` - Texte barré
106
+
107
+ ## 🤝 Contribution
108
+
109
+ Les contributions sont les bienvenues ! Pour contribuer :
110
+
111
+ 1. Forkez le dépôt
112
+ 2. Créez une branche pour votre fonctionnalité (`git checkout -b feature/ma-fonctionnalite`)
113
+ 3. Committez vos changements (`git commit -am 'Ajouter une fonctionnalité'`)
114
+ 4. Poussez vers la branche (`git push origin feature/ma-fonctionnalite`)
115
+ 5. Ouvrez une Pull Request
116
+
117
+ ## 📄 Licence
118
+
119
+ Ce projet est sous licence MIT - voir le fichier [LICENCE](LICENSE) pour plus de détails.
120
+
121
+ ## 🙏 Remerciements
122
+
123
+ - Inspiré par des bibliothèques populaires comme chalk, winston et debug
124
+ - Merci à tous les contributeurs qui ont aidé à améliorer ce projet
125
+ # Afficher l'aide
126
+ ## 🛠️ Interface en Ligne de Commande (CLI)
127
+
128
+ ChromaLogger inclut un utilitaire en ligne de commande `clog` :
129
+
130
+ ```bash
131
+ # Afficher l'aide
132
+ npx clog --help
133
+
134
+ # Afficher un message simple
135
+ npx clog "Mon message"
136
+
137
+ # Utiliser des couleurs et styles
138
+ npx clog --color red --style bright "Message important"
139
+
140
+ ## 🔍 Exemples Complets
141
+
142
+ ### Configuration d'un logger personnalisé
143
+
144
+ ```javascript
145
+ import { createLogger, setLogLevel } from 'chromalogger';
146
+
147
+ // Créer des loggers personnalisés
148
+ const success = createLogger('green', 'bright');
149
+ const error = createLogger('red', 'bold');
150
+ const debug = createLogger('blue', 'dim');
151
+
152
+ // Définir le niveau de log
153
+ setLogLevel('DEBUG');
154
+
155
+ // Utilisation
156
+ success('Connexion réussie !');
157
+ error('Échec de la connexion');
158
+ debug('État de la connexion:', { status: 'connected', time: Date.now() });
159
+ ```
160
+
161
+ ### Journalisation dans une application Express
162
+
163
+ ```javascript
164
+ import express from 'express';
165
+ import { createLogger } from 'chromalogger';
166
+
167
+ const app = express();
168
+ const logger = createLogger('magenta');
169
+ const errorLogger = createLogger('red', 'bold');
170
+
171
+ app.use((req, res, next) => {
172
+ logger(`${req.method} ${req.url}`);
173
+ next();
174
+ });
175
+
176
+ app.get('/', (req, res) => {
177
+ res.send('Bienvenue sur mon API');
178
+ });
179
+
180
+ // Gestion des erreurs
181
+ app.use((err, req, res, next) => {
182
+ errorLogger('ERREUR:', err.message);
183
+ res.status(500).send('Quelque chose a mal tourné !');
184
+ });
185
+
186
+ app.listen(3000, () => {
187
+ logger('Serveur démarré sur http://localhost:3000');
188
+ });
189
+ ```
190
+
191
+ ## 📝 Bonnes Pratiques
192
+
193
+ 1. **Environnement de développement** : Utilisez `DEBUG` pour avoir un maximum d'informations
194
+ 2. **Environnement de production** : Utilisez `WARN` ou `ERROR` pour éviter la surcharge de logs
195
+ 3. **Créer des loggers spécifiques** : Utilisez `createLogger()` pour des catégories de logs différentes
196
+ 4. **Éviter les logs sensibles** : Ne loguez jamais de mots de passe ou informations sensibles
197
+ 5. **Utiliser les bons niveaux** :
198
+ - `debug` pour le débogage détaillé
199
+ - `info` pour les informations importantes
200
+ - `warn` pour les avertissements
201
+ - `error` pour les erreurs
202
+
203
+ ## 📄 Licence
204
+
205
+ MIT © [Votre Nom]
206
+
207
+ Pour plus d'informations sur les fonctionnalités avancées, consultez la [documentation complète](https://github.com/OrssiMp/chromalogger#readme).
208
+
209
+ ## 🤝 Contribuer
210
+
211
+ Les contributions sont les bienvenues ! Voici comment contribuer :
212
+
213
+ 1. Forkez le projet
214
+ 2. Créez une branche pour votre fonctionnalité (`git checkout -b feature/AmazingFeature`)
215
+ 3. Committez vos changements (`git commit -m 'Add some AmazingFeature'`)
216
+ 4. Poussez vers la branche (`git push origin feature/AmazingFeature`)
217
+ 5. Ouvrez une Pull Request
218
+
219
+ ## 📄 Licence
220
+
221
+ Distribué sous licence MIT. Voir le fichier `LICENSE` pour plus d'informations.
222
+
223
+ ## 📞 Contact
224
+
225
+ Orssi Mp - [@OrssiMp](https://github.com/OrssiMp) - orssimpiere5@gmail.com
226
+
227
+ Lien du projet : [https://github.com/OrssiMp/chromalogger](https://github.com/OrssiMp/chromalogger)
228
+
229
+ // Couleurs de base
230
+ logger.red('Ceci est en rouge');
231
+ logger.green('Ceci est en vert');
232
+ logger.blue('Ceci est en bleu');
233
+ logger.yellow('Ceci est en jaune');
234
+
235
+ ````
236
+
237
+ ### Avec CommonJS
238
+
239
+ ```javascript
240
+ const logger = require('logcolor-js');
241
+
242
+ // Arrière-plans colorés
243
+ logger.bgRed(' Fond rouge ');
244
+ logger.bgGreen(' Fond vert ');
245
+ logger.bgBlue(' Fond bleu ');
246
+ ````
247
+
248
+ ## Fonctionnalités
249
+
250
+ ### Couleurs de texte
251
+
252
+ - `red(text)` - Texte rouge
253
+ - `green(text)` - Texte vert
254
+ - `blue(text)` - Texte bleu
255
+ - `yellow(text)` - Texte jaune
256
+ - `white(text)` - Texte blanc
257
+ - `black(text)` - Texte noir
258
+ - `magenta(text)` - Texte magenta
259
+ - `cyan(text)` - Texte cyan
260
+
261
+ ### Arrière-plans
262
+
263
+ - `bgRed(text)` - Fond rouge
264
+ - `bgGreen(text)` - Fond vert
265
+ - `bgBlue(text)` - Fond bleu
266
+ - `bgYellow(text)` - Fond jaune
267
+ - `bgWhite(text)` - Fond blanc
268
+ - `bgBlack(text)` - Fond noir
269
+ - `bgMagenta(text)` - Fond magenta
270
+ - `bgCyan(text)` - Fond cyan
271
+
272
+ ### Styles de texte
273
+
274
+ - `bold(text)` - Texte en gras
275
+ - `underline(text)` - Texte souligné
276
+ - `italic(text)` - Texte en italique
277
+ - `inverse(text)` - Inverse les couleurs
278
+ - `strikethrough(text)` - Texte barré
279
+
280
+ ### Niveaux de log
281
+
282
+ - `setLogLevel(level)` - Définit le niveau de log ('DEBUG', 'INFO', 'WARN', 'ERROR')
283
+ - `debug(...args)` - Message de débogage
284
+ - `info(...args)` - Information
285
+ - `warn(...args)` - Avertissement
286
+ - `error(...args)` - Erreur
287
+ - `success(...args)` - Succès (alias pour info avec icône de succès)
288
+ - `warning(...args)` - Avertissement (alias pour warn avec icône d'avertissement)
289
+
290
+ ## Exemples avancés
291
+
292
+ ### Combinaison de styles
293
+
294
+ ```javascript
295
+ // Combinaison de styles
296
+ logger.bold(logger.red('Texte en gras et rouge'));
297
+ logger.bgBlue(logger.white('Texte blanc sur fond bleu'));
298
+ ```
299
+
300
+ ### Niveaux de log
301
+
302
+ ```javascript
303
+ // Définir le niveau de log (par défaut: 'INFO')
304
+ logger.setLogLevel('DEBUG');
305
+
306
+ // Messages de log
307
+ logger.debug('Message de débogage');
308
+ logger.info('Information');
309
+ logger.warn('Avertissement');
310
+ logger.error('Erreur');
311
+ ```
312
+
313
+ ### Avec des objets et tableaux
314
+
315
+ ```javascript
316
+ // Objets
317
+ const user = {
318
+ name: 'John',
319
+ age: 30,
320
+ roles: ['admin', 'user'],
321
+ };
322
+ logger.info('Utilisateur:', user);
323
+
324
+ // Tableaux
325
+ const numbers = [1, 2, 3, 4, 5];
326
+ logger.info('Nombres:', numbers);
327
+
328
+ // Références circulaires
329
+ const obj1 = { name: 'Objet 1' };
330
+ const obj2 = { name: 'Objet 2', ref: obj1 };
331
+ obj1.ref = obj2;
332
+ logger.info('Objet avec référence circulaire:', obj1);
333
+ ```
334
+
335
+ ## Personnalisation
336
+
337
+ ### Styles personnalisés
338
+
339
+ ```javascript
340
+ // Accès direct aux codes ANSI
341
+ console.log(
342
+ `${logger.styles.bold}${logger.styles.red}Texte en gras et rouge${logger.styles.reset}`
343
+ );
344
+ ```
345
+
346
+ ### Templates
347
+
348
+ ```javascript
349
+ const name = 'Alice';
350
+ const age = 30;
351
+ logger.info('Nom: {0}, Âge: {1}', name, age);
352
+ ```
353
+
354
+ ## Contribution
355
+
356
+ Les contributions sont les bienvenues ! N'hésitez pas à ouvrir une issue ou une pull request.
357
+
358
+ ## Licence
359
+
360
+ MIT
package/README.md CHANGED
@@ -1,148 +1,66 @@
1
- # LogColor
2
-
3
- Une bibliothèque JavaScript simple pour ajouter des couleurs et des styles aux messages de la console en Node.js.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install logcolor-js
9
- ```
10
-
11
- ## Utilisation
12
-
13
- ### Avec ES Modules (recommandé)
14
-
15
- ```javascript
16
- import logger from 'logcolor-js';
17
-
18
- // Couleurs de base
19
- logger.red('Ceci est en rouge');
20
- logger.green('Ceci est en vert');
21
- logger.blue('Ceci est en bleu');
22
- logger.yellow('Ceci est en jaune');
23
- ```
24
-
25
- ### Avec CommonJS
26
-
27
- ```javascript
28
- const logger = require('logcolor-js');
29
-
30
- // Arrière-plans colorés
31
- logger.bgRed(' Fond rouge ');
32
- logger.bgGreen(' Fond vert ');
33
- logger.bgBlue(' Fond bleu ');
34
- ```
35
-
36
- ## Fonctionnalités
37
-
38
- ### Couleurs de texte
39
-
40
- - `red(text)` - Texte rouge
41
- - `green(text)` - Texte vert
42
- - `blue(text)` - Texte bleu
43
- - `yellow(text)` - Texte jaune
44
- - `white(text)` - Texte blanc
45
- - `black(text)` - Texte noir
46
- - `magenta(text)` - Texte magenta
47
- - `cyan(text)` - Texte cyan
48
-
49
- ### Arrière-plans
50
-
51
- - `bgRed(text)` - Fond rouge
52
- - `bgGreen(text)` - Fond vert
53
- - `bgBlue(text)` - Fond bleu
54
- - `bgYellow(text)` - Fond jaune
55
- - `bgWhite(text)` - Fond blanc
56
- - `bgBlack(text)` - Fond noir
57
- - `bgMagenta(text)` - Fond magenta
58
- - `bgCyan(text)` - Fond cyan
59
-
60
- ### Styles de texte
61
-
62
- - `bold(text)` - Texte en gras
63
- - `underline(text)` - Texte souligné
64
- - `italic(text)` - Texte en italique
65
- - `inverse(text)` - Inverse les couleurs
66
- - `strikethrough(text)` - Texte barré
67
-
68
- ### Niveaux de log
69
-
70
- - `setLogLevel(level)` - Définit le niveau de log ('DEBUG', 'INFO', 'WARN', 'ERROR')
71
- - `debug(...args)` - Message de débogage
72
- - `info(...args)` - Information
73
- - `warn(...args)` - Avertissement
74
- - `error(...args)` - Erreur
75
- - `success(...args)` - Succès (alias pour info avec icône de succès)
76
- - `warning(...args)` - Avertissement (alias pour warn avec icône d'avertissement)
77
-
78
- ## Exemples avancés
79
-
80
- ### Combinaison de styles
81
-
82
- ```javascript
83
- // Combinaison de styles
84
- logger.bold(logger.red('Texte en gras et rouge'));
85
- logger.bgBlue(logger.white('Texte blanc sur fond bleu'));
86
- ```
87
-
88
- ### Niveaux de log
89
-
90
- ```javascript
91
- // Définir le niveau de log (par défaut: 'INFO')
92
- logger.setLogLevel('DEBUG');
93
-
94
- // Messages de log
95
- logger.debug('Message de débogage');
96
- logger.info('Information');
97
- logger.warn('Avertissement');
98
- logger.error('Erreur');
99
- ```
100
-
101
- ### Avec des objets et tableaux
102
-
103
- ```javascript
104
- // Objets
105
- const user = {
106
- name: 'John',
107
- age: 30,
108
- roles: ['admin', 'user'],
109
- };
110
- logger.info('Utilisateur:', user);
111
-
112
- // Tableaux
113
- const numbers = [1, 2, 3, 4, 5];
114
- logger.info('Nombres:', numbers);
115
-
116
- // Références circulaires
117
- const obj1 = { name: 'Objet 1' };
118
- const obj2 = { name: 'Objet 2', ref: obj1 };
119
- obj1.ref = obj2;
120
- logger.info('Objet avec référence circulaire:', obj1);
121
- ```
122
-
123
- ## Personnalisation
124
-
125
- ### Styles personnalisés
126
-
127
- ```javascript
128
- // Accès direct aux codes ANSI
129
- console.log(
130
- `${logger.styles.bold}${logger.styles.red}Texte en gras et rouge${logger.styles.reset}`
131
- );
132
- ```
133
-
134
- ### Templates
135
-
136
- ```javascript
137
- const name = 'Alice';
138
- const age = 30;
139
- logger.info('Nom: {0}, Âge: {1}', name, age);
140
- ```
141
-
142
- ## Contribution
143
-
144
- Les contributions sont les bienvenues ! N'hésitez pas à ouvrir une issue ou une pull request.
145
-
146
- ## Licence
147
-
148
- MIT
1
+ # ChromaLogger
2
+
3
+ [![npm version](https://img.shields.io/npm/v/chromalogger.svg?style=flat)](https://www.npmjs.com/package/chromalogger)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![GitHub stars](https://img.shields.io/github/stars/OrssiMp/chromalogger.svg?style=social)](https://github.com/OrssiMp/chromalogger/stargazers)
6
+
7
+ [🇬🇧 English](README.md) | [🇫🇷 Français](README.fr.md)
8
+
9
+ ChromaLogger is a powerful and flexible Node.js console logging library with advanced support for colors, styles, and debugging features. Perfect for Node.js application development and debugging.
10
+
11
+ ## 🚀 Features
12
+
13
+ - 🌈 Rich color and style support (16+ colors, text formatting)
14
+ - 📊 Built-in log levels (DEBUG, INFO, WARN, ERROR)
15
+ - 🔄 Circular reference detection
16
+ - 📝 Template string support
17
+ - 🛠️ Customizable loggers
18
+ - 💻 CLI tool included
19
+ - 🔌 Extensible architecture
20
+
21
+ ## 📦 Installation
22
+
23
+ ```bash
24
+ # With npm
25
+ npm install chromalogger
26
+
27
+ # Or with Yarn
28
+ yarn add chromalogger
29
+ ```
30
+
31
+ ## 💡 Quick Start
32
+
33
+ ```javascript
34
+ import { log, info, warn, error, createLogger } from 'chromalogger';
35
+
36
+ // Basic usage
37
+ log('This is a log message');
38
+ info('Informational message');
39
+ warn('Warning message');
40
+ error('Error message');
41
+
42
+ // With styles
43
+ const success = createLogger('green', 'bold');
44
+ success('Operation completed successfully!');
45
+
46
+ // Template strings
47
+ const user = { name: 'Alice', age: 30 };
48
+ info('User {0} is {1} years old', user.name, user.age);
49
+ ```
50
+
51
+ ## 📚 Documentation
52
+
53
+ For complete documentation, please visit our [GitHub Wiki](https://github.com/yourusername/chromalogger/wiki).
54
+
55
+ ## 🤝 Contributing
56
+
57
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) to get started.
58
+
59
+ ## 📄 License
60
+
61
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
62
+
63
+ ## 🙏 Acknowledgments
64
+
65
+ - Inspired by popular logging libraries like chalk, winston, and debug
66
+ - Thanks to all contributors who have helped improve this project
@@ -9,9 +9,10 @@ import { isObject } from '../utils/validate.js';
9
9
  * Format an object for display
10
10
  * @param {Object} obj - Object to format
11
11
  * @param {number} [depth=0] - Current depth for indentation
12
+ * @param {Set} [refs] - Set to track circular references
12
13
  * @returns {string} Formatted object string
13
14
  */
14
- export const formatObject = (obj, depth = 0) => {
15
+ export const formatObject = (obj, depth = 0, refs = new WeakSet()) => {
15
16
  const indent = ' '.repeat(depth);
16
17
  const nextIndent = ' '.repeat(depth + 1);
17
18
 
@@ -20,24 +21,40 @@ export const formatObject = (obj, depth = 0) => {
20
21
  if (obj === undefined) return 'undefined';
21
22
  if (!isObject(obj)) return String(obj);
22
23
 
24
+ // Vérifier les références circulaires
25
+ if (refs.has(obj)) {
26
+ return '[Circular]';
27
+ }
28
+
29
+ // Marquer cet objet comme visité
30
+ refs.add(obj);
31
+
23
32
  const entries = Object.entries(obj);
24
33
  if (entries.length === 0) return '{}';
25
34
 
26
35
  // For small objects, keep on one line
27
36
  if (entries.every(([_, value]) => !isObject(value) || value === null)) {
28
37
  const content = entries
29
- .map(([key, value]) => `${key}: ${formatValue(value, depth + 1)}`)
38
+ .map(([key, value]) => `${key}: ${formatValue(value, depth + 1, refs)}`)
30
39
  .join(', ');
31
40
  return `{ ${content} }`;
32
41
  }
33
42
 
34
43
  // For larger or complex objects, use multiple lines
35
44
  const content = entries
36
- .map(([key, value]) => `${nextIndent}${key}: ${formatValue(value, depth + 1)}`)
45
+ .map(([key, value]) => `${nextIndent}${key}: ${formatValue(value, depth + 1, refs)}`)
37
46
  .join(',\n');
38
47
 
39
- return `{\n${content}\n${indent}}`;
48
+ const result = `{\n${content}\n${indent}}`;
49
+
50
+ // Nettoyer les références après le formatage
51
+ refs.delete(obj);
52
+ return result;
40
53
  } catch (error) {
54
+ // En cas d'erreur, nettoyer les références
55
+ if (isObject(obj)) {
56
+ refs.delete(obj);
57
+ }
41
58
  return '[Object]';
42
59
  }
43
60
  };
@@ -46,9 +63,10 @@ export const formatObject = (obj, depth = 0) => {
46
63
  * Format a value for display
47
64
  * @param {*} value - Value to format
48
65
  * @param {number} [depth=0] - Current depth for indentation
66
+ * @param {Set} [refs] - Set to track circular references
49
67
  * @returns {string} Formatted value
50
68
  */
51
- const formatValue = (value, depth = 0) => {
69
+ const formatValue = (value, depth = 0, refs = new WeakSet()) => {
52
70
  if (value === null) return 'null';
53
71
  if (value === undefined) return 'undefined';
54
72
 
@@ -57,9 +75,9 @@ const formatValue = (value, depth = 0) => {
57
75
  return `"${value}"`;
58
76
  case 'object':
59
77
  if (Array.isArray(value)) {
60
- return formatArray(value, depth);
78
+ return formatArray(value, depth, refs);
61
79
  }
62
- return formatObject(value, depth);
80
+ return formatObject(value, depth, refs);
63
81
  case 'function':
64
82
  return '[Function]';
65
83
  case 'symbol':
@@ -73,24 +91,37 @@ const formatValue = (value, depth = 0) => {
73
91
  * Format an array for display
74
92
  * @param {Array} arr - Array to format
75
93
  * @param {number} [depth=0] - Current depth for indentation
94
+ * @param {Set} [refs] - Set to track circular references
76
95
  * @returns {string} Formatted array string
77
96
  */
78
- const formatArray = (arr, depth = 0) => {
97
+ const formatArray = (arr, depth = 0, refs = new WeakSet()) => {
79
98
  if (!Array.isArray(arr)) return '[]';
80
99
  if (arr.length === 0) return '[]';
81
100
 
101
+ // Vérifier les références circulaires pour les tableaux
102
+ if (refs.has(arr)) {
103
+ return '[Circular]';
104
+ }
105
+
106
+ // Marquer ce tableau comme visité
107
+ refs.add(arr);
108
+
82
109
  const indent = ' '.repeat(depth);
83
110
  const nextIndent = ' '.repeat(depth + 1);
84
111
 
85
112
  // For small arrays, keep on one line
86
113
  if (arr.length <= 3 && arr.every((item) => !isObject(item) || item === null)) {
87
- return `[ ${arr.map((item) => formatValue(item, depth + 1)).join(', ')} ]`;
114
+ return `[ ${arr.map((item) => formatValue(item, depth + 1, refs)).join(', ')} ]`;
88
115
  }
89
116
 
90
117
  // For larger or complex arrays, use multiple lines
91
- const items = arr.map((item) => `${nextIndent}${formatValue(item, depth + 1)}`).join(',\n');
118
+ const items = arr.map((item) => `${nextIndent}${formatValue(item, depth + 1, refs)}`).join(',\n');
119
+
120
+ const result = `[\n${items}\n${indent}]`;
92
121
 
93
- return `[\n${items}\n${indent}]`;
122
+ // Nettoyer les références après le formatage
123
+ refs.delete(arr);
124
+ return result;
94
125
  };
95
126
 
96
127
  export default {