simple-ascii-chart-cli 1.0.0 → 1.1.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 +96 -970
- package/dist/cli.js +58 -17
- package/dist/tests/cli.test.d.ts +1 -0
- package/dist/tests/cli.test.js +38 -0
- package/dist/tests/validators.test.d.ts +1 -0
- package/dist/tests/validators.test.js +93 -0
- package/dist/validators.d.ts +9 -0
- package/dist/validators.js +157 -0
- package/package.json +21 -32
- package/dist/constants/index.d.ts +0 -19
- package/dist/constants/index.js +0 -22
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -4
- package/dist/services/coords.d.ts +0 -113
- package/dist/services/coords.js +0 -228
- package/dist/services/defaults.d.ts +0 -41
- package/dist/services/defaults.js +0 -119
- package/dist/services/draw.d.ts +0 -83
- package/dist/services/draw.js +0 -183
- package/dist/services/overrides.d.ts +0 -60
- package/dist/services/overrides.js +0 -262
- package/dist/services/plot.d.ts +0 -3
- package/dist/services/plot.js +0 -213
- package/dist/services/settings.d.ts +0 -21
- package/dist/services/settings.js +0 -67
- package/dist/types/index.d.ts +0 -61
- package/dist/types/index.js +0 -2
package/dist/cli.js
CHANGED
|
@@ -38,89 +38,129 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
39
|
};
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
// Import necessary modules and types
|
|
41
42
|
var yargs = __importStar(require("yargs"));
|
|
42
|
-
var
|
|
43
|
+
var simple_ascii_chart_1 = __importDefault(require("simple-ascii-chart"));
|
|
44
|
+
var validators_1 = require("./validators");
|
|
45
|
+
// Define command-line arguments with yargs
|
|
43
46
|
var argv = yargs
|
|
44
47
|
.option('input', {
|
|
45
48
|
alias: 'i',
|
|
46
49
|
type: 'string',
|
|
47
50
|
demandOption: true,
|
|
51
|
+
description: 'Data to be plotted (in JSON format)',
|
|
48
52
|
})
|
|
49
53
|
.option('options', {
|
|
50
54
|
alias: 'o',
|
|
51
55
|
type: 'string',
|
|
52
|
-
description: '
|
|
56
|
+
description: 'Plot settings (in JSON format)',
|
|
53
57
|
})
|
|
54
58
|
.option('height', {
|
|
55
59
|
alias: 'h',
|
|
56
60
|
type: 'number',
|
|
57
|
-
description: 'plot
|
|
61
|
+
description: 'Height of the plot',
|
|
58
62
|
})
|
|
59
63
|
.option('hideXAxis', {
|
|
60
64
|
type: 'boolean',
|
|
61
|
-
description: '
|
|
65
|
+
description: 'Hide the x-axis if set to true',
|
|
62
66
|
})
|
|
63
67
|
.option('hideYAxis', {
|
|
64
68
|
type: 'boolean',
|
|
65
|
-
description: '
|
|
69
|
+
description: 'Hide the y-axis if set to true',
|
|
66
70
|
})
|
|
67
71
|
.option('fillArea', {
|
|
68
72
|
type: 'boolean',
|
|
69
|
-
description: '
|
|
73
|
+
description: 'Fill the plot area if set to true',
|
|
70
74
|
})
|
|
71
75
|
.option('width', {
|
|
72
76
|
alias: 'w',
|
|
73
77
|
type: 'number',
|
|
74
|
-
description: 'plot
|
|
78
|
+
description: 'Width of the plot',
|
|
75
79
|
})
|
|
76
80
|
.option('title', {
|
|
77
81
|
alias: 't',
|
|
78
82
|
type: 'string',
|
|
79
|
-
description: 'plot
|
|
83
|
+
description: 'Title for the plot',
|
|
80
84
|
})
|
|
81
85
|
.option('xLabel', {
|
|
82
86
|
type: 'string',
|
|
83
|
-
description: 'x
|
|
87
|
+
description: 'Label for the x-axis',
|
|
88
|
+
})
|
|
89
|
+
.option('yLabel', {
|
|
90
|
+
type: 'string',
|
|
91
|
+
description: 'Label for the y-axis',
|
|
84
92
|
})
|
|
85
93
|
.option('color', {
|
|
86
94
|
alias: 'c',
|
|
87
95
|
type: 'array',
|
|
88
|
-
description: 'plot
|
|
96
|
+
description: 'Array of colors for plot elements',
|
|
89
97
|
})
|
|
90
98
|
.option('axisCenter', {
|
|
91
99
|
type: 'array',
|
|
92
|
-
description: '
|
|
100
|
+
description: 'Center coordinates for axis alignment',
|
|
93
101
|
})
|
|
94
|
-
.option('
|
|
102
|
+
.option('yRange', {
|
|
103
|
+
type: 'array',
|
|
104
|
+
description: 'Range for the y-axis, formatted as [min, max]',
|
|
105
|
+
})
|
|
106
|
+
.option('showTickLabel', {
|
|
107
|
+
type: 'boolean',
|
|
108
|
+
description: 'Show tick labels on the axis if set to true',
|
|
109
|
+
})
|
|
110
|
+
.option('thresholds', {
|
|
111
|
+
type: 'array',
|
|
112
|
+
description: 'Array of threshold points or lines with optional color',
|
|
113
|
+
})
|
|
114
|
+
.option('legend', {
|
|
115
|
+
type: 'string',
|
|
116
|
+
description: 'Legend settings (position and series labels)',
|
|
117
|
+
})
|
|
118
|
+
.option('formatter', {
|
|
119
|
+
type: 'string',
|
|
120
|
+
description: 'Custom formatter for axis values, as a JavaScript function',
|
|
121
|
+
})
|
|
122
|
+
.option('lineFormatter', {
|
|
123
|
+
type: 'string',
|
|
124
|
+
description: 'Formatter for customizing line appearance, as a JavaScript function',
|
|
125
|
+
})
|
|
126
|
+
.option('symbols', {
|
|
95
127
|
type: 'string',
|
|
96
|
-
description: '
|
|
128
|
+
description: 'Custom symbols for axis, chart, and background',
|
|
97
129
|
}).argv;
|
|
130
|
+
// Helper function to execute code with error handling
|
|
98
131
|
var withError = function (cb) {
|
|
99
132
|
try {
|
|
100
133
|
cb();
|
|
101
134
|
}
|
|
102
135
|
catch (error) {
|
|
136
|
+
// Display an error message and exit the process with a failure code
|
|
103
137
|
process.stderr.write('Oops! Something went wrong!\n');
|
|
104
138
|
process.exit(1);
|
|
105
139
|
}
|
|
106
140
|
};
|
|
141
|
+
// Main function to execute the plot based on input and options
|
|
107
142
|
var execute = function (_a) {
|
|
108
143
|
var input = _a.input, options = _a.options;
|
|
109
144
|
withError(function () {
|
|
110
|
-
|
|
145
|
+
// Generate the ASCII plot based on provided input and settings
|
|
146
|
+
var output = (0, simple_ascii_chart_1.default)(input, options);
|
|
147
|
+
// Output the result to the console
|
|
111
148
|
process.stdout.write(output);
|
|
112
|
-
process.exit(0);
|
|
149
|
+
process.exit(0); // Exit successfully after outputting the plot
|
|
113
150
|
});
|
|
114
151
|
};
|
|
115
152
|
var prepareParams = function (_a) {
|
|
116
|
-
var input = _a.input, options = _a.options, width = _a.width, height = _a.height, hideYAxis = _a.hideYAxis, hideXAxis = _a.hideXAxis, fillArea = _a.fillArea, title = _a.title, xLabel = _a.xLabel, yLabel = _a.yLabel, color = _a.color, axisCenter = _a.axisCenter;
|
|
153
|
+
var input = _a.input, options = _a.options, width = _a.width, height = _a.height, hideYAxis = _a.hideYAxis, hideXAxis = _a.hideXAxis, fillArea = _a.fillArea, title = _a.title, xLabel = _a.xLabel, yLabel = _a.yLabel, color = _a.color, axisCenter = _a.axisCenter, yRange = _a.yRange, showTickLabel = _a.showTickLabel, thresholds = _a.thresholds, legend = _a.legend, formatter = _a.formatter, lineFormatter = _a.lineFormatter, symbols = _a.symbols;
|
|
117
154
|
var currentOptions = options ? JSON.parse(options) : {};
|
|
118
155
|
return {
|
|
119
156
|
input: JSON.parse(input),
|
|
120
|
-
options: __assign(__assign({}, currentOptions), { width: width, height: height, hideYAxis: hideYAxis, hideXAxis: hideXAxis, title: title, xLabel: xLabel, yLabel: yLabel, fillArea: fillArea, color: color, axisCenter: axisCenter
|
|
157
|
+
options: __assign(__assign({}, currentOptions), { width: width, height: height, hideYAxis: hideYAxis, hideXAxis: hideXAxis, title: title, xLabel: xLabel, yLabel: yLabel, fillArea: fillArea, color: color ? (0, validators_1.validateColors)(color) : undefined, axisCenter: (0, validators_1.validateAxisCenter)(axisCenter), yRange: (0, validators_1.validateYRange)(yRange), // Validate and format yRange
|
|
158
|
+
showTickLabel: showTickLabel, thresholds: (0, validators_1.validateThresholds)(thresholds), legend: (0, validators_1.validateLegend)(legend), formatter: (0, validators_1.validateFormatter)(formatter), lineFormatter: (0, validators_1.validateLineFormatter)(lineFormatter), symbols: (0, validators_1.validateSymbols)(symbols) }),
|
|
121
159
|
};
|
|
122
160
|
};
|
|
161
|
+
// Check if argv is a Promise to handle async parsing in yargs
|
|
123
162
|
if (argv instanceof Promise) {
|
|
163
|
+
// If async, wait for arguments and execute the plotting
|
|
124
164
|
argv.then(function (parameters) {
|
|
125
165
|
withError(function () {
|
|
126
166
|
execute(prepareParams(parameters));
|
|
@@ -128,6 +168,7 @@ if (argv instanceof Promise) {
|
|
|
128
168
|
});
|
|
129
169
|
}
|
|
130
170
|
else {
|
|
171
|
+
// Synchronously prepare parameters and execute the plot
|
|
131
172
|
withError(function () {
|
|
132
173
|
execute(prepareParams(argv));
|
|
133
174
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var child_process_1 = require("child_process");
|
|
4
|
+
describe('plotter script', function () {
|
|
5
|
+
// @ts-expect-error tests
|
|
6
|
+
var execPlotterScript = function (args, callback) {
|
|
7
|
+
(0, child_process_1.exec)("node dist/cli.js ".concat(args), callback);
|
|
8
|
+
};
|
|
9
|
+
it('should require the --input option', function (done) {
|
|
10
|
+
// @ts-expect-error tests
|
|
11
|
+
execPlotterScript('', function (error, stdout, stderr) {
|
|
12
|
+
expect(stderr).toContain('Missing required argument: input');
|
|
13
|
+
done();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it('should output a plot when given valid input', function (done) {
|
|
17
|
+
var validInput = JSON.stringify([
|
|
18
|
+
[1, 1],
|
|
19
|
+
[2, 2],
|
|
20
|
+
[3, 3],
|
|
21
|
+
]);
|
|
22
|
+
// @ts-expect-error tests
|
|
23
|
+
execPlotterScript("--input '".concat(validInput, "'"), function (error, stdout, stderr) {
|
|
24
|
+
expect(error).toBeNull();
|
|
25
|
+
expect(stderr).toBe('');
|
|
26
|
+
expect(stdout).toContain("\n \u25B2 \n3\u2524 \u250F\u2501 \n2\u2524\u250F\u251B \n1\u2524\u251B \n \u2514\u252C\u252C\u252C\u25B6\n 123 \n");
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('should handle invalid JSON input gracefully', function (done) {
|
|
31
|
+
var invalidInput = '[ invalid json';
|
|
32
|
+
// @ts-expect-error tests
|
|
33
|
+
execPlotterScript("--input '".concat(invalidInput, "'"), function (error, stdout, stderr) {
|
|
34
|
+
expect(stderr).toContain('Oops! Something went wrong!');
|
|
35
|
+
done();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var validators_1 = require("../validators");
|
|
4
|
+
describe('Utility Functions Tests', function () {
|
|
5
|
+
describe('validateAxisCenter', function () {
|
|
6
|
+
it('returns valid MaybePoint when given two numbers', function () {
|
|
7
|
+
expect((0, validators_1.validateAxisCenter)([1, 2])).toEqual([1, 2]);
|
|
8
|
+
});
|
|
9
|
+
it('returns undefined for invalid input', function () {
|
|
10
|
+
expect((0, validators_1.validateAxisCenter)([1])).toBeUndefined();
|
|
11
|
+
expect((0, validators_1.validateAxisCenter)(['a', 'b'])).toBeUndefined();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe('validateColors', function () {
|
|
15
|
+
it('filters valid ANSI colors from an array', function () {
|
|
16
|
+
expect((0, validators_1.validateColors)(['ansiRed', 'ansiGreen', 'ansiBlue'])).toEqual([
|
|
17
|
+
'ansiRed',
|
|
18
|
+
'ansiGreen',
|
|
19
|
+
'ansiBlue',
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
it('returns undefined for unsupported color strings', function () {
|
|
23
|
+
expect((0, validators_1.validateColors)(['red', 'green'])).toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
it('returns a single ANSI color if input is a valid ANSI color string', function () {
|
|
26
|
+
expect((0, validators_1.validateColors)('ansiRed')).toEqual('ansiRed');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('validateYRange', function () {
|
|
30
|
+
it('returns a valid [number, number] tuple for valid input', function () {
|
|
31
|
+
expect((0, validators_1.validateYRange)([10, 20])).toEqual([10, 20]);
|
|
32
|
+
});
|
|
33
|
+
it('returns undefined for invalid ranges', function () {
|
|
34
|
+
expect((0, validators_1.validateYRange)([10])).toBeUndefined();
|
|
35
|
+
expect((0, validators_1.validateYRange)(['a', 'b'])).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('validateThresholds', function () {
|
|
39
|
+
it('returns a valid array of Thresholds when given correct input', function () {
|
|
40
|
+
expect((0, validators_1.validateThresholds)([{ x: 10, y: 20, color: 'ansiRed' }])).toEqual([
|
|
41
|
+
{ x: 10, y: 20, color: 'ansiRed' },
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
it('ignores invalid items in the array', function () {
|
|
45
|
+
expect((0, validators_1.validateThresholds)([
|
|
46
|
+
{ x: 10, y: 20, color: 'ansiRed' },
|
|
47
|
+
{ x: 'a', y: 'b' },
|
|
48
|
+
])).toEqual([{ x: 10, y: 20, color: 'ansiRed' }]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('validateLegend', function () {
|
|
52
|
+
it('returns a valid Legend object for correct JSON string input', function () {
|
|
53
|
+
var legend = { position: 'top', series: ['series1'] };
|
|
54
|
+
expect((0, validators_1.validateLegend)(JSON.stringify(legend))).toEqual(legend);
|
|
55
|
+
});
|
|
56
|
+
it('returns undefined for invalid JSON or unsupported structure', function () {
|
|
57
|
+
expect((0, validators_1.validateLegend)('{"position": "middle"}')).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('validateFormatter', function () {
|
|
61
|
+
it('returns a valid Formatter function for correct string input', function () {
|
|
62
|
+
var formatterStr = '(value) => value.toFixed(2)';
|
|
63
|
+
var formatter = (0, validators_1.validateFormatter)(formatterStr);
|
|
64
|
+
expect(formatter(10.1234, {})).toBe('10.12');
|
|
65
|
+
});
|
|
66
|
+
it('returns undefined for invalid formatter strings', function () {
|
|
67
|
+
expect((0, validators_1.validateFormatter)('invalid code')).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('validateLineFormatter', function () {
|
|
71
|
+
it('returns a valid LineFormatter function for correct string input', function () {
|
|
72
|
+
var lineFormatterStr = '(args) => ({ x: args.x, y: args.y, symbol: "*" })';
|
|
73
|
+
var lineFormatter = (0, validators_1.validateLineFormatter)(lineFormatterStr);
|
|
74
|
+
expect(lineFormatter({ x: 1, y: 2, plotX: 1, plotY: 2, input: [], index: 0 })).toEqual({
|
|
75
|
+
x: 1,
|
|
76
|
+
y: 2,
|
|
77
|
+
symbol: '*',
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it('returns undefined for invalid lineFormatter strings', function () {
|
|
81
|
+
expect((0, validators_1.validateLineFormatter)('invalid code')).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('validateSymbols', function () {
|
|
85
|
+
it('returns valid Symbols object for correct JSON string input', function () {
|
|
86
|
+
var symbols = { axis: { x: '-', y: '|' }, empty: ' ' };
|
|
87
|
+
expect((0, validators_1.validateSymbols)(JSON.stringify(symbols))).toEqual(symbols);
|
|
88
|
+
});
|
|
89
|
+
it('returns undefined for invalid JSON or unsupported structure', function () {
|
|
90
|
+
expect((0, validators_1.validateSymbols)('{"invalidKey": "-"}')).toBeUndefined();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Colors, CustomSymbol, Formatter, Legend, LineFormatterArgs, MaybePoint, Symbols, Threshold } from 'simple-ascii-chart/dist/types';
|
|
2
|
+
export declare const validateAxisCenter: (axisCenter: (string | number)[] | undefined) => MaybePoint;
|
|
3
|
+
export declare const validateColors: (colors: (string | number)[] | string | undefined) => Colors | undefined;
|
|
4
|
+
export declare const validateYRange: (yRange: (string | number)[] | undefined) => [number, number] | undefined;
|
|
5
|
+
export declare const validateThresholds: (thresholds: any[] | undefined) => Threshold[] | undefined;
|
|
6
|
+
export declare const validateLegend: (legend: string | undefined) => Legend | undefined;
|
|
7
|
+
export declare const validateFormatter: (formatter: string | undefined) => Formatter | undefined;
|
|
8
|
+
export declare const validateLineFormatter: (lineFormatter: string | undefined) => ((args: LineFormatterArgs) => CustomSymbol | CustomSymbol[]) | undefined;
|
|
9
|
+
export declare const validateSymbols: (symbols: string | undefined) => Symbols | undefined;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.validateSymbols = exports.validateLineFormatter = exports.validateFormatter = exports.validateLegend = exports.validateThresholds = exports.validateYRange = exports.validateColors = exports.validateAxisCenter = void 0;
|
|
20
|
+
// Prepares parameters by parsing JSON inputs and merging with optional settings
|
|
21
|
+
// Define ANSI color types for validation
|
|
22
|
+
var ANSI_COLORS = new Set([
|
|
23
|
+
'ansiRed',
|
|
24
|
+
'ansiGreen',
|
|
25
|
+
'ansiBlack',
|
|
26
|
+
'ansiYellow',
|
|
27
|
+
'ansiBlue',
|
|
28
|
+
'ansiMagenta',
|
|
29
|
+
'ansiCyan',
|
|
30
|
+
'ansiWhite',
|
|
31
|
+
]);
|
|
32
|
+
// Type guard to check if a value is a valid ANSI color
|
|
33
|
+
var isAnsiColor = function (value) { return ANSI_COLORS.has(value); };
|
|
34
|
+
// Helper function to validate and format axisCenter as MaybePoint
|
|
35
|
+
var validateAxisCenter = function (axisCenter) {
|
|
36
|
+
if (!axisCenter || axisCenter.length !== 2)
|
|
37
|
+
return undefined;
|
|
38
|
+
var _a = __read(axisCenter, 2), x = _a[0], y = _a[1];
|
|
39
|
+
return typeof x === 'number' && typeof y === 'number' ? [x, y] : undefined;
|
|
40
|
+
};
|
|
41
|
+
exports.validateAxisCenter = validateAxisCenter;
|
|
42
|
+
// Helper function to validate and map colors to the Colors type
|
|
43
|
+
var validateColors = function (colors) {
|
|
44
|
+
if (Array.isArray(colors)) {
|
|
45
|
+
var filteredColors = colors.filter(isAnsiColor);
|
|
46
|
+
return filteredColors.length > 0 ? filteredColors : undefined;
|
|
47
|
+
}
|
|
48
|
+
else if (typeof colors === 'string' && isAnsiColor(colors)) {
|
|
49
|
+
return colors;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
};
|
|
53
|
+
exports.validateColors = validateColors;
|
|
54
|
+
// Updated prepareParams function with validated colors and axisCenter handling
|
|
55
|
+
// Helper function to validate and format yRange as [number, number]
|
|
56
|
+
var validateYRange = function (yRange) {
|
|
57
|
+
if (Array.isArray(yRange) && yRange.length === 2) {
|
|
58
|
+
var _a = __read(yRange, 2), min = _a[0], max = _a[1];
|
|
59
|
+
// Ensure both elements are numbers
|
|
60
|
+
if (typeof min === 'number' && typeof max === 'number') {
|
|
61
|
+
return [min, max];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined; // Return undefined if the format is incorrect
|
|
65
|
+
};
|
|
66
|
+
exports.validateYRange = validateYRange;
|
|
67
|
+
// Helper function to validate and format thresholds as Threshold[]
|
|
68
|
+
var validateThresholds = function (thresholds) {
|
|
69
|
+
if (!Array.isArray(thresholds))
|
|
70
|
+
return undefined;
|
|
71
|
+
return thresholds
|
|
72
|
+
.map(function (item) {
|
|
73
|
+
if (typeof item === 'object' && item !== null) {
|
|
74
|
+
var threshold = item;
|
|
75
|
+
var x = typeof threshold.x === 'number' ? threshold.x : undefined;
|
|
76
|
+
var y = typeof threshold.y === 'number' ? threshold.y : undefined;
|
|
77
|
+
var color = typeof threshold.color === 'string' ? threshold.color : undefined;
|
|
78
|
+
return x !== undefined || y !== undefined ? { x: x, y: y, color: color } : undefined;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
})
|
|
82
|
+
.filter(function (threshold) { return threshold !== undefined; });
|
|
83
|
+
};
|
|
84
|
+
exports.validateThresholds = validateThresholds;
|
|
85
|
+
// Helper function to validate and parse legend as Legend
|
|
86
|
+
var validateLegend = function (legend) {
|
|
87
|
+
if (!legend)
|
|
88
|
+
return undefined;
|
|
89
|
+
try {
|
|
90
|
+
// Attempt to parse the legend string as JSON
|
|
91
|
+
var parsedLegend = JSON.parse(legend);
|
|
92
|
+
// Check if parsed legend has the correct structure for the Legend type
|
|
93
|
+
if ((typeof parsedLegend.position === 'string' &&
|
|
94
|
+
['left', 'right', 'top', 'bottom'].includes(parsedLegend.position)) ||
|
|
95
|
+
parsedLegend.series instanceof Array) {
|
|
96
|
+
return parsedLegend;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (_a) {
|
|
100
|
+
// Ignore JSON parsing errors and return undefined
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
};
|
|
104
|
+
exports.validateLegend = validateLegend;
|
|
105
|
+
// Helper function to parse a formatter string into a function of type Formatter
|
|
106
|
+
var validateFormatter = function (formatter) {
|
|
107
|
+
if (!formatter)
|
|
108
|
+
return undefined;
|
|
109
|
+
try {
|
|
110
|
+
// Create a function from the formatter string; it should accept (value, helpers) parameters
|
|
111
|
+
// Using `new Function` to construct a function from the string (in the form "value => { ... }")
|
|
112
|
+
return new Function('value', 'helpers', "return (".concat(formatter, ")(value, helpers);"));
|
|
113
|
+
}
|
|
114
|
+
catch (_a) {
|
|
115
|
+
// Return undefined if the formatter string cannot be parsed as a function
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
exports.validateFormatter = validateFormatter;
|
|
120
|
+
// Helper function to parse lineFormatter string into a function of type (args: LineFormatterArgs) => CustomSymbol | CustomSymbol[]
|
|
121
|
+
var validateLineFormatter = function (lineFormatter) {
|
|
122
|
+
if (!lineFormatter)
|
|
123
|
+
return undefined;
|
|
124
|
+
try {
|
|
125
|
+
// Using `new Function` to construct a function from the lineFormatter string
|
|
126
|
+
return new Function('args', "return (".concat(lineFormatter, ")(args);"));
|
|
127
|
+
}
|
|
128
|
+
catch (_a) {
|
|
129
|
+
// Return undefined if the lineFormatter string cannot be parsed as a function
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.validateLineFormatter = validateLineFormatter;
|
|
134
|
+
// Helper function to parse and validate symbols as Symbols type
|
|
135
|
+
var validateSymbols = function (symbols) {
|
|
136
|
+
if (!symbols)
|
|
137
|
+
return undefined;
|
|
138
|
+
try {
|
|
139
|
+
// Parse the symbols JSON string
|
|
140
|
+
var parsedSymbols = JSON.parse(symbols);
|
|
141
|
+
// Check if parsedSymbols has the correct structure
|
|
142
|
+
if (typeof parsedSymbols === 'object' &&
|
|
143
|
+
(parsedSymbols.axis ||
|
|
144
|
+
parsedSymbols.chart ||
|
|
145
|
+
parsedSymbols.empty ||
|
|
146
|
+
parsedSymbols.background ||
|
|
147
|
+
parsedSymbols.border)) {
|
|
148
|
+
return parsedSymbols;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (_a) {
|
|
152
|
+
// Return undefined if symbols string cannot be parsed
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
};
|
|
157
|
+
exports.validateSymbols = validateSymbols;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-ascii-chart-cli",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Simple ascii chart generator",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Simple ascii chart generator CLI",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
@@ -9,61 +9,50 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "tsc-watch -p tsconfig.json --preserveWatchOutput -w --onSuccess 'node ./dist/index.js'",
|
|
12
|
-
"lint": "eslint .
|
|
13
|
-
"lint:fix": "eslint . --
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"lint:fix": "eslint . --fix",
|
|
14
14
|
"test": "jest --coverage",
|
|
15
15
|
"test:watch": "jest --watch",
|
|
16
16
|
"build": "tsc -p tsconfig.build.json",
|
|
17
17
|
"build:watch": "tsc -p tsconfig.build.json -w",
|
|
18
|
-
"prepare": "
|
|
19
|
-
"prepublishOnly": "npm test && npm run lint",
|
|
20
|
-
"preversion": "npm run lint",
|
|
21
|
-
"version": "npm run lint && git add -A src",
|
|
22
|
-
"postversion": "git push && git push --tags"
|
|
18
|
+
"prepare": "npm test && npm run lint && npm run build"
|
|
23
19
|
},
|
|
24
20
|
"devDependencies": {
|
|
25
|
-
"@types/jest": "^29.5.
|
|
26
|
-
"@types/node": "^
|
|
27
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
28
|
-
"@typescript-eslint/parser": "^
|
|
29
|
-
"
|
|
30
|
-
"eslint": "^
|
|
31
|
-
"eslint-
|
|
32
|
-
"eslint-config-prettier": "^9.0.0",
|
|
33
|
-
"eslint-plugin-import": "^2.28.1",
|
|
34
|
-
"husky": "^8.0.3",
|
|
21
|
+
"@types/jest": "^29.5.14",
|
|
22
|
+
"@types/node": "^22.8.0",
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
|
24
|
+
"@typescript-eslint/parser": "^8.11.0",
|
|
25
|
+
"eslint": "^9.13.0",
|
|
26
|
+
"eslint-config-prettier": "^9.1.0",
|
|
27
|
+
"eslint-plugin-import": "^2.31.0",
|
|
35
28
|
"jest": "^29.7.0",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"typescript": "^5.2.2"
|
|
41
|
-
},
|
|
42
|
-
"lint-staged": {
|
|
43
|
-
"*.ts": "eslint . --ext .ts,.js --fix",
|
|
44
|
-
"*.{ts,md}": "prettier --write --ignore-unknown"
|
|
29
|
+
"prettier": "^3.3.3",
|
|
30
|
+
"ts-jest": "^29.2.5",
|
|
31
|
+
"tsc-watch": "^6.2.0",
|
|
32
|
+
"typescript": "^5.6.3"
|
|
45
33
|
},
|
|
46
34
|
"keywords": [
|
|
47
35
|
"ascii",
|
|
48
36
|
"js",
|
|
49
37
|
"ts",
|
|
38
|
+
"cli",
|
|
50
39
|
"chart"
|
|
51
40
|
],
|
|
52
41
|
"author": "gtktsc",
|
|
53
42
|
"license": "MIT",
|
|
54
43
|
"repository": {
|
|
55
44
|
"type": "git",
|
|
56
|
-
"url": "git+https://github.com/gtktsc/ascii-chart.git"
|
|
45
|
+
"url": "git+https://github.com/gtktsc/simple-ascii-chart-cli.git"
|
|
57
46
|
},
|
|
58
47
|
"bugs": {
|
|
59
|
-
"url": "https://github.com/gtktsc/ascii-chart/issues"
|
|
48
|
+
"url": "https://github.com/gtktsc/simple-ascii-chart-cli/issues"
|
|
60
49
|
},
|
|
61
|
-
"homepage": "https://github.com/gtktsc/ascii-chart#readme",
|
|
50
|
+
"homepage": "https://github.com/gtktsc/simple-ascii-chart-cli#readme",
|
|
62
51
|
"files": [
|
|
63
52
|
"dist/**/*"
|
|
64
53
|
],
|
|
65
54
|
"dependencies": {
|
|
66
|
-
"simple-ascii-chart": "^4.
|
|
55
|
+
"simple-ascii-chart": "^4.1.1",
|
|
67
56
|
"yargs": "^17.7.2"
|
|
68
57
|
}
|
|
69
58
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare const AXIS: {
|
|
2
|
-
n: string;
|
|
3
|
-
ns: string;
|
|
4
|
-
y: string;
|
|
5
|
-
nse: string;
|
|
6
|
-
x: string;
|
|
7
|
-
we: string;
|
|
8
|
-
e: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const CHART: {
|
|
11
|
-
we: string;
|
|
12
|
-
wns: string;
|
|
13
|
-
ns: string;
|
|
14
|
-
nse: string;
|
|
15
|
-
wsn: string;
|
|
16
|
-
sne: string;
|
|
17
|
-
area: string;
|
|
18
|
-
};
|
|
19
|
-
export declare const EMPTY = " ";
|
package/dist/constants/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EMPTY = exports.CHART = exports.AXIS = void 0;
|
|
4
|
-
exports.AXIS = {
|
|
5
|
-
n: '▲',
|
|
6
|
-
ns: '│',
|
|
7
|
-
y: '┤',
|
|
8
|
-
nse: '└',
|
|
9
|
-
x: '┬',
|
|
10
|
-
we: '─',
|
|
11
|
-
e: '▶',
|
|
12
|
-
};
|
|
13
|
-
exports.CHART = {
|
|
14
|
-
we: '━',
|
|
15
|
-
wns: '┓',
|
|
16
|
-
ns: '┃',
|
|
17
|
-
nse: '┗',
|
|
18
|
-
wsn: '┛',
|
|
19
|
-
sne: '┏',
|
|
20
|
-
area: '█',
|
|
21
|
-
};
|
|
22
|
-
exports.EMPTY = ' ';
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED