@vexify-org/yaggs 6.4.0 → 6.5.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/index.js CHANGED
@@ -122,6 +122,11 @@ class Yaggs {
122
122
  return this;
123
123
  }
124
124
 
125
+ table(data, options = {}) {
126
+ this.parser.table(data, options);
127
+ return this;
128
+ }
129
+
125
130
  check(fn) {
126
131
  this.middleware(fn);
127
132
  return this;
package/lib/parser.js CHANGED
@@ -786,6 +786,46 @@ complete -c ${this.scriptName} `;
786
786
  }
787
787
  }
788
788
 
789
+ table(data, options = {}) {
790
+ if (!data || data.length === 0) {
791
+ console.log('No data to display');
792
+ return;
793
+ }
794
+
795
+ const headers = Object.keys(data[0]);
796
+ const columnWidths = {};
797
+
798
+ for (const header of headers) {
799
+ const maxLen = Math.max(
800
+ header.length,
801
+ ...data.map(row => String(row[header] || '').length)
802
+ );
803
+ columnWidths[header] = maxLen + 2;
804
+ }
805
+
806
+ const border = '─'.repeat(Object.values(columnWidths).reduce((a, b) => a + b, 0) + headers.length + 1);
807
+
808
+ console.log('\u001b[36m' + border + '\u001b[0m');
809
+
810
+ let headerRow = '│ ';
811
+ for (const header of headers) {
812
+ headerRow += header.padEnd(columnWidths[header]) + '│ ';
813
+ }
814
+ console.log('\u001b[35m' + headerRow + '\u001b[0m');
815
+
816
+ console.log('\u001b[36m' + border + '\u001b[0m');
817
+
818
+ for (const row of data) {
819
+ let rowStr = '│ ';
820
+ for (const header of headers) {
821
+ rowStr += String(row[header] || '').padEnd(columnWidths[header]) + '│ ';
822
+ }
823
+ console.log(rowStr);
824
+ }
825
+
826
+ console.log('\u001b[36m' + border + '\u001b[0m');
827
+ }
828
+
789
829
  getHelp() {
790
830
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
791
831
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.4.0",
3
+ "version": "6.5.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {