loading...

re: 5 JavaScript functions to add to your utilities library VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Nice. My only comment would be that the ellipsis cut-off should probably subtract the length of the ellipsis, as typically you may want to conform ...
 

Even better, it should split at the end of a word and not in the middle of one

function summarize(str, max) {
  if (str.length <= max) return str;
  const subString = str.substring(0, max - 1);
  return subString.substring(0, subString.lastIndexOf(" ")) + "...";
}
 

Even better, use the unicode ellipsis (; \u2026).

code of conduct - report abuse