All files / server/src/utils getShortDescriptionFromDescription.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1949x 49x   49x     616x   616x   616x 1584x 1584x 608x     616x    
const SHORT_DESCRIPTION_MAX_LENGTH = 200;
const matchNextSentence = /([.?!])\s*(?=[A-Z])/g;
 
export const getShortDescriptionFromDescription = (
  description: string,
): string => {
  let shortDescription = "";
 
  const sentences = description.replaceAll(matchNextSentence, "$1|").split("|");
 
  for (const sentence of sentences) {
    shortDescription = shortDescription.concat(`${sentence} `);
    if (shortDescription.length >= SHORT_DESCRIPTION_MAX_LENGTH) {
      break;
    }
  }
  return shortDescription;
};