simple-ascii-chart-cli 1.2.0 → 2.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/dist/cli.js CHANGED
@@ -27,13 +27,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
27
27
  }) : function(o, v) {
28
28
  o["default"] = v;
29
29
  });
30
- var __importStar = (this && this.__importStar) || function (mod) {
31
- if (mod && mod.__esModule) return mod;
32
- var result = {};
33
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
34
- __setModuleDefault(result, mod);
35
- return result;
36
- };
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
37
47
  var __importDefault = (this && this.__importDefault) || function (mod) {
38
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
49
  };
@@ -117,7 +127,11 @@ var argv = yargs
117
127
  })
118
128
  .option('thresholds', {
119
129
  type: 'array',
120
- description: 'Array of threshold points or lines with optional color',
130
+ description: 'Array of threshold lines with optional color',
131
+ })
132
+ .option('points', {
133
+ type: 'array',
134
+ description: 'Array of points with optional color',
121
135
  })
122
136
  .option('legend', {
123
137
  type: 'string',
@@ -158,12 +172,12 @@ var execute = function (_a) {
158
172
  });
159
173
  };
160
174
  var prepareParams = function (_a) {
161
- 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, barChart = _a.barChart, horizontalBarChart = _a.horizontalBarChart;
175
+ 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, points = _a.points, legend = _a.legend, formatter = _a.formatter, lineFormatter = _a.lineFormatter, symbols = _a.symbols, barChart = _a.barChart, horizontalBarChart = _a.horizontalBarChart;
162
176
  var currentOptions = options ? JSON.parse(options) : {};
163
177
  return {
164
178
  input: JSON.parse(input),
165
179
  options: __assign(__assign({}, currentOptions), { width: width, height: height, hideYAxis: hideYAxis, hideXAxis: hideXAxis, title: title, xLabel: xLabel, yLabel: yLabel, fillArea: fillArea, barChart: barChart, horizontalBarChart: horizontalBarChart, color: color ? (0, validators_1.validateColors)(color) : undefined, axisCenter: (0, validators_1.validateAxisCenter)(axisCenter), yRange: (0, validators_1.validateYRange)(yRange), // Validate and format yRange
166
- 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) }),
180
+ showTickLabel: showTickLabel, thresholds: (0, validators_1.validateThresholds)(thresholds), points: (0, validators_1.validatePoints)(points), legend: (0, validators_1.validateLegend)(legend), formatter: (0, validators_1.validateFormatter)(formatter), lineFormatter: (0, validators_1.validateLineFormatter)(lineFormatter), symbols: (0, validators_1.validateSymbols)(symbols) }),
167
181
  };
168
182
  };
169
183
  // Check if argv is a Promise to handle async parsing in yargs
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  var child_process_1 = require("child_process");
7
+ var path_1 = __importDefault(require("path"));
8
+ var cliPath = path_1.default.resolve(__dirname, '../../dist/cli.js'); // <-- LOCAL build output
9
+ function execPlotterScript(args, callback) {
10
+ (0, child_process_1.exec)("node ".concat(cliPath, " ").concat(args), callback);
11
+ }
4
12
  describe('plotter script', function () {
5
- // @ts-expect-error tests
6
- var execPlotterScript = function (args, callback) {
7
- (0, child_process_1.exec)("node node_modules/simple-ascii-chart/dist/cli.js ".concat(args), callback);
8
- };
9
13
  it('should require the --input option', function (done) {
10
- // @ts-expect-error tests
11
14
  execPlotterScript('', function (error, stdout, stderr) {
12
15
  expect(stderr).toContain('Missing required argument: input');
13
16
  done();
@@ -19,7 +22,6 @@ describe('plotter script', function () {
19
22
  [2, 2],
20
23
  [3, 3],
21
24
  ]);
22
- // @ts-expect-error tests
23
25
  execPlotterScript("--input '".concat(validInput, "'"), function (error, stdout, stderr) {
24
26
  expect(error).toBeNull();
25
27
  expect(stderr).toBe('');
@@ -29,7 +31,6 @@ describe('plotter script', function () {
29
31
  });
30
32
  it('should handle invalid JSON input gracefully', function (done) {
31
33
  var invalidInput = '[ invalid json';
32
- // @ts-expect-error tests
33
34
  execPlotterScript("--input '".concat(invalidInput, "'"), function (error, stdout, stderr) {
34
35
  expect(stderr).toContain('Oops! Something went wrong!');
35
36
  done();
@@ -1,8 +1,9 @@
1
- import { Colors, CustomSymbol, Formatter, Legend, LineFormatterArgs, MaybePoint, Symbols, Threshold } from 'simple-ascii-chart/dist/types';
1
+ import { Colors, CustomSymbol, Formatter, GraphPoint, Legend, LineFormatterArgs, MaybePoint, Symbols, Threshold } from 'simple-ascii-chart';
2
2
  export declare const validateAxisCenter: (axisCenter: (string | number)[] | undefined) => MaybePoint;
3
3
  export declare const validateColors: (colors: (string | number)[] | string | undefined) => Colors | undefined;
4
4
  export declare const validateYRange: (yRange: (string | number)[] | undefined) => [number, number] | undefined;
5
5
  export declare const validateThresholds: (thresholds: any[] | undefined) => Threshold[] | undefined;
6
+ export declare const validatePoints: (points: any[] | undefined) => GraphPoint[] | undefined;
6
7
  export declare const validateLegend: (legend: string | undefined) => Legend | undefined;
7
8
  export declare const validateFormatter: (formatter: string | undefined) => Formatter | undefined;
8
9
  export declare const validateLineFormatter: (lineFormatter: string | undefined) => ((args: LineFormatterArgs) => CustomSymbol | CustomSymbol[]) | undefined;
@@ -16,7 +16,7 @@ var __read = (this && this.__read) || function (o, n) {
16
16
  return ar;
17
17
  };
18
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;
19
+ exports.validateSymbols = exports.validateLineFormatter = exports.validateFormatter = exports.validateLegend = exports.validatePoints = exports.validateThresholds = exports.validateYRange = exports.validateColors = exports.validateAxisCenter = void 0;
20
20
  // Prepares parameters by parsing JSON inputs and merging with optional settings
21
21
  // Define ANSI color types for validation
22
22
  var ANSI_COLORS = new Set([
@@ -82,6 +82,24 @@ var validateThresholds = function (thresholds) {
82
82
  .filter(function (threshold) { return threshold !== undefined; });
83
83
  };
84
84
  exports.validateThresholds = validateThresholds;
85
+ // Helper function to validate and format thresholds as Threshold[]
86
+ var validatePoints = function (points) {
87
+ if (!Array.isArray(points))
88
+ return undefined;
89
+ return points
90
+ .map(function (item) {
91
+ if (typeof item === 'object' && item !== null) {
92
+ var point = item;
93
+ var x = point.x;
94
+ var y = point.y;
95
+ var color = typeof point.color === 'string' ? point.color : undefined;
96
+ return x !== undefined && y !== undefined ? { x: x, y: y, color: color } : undefined;
97
+ }
98
+ return undefined;
99
+ })
100
+ .filter(function (point) { return point !== undefined; });
101
+ };
102
+ exports.validatePoints = validatePoints;
85
103
  // Helper function to validate and parse legend as Legend
86
104
  var validateLegend = function (legend) {
87
105
  if (!legend)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-ascii-chart-cli",
3
- "version": "1.2.0",
3
+ "version": "2.1.0",
4
4
  "description": "Simple ascii chart generator CLI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,21 +15,21 @@
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": "npm test && npm run lint && npm run build"
18
+ "prepare": "npm run lint && npm run build && npm test"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/jest": "^29.5.14",
22
- "@types/node": "^22.8.1",
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",
22
+ "@types/node": "^22.15.17",
23
+ "@typescript-eslint/eslint-plugin": "^8.32.1",
24
+ "@typescript-eslint/parser": "^8.32.1",
25
+ "eslint": "^9.26.0",
26
+ "eslint-config-prettier": "^10.1.5",
27
27
  "eslint-plugin-import": "^2.31.0",
28
28
  "jest": "^29.7.0",
29
- "prettier": "^3.3.3",
30
- "ts-jest": "^29.2.5",
31
- "tsc-watch": "^6.2.0",
32
- "typescript": "^5.6.3"
29
+ "prettier": "^3.5.3",
30
+ "ts-jest": "^29.3.2",
31
+ "tsc-watch": "^6.2.1",
32
+ "typescript": "^5.8.3"
33
33
  },
34
34
  "keywords": [
35
35
  "ascii",
@@ -52,7 +52,7 @@
52
52
  "dist/**/*"
53
53
  ],
54
54
  "dependencies": {
55
- "simple-ascii-chart": "^4.2.0",
55
+ "simple-ascii-chart": "^5.1.0",
56
56
  "yargs": "^17.7.2"
57
57
  }
58
58
  }