| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1400796 commit 70563b5
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -483,7 +483,11 @@ stream.write('With ES6'); | |||
| 483 | 483 | <!-- YAML | |
| 484 | 484 | added: v0.3.0 | |
| 485 | 485 | changes: | |
| 486 | - - version: v16.14.0 | ||
| 486 | + - version: REPLACEME | ||
| 487 | + pr-url: https://github.com/nodejs/node/pull/43576 | ||
| 488 | + description: add support for `maxArrayLength` when inspecting `Set` and `Map`. | ||
| 489 | + - version: | ||
| 490 | + - v16.14.0 | ||
| 487 | 491 | pr-url: https://github.com/nodejs/node/pull/41003 | |
| 488 | 492 | description: The `numericSeparator` option is supported now. | |
| 489 | 493 | - version: | |
@@ -582,8 +586,9 @@ changes: | |||
| 582 | 586 | * `showProxy` {boolean} If `true`, `Proxy` inspection includes | |
| 583 | 587 | the [`target` and `handler`][] objects. **Default:** `false`. | |
| 584 | 588 | * `maxArrayLength` {integer} Specifies the maximum number of `Array`, | |
| 585 | - [`TypedArray`][], [`WeakMap`][], and [`WeakSet`][] elements to include when | ||
| 586 | - formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or | ||
| 589 | + [`TypedArray`][], [`Map`][], [`Set`][], [`WeakMap`][], | ||
| 590 | + and [`WeakSet`][] elements to include when formatting. | ||
| 591 | + Set to `null` or `Infinity` to show all elements. Set to `0` or | ||
| 587 | 592 | negative to show no elements. **Default:** `100`. | |
| 588 | 593 | * `maxStringLength` {integer} Specifies the maximum number of characters to | |
| 589 | 594 | include when formatting. Set to `null` or `Infinity` to show all elements. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1553,6 +1553,8 @@ function addNumericSeparatorEnd(integerString) { | |||
| 1553 | 1553 | `${result}${integerString.slice(i)}`; | |
| 1554 | 1554 | } | |
| 1555 | 1555 | ||
| 1556 | + const remainingText = (remaining) => `... ${remaining} more item${remaining > 1 ? 's' : ''}`; | ||
| 1557 | + | ||
| 1556 | 1558 | function formatNumber(fn, number, numericSeparator) { | |
| 1557 | 1559 | if (!numericSeparator) { | |
| 1558 | 1560 | // Format -0 as '-0'. Checking `number === -0` won't distinguish 0 from -0. | |
@@ -1680,7 +1682,7 @@ function formatSpecialArray(ctx, value, recurseTimes, maxLength, output, i) { | |||
| 1680 | 1682 | output.push(ctx.stylize(message, 'undefined')); | |
| 1681 | 1683 | } | |
| 1682 | 1684 | } else if (remaining > 0) { | |
| 1683 | - output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); | ||
| 1685 | + output.push(remainingText(remaining)); | ||
| 1684 | 1686 | } | |
| 1685 | 1687 | return output; | |
| 1686 | 1688 | } | |
@@ -1718,7 +1720,7 @@ function formatArray(ctx, value, recurseTimes) { | |||
| 1718 | 1720 | output.push(formatProperty(ctx, value, recurseTimes, i, kArrayType)); | |
| 1719 | 1721 | } | |
| 1720 | 1722 | if (remaining > 0) | |
| 1721 | - output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); | ||
| 1723 | + output.push(remainingText(remaining)); | ||
| 1722 | 1724 | return output; | |
| 1723 | 1725 | } | |
| 1724 | 1726 | ||
@@ -1733,7 +1735,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) { | |||
| 1733 | 1735 | output[i] = elementFormatter(ctx.stylize, value[i], ctx.numericSeparator); | |
| 1734 | 1736 | } | |
| 1735 | 1737 | if (remaining > 0) { | |
| 1736 | - output[maxLength] = `... ${remaining} more item${remaining > 1 ? 's' : ''}`; | ||
| 1738 | + output[maxLength] = remainingText(remaining); | ||
| 1737 | 1739 | } | |
| 1738 | 1740 | if (ctx.showHidden) { | |
| 1739 | 1741 | // .buffer goes last, it's not a primitive like the others. | |
@@ -1755,22 +1757,40 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) { | |||
| 1755 | 1757 | } | |
| 1756 | 1758 | ||
| 1757 | 1759 | function formatSet(value, ctx, ignored, recurseTimes) { | |
| 1760 | + const length = value.size; | ||
| 1761 | + const maxLength = MathMin(MathMax(0, ctx.maxArrayLength), length); | ||
| 1762 | + const remaining = length - maxLength; | ||
| 1758 | 1763 | const output = []; | |
| 1759 | 1764 | ctx.indentationLvl += 2; | |
| 1765 | + let i = 0; | ||
| 1760 | 1766 | for (const v of value) { | |
| 1767 | + if (i >= maxLength) break; | ||
| 1761 | 1768 | ArrayPrototypePush(output, formatValue(ctx, v, recurseTimes)); | |
| 1769 | + i++; | ||
| 1770 | + } | ||
| 1771 | + if (remaining > 0) { | ||
| 1772 | + ArrayPrototypePush(output, remainingText(remaining)); | ||
| 1762 | 1773 | } | |
| 1763 | 1774 | ctx.indentationLvl -= 2; | |
| 1764 | 1775 | return output; | |
| 1765 | 1776 | } | |
| 1766 | 1777 | ||
| 1767 | 1778 | function formatMap(value, ctx, ignored, recurseTimes) { | |
| 1779 | + const length = value.size; | ||
| 1780 | + const maxLength = MathMin(MathMax(0, ctx.maxArrayLength), length); | ||
| 1781 | + const remaining = length - maxLength; | ||
| 1768 | 1782 | const output = []; | |
| 1769 | 1783 | ctx.indentationLvl += 2; | |
| 1784 | + let i = 0; | ||
| 1770 | 1785 | for (const { 0: k, 1: v } of value) { | |
| 1786 | + if (i >= maxLength) break; | ||
| 1771 | 1787 | output.push( | |
| 1772 | 1788 | `${formatValue(ctx, k, recurseTimes)} => ${formatValue(ctx, v, recurseTimes)}` | |
| 1773 | 1789 | ); | |
| 1790 | + i++; | ||
| 1791 | + } | ||
| 1792 | + if (remaining > 0) { | ||
| 1793 | + ArrayPrototypePush(output, remainingText(remaining)); | ||
| 1774 | 1794 | } | |
| 1775 | 1795 | ctx.indentationLvl -= 2; | |
| 1776 | 1796 | return output; | |
@@ -1793,8 +1813,7 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) { | |||
| 1793 | 1813 | } | |
| 1794 | 1814 | const remaining = entries.length - maxLength; | |
| 1795 | 1815 | if (remaining > 0) { | |
| 1796 | - ArrayPrototypePush(output, | ||
| 1797 | - `... ${remaining} more item${remaining > 1 ? 's' : ''}`); | ||
| 1816 | + ArrayPrototypePush(output, remainingText(remaining)); | ||
| 1798 | 1817 | } | |
| 1799 | 1818 | return output; | |
| 1800 | 1819 | } | |
@@ -1832,7 +1851,7 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) { | |||
| 1832 | 1851 | } | |
| 1833 | 1852 | ctx.indentationLvl -= 2; | |
| 1834 | 1853 | if (remaining > 0) { | |
| 1835 | - output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); | ||
| 1854 | + output.push(remainingText(remaining)); | ||
| 1836 | 1855 | } | |
| 1837 | 1856 | return output; | |
| 1838 | 1857 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1172,6 +1172,7 @@ if (typeof Symbol !== 'undefined') { | |||
| 1172 | 1172 | { | |
| 1173 | 1173 | assert.strictEqual(util.inspect(new Set()), 'Set(0) {}'); | |
| 1174 | 1174 | assert.strictEqual(util.inspect(new Set([1, 2, 3])), 'Set(3) { 1, 2, 3 }'); | |
| 1175 | + assert.strictEqual(util.inspect(new Set([1, 2, 3]), { maxArrayLength: 1 }), 'Set(3) { 1, ... 2 more items }'); | ||
| 1175 | 1176 | const set = new Set(['foo']); | |
| 1176 | 1177 | set.bar = 42; | |
| 1177 | 1178 | assert.strictEqual( | |
@@ -1192,6 +1193,8 @@ if (typeof Symbol !== 'undefined') { | |||
| 1192 | 1193 | assert.strictEqual(util.inspect(new Map()), 'Map(0) {}'); | |
| 1193 | 1194 | assert.strictEqual(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), | |
| 1194 | 1195 | "Map(3) { 1 => 'a', 2 => 'b', 3 => 'c' }"); | |
| 1196 | + assert.strictEqual(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']]), { maxArrayLength: 1 }), | ||
| 1197 | + "Map(3) { 1 => 'a', ... 2 more items }"); | ||
| 1195 | 1198 | const map = new Map([['foo', null]]); | |
| 1196 | 1199 | map.bar = 42; | |
| 1197 | 1200 | assert.strictEqual(util.inspect(map, true), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments