@oclif/table 0.2.1 → 0.2.3

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.
Files changed (2) hide show
  1. package/lib/table.js +13 -2
  2. package/package.json +1 -1
package/lib/table.js CHANGED
@@ -60,6 +60,9 @@ export function formatTextWithMargins({ horizontalAlignment, overflow, padding,
60
60
  function calculateMargins(spaces) {
61
61
  let marginLeft;
62
62
  let marginRight;
63
+ if (spaces <= 0 || Number.isNaN(spaces)) {
64
+ return { marginLeft: 0, marginRight: 0 };
65
+ }
63
66
  if (horizontalAlignment === 'left') {
64
67
  marginLeft = padding;
65
68
  marginRight = spaces - marginLeft;
@@ -72,7 +75,11 @@ export function formatTextWithMargins({ horizontalAlignment, overflow, padding,
72
75
  marginRight = padding;
73
76
  marginLeft = spaces - marginRight;
74
77
  }
75
- return { marginLeft, marginRight };
78
+ return {
79
+ // Ensure that the margin is never negative
80
+ marginLeft: Math.max(0, marginLeft),
81
+ marginRight: Math.max(0, marginRight),
82
+ };
76
83
  }
77
84
  // Some terminals don't play nicely with zero-width characters, so we replace them with spaces.
78
85
  // https://github.com/sindresorhus/terminal-link/issues/18
@@ -87,7 +94,11 @@ export function formatTextWithMargins({ horizontalAlignment, overflow, padding,
87
94
  };
88
95
  }
89
96
  if (overflow === 'wrap') {
90
- const wrappedText = wrapAnsi(valueWithNoZeroWidthChars, spaceForText, { hard: true, trim: true, wordWrap: true });
97
+ const wrappedText = wrapAnsi(valueWithNoZeroWidthChars, spaceForText, {
98
+ hard: true,
99
+ trim: true,
100
+ wordWrap: true,
101
+ }).replace(/^\n/, ''); // remove leading newline (wrapAnsi adds it to emojis)
91
102
  const { marginLeft, marginRight } = calculateMargins(width - determineWidthOfWrappedText(stripAnsi(wrappedText)));
92
103
  const lines = wrappedText.split('\n').map((line, idx) => {
93
104
  const { marginLeft: lineSpecificLeftMargin, marginRight: lineSpecificRightMargin } = calculateMargins(width - stripAnsi(line).length);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/table",
3
3
  "description": "Display table in terminal",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/table/issues",
7
7
  "dependencies": {