find-bottleneck-perf 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.
- package/README.md +169 -0
- package/index.js +114 -0
- package/package.json +44 -0
- package/src/analyzer.js +432 -0
- package/src/extractor.js +302 -0
- package/src/reporter.js +249 -0
- package/src/thresholds.js +138 -0
- package/src/utils.js +103 -0
package/src/utils.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions and terminal color codes.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// ANSI color codes for terminal output
|
|
6
|
+
const colors = {
|
|
7
|
+
reset: "\x1b[0m",
|
|
8
|
+
bright: "\x1b[1m",
|
|
9
|
+
dim: "\x1b[2m",
|
|
10
|
+
|
|
11
|
+
// Text colors
|
|
12
|
+
red: "\x1b[31m",
|
|
13
|
+
green: "\x1b[32m",
|
|
14
|
+
yellow: "\x1b[33m",
|
|
15
|
+
blue: "\x1b[34m",
|
|
16
|
+
magenta: "\x1b[35m",
|
|
17
|
+
cyan: "\x1b[36m",
|
|
18
|
+
white: "\x1b[37m",
|
|
19
|
+
|
|
20
|
+
// Background colors
|
|
21
|
+
bgRed: "\x1b[41m",
|
|
22
|
+
bgGreen: "\x1b[42m",
|
|
23
|
+
bgYellow: "\x1b[43m",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Colorize text for terminal output.
|
|
28
|
+
* @param {string} text - Text to colorize
|
|
29
|
+
* @param {string} color - Color key from colors object
|
|
30
|
+
* @returns {string} Colorized string
|
|
31
|
+
*/
|
|
32
|
+
function colorize(text, color) {
|
|
33
|
+
return `${colors[color] || ''}${text}${colors.reset}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Format milliseconds for display.
|
|
38
|
+
* @param {number} ms - Milliseconds
|
|
39
|
+
* @returns {string} Formatted string
|
|
40
|
+
*/
|
|
41
|
+
function formatMs(ms) {
|
|
42
|
+
if (ms >= 1000) {
|
|
43
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
44
|
+
}
|
|
45
|
+
return `${Math.round(ms)}ms`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Format bytes to human-readable size.
|
|
50
|
+
* @param {number} bytes - Bytes
|
|
51
|
+
* @returns {string} Formatted string
|
|
52
|
+
*/
|
|
53
|
+
function formatBytes(bytes) {
|
|
54
|
+
if (bytes >= 1024 * 1024) {
|
|
55
|
+
return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
56
|
+
}
|
|
57
|
+
if (bytes >= 1024) {
|
|
58
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
59
|
+
}
|
|
60
|
+
return `${bytes} B`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get status indicator based on value and thresholds.
|
|
65
|
+
* @param {number} value - Metric value
|
|
66
|
+
* @param {object} threshold - Object with GOOD and POOR keys
|
|
67
|
+
* @param {boolean} lowerIsBetter - Default true
|
|
68
|
+
* @returns {string} Colored status indicator
|
|
69
|
+
*/
|
|
70
|
+
function getStatus(value, threshold, lowerIsBetter = true) {
|
|
71
|
+
if (lowerIsBetter) {
|
|
72
|
+
if (value <= threshold.GOOD) return colorize('●', 'green');
|
|
73
|
+
if (value >= threshold.POOR) return colorize('●', 'red');
|
|
74
|
+
return colorize('●', 'yellow');
|
|
75
|
+
} else {
|
|
76
|
+
if (value >= threshold.GOOD) return colorize('●', 'green');
|
|
77
|
+
if (value <= threshold.POOR) return colorize('●', 'red');
|
|
78
|
+
return colorize('●', 'yellow');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Create a simple progress bar.
|
|
84
|
+
* @param {number} value - Current value
|
|
85
|
+
* @param {number} max - Maximum value for scale
|
|
86
|
+
* @param {number} width - Bar width in characters
|
|
87
|
+
* @returns {string} ASCII progress bar
|
|
88
|
+
*/
|
|
89
|
+
function progressBar(value, max, width = 20) {
|
|
90
|
+
const filled = Math.min(Math.round((value / max) * width), width);
|
|
91
|
+
const empty = width - filled;
|
|
92
|
+
const bar = '█'.repeat(filled) + '░'.repeat(empty);
|
|
93
|
+
return bar;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = {
|
|
97
|
+
colors,
|
|
98
|
+
colorize,
|
|
99
|
+
formatMs,
|
|
100
|
+
formatBytes,
|
|
101
|
+
getStatus,
|
|
102
|
+
progressBar,
|
|
103
|
+
};
|