File tree 2 files changed +44
-2
lines changed 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -86,17 +86,22 @@ export function inspectColor(tree, options = {}) {
86
86
* @returns {string }
87
87
*/
88
88
function inspectNodes ( nodes ) {
89
+ const size = String ( nodes . length - 1 ) . length
89
90
/** @type {Array<string> } */
90
91
const result = [ ]
91
92
let index = - 1
92
93
93
94
while ( ++ index < nodes . length ) {
94
95
result . push (
95
- dim ( ( index < nodes . length - 1 ? '├' : '└' ) + '─' + index ) +
96
+ dim (
97
+ ( index < nodes . length - 1 ? '├' : '└' ) +
98
+ '─' +
99
+ String ( index ) . padEnd ( size )
100
+ ) +
96
101
' ' +
97
102
indent (
98
103
inspectValue ( nodes [ index ] ) ,
99
- ( index < nodes . length - 1 ? dim ( '│' ) : ' ' ) + ' ' ,
104
+ ( index < nodes . length - 1 ? dim ( '│' ) : ' ' ) + ' ' . repeat ( size + 2 ) ,
100
105
true
101
106
)
102
107
)
Original file line number Diff line number Diff line change @@ -64,6 +64,43 @@ test('inspect()', (t) => {
64
64
st . end ( )
65
65
} )
66
66
67
+ t . equal (
68
+ strip (
69
+ inspect (
70
+ Array . from ( { length : 11 } ) . map ( ( /** @type {undefined } */ d , i ) => ( {
71
+ type : 'text' ,
72
+ value : String ( i ) ,
73
+ data : { id : String . fromCodePoint ( 97 + i ) }
74
+ } ) )
75
+ )
76
+ ) ,
77
+ [
78
+ '├─0 text "0"' ,
79
+ '│ data: {"id":"a"}' ,
80
+ '├─1 text "1"' ,
81
+ '│ data: {"id":"b"}' ,
82
+ '├─2 text "2"' ,
83
+ '│ data: {"id":"c"}' ,
84
+ '├─3 text "3"' ,
85
+ '│ data: {"id":"d"}' ,
86
+ '├─4 text "4"' ,
87
+ '│ data: {"id":"e"}' ,
88
+ '├─5 text "5"' ,
89
+ '│ data: {"id":"f"}' ,
90
+ '├─6 text "6"' ,
91
+ '│ data: {"id":"g"}' ,
92
+ '├─7 text "7"' ,
93
+ '│ data: {"id":"h"}' ,
94
+ '├─8 text "8"' ,
95
+ '│ data: {"id":"i"}' ,
96
+ '├─9 text "9"' ,
97
+ '│ data: {"id":"j"}' ,
98
+ '└─10 text "10"' ,
99
+ ' data: {"id":"k"}'
100
+ ] . join ( '\n' ) ,
101
+ 'should align and indent large numbers'
102
+ )
103
+
67
104
t . equal (
68
105
strip (
69
106
inspect ( {
You can’t perform that action at this time.
0 commit comments