@@ -146,6 +146,7 @@ const inspectDefaultOptions = ObjectSeal({
146
146
customInspect : true ,
147
147
showProxy : false ,
148
148
maxArrayLength : 100 ,
149
+ maxStringLength : Infinity ,
149
150
breakLength : 80 ,
150
151
compact : 3 ,
151
152
sorted : false ,
@@ -215,6 +216,7 @@ function getUserOptions(ctx) {
215
216
customInspect : ctx . customInspect ,
216
217
showProxy : ctx . showProxy ,
217
218
maxArrayLength : ctx . maxArrayLength ,
219
+ maxStringLength : ctx . maxStringLength ,
218
220
breakLength : ctx . breakLength ,
219
221
compact : ctx . compact ,
220
222
sorted : ctx . sorted ,
@@ -245,6 +247,7 @@ function inspect(value, opts) {
245
247
customInspect : inspectDefaultOptions . customInspect ,
246
248
showProxy : inspectDefaultOptions . showProxy ,
247
249
maxArrayLength : inspectDefaultOptions . maxArrayLength ,
250
+ maxStringLength : inspectDefaultOptions . maxStringLength ,
248
251
breakLength : inspectDefaultOptions . breakLength ,
249
252
compact : inspectDefaultOptions . compact ,
250
253
sorted : inspectDefaultOptions . sorted ,
@@ -282,6 +285,7 @@ function inspect(value, opts) {
282
285
}
283
286
if ( ctx . colors ) ctx . stylize = stylizeWithColor ;
284
287
if ( ctx . maxArrayLength === null ) ctx . maxArrayLength = Infinity ;
288
+ if ( ctx . maxStringLength === null ) ctx . maxStringLength = Infinity ;
285
289
return formatValue ( ctx , value , 0 ) ;
286
290
}
287
291
inspect . custom = customInspectSymbol ;
@@ -1301,6 +1305,12 @@ function formatBigInt(fn, value) {
1301
1305
1302
1306
function formatPrimitive ( fn , value , ctx ) {
1303
1307
if ( typeof value === 'string' ) {
1308
+ let trailer = '' ;
1309
+ if ( value . length > ctx . maxStringLength ) {
1310
+ const remaining = value . length - ctx . maxStringLength ;
1311
+ value = value . slice ( 0 , ctx . maxStringLength ) ;
1312
+ trailer = `... ${ remaining } more character${ remaining > 1 ? 's' : '' } ` ;
1313
+ }
1304
1314
if ( ctx . compact !== true &&
1305
1315
// TODO(BridgeAR): Add unicode support. Use the readline getStringWidth
1306
1316
// function.
@@ -1309,9 +1319,9 @@ function formatPrimitive(fn, value, ctx) {
1309
1319
return value
1310
1320
. split ( / (?< = \n ) / )
1311
1321
. map ( ( line ) => fn ( strEscape ( line ) , 'string' ) )
1312
- . join ( ` +\n${ ' ' . repeat ( ctx . indentationLvl + 2 ) } ` ) ;
1322
+ . join ( ` +\n${ ' ' . repeat ( ctx . indentationLvl + 2 ) } ` ) + trailer ;
1313
1323
}
1314
- return fn ( strEscape ( value ) , 'string' ) ;
1324
+ return fn ( strEscape ( value ) , 'string' ) + trailer ;
1315
1325
}
1316
1326
if ( typeof value === 'number' )
1317
1327
return formatNumber ( fn , value ) ;
0 commit comments