All files / proxy/utils cookies.ts

100% Statements 12/12
100% Branches 2/2
100% Functions 2/2
100% Lines 12/12

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 19 204x 42x 42x   42x 80x 80x   80x 78x 78x 78x 39x         42x    
export function filterCookie(cookie: string, filterPredicate: (key: string) => boolean): string {
  const newCookie: string[] = []
  const parts = cookie.split(';')
 
  parts.forEach((cookie) => {
    const trimmedCookie = cookie.trim()
    const index = trimmedCookie.indexOf('=')
 
    if (index !== -1) {
      const key = trimmedCookie.substring(0, index)
      const value = trimmedCookie.substring(index + 1)
      if (filterPredicate(key)) {
        newCookie.push(`${key}=${value}`)
      }
    }
  })
 
  return newCookie.join('; ').trim()
}