rslog 2.0.0 → 2.0.1
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 +3 -1
- package/dist/color.d.ts +16 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +39 -24
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ pnpm add rslog
|
|
|
35
35
|
bun add rslog
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
Rslog requires Node.js `^20.19.0 || >=22.12.0`. If you are on Node 18, upgrade Node before using the package.
|
|
39
|
+
|
|
38
40
|
## Usage
|
|
39
41
|
|
|
40
42
|
```js
|
|
@@ -132,7 +134,7 @@ logger.override({
|
|
|
132
134
|
|
|
133
135
|
## Environment
|
|
134
136
|
|
|
135
|
-
Rslog
|
|
137
|
+
Rslog supports Node.js `^20.19.0 || >=22.12.0`.
|
|
136
138
|
|
|
137
139
|
## Credits
|
|
138
140
|
|
package/dist/color.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
export type ColorFn = (text: string | number) => string;
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export declare const color: {
|
|
3
|
+
dim: ColorFn;
|
|
4
|
+
red: ColorFn;
|
|
5
|
+
bold: ColorFn;
|
|
6
|
+
blue: ColorFn;
|
|
7
|
+
cyan: ColorFn;
|
|
8
|
+
gray: ColorFn;
|
|
9
|
+
black: ColorFn;
|
|
10
|
+
green: ColorFn;
|
|
11
|
+
white: ColorFn;
|
|
12
|
+
reset: ColorFn;
|
|
13
|
+
yellow: ColorFn;
|
|
14
|
+
magenta: ColorFn;
|
|
15
|
+
underline: ColorFn;
|
|
16
|
+
strikethrough: ColorFn;
|
|
17
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import node_util from "node:util";
|
|
2
2
|
import node_process from "node:process";
|
|
3
3
|
import node_os from "node:os";
|
|
4
4
|
import node_tty from "node:tty";
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
5
|
+
function checkNodeVersion() {
|
|
6
|
+
const { versions } = process;
|
|
7
|
+
if ("styleText" in node_util || !versions.node || versions.bun || versions.deno) return;
|
|
8
|
+
throw new Error(`Unsupported Node.js version: "${process.versions.node || 'unknown'}". Expected Node.js >= 20.`);
|
|
9
|
+
}
|
|
10
|
+
checkNodeVersion();
|
|
11
|
+
const createStyler = (style)=>(text)=>node_util.styleText(style, String(text));
|
|
12
|
+
const color = {
|
|
13
|
+
dim: createStyler('dim'),
|
|
14
|
+
red: createStyler('red'),
|
|
15
|
+
bold: createStyler('bold'),
|
|
16
|
+
blue: createStyler('blue'),
|
|
17
|
+
cyan: createStyler('cyan'),
|
|
18
|
+
gray: createStyler('gray'),
|
|
19
|
+
black: createStyler('black'),
|
|
20
|
+
green: createStyler('green'),
|
|
21
|
+
white: createStyler('white'),
|
|
22
|
+
reset: createStyler('reset'),
|
|
23
|
+
yellow: createStyler('yellow'),
|
|
24
|
+
magenta: createStyler('magenta'),
|
|
25
|
+
underline: createStyler('underline'),
|
|
26
|
+
strikethrough: createStyler('strikethrough')
|
|
27
|
+
};
|
|
13
28
|
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
|
|
14
29
|
const prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--';
|
|
15
30
|
const position = argv.indexOf(prefix + flag);
|
|
16
31
|
const terminatorPosition = argv.indexOf('--');
|
|
17
32
|
return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
|
|
18
33
|
}
|
|
19
|
-
const { env } = node_process;
|
|
34
|
+
const { env: env } = node_process;
|
|
20
35
|
let flagForceColor;
|
|
21
36
|
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) flagForceColor = 0;
|
|
22
37
|
else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) flagForceColor = 1;
|
|
@@ -128,7 +143,7 @@ let endColor = [
|
|
|
128
143
|
];
|
|
129
144
|
let isWord = (char)=>!/[\s\n]/.test(char);
|
|
130
145
|
let gradient = (message)=>{
|
|
131
|
-
if (colorLevel < 3) return 2 === colorLevel ?
|
|
146
|
+
if (colorLevel < 3) return 2 === colorLevel ? color.cyan(message) : message;
|
|
132
147
|
let chars = [
|
|
133
148
|
...message
|
|
134
149
|
];
|
|
@@ -148,7 +163,7 @@ let gradient = (message)=>{
|
|
|
148
163
|
}
|
|
149
164
|
output += `\x1b[38;2;${Math.round(r)};${Math.round(g)};${Math.round(b)}m${char}\x1b[39m`;
|
|
150
165
|
}
|
|
151
|
-
return bold(output);
|
|
166
|
+
return color.bold(output);
|
|
152
167
|
};
|
|
153
168
|
let LOG_LEVEL = {
|
|
154
169
|
silent: -1,
|
|
@@ -162,32 +177,32 @@ let LOG_TYPES = {
|
|
|
162
177
|
error: {
|
|
163
178
|
label: 'error',
|
|
164
179
|
level: 'error',
|
|
165
|
-
color: red
|
|
180
|
+
color: color.red
|
|
166
181
|
},
|
|
167
182
|
warn: {
|
|
168
183
|
label: 'warn',
|
|
169
184
|
level: 'warn',
|
|
170
|
-
color: yellow
|
|
185
|
+
color: color.yellow
|
|
171
186
|
},
|
|
172
187
|
info: {
|
|
173
188
|
label: 'info',
|
|
174
189
|
level: 'info',
|
|
175
|
-
color: cyan
|
|
190
|
+
color: color.cyan
|
|
176
191
|
},
|
|
177
192
|
start: {
|
|
178
193
|
label: 'start',
|
|
179
194
|
level: 'info',
|
|
180
|
-
color: cyan
|
|
195
|
+
color: color.cyan
|
|
181
196
|
},
|
|
182
197
|
ready: {
|
|
183
198
|
label: 'ready',
|
|
184
199
|
level: 'info',
|
|
185
|
-
color: green
|
|
200
|
+
color: color.green
|
|
186
201
|
},
|
|
187
202
|
success: {
|
|
188
203
|
label: 'success',
|
|
189
204
|
level: 'info',
|
|
190
|
-
color: green
|
|
205
|
+
color: color.green
|
|
191
206
|
},
|
|
192
207
|
log: {
|
|
193
208
|
level: 'info'
|
|
@@ -195,14 +210,14 @@ let LOG_TYPES = {
|
|
|
195
210
|
debug: {
|
|
196
211
|
label: 'debug',
|
|
197
212
|
level: 'verbose',
|
|
198
|
-
color: magenta
|
|
213
|
+
color: color.magenta
|
|
199
214
|
}
|
|
200
215
|
};
|
|
201
216
|
const normalizeErrorMessage = (err)=>{
|
|
202
217
|
if (err.stack) {
|
|
203
218
|
let [name, ...rest] = err.stack.split('\n');
|
|
204
219
|
if (name.startsWith('Error: ')) name = name.slice(7);
|
|
205
|
-
return `${name}\n${gray(rest.join('\n'))}`;
|
|
220
|
+
return `${name}\n${color.gray(rest.join('\n'))}`;
|
|
206
221
|
}
|
|
207
222
|
return err.message;
|
|
208
223
|
};
|
|
@@ -217,18 +232,18 @@ let createLogger = (options = {})=>{
|
|
|
217
232
|
let text = '';
|
|
218
233
|
if ('label' in logType) {
|
|
219
234
|
label = (logType.label || '').padEnd(7);
|
|
220
|
-
label = bold(logType.color ? logType.color(label) : label);
|
|
235
|
+
label = color.bold(logType.color ? logType.color(label) : label);
|
|
221
236
|
}
|
|
222
237
|
if (message instanceof Error) {
|
|
223
238
|
text += normalizeErrorMessage(message);
|
|
224
239
|
const { cause } = message;
|
|
225
240
|
if (cause) {
|
|
226
|
-
text += yellow('\n [cause]: ');
|
|
241
|
+
text += color.yellow('\n [cause]: ');
|
|
227
242
|
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
228
243
|
}
|
|
229
244
|
} else if ('error' === level && 'string' == typeof message) {
|
|
230
245
|
let lines = message.split('\n');
|
|
231
|
-
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join('\n');
|
|
246
|
+
text = lines.map((line)=>isErrorStackMessage(line) ? color.gray(line) : line).join('\n');
|
|
232
247
|
} else text = `${message}`;
|
|
233
248
|
const method = 'error' === level || 'warn' === level ? level : 'log';
|
|
234
249
|
console[method](label.length ? `${label} ${text}` : text, ...args);
|
|
@@ -251,4 +266,4 @@ let createLogger = (options = {})=>{
|
|
|
251
266
|
return logger;
|
|
252
267
|
};
|
|
253
268
|
let src_logger = createLogger();
|
|
254
|
-
export { createLogger, src_logger as logger };
|
|
269
|
+
export { color, createLogger, src_logger as logger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rslog",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/rstackjs/rslog.git"
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"test": "rstest"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@rslib/core": "^0.
|
|
30
|
-
"@rstest/core": "^0.
|
|
31
|
-
"@types/node": "^24.
|
|
29
|
+
"@rslib/core": "^0.19.6",
|
|
30
|
+
"@rstest/core": "^0.8.5",
|
|
31
|
+
"@types/node": "^24.11.0",
|
|
32
32
|
"path-serializer": "^0.5.1",
|
|
33
|
-
"prettier": "~3.
|
|
34
|
-
"strip-ansi": "^7.
|
|
33
|
+
"prettier": "~3.8.1",
|
|
34
|
+
"strip-ansi": "^7.2.0",
|
|
35
35
|
"supports-color": "^10.2.2",
|
|
36
36
|
"typescript": "~5.9.3"
|
|
37
37
|
},
|
|
38
|
-
"packageManager": "pnpm@10.
|
|
38
|
+
"packageManager": "pnpm@10.30.3",
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": "^20.19.0 || >=22.12.0"
|
|
41
41
|
},
|