All files / server/src/utils getShortDescriptionFromDescription.ts

30% Statements 3/10
0% Branches 0/2
100% Functions 1/1
30% Lines 3/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 1944x 44x   44x                              
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;
};