@helzady/zady 1.1.0 → 1.2.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 +87 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,19 +15,22 @@ npm install @helzady/zady
|
|
|
15
15
|
## 🚀 Uso
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import zady from "@helzady/zady"
|
|
19
|
-
|
|
20
|
-
zady.log("Mensagem de debug")
|
|
21
|
-
zady.info("Servidor iniciado na porta 3000")
|
|
22
|
-
zady.warn("Variável de ambiente não definida")
|
|
23
|
-
zady.success("Conexão estabelecida")
|
|
24
|
-
zady.error("Falha crítica", { error: new Error("stack trace aqui") })
|
|
18
|
+
import zady from "@helzady/zady";
|
|
19
|
+
|
|
20
|
+
zady.log("Mensagem de debug");
|
|
21
|
+
zady.info("Servidor iniciado na porta 3000");
|
|
22
|
+
zady.warn("Variável de ambiente não definida");
|
|
23
|
+
zady.success("Conexão estabelecida");
|
|
24
|
+
zady.error("Falha crítica", { error: new Error("stack trace aqui") });
|
|
25
|
+
zady.debug("Valor da variável x: 42");
|
|
26
|
+
zady.divider();
|
|
27
|
+
zady.timer("query ao banco");
|
|
25
28
|
```
|
|
26
29
|
|
|
27
30
|
Ou com destructuring:
|
|
28
31
|
|
|
29
32
|
```ts
|
|
30
|
-
import { log, info, warn, success, error } from "@helzady/zady"
|
|
33
|
+
import { log, info, warn, success, error, debug, divider, timer } from "@helzady/zady";
|
|
31
34
|
```
|
|
32
35
|
|
|
33
36
|
---
|
|
@@ -35,24 +38,32 @@ import { log, info, warn, success, error } from "@helzady/zady"
|
|
|
35
38
|
## 🧾 Saída
|
|
36
39
|
|
|
37
40
|
```bash
|
|
38
|
-
[18/05/2026 14:00] [LOG] Mensagem de debug
|
|
39
|
-
[18/05/2026 14:00] [INFO] Servidor na porta 3000
|
|
40
|
-
[18/05/2026 14:00] [WARN] Variável não definida
|
|
41
|
-
[18/05/2026 14:00] [SUCCESS] Conexão estabelecida
|
|
42
|
-
[18/05/2026 14:00] [ERROR] Falha crítica
|
|
41
|
+
[18/05/2026 14:00] [LOG] Mensagem de debug
|
|
42
|
+
[18/05/2026 14:00] [INFO] Servidor na porta 3000
|
|
43
|
+
[18/05/2026 14:00] [WARN] Variável de ambiente não definida
|
|
44
|
+
[18/05/2026 14:00] [SUCCESS] Conexão estabelecida
|
|
45
|
+
[18/05/2026 14:00] [ERROR] Falha crítica
|
|
46
|
+
[18/05/2026 14:00] [DEBUG] Valor da variável x: 42
|
|
47
|
+
────────────────────────────────────────
|
|
48
|
+
[18/05/2026 14:00] [TIMER] query ao banco — 42.31ms
|
|
43
49
|
```
|
|
44
50
|
|
|
51
|
+
> As cores e o formato dos logs são aplicados via ANSI no terminal.
|
|
52
|
+
|
|
45
53
|
---
|
|
46
54
|
|
|
47
55
|
## 📌 Funções disponíveis
|
|
48
56
|
|
|
49
|
-
| Função
|
|
50
|
-
|
|
51
|
-
| `log(message)`
|
|
52
|
-
| `info(message)`
|
|
53
|
-
| `warn(message)`
|
|
54
|
-
| `success(message)`
|
|
55
|
-
| `error(message, options?)`
|
|
57
|
+
| Função | Prefixo | Cor | Descrição |
|
|
58
|
+
| ---------------------------- | --------- | -------- | -------------------------------------------------- |
|
|
59
|
+
| `log(message)` | `LOG` | Cinza | Debug e mensagens de desenvolvimento |
|
|
60
|
+
| `info(message)` | `INFO` | Azul | Informações relevantes do sistema |
|
|
61
|
+
| `warn(message)` | `WARN` | Amarelo | Avisos que não encerram o processo |
|
|
62
|
+
| `success(message)` | `SUCCESS` | Verde | Confirmação de operações bem-sucedidas |
|
|
63
|
+
| `error(message, options?)` | `ERROR` | Vermelho | Erro crítico — **encerra o processo** |
|
|
64
|
+
| `debug(message)` | `DEBUG` | Magenta | Log condicional — só exibe quando `DEBUG=true` |
|
|
65
|
+
| `divider(char?, length?)` | — | Cinza | Linha separadora no terminal |
|
|
66
|
+
| `timer(label)` | `TIMER` | Ciano | Mede o tempo de uma operação |
|
|
56
67
|
|
|
57
68
|
---
|
|
58
69
|
|
|
@@ -62,11 +73,11 @@ A função `error` aceita um segundo argumento com as seguintes opções:
|
|
|
62
73
|
|
|
63
74
|
```ts
|
|
64
75
|
error("Mensagem de erro", {
|
|
65
|
-
code?: number
|
|
66
|
-
prefix?: string
|
|
76
|
+
code?: number // código de saída do processo (padrão: 1)
|
|
77
|
+
prefix?: string // prefixo customizado (padrão: "ERROR")
|
|
67
78
|
showStack?: boolean // exibir stack trace (padrão: true)
|
|
68
79
|
timestamp?: boolean // exibir data/hora (padrão: true)
|
|
69
|
-
error?: unknown
|
|
80
|
+
error?: unknown // objeto de erro para exibir o stack
|
|
70
81
|
})
|
|
71
82
|
```
|
|
72
83
|
|
|
@@ -80,32 +91,80 @@ try {
|
|
|
80
91
|
code: 1,
|
|
81
92
|
error: err,
|
|
82
93
|
showStack: true,
|
|
83
|
-
})
|
|
94
|
+
});
|
|
84
95
|
}
|
|
85
96
|
```
|
|
86
97
|
|
|
87
98
|
---
|
|
88
99
|
|
|
100
|
+
## 🐛 Debug
|
|
101
|
+
|
|
102
|
+
A função `debug` só exibe logs quando a variável de ambiente `DEBUG=true` estiver ativa:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
debug("Valor da variável x: 42");
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
DEBUG=true node app.js
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## ─ Divider
|
|
115
|
+
|
|
116
|
+
Imprime uma linha separadora para organizar a saída do terminal:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
divider() // ────────────────────────────────────────
|
|
120
|
+
divider("=", 20) // ====================
|
|
121
|
+
divider("*", 10) // **********
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## ⏱ Timer
|
|
127
|
+
|
|
128
|
+
Mede o tempo de execução de uma operação:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const t = timer("query ao banco");
|
|
132
|
+
|
|
133
|
+
await db.query("SELECT ...");
|
|
134
|
+
|
|
135
|
+
t.stop("Query concluída");
|
|
136
|
+
// → [TIMER] Query concluída — 42.31ms
|
|
137
|
+
|
|
138
|
+
// ou sem mensagem
|
|
139
|
+
t.stop();
|
|
140
|
+
// → [TIMER] query ao banco — 42.31ms
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
89
145
|
## 🎨 Estilos
|
|
90
146
|
|
|
91
147
|
A lib também expõe utilitários de estilo ANSI para uso direto no terminal:
|
|
92
148
|
|
|
93
149
|
```ts
|
|
94
|
-
import zady from "@helzady/zady"
|
|
150
|
+
import zady from "@helzady/zady";
|
|
95
151
|
|
|
96
|
-
const { colors, bgColors, terminalStyle } = zady.style
|
|
152
|
+
const { colors, bgColors, terminalStyle } = zady.style;
|
|
97
153
|
|
|
98
|
-
console.log(`${colors.cyan}Texto ciano${terminalStyle.reset}`)
|
|
99
|
-
console.log(`${bgColors.red}Fundo vermelho${terminalStyle.reset}`)
|
|
154
|
+
console.log(`${colors.cyan}Texto ciano${terminalStyle.reset}`);
|
|
155
|
+
console.log(`${bgColors.red}Fundo vermelho${terminalStyle.reset}`);
|
|
100
156
|
```
|
|
101
157
|
|
|
102
158
|
### `colors`
|
|
159
|
+
|
|
103
160
|
`black` · `red` · `green` · `yellow` · `blue` · `magenta` · `cyan` · `white` · `gray`
|
|
104
161
|
|
|
105
162
|
### `bgColors`
|
|
163
|
+
|
|
106
164
|
`black` · `red` · `green` · `yellow` · `blue` · `magenta` · `cyan` · `white`
|
|
107
165
|
|
|
108
166
|
### `terminalStyle`
|
|
167
|
+
|
|
109
168
|
`reset` · `negrito` · `fraco` · `italico` · `sublinhado` · `riscado`
|
|
110
169
|
|
|
111
170
|
---
|