All files / Rindu/utils parseAcceptLanguage.ts

100% Statements 9/9
50% Branches 1/2
100% Functions 5/5
100% Lines 9/9

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 135x 1x 2x 2x 2x     1x 1x 2x 2x    
export function parseAcceptLanguage(acceptLanguage = ""): string[] {
  const languages = acceptLanguage.split(",").map((lang) => {
    const [code, q = "1"] = lang.trim().split(";q=");
    const baseCode = code.split("-")[0];
    return { code: baseCode.trim(), q: parseFloat(q) };
  });
 
  return languages
    .toSorted((a, b) => b.q - a.q)
    .map(({ code }) => code)
    .filter((code, index, self) => self.indexOf(code) === index);
}