code: function trimToNearestSpace (str) {
    const trimThreshold = 15
    if (str.length < trimThreshold) return str
    const acceptableStretch = 3
    let trimmed = ''
    for (const word of str.split(' ')) {
      const combined = trimmed + ' ' + word
      if (combined.length > trimThreshold + acceptableStretch) {
        const previousSpaceAvailable = trimmed.length > trimThreshold - acceptableStretch && trimmed.length <= trimThreshold
        const resolved = previousSpaceAvailable ? trimmed : combined.slice(0, trimThreshold + 1)
        trimmed = resolved
        break
      }
      trimmed = combined
    }
    trimmed = trimmed.trim() // drop excess spaces
    return trimmed + '…'
  }
docs: Attempts to aesthetically limit string length Initially it breaks string into words (space split) Then it tries to detect a natural break that's not far from the max (15 +/- 3) And prioritize such break over a hard cut, if available