bananass-utils-console 0.7.0 → 0.9.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 +11 -153
- package/build/icons.d.ts +31 -0
- package/{src/icons → build}/icons.js +10 -51
- package/build/{is-interactive/is-interactive.d.ts → is-interactive.d.ts} +5 -4
- package/{src/is-interactive → build}/is-interactive.js +4 -8
- package/build/{is-unicode-supported/is-unicode-supported.d.ts → is-unicode-supported.d.ts} +6 -1
- package/{src/is-unicode-supported → build}/is-unicode-supported.js +16 -24
- package/build/{logger/logger.d.ts → logger.d.ts} +32 -35
- package/build/logger.js +163 -0
- package/build/{spinner/spinner.d.ts → spinner.d.ts} +57 -78
- package/build/spinner.js +277 -0
- package/build/theme.d.ts +64 -0
- package/{src/theme → build}/theme.js +31 -46
- package/package.json +25 -26
- package/build/icons/icons.d.ts +0 -28
- package/build/icons/index.d.ts +0 -1
- package/build/is-interactive/index.d.ts +0 -2
- package/build/is-unicode-supported/index.d.ts +0 -2
- package/build/logger/index.d.ts +0 -2
- package/build/spinner/index.d.ts +0 -2
- package/build/theme/index.d.ts +0 -1
- package/build/theme/theme.d.ts +0 -60
- package/src/icons/index.js +0 -1
- package/src/is-interactive/index.js +0 -3
- package/src/is-unicode-supported/index.js +0 -3
- package/src/logger/index.js +0 -3
- package/src/logger/logger.js +0 -208
- package/src/spinner/index.js +0 -3
- package/src/spinner/spinner.js +0 -388
- package/src/theme/index.js +0 -1
package/build/theme.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Console theme.
|
|
3
|
+
* @module bananass-utils-console/theme
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns a green-colored success message prefixed with an icon.
|
|
7
|
+
*
|
|
8
|
+
* @param str The success message to format.
|
|
9
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
10
|
+
* @returns Returns a green-colored success message prefixed with an icon.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* console.log(complete('Operation successful.'));
|
|
14
|
+
* // Output: (icon?) Operation successful. (displayed in green text in the terminal.)
|
|
15
|
+
*/
|
|
16
|
+
export declare function success(str: string, showIcon?: boolean): string;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a red-colored error message prefixed with an icon.
|
|
19
|
+
*
|
|
20
|
+
* @param str The error message to format.
|
|
21
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
22
|
+
* @returns Returns a red-colored error message prefixed with an icon.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* console.log(error('Something went wrong.'));
|
|
26
|
+
* // Output: (icon?) Something went wrong. (displayed in red text in the terminal.)
|
|
27
|
+
*/
|
|
28
|
+
export declare function error(str: string, showIcon?: boolean): string;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a yellow-colored warning message prefixed with an icon.
|
|
31
|
+
*
|
|
32
|
+
* @param str The warning message to format.
|
|
33
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
34
|
+
* @returns Returns a yellow-colored warning message prefixed with an icon.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* console.log(warning('This is a warning.'));
|
|
38
|
+
* // Output: (icon?) This is a warning. (displayed in yellow text in the terminal.)
|
|
39
|
+
*/
|
|
40
|
+
export declare function warning(str: string, showIcon?: boolean): string;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a blue-colored info message prefixed with an icon.
|
|
43
|
+
*
|
|
44
|
+
* @param str The info message to format.
|
|
45
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
46
|
+
* @returns Returns a blue-colored info message prefixed with an icon.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* console.log(info('Informational message.'));
|
|
50
|
+
* // Output: (icon?) Informational message. (displayed in blue text in the terminal.)
|
|
51
|
+
*/
|
|
52
|
+
export declare function info(str: string, showIcon?: boolean): string;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a yellow-colored bananass message prefixed with an icon.
|
|
55
|
+
*
|
|
56
|
+
* @param str The bananass message to format.
|
|
57
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
58
|
+
* @returns Returns a yellow-colored bananass message prefixed with an icon.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* console.log(bananass('Hello, Bananass.'));
|
|
62
|
+
* // Output: (icon?) Hello, Bananass. (displayed in yellow text in the terminal.)
|
|
63
|
+
*/
|
|
64
|
+
export declare function bananass(str: string, showIcon?: boolean): string;
|
|
@@ -2,111 +2,96 @@
|
|
|
2
2
|
* @fileoverview Console theme.
|
|
3
3
|
* @module bananass-utils-console/theme
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
// --------------------------------------------------------------------------------
|
|
7
6
|
// Import
|
|
8
7
|
// --------------------------------------------------------------------------------
|
|
9
|
-
|
|
10
8
|
import { styleText } from 'node:util';
|
|
11
|
-
import {
|
|
12
|
-
successText,
|
|
13
|
-
errorText,
|
|
14
|
-
warningText,
|
|
15
|
-
infoText,
|
|
16
|
-
bananassIcon,
|
|
17
|
-
} from '../icons/index.js';
|
|
18
|
-
|
|
9
|
+
import { successText, errorText, warningText, infoText, bananassIcon } from "./icons.js";
|
|
19
10
|
// --------------------------------------------------------------------------------
|
|
20
|
-
//
|
|
11
|
+
// Helper
|
|
21
12
|
// --------------------------------------------------------------------------------
|
|
22
|
-
|
|
23
13
|
/**
|
|
24
14
|
* Formats a string with an optional color and icon.
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @returns
|
|
15
|
+
* @param str The string to format.
|
|
16
|
+
* @param showIcon Whether to show the icon.
|
|
17
|
+
* @param color The color to apply to the string.
|
|
18
|
+
* @param icon The icon to prepend to the string if `showIcon` is true.
|
|
19
|
+
* @returns The formatted string with the optional icon and color applied.
|
|
30
20
|
* @private
|
|
31
21
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
function format(str, showIcon, color, icon) {
|
|
23
|
+
return `${showIcon ? `${icon} ` : ''}${styleText(color, str)}`;
|
|
24
|
+
}
|
|
35
25
|
// --------------------------------------------------------------------------------
|
|
36
26
|
// Export
|
|
37
27
|
// --------------------------------------------------------------------------------
|
|
38
|
-
|
|
39
28
|
/**
|
|
40
29
|
* Returns a green-colored success message prefixed with an icon.
|
|
41
30
|
*
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* @returns
|
|
31
|
+
* @param str The success message to format.
|
|
32
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
33
|
+
* @returns Returns a green-colored success message prefixed with an icon.
|
|
45
34
|
*
|
|
46
35
|
* @example
|
|
47
36
|
* console.log(complete('Operation successful.'));
|
|
48
37
|
* // Output: (icon?) Operation successful. (displayed in green text in the terminal.)
|
|
49
38
|
*/
|
|
50
39
|
export function success(str, showIcon = false) {
|
|
51
|
-
|
|
40
|
+
return format(str, showIcon, 'green', successText);
|
|
52
41
|
}
|
|
53
|
-
|
|
54
42
|
/**
|
|
55
43
|
* Returns a red-colored error message prefixed with an icon.
|
|
56
44
|
*
|
|
57
|
-
* @param
|
|
58
|
-
* @param
|
|
59
|
-
* @returns
|
|
45
|
+
* @param str The error message to format.
|
|
46
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
47
|
+
* @returns Returns a red-colored error message prefixed with an icon.
|
|
60
48
|
*
|
|
61
49
|
* @example
|
|
62
50
|
* console.log(error('Something went wrong.'));
|
|
63
51
|
* // Output: (icon?) Something went wrong. (displayed in red text in the terminal.)
|
|
64
52
|
*/
|
|
65
53
|
export function error(str, showIcon = false) {
|
|
66
|
-
|
|
54
|
+
return format(str, showIcon, 'red', errorText);
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
/**
|
|
70
57
|
* Returns a yellow-colored warning message prefixed with an icon.
|
|
71
58
|
*
|
|
72
|
-
* @param
|
|
73
|
-
* @param
|
|
74
|
-
* @returns
|
|
59
|
+
* @param str The warning message to format.
|
|
60
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
61
|
+
* @returns Returns a yellow-colored warning message prefixed with an icon.
|
|
75
62
|
*
|
|
76
63
|
* @example
|
|
77
64
|
* console.log(warning('This is a warning.'));
|
|
78
65
|
* // Output: (icon?) This is a warning. (displayed in yellow text in the terminal.)
|
|
79
66
|
*/
|
|
80
67
|
export function warning(str, showIcon = false) {
|
|
81
|
-
|
|
68
|
+
return format(str, showIcon, 'yellow', warningText);
|
|
82
69
|
}
|
|
83
|
-
|
|
84
70
|
/**
|
|
85
71
|
* Returns a blue-colored info message prefixed with an icon.
|
|
86
72
|
*
|
|
87
|
-
* @param
|
|
88
|
-
* @param
|
|
89
|
-
* @returns
|
|
73
|
+
* @param str The info message to format.
|
|
74
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
75
|
+
* @returns Returns a blue-colored info message prefixed with an icon.
|
|
90
76
|
*
|
|
91
77
|
* @example
|
|
92
78
|
* console.log(info('Informational message.'));
|
|
93
79
|
* // Output: (icon?) Informational message. (displayed in blue text in the terminal.)
|
|
94
80
|
*/
|
|
95
81
|
export function info(str, showIcon = false) {
|
|
96
|
-
|
|
82
|
+
return format(str, showIcon, 'blue', infoText);
|
|
97
83
|
}
|
|
98
|
-
|
|
99
84
|
/**
|
|
100
|
-
* Returns a yellow-colored
|
|
85
|
+
* Returns a yellow-colored bananass message prefixed with an icon.
|
|
101
86
|
*
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
104
|
-
* @returns Returns a yellow-colored
|
|
87
|
+
* @param str The bananass message to format.
|
|
88
|
+
* @param showIcon Whether to show the icon. Defaults to `false`.
|
|
89
|
+
* @returns Returns a yellow-colored bananass message prefixed with an icon.
|
|
105
90
|
*
|
|
106
91
|
* @example
|
|
107
92
|
* console.log(bananass('Hello, Bananass.'));
|
|
108
93
|
* // Output: (icon?) Hello, Bananass. (displayed in yellow text in the terminal.)
|
|
109
94
|
*/
|
|
110
95
|
export function bananass(str, showIcon = false) {
|
|
111
|
-
|
|
96
|
+
return format(str, showIcon, 'yellow', bananassIcon);
|
|
112
97
|
}
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bananass-utils-console",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Console Utilities for Bananass Framework.🍌",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./icons": {
|
|
8
|
-
"types": "./build/icons
|
|
9
|
-
"default": "./
|
|
8
|
+
"types": "./build/icons.d.ts",
|
|
9
|
+
"default": "./build/icons.js"
|
|
10
10
|
},
|
|
11
11
|
"./is-interactive": {
|
|
12
|
-
"types": "./build/is-interactive
|
|
13
|
-
"default": "./
|
|
12
|
+
"types": "./build/is-interactive.d.ts",
|
|
13
|
+
"default": "./build/is-interactive.js"
|
|
14
14
|
},
|
|
15
15
|
"./is-unicode-supported": {
|
|
16
|
-
"types": "./build/is-unicode-supported
|
|
17
|
-
"default": "./
|
|
16
|
+
"types": "./build/is-unicode-supported.d.ts",
|
|
17
|
+
"default": "./build/is-unicode-supported.js"
|
|
18
18
|
},
|
|
19
19
|
"./logger": {
|
|
20
|
-
"types": "./build/logger
|
|
21
|
-
"default": "./
|
|
20
|
+
"types": "./build/logger.d.ts",
|
|
21
|
+
"default": "./build/logger.js"
|
|
22
22
|
},
|
|
23
23
|
"./spinner": {
|
|
24
|
-
"types": "./build/spinner
|
|
25
|
-
"default": "./
|
|
24
|
+
"types": "./build/spinner.d.ts",
|
|
25
|
+
"default": "./build/spinner.js"
|
|
26
26
|
},
|
|
27
27
|
"./theme": {
|
|
28
|
-
"types": "./build/theme
|
|
29
|
-
"default": "./
|
|
28
|
+
"types": "./build/theme.d.ts",
|
|
29
|
+
"default": "./build/theme.js"
|
|
30
30
|
},
|
|
31
31
|
"./package.json": "./package.json"
|
|
32
32
|
},
|
|
@@ -36,32 +36,29 @@
|
|
|
36
36
|
"./build/*"
|
|
37
37
|
],
|
|
38
38
|
"icons": [
|
|
39
|
-
"./build/icons
|
|
39
|
+
"./build/icons.d.ts"
|
|
40
40
|
],
|
|
41
41
|
"is-interactive": [
|
|
42
|
-
"./build/is-interactive
|
|
42
|
+
"./build/is-interactive.d.ts"
|
|
43
43
|
],
|
|
44
44
|
"is-unicode-supported": [
|
|
45
|
-
"./build/is-unicode-supported
|
|
45
|
+
"./build/is-unicode-supported.d.ts"
|
|
46
46
|
],
|
|
47
47
|
"logger": [
|
|
48
|
-
"./build/logger
|
|
48
|
+
"./build/logger.d.ts"
|
|
49
49
|
],
|
|
50
50
|
"spinner": [
|
|
51
|
-
"./build/spinner
|
|
51
|
+
"./build/spinner.d.ts"
|
|
52
52
|
],
|
|
53
53
|
"theme": [
|
|
54
|
-
"./build/theme
|
|
54
|
+
"./build/theme.d.ts"
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
58
|
"files": [
|
|
59
|
-
"src",
|
|
60
59
|
"build",
|
|
61
60
|
"LICENSE.md",
|
|
62
|
-
"README.md"
|
|
63
|
-
"!src/**/*.test.{js,ts}",
|
|
64
|
-
"!**/fixtures/**"
|
|
61
|
+
"README.md"
|
|
65
62
|
],
|
|
66
63
|
"keywords": [
|
|
67
64
|
"bananass",
|
|
@@ -89,14 +86,16 @@
|
|
|
89
86
|
"url": "https://github.com/lumirlumir/npm-bananass/issues"
|
|
90
87
|
},
|
|
91
88
|
"engines": {
|
|
92
|
-
"node": "^
|
|
89
|
+
"node": "^22.23.0 || ^24.15.0 || >=26.0.0"
|
|
93
90
|
},
|
|
94
91
|
"publishConfig": {
|
|
95
92
|
"provenance": true
|
|
96
93
|
},
|
|
97
94
|
"scripts": {
|
|
98
95
|
"prepublishOnly": "npm run build",
|
|
99
|
-
"build": "tsc
|
|
100
|
-
"test": "
|
|
96
|
+
"build": "tsc -b tsconfig.build.json",
|
|
97
|
+
"test": "npm run test:types && npm run test:unit",
|
|
98
|
+
"test:types": "tsc -b tsconfig.json",
|
|
99
|
+
"test:unit": "node --test"
|
|
101
100
|
}
|
|
102
101
|
}
|
package/build/icons/icons.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/** @type {string} */
|
|
2
|
-
export const successIcon: string;
|
|
3
|
-
/** @type {string} */
|
|
4
|
-
export const errorIcon: string;
|
|
5
|
-
/** @type {string} */
|
|
6
|
-
export const warningIcon: string;
|
|
7
|
-
/** @type {string} */
|
|
8
|
-
export const infoIcon: string;
|
|
9
|
-
/** @type {string} */
|
|
10
|
-
export const bananassIcon: string;
|
|
11
|
-
/** @type {string} U+2022: "Bullet" (•) */
|
|
12
|
-
export const bulletIcon: string;
|
|
13
|
-
/** @type {string} U+2500: "Box Drawings Light Horizontal" (─) */
|
|
14
|
-
export const boxDrawingsLightHorizontalIcon: string;
|
|
15
|
-
/** @type {string} */
|
|
16
|
-
export const successText: string;
|
|
17
|
-
/** @type {string} */
|
|
18
|
-
export const errorText: string;
|
|
19
|
-
/** @type {string} */
|
|
20
|
-
export const warningText: string;
|
|
21
|
-
/** @type {string} */
|
|
22
|
-
export const infoText: string;
|
|
23
|
-
/** @type {SpinnerStyle} */
|
|
24
|
-
export const defaultSpinner: SpinnerStyle;
|
|
25
|
-
export type SpinnerStyle = {
|
|
26
|
-
frames: string[];
|
|
27
|
-
interval: number;
|
|
28
|
-
};
|
package/build/icons/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./icons.js";
|
package/build/logger/index.d.ts
DELETED
package/build/spinner/index.d.ts
DELETED
package/build/theme/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./theme.js";
|
package/build/theme/theme.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a green-colored success message prefixed with an icon.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} str The success message to format.
|
|
5
|
-
* @param {boolean} [showIcon] Whether to show the icon. Defaults to `false`.
|
|
6
|
-
* @returns {string} Returns a green-colored success message prefixed with an icon.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* console.log(complete('Operation successful.'));
|
|
10
|
-
* // Output: (icon?) Operation successful. (displayed in green text in the terminal.)
|
|
11
|
-
*/
|
|
12
|
-
export function success(str: string, showIcon?: boolean): string;
|
|
13
|
-
/**
|
|
14
|
-
* Returns a red-colored error message prefixed with an icon.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} str The error message to format.
|
|
17
|
-
* @param {boolean} [showIcon] Whether to show the icon. Defaults to `false`.
|
|
18
|
-
* @returns {string} Returns a red-colored error message prefixed with an icon.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* console.log(error('Something went wrong.'));
|
|
22
|
-
* // Output: (icon?) Something went wrong. (displayed in red text in the terminal.)
|
|
23
|
-
*/
|
|
24
|
-
export function error(str: string, showIcon?: boolean): string;
|
|
25
|
-
/**
|
|
26
|
-
* Returns a yellow-colored warning message prefixed with an icon.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} str The warning message to format.
|
|
29
|
-
* @param {boolean} [showIcon] Whether to show the icon. Defaults to `false`.
|
|
30
|
-
* @returns {string} Returns a yellow-colored warning message prefixed with an icon.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* console.log(warning('This is a warning.'));
|
|
34
|
-
* // Output: (icon?) This is a warning. (displayed in yellow text in the terminal.)
|
|
35
|
-
*/
|
|
36
|
-
export function warning(str: string, showIcon?: boolean): string;
|
|
37
|
-
/**
|
|
38
|
-
* Returns a blue-colored info message prefixed with an icon.
|
|
39
|
-
*
|
|
40
|
-
* @param {string} str The info message to format.
|
|
41
|
-
* @param {boolean} [showIcon] Whether to show the icon. Defaults to `false`.
|
|
42
|
-
* @returns {string} Returns a blue-colored info message prefixed with an icon.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* console.log(info('Informational message.'));
|
|
46
|
-
* // Output: (icon?) Informational message. (displayed in blue text in the terminal.)
|
|
47
|
-
*/
|
|
48
|
-
export function info(str: string, showIcon?: boolean): string;
|
|
49
|
-
/**
|
|
50
|
-
* Returns a yellow-colored error message prefixed with an icon.
|
|
51
|
-
*
|
|
52
|
-
* @param {string} str The bananass message to format.
|
|
53
|
-
* @param {boolean} [showIcon] Whether to show the icon. Defaults to `false`.
|
|
54
|
-
* @returns Returns a yellow-colored error message prefixed with an icon.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* console.log(bananass('Hello, Bananass.'));
|
|
58
|
-
* // Output: (icon?) Hello, Bananass. (displayed in yellow text in the terminal.)
|
|
59
|
-
*/
|
|
60
|
-
export function bananass(str: string, showIcon?: boolean): string;
|
package/src/icons/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './icons.js';
|
package/src/logger/index.js
DELETED
package/src/logger/logger.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Console logger.
|
|
3
|
-
* @module bananass-utils-console/logger
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// --------------------------------------------------------------------------------
|
|
7
|
-
// Import
|
|
8
|
-
// --------------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
import { styleText } from 'node:util';
|
|
11
|
-
|
|
12
|
-
// --------------------------------------------------------------------------------
|
|
13
|
-
// Typedefs
|
|
14
|
-
// --------------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {object} Options Logger options.
|
|
18
|
-
* @property {boolean | undefined} [debug] Enable debug mode.
|
|
19
|
-
* @property {boolean | undefined} [quiet] Enable quiet mode.
|
|
20
|
-
* @property {string | boolean | undefined} [textPrefix] Text prefix.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
// --------------------------------------------------------------------------------
|
|
24
|
-
// Class
|
|
25
|
-
// --------------------------------------------------------------------------------
|
|
26
|
-
|
|
27
|
-
class Logger {
|
|
28
|
-
// ------------------------------------------------------------------------------
|
|
29
|
-
// Private Properties
|
|
30
|
-
// ------------------------------------------------------------------------------
|
|
31
|
-
|
|
32
|
-
/** @type {boolean} */
|
|
33
|
-
#debug;
|
|
34
|
-
/** @type {boolean} */
|
|
35
|
-
#quiet;
|
|
36
|
-
/** @type {string | symbol} */
|
|
37
|
-
#textPrefix;
|
|
38
|
-
/** @type {string} */
|
|
39
|
-
#textPrefixDefault = '>';
|
|
40
|
-
/** @type {'log' | 'debug'} */
|
|
41
|
-
#lastMethodCalled = 'log';
|
|
42
|
-
/** @type {symbol} */
|
|
43
|
-
#undeclaredValue = Symbol('undeclared-value');
|
|
44
|
-
|
|
45
|
-
/** @param {Options} options */
|
|
46
|
-
constructor(options = {}) {
|
|
47
|
-
this.#debug = options.debug ?? false;
|
|
48
|
-
this.#quiet = options.quiet ?? false;
|
|
49
|
-
this.#textPrefix =
|
|
50
|
-
typeof options.textPrefix === 'boolean'
|
|
51
|
-
? options.textPrefix
|
|
52
|
-
? this.#textPrefixDefault
|
|
53
|
-
: this.#undeclaredValue
|
|
54
|
-
: (options.textPrefix ?? this.#textPrefixDefault);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// ------------------------------------------------------------------------------
|
|
58
|
-
// Public Methods
|
|
59
|
-
// ------------------------------------------------------------------------------
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Log a message or executes a callback.
|
|
63
|
-
*
|
|
64
|
-
* The first parameter can be a message or a callback function.
|
|
65
|
-
* - If it's a function, it's invoked with subsequent arguments.
|
|
66
|
-
* - Otherwise, the message (with a configured text prefix) and additional arguments are logged.
|
|
67
|
-
*
|
|
68
|
-
* Behavior based on `quiet` option:
|
|
69
|
-
* - `quiet === true`: output X
|
|
70
|
-
* - `quiet === false`: output O
|
|
71
|
-
*
|
|
72
|
-
* @param {...unknown} params
|
|
73
|
-
* @returns {Logger}
|
|
74
|
-
*/
|
|
75
|
-
log(...params) {
|
|
76
|
-
const textOrCallback =
|
|
77
|
-
typeof params[0] !== 'undefined' // Same with default parameter implemetation using `arguments`
|
|
78
|
-
? params[0]
|
|
79
|
-
: params.length > 0
|
|
80
|
-
? undefined
|
|
81
|
-
: this.#undeclaredValue;
|
|
82
|
-
const args = params.slice(1);
|
|
83
|
-
|
|
84
|
-
this.#lastMethodCalled = 'log';
|
|
85
|
-
|
|
86
|
-
if (this.#quiet) return this;
|
|
87
|
-
|
|
88
|
-
if (typeof textOrCallback === 'function') {
|
|
89
|
-
textOrCallback(...args);
|
|
90
|
-
} else {
|
|
91
|
-
// eslint-disable-next-line no-console -- Needed for logging.
|
|
92
|
-
console.log(
|
|
93
|
-
...[this.#textPrefix, textOrCallback, ...args].filter(
|
|
94
|
-
arg => arg !== this.#undeclaredValue,
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Log a message or executes a callback in debug mode.
|
|
104
|
-
*
|
|
105
|
-
* The first parameter can be a message or a callback function.
|
|
106
|
-
* - If it's a function, it's invoked with subsequent arguments.
|
|
107
|
-
* - Otherwise, the message (with a configured text prefix) and additional arguments are logged in debug mode.
|
|
108
|
-
*
|
|
109
|
-
* Behavior based on `debug` and `quiet` options:
|
|
110
|
-
* - `quiet === true`: output X
|
|
111
|
-
* - `quiet === false && debug === true`: output O
|
|
112
|
-
* - `quiet === false && debug === false`: output X
|
|
113
|
-
*
|
|
114
|
-
* @param {...unknown} params
|
|
115
|
-
* @returns {Logger}
|
|
116
|
-
*/
|
|
117
|
-
debug(...params) {
|
|
118
|
-
const textOrCallback =
|
|
119
|
-
typeof params[0] !== 'undefined'
|
|
120
|
-
? params[0]
|
|
121
|
-
: params.length > 0
|
|
122
|
-
? undefined
|
|
123
|
-
: this.#undeclaredValue;
|
|
124
|
-
const args = params.slice(1);
|
|
125
|
-
|
|
126
|
-
this.#lastMethodCalled = 'debug';
|
|
127
|
-
|
|
128
|
-
if (this.#quiet) return this;
|
|
129
|
-
if (!this.#debug) return this;
|
|
130
|
-
|
|
131
|
-
if (typeof textOrCallback === 'function') {
|
|
132
|
-
textOrCallback(...args);
|
|
133
|
-
} else {
|
|
134
|
-
// eslint-disable-next-line no-console -- Needed for logging.
|
|
135
|
-
console.log(
|
|
136
|
-
...[this.#textPrefix, textOrCallback, ...args]
|
|
137
|
-
.filter(arg => arg !== this.#undeclaredValue)
|
|
138
|
-
.map(arg => (typeof arg === 'string' ? styleText('gray', arg) : arg)),
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Ends the current line by logging an empty line using the last method called.
|
|
147
|
-
*
|
|
148
|
-
* This method temporarily sets the text prefix to an undeclared value,
|
|
149
|
-
* then invokes either `log()` or `debug()` depending on the previously method called.
|
|
150
|
-
* After logging, it restores the original text prefix.
|
|
151
|
-
*
|
|
152
|
-
* @returns {Logger}
|
|
153
|
-
*/
|
|
154
|
-
eol() {
|
|
155
|
-
const prevTextPrefix = this.#textPrefix;
|
|
156
|
-
this.#textPrefix = this.#undeclaredValue;
|
|
157
|
-
|
|
158
|
-
if (this.#lastMethodCalled === 'log') {
|
|
159
|
-
this.log();
|
|
160
|
-
} else {
|
|
161
|
-
this.debug();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
this.#textPrefix = prevTextPrefix;
|
|
165
|
-
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// ------------------------------------------------------------------------------
|
|
170
|
-
// Getters and Setters
|
|
171
|
-
// ------------------------------------------------------------------------------
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Get the last method called.
|
|
175
|
-
* @returns {'log' | 'debug'}
|
|
176
|
-
*/
|
|
177
|
-
get lastMethodCalled() {
|
|
178
|
-
return this.#lastMethodCalled;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// --------------------------------------------------------------------------------
|
|
183
|
-
// Export
|
|
184
|
-
// --------------------------------------------------------------------------------
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Create a new `Logger` instance.
|
|
188
|
-
*
|
|
189
|
-
* @param {Options} [options]
|
|
190
|
-
* @returns {Logger} A new `Logger` instance.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* import createLogger from 'bananass-utils-console/logger';
|
|
194
|
-
*
|
|
195
|
-
* const logger = createLogger({
|
|
196
|
-
* debug: false,
|
|
197
|
-
* quiet: false,
|
|
198
|
-
* textPrefix: '>',
|
|
199
|
-
* })
|
|
200
|
-
*
|
|
201
|
-
* logger
|
|
202
|
-
* .log('Hello, log!');
|
|
203
|
-
* .debug('Hello, debug!');
|
|
204
|
-
* .eol();
|
|
205
|
-
*/
|
|
206
|
-
export default function createLogger(options) {
|
|
207
|
-
return new Logger(options);
|
|
208
|
-
}
|
package/src/spinner/index.js
DELETED