summaryrefslogtreecommitdiff
path: root/lib/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util.js')
-rw-r--r--lib/util.js40
1 files changed, 18 insertions, 22 deletions
diff --git a/lib/util.js b/lib/util.js
index 240489ad0d..793aa3ca16 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -971,33 +971,29 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
function formatSpecialArray(ctx, value, recurseTimes, keys, maxLength, valLen) {
const output = [];
const keyLen = keys.length;
- let visibleLength = 0;
let i = 0;
- if (keyLen !== 0 && numberRegExp.test(keys[0])) {
- for (const key of keys) {
- if (visibleLength === maxLength)
+ for (const key of keys) {
+ if (output.length === maxLength)
+ break;
+ const index = +key;
+ // Arrays can only have up to 2^32 - 1 entries
+ if (index > 2 ** 32 - 2)
+ break;
+ if (`${i}` !== key) {
+ if (!numberRegExp.test(key))
break;
- const index = +key;
- // Arrays can only have up to 2^32 - 1 entries
- if (index > 2 ** 32 - 2)
+ const emptyItems = index - i;
+ const ending = emptyItems > 1 ? 's' : '';
+ const message = `<${emptyItems} empty item${ending}>`;
+ output.push(ctx.stylize(message, 'undefined'));
+ i = index;
+ if (output.length === maxLength)
break;
- if (i !== index) {
- if (!numberRegExp.test(key))
- break;
- const emptyItems = index - i;
- const ending = emptyItems > 1 ? 's' : '';
- const message = `<${emptyItems} empty item${ending}>`;
- output.push(ctx.stylize(message, 'undefined'));
- i = index;
- if (++visibleLength === maxLength)
- break;
- }
- output.push(formatProperty(ctx, value, recurseTimes, key, 1));
- visibleLength++;
- i++;
}
+ output.push(formatProperty(ctx, value, recurseTimes, key, 1));
+ i++;
}
- if (i < valLen && visibleLength !== maxLength) {
+ if (i < valLen && output.length !== maxLength) {
const len = valLen - i;
const ending = len > 1 ? 's' : '';
const message = `<${len} empty item${ending}>`;