| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a5fdedb commit c3243de
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -946,12 +946,17 @@ function groupArrayElements(ctx, output) { | |||
| 946 | 946 | let totalLength = 0; | |
| 947 | 947 | let maxLength = 0; | |
| 948 | 948 | let i = 0; | |
| 949 | + let outputLength = output.length; | ||
| 950 | + if (ctx.maxArrayLength < output.length) { | ||
| 951 | + // This makes sure the "... n more items" part is not taken into account. | ||
| 952 | + outputLength--; | ||
| 953 | + } | ||
| 949 | 954 | const separatorSpace = 2; // Add 1 for the space and 1 for the separator. | |
| 950 | - const dataLen = new Array(output.length); | ||
| 955 | + const dataLen = new Array(outputLength); | ||
| 951 | 956 | // Calculate the total length of all output entries and the individual max | |
| 952 | 957 | // entries length of all output entries. We have to remove colors first, | |
| 953 | 958 | // otherwise the length would not be calculated properly. | |
| 954 | - for (; i < output.length; i++) { | ||
| 959 | + for (; i < outputLength; i++) { | ||
| 955 | 960 | const len = ctx.colors ? removeColors(output[i]).length : output[i].length; | |
| 956 | 961 | dataLen[i] = len; | |
| 957 | 962 | totalLength += len + separatorSpace; | |
@@ -979,7 +984,7 @@ function groupArrayElements(ctx, output) { | |||
| 979 | 984 | // The added bias slightly increases the columns for short entries. | |
| 980 | 985 | Math.round( | |
| 981 | 986 | Math.sqrt( | |
| 982 | - approxCharHeights * (actualMax - bias) * output.length | ||
| 987 | + approxCharHeights * (actualMax - bias) * outputLength | ||
| 983 | 988 | ) / (actualMax - bias) | |
| 984 | 989 | ), | |
| 985 | 990 | // Do not exceed the breakLength. | |
@@ -1003,20 +1008,23 @@ function groupArrayElements(ctx, output) { | |||
| 1003 | 1008 | firstLineMaxLength = dataLen[i]; | |
| 1004 | 1009 | } | |
| 1005 | 1010 | // Each iteration creates a single line of grouped entries. | |
| 1006 | - for (i = 0; i < output.length; i += columns) { | ||
| 1011 | + for (i = 0; i < outputLength; i += columns) { | ||
| 1007 | 1012 | // Calculate extra color padding in case it's active. This has to be done | |
| 1008 | 1013 | // line by line as some lines might contain more colors than others. | |
| 1009 | 1014 | let colorPadding = output[i].length - dataLen[i]; | |
| 1010 | 1015 | // Add padding to the first column of the output. | |
| 1011 | 1016 | let str = output[i].padStart(firstLineMaxLength + colorPadding, ' '); | |
| 1012 | 1017 | // The last lines may contain less entries than columns. | |
| 1013 | - const max = Math.min(i + columns, output.length); | ||
| 1018 | + const max = Math.min(i + columns, outputLength); | ||
| 1014 | 1019 | for (var j = i + 1; j < max; j++) { | |
| 1015 | 1020 | colorPadding = output[j].length - dataLen[j]; | |
| 1016 | 1021 | str += `, ${output[j].padStart(maxLength + colorPadding, ' ')}`; | |
| 1017 | 1022 | } | |
| 1018 | 1023 | tmp.push(str); | |
| 1019 | 1024 | } | |
| 1025 | + if (ctx.maxArrayLength < output.length) { | ||
| 1026 | + tmp.push(output[outputLength]); | ||
| 1027 | + } | ||
| 1020 | 1028 | output = tmp; | |
| 1021 | 1029 | } | |
| 1022 | 1030 | return output; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2175,7 +2175,7 @@ assert.strictEqual( | |||
| 2175 | 2175 | [ 1, 2, { a: 1, b: 2, c: 3 } ] | |
| 2176 | 2176 | ], | |
| 2177 | 2177 | c: ['foo', 4, 444444], | |
| 2178 | - d: Array.from({ length: 100 }).map((e, i) => { | ||
| 2178 | + d: Array.from({ length: 101 }).map((e, i) => { | ||
| 2179 | 2179 | return i % 2 === 0 ? i * i : i; | |
| 2180 | 2180 | }), | |
| 2181 | 2181 | e: Array(6).fill('foobar'), | |
@@ -2224,7 +2224,8 @@ assert.strictEqual( | |||
| 2224 | 2224 | ' 77, 6084, 79, 6400, 81, 6724, 83,', | |
| 2225 | 2225 | ' 7056, 85, 7396, 87, 7744, 89, 8100,', | |
| 2226 | 2226 | ' 91, 8464, 93, 8836, 95, 9216, 97,', | |
| 2227 | - ' 9604, 99', | ||
| 2227 | + ' 9604, 99,', | ||
| 2228 | + ' ... 1 more item', | ||
| 2228 | 2229 | ' ],', | |
| 2229 | 2230 | ' e: [', | |
| 2230 | 2231 | " 'foobar',", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments