@yahlex/jolilogs 1.0.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/index.js +157 -0
  4. package/package.json +47 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ton Pseudo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # jolilogs
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@yahlex/jolilogs.svg)](https://www.npmjs.com/package/@yahlex/jolilogs)
4
+ [![license](https://img.shields.io/npm/l/@yahlex/jolilogs.svg)](./LICENSE)
5
+
6
+ > Logs Node.js stylés : couleurs ANSI, icônes, cadres ASCII et bannières. **Zéro dépendance.**
7
+
8
+ Une petite librairie pour rendre les logs de tes scripts Node.js (CLI, serveurs, scripts de déploiement…) lisibles et jolis en un import.
9
+
10
+ ```
11
+ ╭─────────────────────────────────────────────╮
12
+ │ [14:32:01] ✅ SUCCESS Serveur démarré │
13
+ ╰─────────────────────────────────────────────╯
14
+ ```
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @yahlex/jolilogs
20
+ ```
21
+
22
+ ## Utilisation rapide
23
+
24
+ ```js
25
+ import { success, error, warn, info, debug, box, banner, divider } from "@yahlex/jolilogs";
26
+
27
+ banner("Mon Application v1.0");
28
+
29
+ success("Serveur démarré sur le port 3000");
30
+ info("Mode développement activé");
31
+ warn("Cache expiré");
32
+ error("Connexion DB perdue");
33
+ debug("user = { id: 42 }");
34
+
35
+ divider();
36
+
37
+ box("Hello, monde !");
38
+ ```
39
+
40
+ ## API
41
+
42
+ ### Logs avec niveau
43
+
44
+ Chaque fonction prend un message et un objet d'options optionnel.
45
+
46
+ | Fonction | Icône | Couleur |
47
+ |---|---|---|
48
+ | `success(msg, opts?)` | ✅ | vert |
49
+ | `error(msg, opts?)` | ❌ | rouge |
50
+ | `warn(msg, opts?)` | ⚠️ | jaune |
51
+ | `info(msg, opts?)` | ℹ️ | cyan |
52
+ | `debug(msg, opts?)` | 🔍 | gris |
53
+
54
+ **Options :**
55
+ - `timestamp` *(boolean, défaut `true`)* — affiche l'heure devant le message
56
+ - `box` *(boolean, défaut `false`)* — entoure le log d'un cadre coloré
57
+
58
+ ```js
59
+ success("Build réussi", { box: true });
60
+ info("Sans horodatage", { timestamp: false });
61
+ ```
62
+
63
+ ### `box(message, options?)`
64
+
65
+ Encadre un texte (mono ou multi-lignes).
66
+
67
+ **Options :**
68
+ - `style` — `"simple"` (┌─┐) · `"double"` (╔═╗) · `"rounded"` (╭─╮) · `"bold"` (┏━┓). Défaut : `"rounded"`.
69
+ - `color` — `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `gray`. Défaut : aucune.
70
+ - `padding` — espacement intérieur en nombre de caractères. Défaut : `1`.
71
+
72
+ ```js
73
+ box("Important !", { style: "double", color: "red", padding: 2 });
74
+ box("Sur\nplusieurs\nlignes");
75
+ ```
76
+
77
+ ### `banner(message, options?)`
78
+
79
+ Comme `box`, mais en MAJUSCULES, avec plus de padding et un style double par défaut. Idéal pour l'écran de démarrage d'une CLI.
80
+
81
+ ```js
82
+ banner("MyApp v2.0", { color: "magenta" });
83
+ ```
84
+
85
+ ### `divider(options?)`
86
+
87
+ Affiche une ligne de séparation.
88
+
89
+ **Options :** `char` (défaut `"─"`), `length` (défaut `60`), `color` (défaut `"gray"`).
90
+
91
+ ```js
92
+ divider();
93
+ divider({ char: "═", length: 40, color: "cyan" });
94
+ ```
95
+
96
+ ## Désactiver les couleurs
97
+
98
+ `jolilogs` respecte la convention [NO_COLOR](https://no-color.org/) et désactive automatiquement les codes ANSI si la sortie n'est pas un terminal (redirection vers un fichier, CI, etc.).
99
+
100
+ ```bash
101
+ NO_COLOR=1 node mon-script.js
102
+ ```
103
+
104
+ ## Exemple complet
105
+
106
+ ```js
107
+ import { banner, success, error, divider, box } from "@yahlex/jolilogs";
108
+
109
+ banner("Déploiement Prod");
110
+
111
+ success("Tests passés (124/124)");
112
+ success("Build terminé en 8.3s");
113
+ error("Échec du push sur le registry");
114
+
115
+ divider();
116
+
117
+ box("Annulation du déploiement.\nVérifiez vos credentials Docker.", {
118
+ style: "double",
119
+ color: "red",
120
+ });
121
+ ```
122
+
123
+ ## Versions
124
+
125
+ Ce projet suit [Semantic Versioning](https://semver.org/lang/fr/).
126
+
127
+ - **1.0.0** — Version initiale : `success`, `error`, `warn`, `info`, `debug`, `box`, `banner`, `divider`.
128
+
129
+ ## Licence
130
+
131
+ [MIT](./LICENSE)
package/index.js ADDED
@@ -0,0 +1,157 @@
1
+ // jolilogs — logs et cadres ASCII stylés, zéro dépendance.
2
+ // MIT License
3
+
4
+ // =====================================================
5
+ // Couleurs ANSI
6
+ // =====================================================
7
+ const COLORS = {
8
+ reset: "\x1b[0m",
9
+ bold: "\x1b[1m",
10
+ dim: "\x1b[2m",
11
+ red: "\x1b[31m",
12
+ green: "\x1b[32m",
13
+ yellow: "\x1b[33m",
14
+ blue: "\x1b[34m",
15
+ magenta: "\x1b[35m",
16
+ cyan: "\x1b[36m",
17
+ white: "\x1b[37m",
18
+ gray: "\x1b[90m",
19
+ };
20
+
21
+ // Désactive les couleurs si NO_COLOR est défini (convention standard)
22
+ // ou si la sortie n'est pas un terminal (ex: redirection vers un fichier)
23
+ const COLOR_ENABLED =
24
+ !process.env.NO_COLOR && process.stdout && process.stdout.isTTY !== false;
25
+
26
+ function colorize(text, color) {
27
+ if (!COLOR_ENABLED || !color || !COLORS[color]) return text;
28
+ return `${COLORS[color]}${text}${COLORS.reset}`;
29
+ }
30
+
31
+ // =====================================================
32
+ // Styles de cadres
33
+ // =====================================================
34
+ const BOX_STYLES = {
35
+ simple: { tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│" },
36
+ double: { tl: "╔", tr: "╗", bl: "╚", br: "╝", h: "═", v: "║" },
37
+ rounded: { tl: "╭", tr: "╮", bl: "╰", br: "╯", h: "─", v: "│" },
38
+ bold: { tl: "┏", tr: "┓", bl: "┗", br: "┛", h: "━", v: "┃" },
39
+ };
40
+
41
+ // Calcule la longueur visible d'une chaîne (ignore les codes ANSI)
42
+ function visibleLength(str) {
43
+ return String(str).replaceAll(/\x1b\[[0-9;]*m/g, "").length;
44
+ }
45
+
46
+ // =====================================================
47
+ // Cadre (box)
48
+ // =====================================================
49
+ export function box(message, options = {}) {
50
+ const {
51
+ style = "rounded",
52
+ color = null,
53
+ padding = 1,
54
+ print = true,
55
+ } = options;
56
+ const chars = BOX_STYLES[style] || BOX_STYLES.rounded;
57
+
58
+ const lines = String(message).split("\n");
59
+ const maxLen = Math.max(...lines.map(visibleLength));
60
+ const innerWidth = maxLen + padding * 2;
61
+
62
+ const top = colorize(chars.tl + chars.h.repeat(innerWidth) + chars.tr, color);
63
+ const bottom = colorize(
64
+ chars.bl + chars.h.repeat(innerWidth) + chars.br,
65
+ color
66
+ );
67
+ const v = colorize(chars.v, color);
68
+
69
+ const middle = lines
70
+ .map((line) => {
71
+ const pad = " ".repeat(maxLen - visibleLength(line));
72
+ return `${v}${" ".repeat(padding)}${line}${pad}${" ".repeat(padding)}${v}`;
73
+ })
74
+ .join("\n");
75
+
76
+ const result = `${top}\n${middle}\n${bottom}`;
77
+ if (print) console.log(result);
78
+ return result;
79
+ }
80
+
81
+ // =====================================================
82
+ // Bannière (gros cadre stylé)
83
+ // =====================================================
84
+ export function banner(message, options = {}) {
85
+ const { color = "cyan", style = "double", padding = 3 } = options;
86
+ return box(String(message).toUpperCase(), { style, color, padding });
87
+ }
88
+
89
+ // =====================================================
90
+ // Ligne de séparation
91
+ // =====================================================
92
+ export function divider(options = {}) {
93
+ const { char = "─", length = 60, color = "gray" } = options;
94
+ console.log(colorize(char.repeat(length), color));
95
+ }
96
+
97
+ // =====================================================
98
+ // Logs avec niveau
99
+ // =====================================================
100
+ function timestamp() {
101
+ const d = new Date();
102
+ const p = (n) => String(n).padStart(2, "0");
103
+ return `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
104
+ }
105
+
106
+ function formatLog(level, icon, color, message, options = {}) {
107
+ const showTime = options.timestamp !== false;
108
+ const time = showTime ? colorize(`[${timestamp()}]`, "gray") + " " : "";
109
+ const tag = colorize(level.padEnd(7), color);
110
+ return `${time}${icon} ${tag} ${message}`;
111
+ }
112
+
113
+ const LEVELS = {
114
+ success: { icon: "✅", color: "green", boxStyle: "rounded" },
115
+ error: { icon: "❌", color: "red", boxStyle: "double" },
116
+ warn: { icon: "⚠️ ", color: "yellow", boxStyle: "simple" },
117
+ info: { icon: "ℹ️ ", color: "cyan", boxStyle: "simple" },
118
+ debug: { icon: "🔍", color: "gray", boxStyle: "simple" },
119
+ };
120
+
121
+ function makeLogger(level) {
122
+ const cfg = LEVELS[level];
123
+ return function (message, options = {}) {
124
+ const line = formatLog(
125
+ level.toUpperCase(),
126
+ cfg.icon,
127
+ cfg.color,
128
+ message,
129
+ options
130
+ );
131
+ if (options.box) {
132
+ box(line, { style: cfg.boxStyle, color: cfg.color });
133
+ } else {
134
+ console.log(line);
135
+ }
136
+ };
137
+ }
138
+
139
+ export const success = makeLogger("success");
140
+ export const error = makeLogger("error");
141
+ export const warn = makeLogger("warn");
142
+ export const info = makeLogger("info");
143
+ export const debug = makeLogger("debug");
144
+
145
+ // =====================================================
146
+ // Export par défaut
147
+ // =====================================================
148
+ export default {
149
+ success,
150
+ error,
151
+ warn,
152
+ info,
153
+ debug,
154
+ box,
155
+ banner,
156
+ divider,
157
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@yahlex/jolilogs",
3
+ "version": "1.0.0",
4
+ "description": "Logs Node.js stylés : couleurs ANSI, icônes, cadres ASCII et bannières. Zéro dépendance.",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "demo": "node demo.js"
17
+ },
18
+ "keywords": [
19
+ "console",
20
+ "log",
21
+ "logger",
22
+ "ansi",
23
+ "color",
24
+ "couleur",
25
+ "box",
26
+ "cadre",
27
+ "banner",
28
+ "cli",
29
+ "terminal",
30
+ "pretty",
31
+ "français",
32
+ "zero-dependency"
33
+ ],
34
+ "author": "Ton Pseudo <ton.email@example.com>",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/yahlex/jolilogs.git"
39
+ },
40
+ "homepage": "https://github.com/yahlex/jolilogs#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/yahlex/jolilogs/issues"
43
+ },
44
+ "engines": {
45
+ "node": ">=18"
46
+ }
47
+ }