term-sparkline 0.0.0-stage → 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 CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # term-sparkline
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Zero-dependency micro ASCII and Unicode charts, sparklines, progress bars, and heatmap lines for Node.js terminal logs and CLI dashboards.
4
+
5
+ ## Features
6
+
7
+ - **Zero Dependencies**: Pure TypeScript, tiny footprint.
8
+ - **Sparklines**: Renders smooth Unicode block trends (` ▂▃▄▅▆▇█`).
9
+ - **Progress Mini-Bars**: Compact horizontal bar graphs for memory, CPU, or download progress.
10
+ - **KPI Bullet Charts**: Visualizes current value against targets and max thresholds.
11
+ - **Intensity Heatmaps**: Character shade blocks (`░▒▓█`) for latency or traffic density.
12
+ - **ANSI Color Support**: Includes built-in coloring helpers or works with `chalk`.
13
+ - **CLI Ready**: Executable via `npx term-sparkline`.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install term-sparkline
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```typescript
24
+ import { sparkline, miniBar, bulletChart } from 'term-sparkline';
25
+
26
+ // Trend Sparklines
27
+ console.log('Latency:', sparkline([12, 15, 30, 95, 110, 45, 20, 15]));
28
+ // Latency: ▂▃██▄▂
29
+
30
+ // Horizontal Mini-Bars
31
+ console.log('RAM Usage:', miniBar(72, { width: 15 }));
32
+ // RAM Usage: [██████████░░░░░] 72%
33
+
34
+ // Bullet KPI Charts
35
+ console.log('Coverage:', bulletChart(88, 80, { width: 15, max: 100 }));
36
+ // Coverage: [████████████|░░] 88/80 (max 100)
37
+ ```
38
+
39
+ ## CLI Usage
40
+
41
+ ```bash
42
+ npx term-sparkline 10 25 45 90 70 30 15
43
+ ```
44
+
45
+ ## License
46
+
47
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { sparkline, miniBar, heatmapLine } from '../dist/index.js';
4
+
5
+ const args = process.argv.slice(2);
6
+
7
+ if (args.length === 0 || args.includes('-h') || args.includes('--help')) {
8
+ console.log(`
9
+ term-sparkline — Zero-dependency micro ASCII and Unicode charts for terminal
10
+
11
+ Usage:
12
+ npx term-sparkline <numbers...> [options]
13
+
14
+ Examples:
15
+ npx term-sparkline 10 20 45 80 60 30 15
16
+ npx term-sparkline 12,34,56,78,90,45,23 --bar
17
+ npx term-sparkline 75 --progress
18
+
19
+ Options:
20
+ --bar Display as horizontal progress mini-bars
21
+ --heatmap Display as intensity heatmap blocks
22
+ -h, --help Show documentation
23
+ `);
24
+ process.exit(0);
25
+ }
26
+
27
+ // Parse input numbers
28
+ const rawInput = args.filter((a) => !a.startsWith('-')).join(',');
29
+ const numbers = rawInput
30
+ .split(/[\s,]+/)
31
+ .map((s) => parseFloat(s.trim()))
32
+ .filter((n) => !isNaN(n));
33
+
34
+ if (numbers.length === 0) {
35
+ console.error('Please provide at least one valid number.');
36
+ process.exit(1);
37
+ }
38
+
39
+ if (args.includes('--progress')) {
40
+ console.log(miniBar(numbers[0], { width: 25 }));
41
+ } else if (args.includes('--heatmap')) {
42
+ console.log('Heatmap: ', heatmapLine(numbers));
43
+ } else {
44
+ console.log('Sparkline: ', sparkline(numbers));
45
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ // src/colors.ts
4
+ var colors = {
5
+ reset: (text) => `\x1B[0m${text}\x1B[0m`,
6
+ red: (text) => `\x1B[31m${text}\x1B[0m`,
7
+ green: (text) => `\x1B[32m${text}\x1B[0m`,
8
+ yellow: (text) => `\x1B[33m${text}\x1B[0m`,
9
+ blue: (text) => `\x1B[34m${text}\x1B[0m`,
10
+ magenta: (text) => `\x1B[35m${text}\x1B[0m`,
11
+ cyan: (text) => `\x1B[36m${text}\x1B[0m`,
12
+ gray: (text) => `\x1B[90m${text}\x1B[0m`,
13
+ bold: (text) => `\x1B[1m${text}\x1B[0m`,
14
+ dim: (text) => `\x1B[2m${text}\x1B[0m`
15
+ };
16
+
17
+ // src/sparkline.ts
18
+ var SPARK_TICKS = [" ", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
19
+ function sparkline(values, options = {}) {
20
+ if (!Array.isArray(values) || values.length === 0) {
21
+ return "";
22
+ }
23
+ const validValues = values.filter((v) => typeof v === "number" && !isNaN(v));
24
+ if (validValues.length === 0) return "";
25
+ const min = options.min ?? Math.min(...validValues);
26
+ const max = options.max ?? Math.max(...validValues);
27
+ const range = max - min;
28
+ const result = [];
29
+ for (let i = 0; i < values.length; i++) {
30
+ const val = values[i];
31
+ if (typeof val !== "number" || isNaN(val)) {
32
+ result.push(" ");
33
+ continue;
34
+ }
35
+ let tickIndex = 0;
36
+ if (range > 0) {
37
+ const normalized = (val - min) / range;
38
+ tickIndex = Math.min(
39
+ SPARK_TICKS.length - 1,
40
+ Math.max(0, Math.floor(normalized * SPARK_TICKS.length))
41
+ );
42
+ }
43
+ const char = SPARK_TICKS[tickIndex];
44
+ if (options.color) {
45
+ result.push(options.color(char, val, i));
46
+ } else {
47
+ result.push(char);
48
+ }
49
+ }
50
+ return result.join("");
51
+ }
52
+
53
+ // src/bar.ts
54
+ var HEATMAP_SHADES = ["\u2591", "\u2592", "\u2593", "\u2588"];
55
+ function miniBar(value, options = {}) {
56
+ const width = options.width ?? 20;
57
+ const max = options.max ?? 100;
58
+ const min = options.min ?? 0;
59
+ const showPercentage = options.showPercentage ?? true;
60
+ const filledChar = options.filledChar ?? "\u2588";
61
+ const emptyChar = options.emptyChar ?? "\u2591";
62
+ const range = max - min;
63
+ const clamped = Math.min(max, Math.max(min, value));
64
+ const ratio = range > 0 ? (clamped - min) / range : 0;
65
+ const filledCount = Math.round(ratio * width);
66
+ const emptyCount = Math.max(0, width - filledCount);
67
+ const bar = `${filledChar.repeat(filledCount)}${emptyChar.repeat(emptyCount)}`;
68
+ const pct = Math.round(ratio * 100);
69
+ return showPercentage ? `[${bar}] ${pct}%` : `[${bar}]`;
70
+ }
71
+ function bulletChart(current, target, options = {}) {
72
+ const width = options.width ?? 20;
73
+ const min = options.min ?? 0;
74
+ const max = options.max ?? 100;
75
+ const targetMarker = options.targetMarker ?? "|";
76
+ const range = max - min;
77
+ const currentRatio = Math.min(1, Math.max(0, (current - min) / range));
78
+ const targetRatio = Math.min(1, Math.max(0, (target - min) / range));
79
+ const currentIdx = Math.round(currentRatio * (width - 1));
80
+ const targetIdx = Math.round(targetRatio * (width - 1));
81
+ const chars = new Array(width).fill("\u2591");
82
+ for (let i = 0; i <= currentIdx; i++) {
83
+ chars[i] = "\u2588";
84
+ }
85
+ chars[targetIdx] = targetMarker;
86
+ return `[${chars.join("")}] ${current}/${target} (max ${max})`;
87
+ }
88
+ function heatmapLine(values, minVal, maxVal) {
89
+ if (values.length === 0) return "";
90
+ const min = minVal ?? Math.min(...values);
91
+ const max = maxVal ?? Math.max(...values);
92
+ const range = max - min;
93
+ return values.map((v) => {
94
+ if (range === 0) return HEATMAP_SHADES[0];
95
+ const ratio = Math.min(1, Math.max(0, (v - min) / range));
96
+ const idx = Math.min(HEATMAP_SHADES.length - 1, Math.floor(ratio * HEATMAP_SHADES.length));
97
+ return HEATMAP_SHADES[idx];
98
+ }).join("");
99
+ }
100
+
101
+ exports.SPARK_TICKS = SPARK_TICKS;
102
+ exports.bulletChart = bulletChart;
103
+ exports.colors = colors;
104
+ exports.heatmapLine = heatmapLine;
105
+ exports.miniBar = miniBar;
106
+ exports.sparkline = sparkline;
107
+ //# sourceMappingURL=index.cjs.map
108
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/colors.ts","../src/sparkline.ts","../src/bar.ts"],"names":[],"mappings":";;;AAGO,IAAM,MAAA,GAAS;AAAA,EACpB,KAAA,EAAO,CAAC,IAAA,KAAiB,CAAA,OAAA,EAAU,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AK,OAAO,CAAA,CAAA,EAAI,MAAM,CAAA,MAAA,EAAS,GAAG,CAAA,CAAA,CAAA;AAC7D;AAKO,SAAS,WAAA,CAAY,MAAA,EAAkB,MAAA,EAAiB,MAAA,EAAyB;AACtF,EAAA,IAAI,MAAA,CAAO,MAAA,KAAW,CAAA,EAAG,OAAO,EAAA;AAChC,EAAA,MAAM,GAAA,GAAM,MAAA,IAAU,IAAA,CAAK,GAAA,CAAI,GAAG,MAAM,CAAA;AACxC,EAAA,MAAM,GAAA,GAAM,MAAA,IAAU,IAAA,CAAK,GAAA,CAAI,GAAG,MAAM,CAAA;AACxC,EAAA,MAAM,QAAQ,GAAA,GAAM,GAAA;AAEpB,EAAA,OAAO,MAAA,CACJ,GAAA,CAAI,CAAC,CAAA,KAAM;AACV,IAAA,IAAI,KAAA,KAAU,CAAA,EAAG,OAAO,cAAA,CAAe,CAAC,CAAA;AACxC,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,EAAA,CAAI,CAAA,GAAI,GAAA,IAAO,KAAK,CAAC,CAAA;AACxD,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,cAAA,CAAe,MAAA,GAAS,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,cAAA,CAAe,MAAM,CAAC,CAAA;AACzF,IAAA,OAAO,eAAe,GAAG,CAAA;AAAA,EAC3B,CAAC,CAAA,CACA,IAAA,CAAK,EAAE,CAAA;AACZ","file":"index.cjs","sourcesContent":["/**\n * Lightweight, zero-dependency ANSI color utilities\n */\nexport const colors = {\n reset: (text: string) => `\\x1b[0m${text}\\x1b[0m`,\n red: (text: string) => `\\x1b[31m${text}\\x1b[0m`,\n green: (text: string) => `\\x1b[32m${text}\\x1b[0m`,\n yellow: (text: string) => `\\x1b[33m${text}\\x1b[0m`,\n blue: (text: string) => `\\x1b[34m${text}\\x1b[0m`,\n magenta: (text: string) => `\\x1b[35m${text}\\x1b[0m`,\n cyan: (text: string) => `\\x1b[36m${text}\\x1b[0m`,\n gray: (text: string) => `\\x1b[90m${text}\\x1b[0m`,\n bold: (text: string) => `\\x1b[1m${text}\\x1b[0m`,\n dim: (text: string) => `\\x1b[2m${text}\\x1b[0m`,\n};\n","import type { SparklineOptions } from './types.js';\n\nexport const SPARK_TICKS = [' ', '▂', '▃', '▄', '▅', '▆', '▇', '█'];\n\n/**\n * Generates an inline unicode sparkline from an array of numbers\n * @example\n * sparkline([10, 20, 50, 80, 40, 20]) // \" ▂▅█▄▂\"\n */\nexport function sparkline(values: number[], options: SparklineOptions = {}): string {\n if (!Array.isArray(values) || values.length === 0) {\n return '';\n }\n\n const validValues = values.filter((v) => typeof v === 'number' && !isNaN(v));\n if (validValues.length === 0) return '';\n\n const min = options.min ?? Math.min(...validValues);\n const max = options.max ?? Math.max(...validValues);\n const range = max - min;\n\n const result: string[] = [];\n\n for (let i = 0; i < values.length; i++) {\n const val = values[i];\n if (typeof val !== 'number' || isNaN(val)) {\n result.push(' ');\n continue;\n }\n\n let tickIndex = 0;\n if (range > 0) {\n const normalized = (val - min) / range;\n tickIndex = Math.min(\n SPARK_TICKS.length - 1,\n Math.max(0, Math.floor(normalized * SPARK_TICKS.length))\n );\n }\n\n const char = SPARK_TICKS[tickIndex];\n if (options.color) {\n result.push(options.color(char, val, i));\n } else {\n result.push(char);\n }\n }\n\n return result.join('');\n}\n","import type { MiniBarOptions, BulletChartOptions } from './types.js';\n\nconst HEATMAP_SHADES = ['░', '▒', '▓', '█'];\n\n/**\n * Generates a horizontal progress mini-bar\n * @example\n * miniBar(65, { width: 10 }) // \"[██████░░░░] 65%\"\n */\nexport function miniBar(value: number, options: MiniBarOptions = {}): string {\n const width = options.width ?? 20;\n const max = options.max ?? 100;\n const min = options.min ?? 0;\n const showPercentage = options.showPercentage ?? true;\n const filledChar = options.filledChar ?? '█';\n const emptyChar = options.emptyChar ?? '░';\n\n const range = max - min;\n const clamped = Math.min(max, Math.max(min, value));\n const ratio = range > 0 ? (clamped - min) / range : 0;\n\n const filledCount = Math.round(ratio * width);\n const emptyCount = Math.max(0, width - filledCount);\n\n const bar = `${filledChar.repeat(filledCount)}${emptyChar.repeat(emptyCount)}`;\n const pct = Math.round(ratio * 100);\n\n return showPercentage ? `[${bar}] ${pct}%` : `[${bar}]`;\n}\n\n/**\n * Generates a KPI Bullet Chart showing current progress against a target\n */\nexport function bulletChart(\n current: number,\n target: number,\n options: BulletChartOptions = {}\n): string {\n const width = options.width ?? 20;\n const min = options.min ?? 0;\n const max = options.max ?? 100;\n const targetMarker = options.targetMarker ?? '|';\n\n const range = max - min;\n const currentRatio = Math.min(1, Math.max(0, (current - min) / range));\n const targetRatio = Math.min(1, Math.max(0, (target - min) / range));\n\n const currentIdx = Math.round(currentRatio * (width - 1));\n const targetIdx = Math.round(targetRatio * (width - 1));\n\n const chars: string[] = new Array(width).fill('░');\n\n for (let i = 0; i <= currentIdx; i++) {\n chars[i] = '█';\n }\n\n chars[targetIdx] = targetMarker;\n\n return `[${chars.join('')}] ${current}/${target} (max ${max})`;\n}\n\n/**\n * Generates an intensity heatmap line\n */\nexport function heatmapLine(values: number[], minVal?: number, maxVal?: number): string {\n if (values.length === 0) return '';\n const min = minVal ?? Math.min(...values);\n const max = maxVal ?? Math.max(...values);\n const range = max - min;\n\n return values\n .map((v) => {\n if (range === 0) return HEATMAP_SHADES[0];\n const ratio = Math.min(1, Math.max(0, (v - min) / range));\n const idx = Math.min(HEATMAP_SHADES.length - 1, Math.floor(ratio * HEATMAP_SHADES.length));\n return HEATMAP_SHADES[idx];\n })\n .join('');\n}\n"]}
@@ -0,0 +1,73 @@
1
+ interface SparklineOptions {
2
+ /** Minimum value for scale. If omitted, uses Math.min(...numbers) */
3
+ min?: number;
4
+ /** Maximum value for scale. If omitted, uses Math.max(...numbers) */
5
+ max?: number;
6
+ /** Custom colorizer function returning ANSI formatted string for each tick */
7
+ color?: (char: string, val: number, index: number) => string;
8
+ }
9
+ interface MiniBarOptions {
10
+ /** Width of the bar in characters. Default: 20 */
11
+ width?: number;
12
+ /** Maximum value representing 100%. Default: 100 */
13
+ max?: number;
14
+ /** Minimum value representing 0%. Default: 0 */
15
+ min?: number;
16
+ /** Whether to append numeric percentage. Default: true */
17
+ showPercentage?: boolean;
18
+ /** Character used for filled segments. Default: '█' */
19
+ filledChar?: string;
20
+ /** Character used for empty segments. Default: '░' */
21
+ emptyChar?: string;
22
+ }
23
+ interface BulletChartOptions {
24
+ /** Width of the total bar in characters. Default: 20 */
25
+ width?: number;
26
+ /** Maximum upper bound value. Default: 100 */
27
+ max?: number;
28
+ /** Minimum lower bound value. Default: 0 */
29
+ min?: number;
30
+ /** Marker symbol for target value. Default: '|' */
31
+ targetMarker?: string;
32
+ }
33
+
34
+ /**
35
+ * Lightweight, zero-dependency ANSI color utilities
36
+ */
37
+ declare const colors: {
38
+ reset: (text: string) => string;
39
+ red: (text: string) => string;
40
+ green: (text: string) => string;
41
+ yellow: (text: string) => string;
42
+ blue: (text: string) => string;
43
+ magenta: (text: string) => string;
44
+ cyan: (text: string) => string;
45
+ gray: (text: string) => string;
46
+ bold: (text: string) => string;
47
+ dim: (text: string) => string;
48
+ };
49
+
50
+ declare const SPARK_TICKS: string[];
51
+ /**
52
+ * Generates an inline unicode sparkline from an array of numbers
53
+ * @example
54
+ * sparkline([10, 20, 50, 80, 40, 20]) // " ▂▅█▄▂"
55
+ */
56
+ declare function sparkline(values: number[], options?: SparklineOptions): string;
57
+
58
+ /**
59
+ * Generates a horizontal progress mini-bar
60
+ * @example
61
+ * miniBar(65, { width: 10 }) // "[██████░░░░] 65%"
62
+ */
63
+ declare function miniBar(value: number, options?: MiniBarOptions): string;
64
+ /**
65
+ * Generates a KPI Bullet Chart showing current progress against a target
66
+ */
67
+ declare function bulletChart(current: number, target: number, options?: BulletChartOptions): string;
68
+ /**
69
+ * Generates an intensity heatmap line
70
+ */
71
+ declare function heatmapLine(values: number[], minVal?: number, maxVal?: number): string;
72
+
73
+ export { type BulletChartOptions, type MiniBarOptions, SPARK_TICKS, type SparklineOptions, bulletChart, colors, heatmapLine, miniBar, sparkline };
@@ -0,0 +1,73 @@
1
+ interface SparklineOptions {
2
+ /** Minimum value for scale. If omitted, uses Math.min(...numbers) */
3
+ min?: number;
4
+ /** Maximum value for scale. If omitted, uses Math.max(...numbers) */
5
+ max?: number;
6
+ /** Custom colorizer function returning ANSI formatted string for each tick */
7
+ color?: (char: string, val: number, index: number) => string;
8
+ }
9
+ interface MiniBarOptions {
10
+ /** Width of the bar in characters. Default: 20 */
11
+ width?: number;
12
+ /** Maximum value representing 100%. Default: 100 */
13
+ max?: number;
14
+ /** Minimum value representing 0%. Default: 0 */
15
+ min?: number;
16
+ /** Whether to append numeric percentage. Default: true */
17
+ showPercentage?: boolean;
18
+ /** Character used for filled segments. Default: '█' */
19
+ filledChar?: string;
20
+ /** Character used for empty segments. Default: '░' */
21
+ emptyChar?: string;
22
+ }
23
+ interface BulletChartOptions {
24
+ /** Width of the total bar in characters. Default: 20 */
25
+ width?: number;
26
+ /** Maximum upper bound value. Default: 100 */
27
+ max?: number;
28
+ /** Minimum lower bound value. Default: 0 */
29
+ min?: number;
30
+ /** Marker symbol for target value. Default: '|' */
31
+ targetMarker?: string;
32
+ }
33
+
34
+ /**
35
+ * Lightweight, zero-dependency ANSI color utilities
36
+ */
37
+ declare const colors: {
38
+ reset: (text: string) => string;
39
+ red: (text: string) => string;
40
+ green: (text: string) => string;
41
+ yellow: (text: string) => string;
42
+ blue: (text: string) => string;
43
+ magenta: (text: string) => string;
44
+ cyan: (text: string) => string;
45
+ gray: (text: string) => string;
46
+ bold: (text: string) => string;
47
+ dim: (text: string) => string;
48
+ };
49
+
50
+ declare const SPARK_TICKS: string[];
51
+ /**
52
+ * Generates an inline unicode sparkline from an array of numbers
53
+ * @example
54
+ * sparkline([10, 20, 50, 80, 40, 20]) // " ▂▅█▄▂"
55
+ */
56
+ declare function sparkline(values: number[], options?: SparklineOptions): string;
57
+
58
+ /**
59
+ * Generates a horizontal progress mini-bar
60
+ * @example
61
+ * miniBar(65, { width: 10 }) // "[██████░░░░] 65%"
62
+ */
63
+ declare function miniBar(value: number, options?: MiniBarOptions): string;
64
+ /**
65
+ * Generates a KPI Bullet Chart showing current progress against a target
66
+ */
67
+ declare function bulletChart(current: number, target: number, options?: BulletChartOptions): string;
68
+ /**
69
+ * Generates an intensity heatmap line
70
+ */
71
+ declare function heatmapLine(values: number[], minVal?: number, maxVal?: number): string;
72
+
73
+ export { type BulletChartOptions, type MiniBarOptions, SPARK_TICKS, type SparklineOptions, bulletChart, colors, heatmapLine, miniBar, sparkline };
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ // src/colors.ts
2
+ var colors = {
3
+ reset: (text) => `\x1B[0m${text}\x1B[0m`,
4
+ red: (text) => `\x1B[31m${text}\x1B[0m`,
5
+ green: (text) => `\x1B[32m${text}\x1B[0m`,
6
+ yellow: (text) => `\x1B[33m${text}\x1B[0m`,
7
+ blue: (text) => `\x1B[34m${text}\x1B[0m`,
8
+ magenta: (text) => `\x1B[35m${text}\x1B[0m`,
9
+ cyan: (text) => `\x1B[36m${text}\x1B[0m`,
10
+ gray: (text) => `\x1B[90m${text}\x1B[0m`,
11
+ bold: (text) => `\x1B[1m${text}\x1B[0m`,
12
+ dim: (text) => `\x1B[2m${text}\x1B[0m`
13
+ };
14
+
15
+ // src/sparkline.ts
16
+ var SPARK_TICKS = [" ", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
17
+ function sparkline(values, options = {}) {
18
+ if (!Array.isArray(values) || values.length === 0) {
19
+ return "";
20
+ }
21
+ const validValues = values.filter((v) => typeof v === "number" && !isNaN(v));
22
+ if (validValues.length === 0) return "";
23
+ const min = options.min ?? Math.min(...validValues);
24
+ const max = options.max ?? Math.max(...validValues);
25
+ const range = max - min;
26
+ const result = [];
27
+ for (let i = 0; i < values.length; i++) {
28
+ const val = values[i];
29
+ if (typeof val !== "number" || isNaN(val)) {
30
+ result.push(" ");
31
+ continue;
32
+ }
33
+ let tickIndex = 0;
34
+ if (range > 0) {
35
+ const normalized = (val - min) / range;
36
+ tickIndex = Math.min(
37
+ SPARK_TICKS.length - 1,
38
+ Math.max(0, Math.floor(normalized * SPARK_TICKS.length))
39
+ );
40
+ }
41
+ const char = SPARK_TICKS[tickIndex];
42
+ if (options.color) {
43
+ result.push(options.color(char, val, i));
44
+ } else {
45
+ result.push(char);
46
+ }
47
+ }
48
+ return result.join("");
49
+ }
50
+
51
+ // src/bar.ts
52
+ var HEATMAP_SHADES = ["\u2591", "\u2592", "\u2593", "\u2588"];
53
+ function miniBar(value, options = {}) {
54
+ const width = options.width ?? 20;
55
+ const max = options.max ?? 100;
56
+ const min = options.min ?? 0;
57
+ const showPercentage = options.showPercentage ?? true;
58
+ const filledChar = options.filledChar ?? "\u2588";
59
+ const emptyChar = options.emptyChar ?? "\u2591";
60
+ const range = max - min;
61
+ const clamped = Math.min(max, Math.max(min, value));
62
+ const ratio = range > 0 ? (clamped - min) / range : 0;
63
+ const filledCount = Math.round(ratio * width);
64
+ const emptyCount = Math.max(0, width - filledCount);
65
+ const bar = `${filledChar.repeat(filledCount)}${emptyChar.repeat(emptyCount)}`;
66
+ const pct = Math.round(ratio * 100);
67
+ return showPercentage ? `[${bar}] ${pct}%` : `[${bar}]`;
68
+ }
69
+ function bulletChart(current, target, options = {}) {
70
+ const width = options.width ?? 20;
71
+ const min = options.min ?? 0;
72
+ const max = options.max ?? 100;
73
+ const targetMarker = options.targetMarker ?? "|";
74
+ const range = max - min;
75
+ const currentRatio = Math.min(1, Math.max(0, (current - min) / range));
76
+ const targetRatio = Math.min(1, Math.max(0, (target - min) / range));
77
+ const currentIdx = Math.round(currentRatio * (width - 1));
78
+ const targetIdx = Math.round(targetRatio * (width - 1));
79
+ const chars = new Array(width).fill("\u2591");
80
+ for (let i = 0; i <= currentIdx; i++) {
81
+ chars[i] = "\u2588";
82
+ }
83
+ chars[targetIdx] = targetMarker;
84
+ return `[${chars.join("")}] ${current}/${target} (max ${max})`;
85
+ }
86
+ function heatmapLine(values, minVal, maxVal) {
87
+ if (values.length === 0) return "";
88
+ const min = minVal ?? Math.min(...values);
89
+ const max = maxVal ?? Math.max(...values);
90
+ const range = max - min;
91
+ return values.map((v) => {
92
+ if (range === 0) return HEATMAP_SHADES[0];
93
+ const ratio = Math.min(1, Math.max(0, (v - min) / range));
94
+ const idx = Math.min(HEATMAP_SHADES.length - 1, Math.floor(ratio * HEATMAP_SHADES.length));
95
+ return HEATMAP_SHADES[idx];
96
+ }).join("");
97
+ }
98
+
99
+ export { SPARK_TICKS, bulletChart, colors, heatmapLine, miniBar, sparkline };
100
+ //# sourceMappingURL=index.js.map
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/colors.ts","../src/sparkline.ts","../src/bar.ts"],"names":[],"mappings":";AAGO,IAAM,MAAA,GAAS;AAAA,EACpB,KAAA,EAAO,CAAC,IAAA,KAAiB,CAAA,OAAA,EAAU,IAAI,CAAA,OAAA,CAAA;AAAA,EACvC,GAAA,EAAK,CAAC,IAAA,KAAiB,CAAA,QAAA,EAAW,IAAI,CAAA,OAAA,CAAA;AAAA,EACtC,KAAA,EAAO,CAAC,IAAA,KAAiB,CAAA,QAAA,EAAW,IAAI,CAAA,OAAA,CAAA;AAAA,EACxC,MAAA,EAAQ,CAAC,IAAA,KAAiB,CAAA,QAAA,EAAW,IAAI,CAAA,OAAA,CAAA;AAAA,EACzC,IAAA,EAAM,CAAC,IAAA,KAAiB,CAAA,QAAA,EAAW,IAAI,CAAA,OAAA,CAAA;AAAA,EACvC,OAAA,EAAS,CAAC,IAAA,KAAiB,CAAA,QAAA,EAAW,IAAI,CAAA,OAAA,CAAA;AAAA,EAC1C,IAAA,EAAM,CAAC,IAAA,KAAiB,CAAA,QAAA,EAAW,IAAI,CAAA,OAAA,CAAA;AAAA,EACvC,IAAA,EAAM,CAAC,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MAAM,KAAA,GAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,EAAA,CAAI,CAAA,GAAI,GAAA,IAAO,KAAK,CAAC,CAAA;AACxD,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,cAAA,CAAe,MAAA,GAAS,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,cAAA,CAAe,MAAM,CAAC,CAAA;AACzF,IAAA,OAAO,eAAe,GAAG,CAAA;AAAA,EAC3B,CAAC,CAAA,CACA,IAAA,CAAK,EAAE,CAAA;AACZ","file":"index.js","sourcesContent":["/**\n * Lightweight, zero-dependency ANSI color utilities\n */\nexport const colors = {\n reset: (text: string) => `\\x1b[0m${text}\\x1b[0m`,\n red: (text: string) => `\\x1b[31m${text}\\x1b[0m`,\n green: (text: string) => `\\x1b[32m${text}\\x1b[0m`,\n yellow: (text: string) => `\\x1b[33m${text}\\x1b[0m`,\n blue: (text: string) => `\\x1b[34m${text}\\x1b[0m`,\n magenta: (text: string) => `\\x1b[35m${text}\\x1b[0m`,\n cyan: (text: string) => `\\x1b[36m${text}\\x1b[0m`,\n gray: (text: string) => `\\x1b[90m${text}\\x1b[0m`,\n bold: (text: string) => `\\x1b[1m${text}\\x1b[0m`,\n dim: (text: string) => `\\x1b[2m${text}\\x1b[0m`,\n};\n","import type { SparklineOptions } from './types.js';\n\nexport const SPARK_TICKS = [' ', '▂', '▃', '▄', '▅', '▆', '▇', '█'];\n\n/**\n * Generates an inline unicode sparkline from an array of numbers\n * @example\n * sparkline([10, 20, 50, 80, 40, 20]) // \" ▂▅█▄▂\"\n */\nexport function sparkline(values: number[], options: SparklineOptions = {}): string {\n if (!Array.isArray(values) || values.length === 0) {\n return '';\n }\n\n const validValues = values.filter((v) => typeof v === 'number' && !isNaN(v));\n if (validValues.length === 0) return '';\n\n const min = options.min ?? Math.min(...validValues);\n const max = options.max ?? Math.max(...validValues);\n const range = max - min;\n\n const result: string[] = [];\n\n for (let i = 0; i < values.length; i++) {\n const val = values[i];\n if (typeof val !== 'number' || isNaN(val)) {\n result.push(' ');\n continue;\n }\n\n let tickIndex = 0;\n if (range > 0) {\n const normalized = (val - min) / range;\n tickIndex = Math.min(\n SPARK_TICKS.length - 1,\n Math.max(0, Math.floor(normalized * SPARK_TICKS.length))\n );\n }\n\n const char = SPARK_TICKS[tickIndex];\n if (options.color) {\n result.push(options.color(char, val, i));\n } else {\n result.push(char);\n }\n }\n\n return result.join('');\n}\n","import type { MiniBarOptions, BulletChartOptions } from './types.js';\n\nconst HEATMAP_SHADES = ['░', '▒', '▓', '█'];\n\n/**\n * Generates a horizontal progress mini-bar\n * @example\n * miniBar(65, { width: 10 }) // \"[██████░░░░] 65%\"\n */\nexport function miniBar(value: number, options: MiniBarOptions = {}): string {\n const width = options.width ?? 20;\n const max = options.max ?? 100;\n const min = options.min ?? 0;\n const showPercentage = options.showPercentage ?? true;\n const filledChar = options.filledChar ?? '█';\n const emptyChar = options.emptyChar ?? '░';\n\n const range = max - min;\n const clamped = Math.min(max, Math.max(min, value));\n const ratio = range > 0 ? (clamped - min) / range : 0;\n\n const filledCount = Math.round(ratio * width);\n const emptyCount = Math.max(0, width - filledCount);\n\n const bar = `${filledChar.repeat(filledCount)}${emptyChar.repeat(emptyCount)}`;\n const pct = Math.round(ratio * 100);\n\n return showPercentage ? `[${bar}] ${pct}%` : `[${bar}]`;\n}\n\n/**\n * Generates a KPI Bullet Chart showing current progress against a target\n */\nexport function bulletChart(\n current: number,\n target: number,\n options: BulletChartOptions = {}\n): string {\n const width = options.width ?? 20;\n const min = options.min ?? 0;\n const max = options.max ?? 100;\n const targetMarker = options.targetMarker ?? '|';\n\n const range = max - min;\n const currentRatio = Math.min(1, Math.max(0, (current - min) / range));\n const targetRatio = Math.min(1, Math.max(0, (target - min) / range));\n\n const currentIdx = Math.round(currentRatio * (width - 1));\n const targetIdx = Math.round(targetRatio * (width - 1));\n\n const chars: string[] = new Array(width).fill('░');\n\n for (let i = 0; i <= currentIdx; i++) {\n chars[i] = '█';\n }\n\n chars[targetIdx] = targetMarker;\n\n return `[${chars.join('')}] ${current}/${target} (max ${max})`;\n}\n\n/**\n * Generates an intensity heatmap line\n */\nexport function heatmapLine(values: number[], minVal?: number, maxVal?: number): string {\n if (values.length === 0) return '';\n const min = minVal ?? Math.min(...values);\n const max = maxVal ?? Math.max(...values);\n const range = max - min;\n\n return values\n .map((v) => {\n if (range === 0) return HEATMAP_SHADES[0];\n const ratio = Math.min(1, Math.max(0, (v - min) / range));\n const idx = Math.min(HEATMAP_SHADES.length - 1, Math.floor(ratio * HEATMAP_SHADES.length));\n return HEATMAP_SHADES[idx];\n })\n .join('');\n}\n"]}
@@ -0,0 +1,34 @@
1
+ import { sparkline, miniBar, bulletChart, heatmapLine, colors } from '../dist/index.js';
2
+
3
+ console.log('\n========================================');
4
+ console.log(' 📊 TERM-SPARKLINE LIVE DEMO');
5
+ console.log('========================================\n');
6
+
7
+ // 1. Sparklines for response times & traffic
8
+ console.log('--- 1. Service Latency Sparklines ---');
9
+ const pingTimes = [12, 14, 18, 25, 95, 120, 45, 22, 15, 12, 11];
10
+ console.log('API Latency Trend (ms):', sparkline(pingTimes));
11
+
12
+ // Colored sparkline (red for high latency, green for normal)
13
+ const coloredLine = sparkline(pingTimes, {
14
+ color: (char, val) => (val > 80 ? colors.red(char) : val > 30 ? colors.yellow(char) : colors.green(char)),
15
+ });
16
+ console.log('Colored Latency Alert: ', coloredLine);
17
+
18
+ // 2. Resource Usage Mini-Bars
19
+ console.log('\n--- 2. Resource Usage Mini-Bars ---');
20
+ console.log('CPU Usage: ', miniBar(42, { width: 20 }));
21
+ console.log('Memory Usage: ', miniBar(88, { width: 20 }));
22
+ console.log('Disk IO: ', miniBar(15, { width: 20 }));
23
+
24
+ // 3. Bullet Charts for KPI Metrics
25
+ console.log('\n--- 3. KPI Bullet Charts ---');
26
+ console.log('Sales Goal: ', bulletChart(7800, 9000, { width: 15, max: 10000 }));
27
+ console.log('Test Coverage:', bulletChart(85, 80, { width: 15, max: 100 }));
28
+
29
+ // 4. Activity Heatmap
30
+ console.log('\n--- 4. Weekly Server Load Heatmap ---');
31
+ const hourlyLoad = [10, 20, 15, 30, 60, 95, 100, 80, 50, 40, 25, 15];
32
+ console.log('Load Heatmap: ', heatmapLine(hourlyLoad));
33
+
34
+ console.log('\n✅ Demo completed successfully!\n');
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "term-sparkline",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "Zero-dependency micro ASCII and Unicode sparklines, mini-bars, and terminal charts for Node.js logs and CLIs",
6
+ "bin": {
7
+ "term-sparkline": "bin/cli.js"
8
+ },
9
+ "main": "./dist/index.cjs",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "bin",
22
+ "src",
23
+ "examples",
24
+ "test",
25
+ "README.md"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "test": "node --test --experimental-strip-types test/index.test.ts",
30
+ "demo": "node examples/demo.js",
31
+ "prepublishOnly": "npm run build && npm test"
32
+ },
33
+ "keywords": [
34
+ "sparkline",
35
+ "terminal",
36
+ "chart",
37
+ "ascii",
38
+ "unicode",
39
+ "cli",
40
+ "console",
41
+ "logging",
42
+ "metrics",
43
+ "dashboard"
44
+ ],
45
+ "author": "Anish Choudhary",
46
+ "license": "MIT",
47
+ "engines": {
48
+ "node": ">=18.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.10.2",
52
+ "tsup": "^8.3.5",
53
+ "typescript": "^5.7.3"
54
+ }
55
+ }
package/src/bar.ts ADDED
@@ -0,0 +1,79 @@
1
+ import type { MiniBarOptions, BulletChartOptions } from './types.js';
2
+
3
+ const HEATMAP_SHADES = ['░', '▒', '▓', '█'];
4
+
5
+ /**
6
+ * Generates a horizontal progress mini-bar
7
+ * @example
8
+ * miniBar(65, { width: 10 }) // "[██████░░░░] 65%"
9
+ */
10
+ export function miniBar(value: number, options: MiniBarOptions = {}): string {
11
+ const width = options.width ?? 20;
12
+ const max = options.max ?? 100;
13
+ const min = options.min ?? 0;
14
+ const showPercentage = options.showPercentage ?? true;
15
+ const filledChar = options.filledChar ?? '█';
16
+ const emptyChar = options.emptyChar ?? '░';
17
+
18
+ const range = max - min;
19
+ const clamped = Math.min(max, Math.max(min, value));
20
+ const ratio = range > 0 ? (clamped - min) / range : 0;
21
+
22
+ const filledCount = Math.round(ratio * width);
23
+ const emptyCount = Math.max(0, width - filledCount);
24
+
25
+ const bar = `${filledChar.repeat(filledCount)}${emptyChar.repeat(emptyCount)}`;
26
+ const pct = Math.round(ratio * 100);
27
+
28
+ return showPercentage ? `[${bar}] ${pct}%` : `[${bar}]`;
29
+ }
30
+
31
+ /**
32
+ * Generates a KPI Bullet Chart showing current progress against a target
33
+ */
34
+ export function bulletChart(
35
+ current: number,
36
+ target: number,
37
+ options: BulletChartOptions = {}
38
+ ): string {
39
+ const width = options.width ?? 20;
40
+ const min = options.min ?? 0;
41
+ const max = options.max ?? 100;
42
+ const targetMarker = options.targetMarker ?? '|';
43
+
44
+ const range = max - min;
45
+ const currentRatio = Math.min(1, Math.max(0, (current - min) / range));
46
+ const targetRatio = Math.min(1, Math.max(0, (target - min) / range));
47
+
48
+ const currentIdx = Math.round(currentRatio * (width - 1));
49
+ const targetIdx = Math.round(targetRatio * (width - 1));
50
+
51
+ const chars: string[] = new Array(width).fill('░');
52
+
53
+ for (let i = 0; i <= currentIdx; i++) {
54
+ chars[i] = '█';
55
+ }
56
+
57
+ chars[targetIdx] = targetMarker;
58
+
59
+ return `[${chars.join('')}] ${current}/${target} (max ${max})`;
60
+ }
61
+
62
+ /**
63
+ * Generates an intensity heatmap line
64
+ */
65
+ export function heatmapLine(values: number[], minVal?: number, maxVal?: number): string {
66
+ if (values.length === 0) return '';
67
+ const min = minVal ?? Math.min(...values);
68
+ const max = maxVal ?? Math.max(...values);
69
+ const range = max - min;
70
+
71
+ return values
72
+ .map((v) => {
73
+ if (range === 0) return HEATMAP_SHADES[0];
74
+ const ratio = Math.min(1, Math.max(0, (v - min) / range));
75
+ const idx = Math.min(HEATMAP_SHADES.length - 1, Math.floor(ratio * HEATMAP_SHADES.length));
76
+ return HEATMAP_SHADES[idx];
77
+ })
78
+ .join('');
79
+ }
package/src/colors.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Lightweight, zero-dependency ANSI color utilities
3
+ */
4
+ export const colors = {
5
+ reset: (text: string) => `\x1b[0m${text}\x1b[0m`,
6
+ red: (text: string) => `\x1b[31m${text}\x1b[0m`,
7
+ green: (text: string) => `\x1b[32m${text}\x1b[0m`,
8
+ yellow: (text: string) => `\x1b[33m${text}\x1b[0m`,
9
+ blue: (text: string) => `\x1b[34m${text}\x1b[0m`,
10
+ magenta: (text: string) => `\x1b[35m${text}\x1b[0m`,
11
+ cyan: (text: string) => `\x1b[36m${text}\x1b[0m`,
12
+ gray: (text: string) => `\x1b[90m${text}\x1b[0m`,
13
+ bold: (text: string) => `\x1b[1m${text}\x1b[0m`,
14
+ dim: (text: string) => `\x1b[2m${text}\x1b[0m`,
15
+ };
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './types.js';
2
+ export * from './colors.js';
3
+ export * from './sparkline.js';
4
+ export * from './bar.js';
@@ -0,0 +1,49 @@
1
+ import type { SparklineOptions } from './types.js';
2
+
3
+ export const SPARK_TICKS = [' ', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
4
+
5
+ /**
6
+ * Generates an inline unicode sparkline from an array of numbers
7
+ * @example
8
+ * sparkline([10, 20, 50, 80, 40, 20]) // " ▂▅█▄▂"
9
+ */
10
+ export function sparkline(values: number[], options: SparklineOptions = {}): string {
11
+ if (!Array.isArray(values) || values.length === 0) {
12
+ return '';
13
+ }
14
+
15
+ const validValues = values.filter((v) => typeof v === 'number' && !isNaN(v));
16
+ if (validValues.length === 0) return '';
17
+
18
+ const min = options.min ?? Math.min(...validValues);
19
+ const max = options.max ?? Math.max(...validValues);
20
+ const range = max - min;
21
+
22
+ const result: string[] = [];
23
+
24
+ for (let i = 0; i < values.length; i++) {
25
+ const val = values[i];
26
+ if (typeof val !== 'number' || isNaN(val)) {
27
+ result.push(' ');
28
+ continue;
29
+ }
30
+
31
+ let tickIndex = 0;
32
+ if (range > 0) {
33
+ const normalized = (val - min) / range;
34
+ tickIndex = Math.min(
35
+ SPARK_TICKS.length - 1,
36
+ Math.max(0, Math.floor(normalized * SPARK_TICKS.length))
37
+ );
38
+ }
39
+
40
+ const char = SPARK_TICKS[tickIndex];
41
+ if (options.color) {
42
+ result.push(options.color(char, val, i));
43
+ } else {
44
+ result.push(char);
45
+ }
46
+ }
47
+
48
+ return result.join('');
49
+ }
package/src/types.ts ADDED
@@ -0,0 +1,34 @@
1
+ export interface SparklineOptions {
2
+ /** Minimum value for scale. If omitted, uses Math.min(...numbers) */
3
+ min?: number;
4
+ /** Maximum value for scale. If omitted, uses Math.max(...numbers) */
5
+ max?: number;
6
+ /** Custom colorizer function returning ANSI formatted string for each tick */
7
+ color?: (char: string, val: number, index: number) => string;
8
+ }
9
+
10
+ export interface MiniBarOptions {
11
+ /** Width of the bar in characters. Default: 20 */
12
+ width?: number;
13
+ /** Maximum value representing 100%. Default: 100 */
14
+ max?: number;
15
+ /** Minimum value representing 0%. Default: 0 */
16
+ min?: number;
17
+ /** Whether to append numeric percentage. Default: true */
18
+ showPercentage?: boolean;
19
+ /** Character used for filled segments. Default: '█' */
20
+ filledChar?: string;
21
+ /** Character used for empty segments. Default: '░' */
22
+ emptyChar?: string;
23
+ }
24
+
25
+ export interface BulletChartOptions {
26
+ /** Width of the total bar in characters. Default: 20 */
27
+ width?: number;
28
+ /** Maximum upper bound value. Default: 100 */
29
+ max?: number;
30
+ /** Minimum lower bound value. Default: 0 */
31
+ min?: number;
32
+ /** Marker symbol for target value. Default: '|' */
33
+ targetMarker?: string;
34
+ }
@@ -0,0 +1,39 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { sparkline, miniBar, bulletChart, heatmapLine } from '../dist/index.js';
4
+
5
+ test('sparkline generates unicode sparkline correctly', () => {
6
+ const line = sparkline([0, 50, 100]);
7
+ assert.equal(line.length, 3);
8
+ assert.equal(line[0], ' ');
9
+ assert.equal(line[line.length - 1], '█');
10
+ });
11
+
12
+ test('sparkline handles flat constant data', () => {
13
+ const line = sparkline([10, 10, 10, 10]);
14
+ assert.equal(line, ' ');
15
+ });
16
+
17
+ test('miniBar renders bounded progress with percentage', () => {
18
+ const bar = miniBar(50, { width: 10 });
19
+ assert.equal(bar, '[█████░░░░░] 50%');
20
+
21
+ const full = miniBar(100, { width: 5 });
22
+ assert.equal(full, '[█████] 100%');
23
+
24
+ const empty = miniBar(0, { width: 5, showPercentage: false });
25
+ assert.equal(empty, '[░░░░░]');
26
+ });
27
+
28
+ test('bulletChart includes current value and target indicator', () => {
29
+ const bullet = bulletChart(70, 90, { width: 10, max: 100 });
30
+ assert.ok(bullet.includes('|'));
31
+ assert.ok(bullet.includes('70/90'));
32
+ });
33
+
34
+ test('heatmapLine converts intensity to unicode block shades', () => {
35
+ const heat = heatmapLine([0, 33, 66, 100]);
36
+ assert.equal(heat.length, 4);
37
+ assert.equal(heat[0], '░');
38
+ assert.equal(heat[3], '█');
39
+ });