packages/devtools-reps/src/reps/string.js
function getCroppedString(text, offset = 0, startCropIndex, endCropIndex) {
  if (!startCropIndex) {
    return text;
  }

  const start = offset;
  const end = offset + text.length;

  const shouldBeVisible = !(start >= startCropIndex && end <= endCropIndex);
  if (!shouldBeVisible) {
    return null;
  }

  const shouldCropEnd = start < startCropIndex && end > startCropIndex;
  const shouldCropStart = start < endCropIndex && end > endCropIndex;
  if (shouldCropEnd) {
    const cutIndex = startCropIndex - start;
    return (
      text.substring(0, cutIndex) +
      ELLIPSIS +
      (shouldCropStart ? text.substring(endCropIndex - start) : "")
    );
  }

  if (shouldCropStart) {
    // The string should be cropped at the beginning.
    const cutIndex = endCropIndex - start;
    return text.substring(cutIndex);
  }

  return text;
}
function getCroppedString(text, offset = 0, startCropIndex, endCropIndex) {
  if (!startCropIndex) {
    return text;
  }

  const start = offset;
  const end = offset + text.length;

  const shouldBeVisible = !(start >= startCropIndex && end <= endCropIndex);
  if (!shouldBeVisible) {
    return null;
  }

  const shouldCropEnd = start < startCropIndex && end > startCropIndex;
  const shouldCropStart = start < endCropIndex && end > endCropIndex;
  if (shouldCropEnd) {
    const cutIndex = startCropIndex - start;
    return (
      text.substring(0, cutIndex) +
      ELLIPSIS +
      (shouldCropStart ? text.substring(endCropIndex - start) : "")
    );
  }

  if (shouldCropStart) {
    // The string should be cropped at the beginning.
    const cutIndex = endCropIndex - start;
    return text.substring(cutIndex);
  }

  return text;
}
function getCroppedString ( text , offset = 0 , startCropIndex , endCropIndex ) { if ( ! startCropIndex ) { return text ; } const start = offset ; const end = offset + text . length ; const shouldBeVisible = ! ( start >= startCropIndex && end <= endCropIndex ) ; if ( ! shouldBeVisible ) { return null ; } const shouldCropEnd = start < startCropIndex && end > startCropIndex ; const shouldCropStart = start < endCropIndex && end > endCropIndex ; if ( shouldCropEnd ) { const cutIndex = startCropIndex - start ; return ( text . substring ( 0 , cutIndex ) + ELLIPSIS + ( shouldCropStart ? text . substring ( endCropIndex - start ) : "" ) ) ; } if ( shouldCropStart ) { // The string should be cropped at the beginning. const cutIndex = endCropIndex - start ; return text . substring ( cutIndex ) ; } return text ; }
Returns a cropped substring given an offset, start and end crop indices in a
parent string.

@param {String} text: The substring to crop.
@param {Integer} offset: The offset corresponding to the index at which
the substring is in the parent string.
@param {Integer|null} startCropIndex: the index where the start of the crop
should happen in the parent string.
@param {Integer|null} endCropIndex: the index where the end of the crop
should happen in the parent string
@returns {String|null} The cropped substring, or null if the text is
completly cropped.
Returns a cropped substring given an offset start and end crop indices in a parent string .