| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 56b150b commit 9ced334
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,8 +127,6 @@ const numberRegExp = /^(0|[1-9][0-9]*)$/; | |||
| 127 | 127 | const coreModuleRegExp = /^ at (?:[^/\\(]+ \(|)((?<![/\\]).+)\.js:\d+:\d+\)?$/; | |
| 128 | 128 | const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g; | |
| 129 | 129 | ||
| 130 | - const readableRegExps = {}; | ||
| 131 | - | ||
| 132 | 130 | const kMinLineLength = 16; | |
| 133 | 131 | ||
| 134 | 132 | // Constants to map the iterator state. | |
@@ -1055,37 +1053,12 @@ function formatBigInt(fn, value) { | |||
| 1055 | 1053 | function formatPrimitive(fn, value, ctx) { | |
| 1056 | 1054 | if (typeof value === 'string') { | |
| 1057 | 1055 | if (ctx.compact !== true && | |
| 1058 | - ctx.indentationLvl + value.length + 4 > ctx.breakLength && | ||
| 1059 | - value.length > kMinLineLength) { | ||
| 1060 | - // Subtract the potential quotes, the space and the plus as well (4). | ||
| 1061 | - const rawMaxLineLength = ctx.breakLength - ctx.indentationLvl - 4; | ||
| 1062 | - const maxLineLength = Math.max(rawMaxLineLength, kMinLineLength); | ||
| 1063 | - const lines = Math.ceil(value.length / maxLineLength); | ||
| 1064 | - const averageLineLength = Math.ceil(value.length / lines); | ||
| 1065 | - const divisor = Math.max(averageLineLength, kMinLineLength); | ||
| 1066 | - if (readableRegExps[divisor] === undefined) { | ||
| 1067 | - // Build a new RegExp that naturally breaks text into multiple lines. | ||
| 1068 | - // | ||
| 1069 | - // Rules | ||
| 1070 | - // 1. Greedy match all text up the max line length that ends with a | ||
| 1071 | - // whitespace or the end of the string. | ||
| 1072 | - // 2. If none matches, non-greedy match any text up to a whitespace or | ||
| 1073 | - // the end of the string. | ||
| 1074 | - // | ||
| 1075 | - // eslint-disable-next-line max-len, node-core/no-unescaped-regexp-dot | ||
| 1076 | - readableRegExps[divisor] = new RegExp(`(.|\\n){1,${divisor}}(\\s|$)|(\\n|.)+?(\\s|$)`, 'gm'); | ||
| 1077 | - } | ||
| 1078 | - const matches = value.match(readableRegExps[divisor]); | ||
| 1079 | - if (matches.length > 1) { | ||
| 1080 | - const indent = ' '.repeat(ctx.indentationLvl); | ||
| 1081 | - let res = `${fn(strEscape(matches[0]), 'string')} +\n`; | ||
| 1082 | - const lastIndex = matches.length - 1; | ||
| 1083 | - for (let i = 1; i < lastIndex; i++) { | ||
| 1084 | - res += `${indent} ${fn(strEscape(matches[i]), 'string')} +\n`; | ||
| 1085 | - } | ||
| 1086 | - res += `${indent} ${fn(strEscape(matches[lastIndex]), 'string')}`; | ||
| 1087 | - return res; | ||
| 1088 | - } | ||
| 1056 | + value.length > kMinLineLength && | ||
| 1057 | + value.length > ctx.breakLength - ctx.indentationLvl - 4) { | ||
| 1058 | + return value | ||
| 1059 | + .split(/(?<=\n)/) | ||
| 1060 | + .map((line) => fn(strEscape(line), 'string')) | ||
| 1061 | + .join(` +\n${' '.repeat(ctx.indentationLvl + 2)}`); | ||
| 1089 | 1062 | } | |
| 1090 | 1063 | return fn(strEscape(value), 'string'); | |
| 1091 | 1064 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,7 +93,7 @@ assert.strictEqual(util.inspect(new Date('')), (new Date('')).toString()); | |||
| 93 | 93 | assert.strictEqual(util.inspect('\n\u0001'), "'\\n\\u0001'"); | |
| 94 | 94 | assert.strictEqual( | |
| 95 | 95 | util.inspect(`${Array(75).fill(1)}'\n\u001d\n\u0003`), | |
| 96 | - `"${Array(75).fill(1)}'\\n" +\n '\\u001d\\n\\u0003'` | ||
| 96 | + `"${Array(75).fill(1)}'\\n" +\n '\\u001d\\n' +\n '\\u0003'` | ||
| 97 | 97 | ); | |
| 98 | 98 | assert.strictEqual(util.inspect([]), '[]'); | |
| 99 | 99 | assert.strictEqual(util.inspect(Object.create([])), 'Array {}'); | |
@@ -1487,10 +1487,9 @@ util.inspect(process); | |||
| 1487 | 1487 | ' 2,', | |
| 1488 | 1488 | ' [', | |
| 1489 | 1489 | ' [', | |
| 1490 | - " 'Lorem ipsum dolor\\nsit amet,\\tconsectetur ' +", | ||
| 1491 | - " 'adipiscing elit, sed do eiusmod tempor ' +", | ||
| 1492 | - " 'incididunt ut labore et dolore magna ' +", | ||
| 1493 | - " 'aliqua.',", | ||
| 1490 | + " 'Lorem ipsum dolor\\n' +", | ||
| 1491 | + " 'sit amet,\\tconsectetur adipiscing elit, sed do eiusmod " + | ||
| 1492 | + "tempor incididunt ut labore et dolore magna aliqua.',", | ||
| 1494 | 1493 | " 'test',", | |
| 1495 | 1494 | " 'foo'", | |
| 1496 | 1495 | ' ]', | |
@@ -1507,12 +1506,9 @@ util.inspect(process); | |||
| 1507 | 1506 | ||
| 1508 | 1507 | out = util.inspect(o.a[2][0][0], { compact: false, breakLength: 30 }); | |
| 1509 | 1508 | expect = [ | |
| 1510 | - "'Lorem ipsum dolor\\nsit ' +", | ||
| 1511 | - " 'amet,\\tconsectetur ' +", | ||
| 1512 | - " 'adipiscing elit, sed do ' +", | ||
| 1513 | - " 'eiusmod tempor incididunt ' +", | ||
| 1514 | - " 'ut labore et dolore magna ' +", | ||
| 1515 | - " 'aliqua.'" | ||
| 1509 | + "'Lorem ipsum dolor\\n' +", | ||
| 1510 | + " 'sit amet,\\tconsectetur adipiscing elit, sed do eiusmod tempor " + | ||
| 1511 | + "incididunt ut labore et dolore magna aliqua.'" | ||
| 1516 | 1512 | ].join('\n'); | |
| 1517 | 1513 | assert.strictEqual(out, expect); | |
| 1518 | 1514 | ||
@@ -1526,30 +1522,7 @@ util.inspect(process); | |||
| 1526 | 1522 | '12 45 78 01 34 67 90 23 56 89 123456789012345678901234567890', | |
| 1527 | 1523 | { compact: false, breakLength: 3 }); | |
| 1528 | 1524 | expect = [ | |
| 1529 | - "'12 45 78 01 34 ' +", | ||
| 1530 | - " '67 90 23 56 89 ' +", | ||
| 1531 | - " '123456789012345678901234567890'" | ||
| 1532 | - ].join('\n'); | ||
| 1533 | - assert.strictEqual(out, expect); | ||
| 1534 | - | ||
| 1535 | - out = util.inspect( | ||
| 1536 | - '12 45 78 01 34 67 90 23 56 89 1234567890123 0', | ||
| 1537 | - { compact: false, breakLength: 3 }); | ||
| 1538 | - expect = [ | ||
| 1539 | - "'12 45 78 01 34 ' +", | ||
| 1540 | - " '67 90 23 56 89 ' +", | ||
| 1541 | - " '1234567890123 0'" | ||
| 1542 | - ].join('\n'); | ||
| 1543 | - assert.strictEqual(out, expect); | ||
| 1544 | - | ||
| 1545 | - out = util.inspect( | ||
| 1546 | - '12 45 78 01 34 67 90 23 56 89 12345678901234567 0', | ||
| 1547 | - { compact: false, breakLength: 3 }); | ||
| 1548 | - expect = [ | ||
| 1549 | - "'12 45 78 01 34 ' +", | ||
| 1550 | - " '67 90 23 56 89 ' +", | ||
| 1551 | - " '12345678901234567 ' +", | ||
| 1552 | - " '0'" | ||
| 1525 | + "'12 45 78 01 34 67 90 23 56 89 123456789012345678901234567890'" | ||
| 1553 | 1526 | ].join('\n'); | |
| 1554 | 1527 | assert.strictEqual(out, expect); | |
| 1555 | 1528 | ||
@@ -1588,7 +1561,7 @@ util.inspect(process); | |||
| 1588 | 1561 | ||
| 1589 | 1562 | o[util.inspect.custom] = () => ({ a: '12 45 78 01 34 67 90 23' }); | |
| 1590 | 1563 | out = util.inspect(o, { compact: false, breakLength: 3 }); | |
| 1591 | - expect = "{\n a: '12 45 78 01 34 ' +\n '67 90 23'\n}"; | ||
| 1564 | + expect = "{\n a: '12 45 78 01 34 67 90 23'\n}"; | ||
| 1592 | 1565 | assert.strictEqual(out, expect); | |
| 1593 | 1566 | } | |
| 1594 | 1567 | ||
@@ -2192,16 +2165,13 @@ assert.strictEqual( | |||
| 2192 | 2165 | ' b: {', | |
| 2193 | 2166 | ' x: 5,', | |
| 2194 | 2167 | ' c: {', | |
| 2195 | - " x: '10000000000000000 00000000000000000 ' +", | ||
| 2196 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2197 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2198 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2199 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2200 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2201 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2202 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2203 | - " '10000000000000000 00000000000000000 ' +", | ||
| 2204 | - " '10000000000000000 00000000000000000 ',", | ||
| 2168 | + " x: '10000000000000000 00000000000000000 10000000000000000 " + | ||
| 2169 | + '00000000000000000 10000000000000000 00000000000000000 ' + | ||
| 2170 | + '10000000000000000 00000000000000000 10000000000000000 ' + | ||
| 2171 | + '00000000000000000 10000000000000000 00000000000000000 ' + | ||
| 2172 | + '10000000000000000 00000000000000000 10000000000000000 ' + | ||
| 2173 | + '00000000000000000 10000000000000000 00000000000000000 ' + | ||
| 2174 | + "10000000000000000 00000000000000000 ',", | ||
| 2205 | 2175 | ' d: 2,', | |
| 2206 | 2176 | ' e: 3', | |
| 2207 | 2177 | ' }', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments