@helzady/zady 1.0.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 CHANGED
@@ -1,78 +1,174 @@
1
- # zady
1
+ # Zady
2
2
 
3
- Biblioteca leve para logs no Node.js com suporte a cores, prefixos, timestamp e controle de erros.
3
+ Logger leve para Node.js com saída colorida no terminal.
4
4
 
5
5
  ---
6
6
 
7
7
  ## 📦 Instalação
8
8
 
9
9
  ```bash
10
- npm install zady
10
+ npm install @helzady/zady
11
11
  ```
12
12
 
13
13
  ---
14
14
 
15
- ## 🚀 Uso básico
15
+ ## 🚀 Uso
16
16
 
17
17
  ```ts
18
- // Importa funções da biblioteca
19
- import { log, warn, error, success, crash } from "@helzady/logger"
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");
28
+ ```
20
29
 
21
- // Log padrão
22
- log("Mensagem simples")
30
+ Ou com destructuring:
23
31
 
24
- // Aviso
25
- warn("Atenção")
32
+ ```ts
33
+ import { log, info, warn, success, error, debug, divider, timer } from "@helzady/zady";
34
+ ```
26
35
 
27
- // Erro
28
- error("Algo deu errado")
36
+ ---
29
37
 
30
- // Sucesso
31
- success("Operação concluída")
38
+ ## 🧾 Saída
32
39
 
33
- // Erro fatal (encerra o processo)
34
- crash("Erro crítico")
40
+ ```bash
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
35
49
  ```
36
50
 
51
+ > As cores e o formato dos logs são aplicados via ANSI no terminal.
52
+
37
53
  ---
38
54
 
39
- ## ⚙️ Opções do crash
55
+ ## 📌 Funções disponíveis
56
+
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 |
67
+
68
+ ---
69
+
70
+ ## ⚙️ Opções da função `error`
71
+
72
+ A função `error` aceita um segundo argumento com as seguintes opções:
40
73
 
41
74
  ```ts
42
- crash("Erro crítico", {
43
- code: 1, // Código de saída do processo
44
- prefix: "FATAL", // Prefixo da mensagem
45
- showStack: true, // Mostrar stack trace
46
- timestamp: true, // Mostrar data/hora
47
- error: new Error("Detalhes do erro") // Objeto de erro
75
+ error("Mensagem de erro", {
76
+ code?: number // código de saída do processo (padrão: 1)
77
+ prefix?: string // prefixo customizado (padrão: "ERROR")
78
+ showStack?: boolean // exibir stack trace (padrão: true)
79
+ timestamp?: boolean // exibir data/hora (padrão: true)
80
+ error?: unknown // objeto de erro para exibir o stack
48
81
  })
49
82
  ```
50
83
 
84
+ Exemplo:
85
+
86
+ ```ts
87
+ try {
88
+ // ...
89
+ } catch (err) {
90
+ error("Falha ao conectar ao banco", {
91
+ code: 1,
92
+ error: err,
93
+ showStack: true,
94
+ });
95
+ }
96
+ ```
97
+
51
98
  ---
52
99
 
53
- ## 🎨 Recursos
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
+ ```
54
107
 
55
- * Logs coloridos (ANSI)
56
- * Prefixos personalizados
57
- * Timestamp formatado (DD/MM/YYYY HH:mm)
58
- * Stack trace opcional
59
- * Encerramento seguro do processo
108
+ ```bash
109
+ DEBUG=true node app.js
110
+ ```
60
111
 
61
112
  ---
62
113
 
63
- ## 📁 Estrutura
114
+ ## Divider
64
115
 
116
+ Imprime uma linha separadora para organizar a saída do terminal:
117
+
118
+ ```ts
119
+ divider() // ────────────────────────────────────────
120
+ divider("=", 20) // ====================
121
+ divider("*", 10) // **********
65
122
  ```
66
- src/
67
- ├── core/ # Núcleo (formatter, colors, types)
68
- ├── functions/ # Funções principais (log, error, etc)
69
- ├── utils/ # Utilitários internos
70
- ├── config/ # Configurações padrão
71
- └── index.ts # Entry point
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
72
141
  ```
73
142
 
74
143
  ---
75
144
 
145
+ ## 🎨 Estilos
146
+
147
+ A lib também expõe utilitários de estilo ANSI para uso direto no terminal:
148
+
149
+ ```ts
150
+ import zady from "@helzady/zady";
151
+
152
+ const { colors, bgColors, terminalStyle } = zady.style;
153
+
154
+ console.log(`${colors.cyan}Texto ciano${terminalStyle.reset}`);
155
+ console.log(`${bgColors.red}Fundo vermelho${terminalStyle.reset}`);
156
+ ```
157
+
158
+ ### `colors`
159
+
160
+ `black` · `red` · `green` · `yellow` · `blue` · `magenta` · `cyan` · `white` · `gray`
161
+
162
+ ### `bgColors`
163
+
164
+ `black` · `red` · `green` · `yellow` · `blue` · `magenta` · `cyan` · `white`
165
+
166
+ ### `terminalStyle`
167
+
168
+ `reset` · `negrito` · `fraco` · `italico` · `sublinhado` · `riscado`
169
+
170
+ ---
171
+
76
172
  ## 📄 Licença
77
173
 
78
- MIT License
174
+ MIT — [HelzadyDev](https://github.com/HelzadyDev)
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@helzady/zady",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
4
7
  "description": "um logger simples e poderoso para Node.js, com saídas formatadas no console, tratamento de erros e utilitários focados no desenvolvedor.",
5
8
  "homepage": "https://github.com/HelzadyDev/zady#readme",
6
9
  "bugs": {
@@ -11,7 +14,7 @@
11
14
  "url": "git+https://github.com/HelzadyDev/zady.git"
12
15
  },
13
16
  "license": "MIT",
14
- "author": "Helzady",
17
+ "author": "HelzadyDev",
15
18
  "type": "module",
16
19
  "files": [
17
20
  "build"
@@ -1,6 +0,0 @@
1
- export declare const defaults: {
2
- prefix: string;
3
- code: number;
4
- showStack: boolean;
5
- timeStamp: boolean;
6
- };
@@ -1,6 +0,0 @@
1
- export const defaults = {
2
- prefix: "LOGGER",
3
- code: 1,
4
- showStack: true,
5
- timeStamp: true,
6
- };
@@ -1 +0,0 @@
1
- export * from "./defaults.js";
@@ -1 +0,0 @@
1
- export * from "./defaults.js";
@@ -1,21 +0,0 @@
1
- export declare const colors: {
2
- black: string;
3
- red: string;
4
- green: string;
5
- yellow: string;
6
- blue: string;
7
- magenta: string;
8
- cyan: string;
9
- white: string;
10
- gray: string;
11
- };
12
- export declare const bgColors: {
13
- black: string;
14
- red: string;
15
- green: string;
16
- yellow: string;
17
- blue: string;
18
- magenta: string;
19
- cyan: string;
20
- white: string;
21
- };
@@ -1,22 +0,0 @@
1
- // Define cores ANSI para terminal
2
- export const colors = {
3
- "black": "\x1b[30",
4
- "red": "\x1b[31m",
5
- "green": "\x1b[32m",
6
- "yellow": "\x1b[33m",
7
- "blue": "\x1b[34m",
8
- "magenta": "\x1b[35",
9
- "cyan": "\x1b[36",
10
- "white": "\x1b[37m",
11
- "gray": "\x1b[90m",
12
- };
13
- export const bgColors = {
14
- "black": "\x1b[40m",
15
- "red": "\x1b[41m",
16
- "green": "\x1b[42m",
17
- "yellow": "\x1b[43m",
18
- "blue": "\x1b[44m",
19
- "magenta": "\x1b[45m",
20
- "cyan": "\x1b[46m",
21
- "white": "\x1b[47m",
22
- };
@@ -1 +0,0 @@
1
- export declare function formatMenssage(message: string, prefix: string, color: string, useTimestamp: boolean): string;
@@ -1,9 +0,0 @@
1
- import { colors, terminalStyle } from "#core";
2
- import { getTimestamp } from "#utils";
3
- // Função responsavel por montar a mensagem fatal
4
- export function formatMenssage(message, prefix, color, useTimestamp) {
5
- const time = useTimestamp
6
- ? `${colors.gray}[${getTimestamp()}]${terminalStyle.reset}`
7
- : "";
8
- return `${time}${color}[${prefix}]${terminalStyle.reset} ${message}`;
9
- }
@@ -1,4 +0,0 @@
1
- export * from "./colors.js";
2
- export * from "./types.js";
3
- export * from "./formatter.js";
4
- export * from "./terminalStyle.js";
@@ -1,4 +0,0 @@
1
- export * from "./colors.js";
2
- export * from "./types.js";
3
- export * from "./formatter.js";
4
- export * from "./terminalStyle.js";
@@ -1,8 +0,0 @@
1
- export declare const terminalStyle: {
2
- reset: string;
3
- negrito: string;
4
- fraco: string;
5
- italico: string;
6
- sublinhado: string;
7
- riscado: string;
8
- };
@@ -1,8 +0,0 @@
1
- export const terminalStyle = {
2
- "reset": "\x1b[0m", // Reseta cor
3
- "negrito": "\x1b[1m", // Formata o texto em negrito
4
- "fraco": "\x1b[2m",
5
- "italico": "\x1b[3m",
6
- "sublinhado": "\x1b[4m",
7
- "riscado": "\x1b[9m",
8
- };
@@ -1,7 +0,0 @@
1
- export interface ErrorOptions {
2
- code?: number;
3
- prefix?: string;
4
- showStack?: boolean;
5
- timestamp?: boolean;
6
- error?: unknown;
7
- }
@@ -1,2 +0,0 @@
1
- ;
2
- export {};
@@ -1,2 +0,0 @@
1
- import { ErrorOptions } from "#core";
2
- export declare function error(message: string, options?: ErrorOptions): never;
@@ -1,19 +0,0 @@
1
- // import { colors, formatMenssage } from "#core";
2
- // // log de erro
3
- // export function error(message: string): void {
4
- // console.error(formatMenssage(message, "ERROR", colors.red, true))
5
- // }
6
- import { colors, formatMenssage } from "#core";
7
- import { defaults } from "#config";
8
- // função fatal que encerra o processo
9
- export function error(message, options = {}) {
10
- const { code = defaults.code, prefix = "FATAL", showStack = defaults.showStack, timestamp = defaults.timeStamp, error, } = options;
11
- // Exibe mensagen formatada
12
- console.error(formatMenssage(message, prefix, colors.red, timestamp));
13
- // Exibe stack trace se existir
14
- if (showStack && error instanceof Error) {
15
- console.error(error.stack);
16
- }
17
- // Encerra o processo
18
- process.exit(code);
19
- }
@@ -1,4 +0,0 @@
1
- export * from "./error.js";
2
- export * from "./log.js";
3
- export * from "./success.js";
4
- export * from "./warn.js";
@@ -1,4 +0,0 @@
1
- export * from "./error.js";
2
- export * from "./log.js";
3
- export * from "./success.js";
4
- export * from "./warn.js";
@@ -1 +0,0 @@
1
- export declare function log(message: string): void;
@@ -1,5 +0,0 @@
1
- import { colors, formatMenssage } from "#core";
2
- // Log padrão (info)
3
- export function log(message) {
4
- console.log(formatMenssage(message, "INFO", colors.blue, true));
5
- }
@@ -1 +0,0 @@
1
- export declare function success(message: string): void;
@@ -1,5 +0,0 @@
1
- import { colors, formatMenssage } from "#core";
2
- // Log de sucesso
3
- export function success(message) {
4
- console.log(formatMenssage(message, "SUCCESS", colors.green, true));
5
- }
@@ -1 +0,0 @@
1
- export declare function warn(message: string): void;
@@ -1,5 +0,0 @@
1
- import { colors, formatMenssage } from "#core";
2
- // log de aviso
3
- export function warn(message) {
4
- console.log(formatMenssage(message, "WARN", colors.yellow, true));
5
- }
package/build/index.d.ts DELETED
@@ -1,38 +0,0 @@
1
- declare const logger: {
2
- style: {
3
- bgColors: {
4
- black: string;
5
- red: string;
6
- green: string;
7
- yellow: string;
8
- blue: string;
9
- magenta: string;
10
- cyan: string;
11
- white: string;
12
- };
13
- colors: {
14
- black: string;
15
- red: string;
16
- green: string;
17
- yellow: string;
18
- blue: string;
19
- magenta: string;
20
- cyan: string;
21
- white: string;
22
- gray: string;
23
- };
24
- terminalStyle: {
25
- reset: string;
26
- negrito: string;
27
- fraco: string;
28
- italico: string;
29
- sublinhado: string;
30
- riscado: string;
31
- };
32
- };
33
- error(message: string, options?: import("#core").ErrorOptions): never;
34
- log(message: string): void;
35
- success(message: string): void;
36
- warn(message: string): void;
37
- };
38
- export default logger;
package/build/index.js DELETED
@@ -1,11 +0,0 @@
1
- import * as functions from "#functions";
2
- import { bgColors, colors, terminalStyle } from "#core";
3
- const logger = {
4
- ...functions,
5
- style: {
6
- bgColors,
7
- colors,
8
- terminalStyle
9
- }
10
- };
11
- export default logger;
@@ -1 +0,0 @@
1
- export declare function getTimestamp(): string;
@@ -1,10 +0,0 @@
1
- // Retorna data no formato DD/MM/YYYY HH:mm
2
- export function getTimestamp() {
3
- const now = new Date();
4
- const day = String(now.getDate()).padStart(2, "0");
5
- const month = String(now.getMonth() + 1).padStart(2, "0");
6
- const year = now.getFullYear();
7
- const hours = String(now.getHours()).padStart(2, "0");
8
- const minutes = String(now.getMinutes()).padStart(2, "0");
9
- return `${day}/${month}/${year} ${hours}:${minutes}`;
10
- }
@@ -1,2 +0,0 @@
1
- export * from "./formatDate.js";
2
- export * from "./precess.js";
@@ -1,2 +0,0 @@
1
- export * from "./formatDate.js";
2
- export * from "./precess.js";
@@ -1 +0,0 @@
1
- export declare function exitProcess(code: string): never;
@@ -1,4 +0,0 @@
1
- // wrapper do proces.exit
2
- export function exitProcess(code) {
3
- process.exit(code);
4
- }