@heroku/heroku-cli-util 10.5.0 → 10.6.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/ux/styled-object.js +12 -5
- package/package.json +1 -1
package/dist/ux/styled-object.js
CHANGED
|
@@ -27,11 +27,18 @@ export function styledObject(obj, keys) {
|
|
|
27
27
|
if (typeof obj === 'boolean')
|
|
28
28
|
return obj.toString();
|
|
29
29
|
const output = [];
|
|
30
|
-
const
|
|
31
|
-
|
|
30
|
+
const keysToIterate = keys || Object.keys(obj);
|
|
31
|
+
// Only calculate max key length for keys that will actually be displayed
|
|
32
|
+
const displayableKeys = keysToIterate.filter(key => {
|
|
33
|
+
const value = obj[key];
|
|
34
|
+
return value !== null && value !== undefined && (!Array.isArray(value) || value.length > 0);
|
|
35
|
+
});
|
|
36
|
+
const keyLengths = displayableKeys.map(key => key.toString().length);
|
|
37
|
+
const maxKeyLength = keyLengths.length > 0 ? Math.max(...keyLengths) + 2 : 0;
|
|
32
38
|
const logKeyValue = (key, value) => `${color.label(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + prettyPrint(value);
|
|
33
|
-
for (const
|
|
34
|
-
|
|
39
|
+
for (const key of keysToIterate) {
|
|
40
|
+
const value = obj[key];
|
|
41
|
+
if (value === null || value === undefined)
|
|
35
42
|
continue;
|
|
36
43
|
if (Array.isArray(value)) {
|
|
37
44
|
if (value.length > 0) {
|
|
@@ -41,7 +48,7 @@ export function styledObject(obj, keys) {
|
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
|
-
else
|
|
51
|
+
else {
|
|
45
52
|
output.push(logKeyValue(key, value));
|
|
46
53
|
}
|
|
47
54
|
}
|