MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / truncateMiddle

Function truncateMiddle

example/tests/gm_xhr_test.js:365–377  ·  view source on GitHub ↗
(value, max)

Source from the content-addressed store, hash-verified

363 }
364
365 function truncateMiddle(value, max) {
366 const str = String(value);
367
368 if (!Number.isFinite(max) || max <= 0) return "";
369 if (str.length <= max) return str;
370 if (max <= 3) return str.slice(0, max);
371
372 const available = max - 1;
373 const left = Math.ceil(available / 2);
374 const right = Math.floor(available / 2);
375
376 return `${str.slice(0, left)}…${str.slice(-right)}`;
377 }
378
379 function padRight(value, width) {
380 return String(value).padEnd(width, " ");

Callers 2

prettyStackFunction · 0.85
cleanFileNameFunction · 0.85

Calls 1

sliceMethod · 0.45

Tested by

no test coverage detected