Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: absence of the consent state cookie is not handled correctly #15

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: 🏷️ add explicit return types
  • Loading branch information
switchnollie committed Apr 24, 2023
commit 0b44f32e341fa37bf6be82d1d6c30111816704f3
8 changes: 5 additions & 3 deletions packages/cookie-consent-banner/src/utils/parseCookies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export const parseCookies = () =>
export type CookieMap = Record<string, string | undefined>

export const parseCookies = (): CookieMap =>
document.cookie
.split(";")
.reduce<Record<string, string | undefined>>((acc, curr) => {
.reduce<CookieMap>((acc, curr) => {
const [key, value] = curr.split("=");

// key and value may be surrounded by whitespace (space and tab characters)
@@ -10,4 +12,4 @@ export const parseCookies = () =>
return { ...acc, [cookieKey]: cookieValue };
}, {});

export const getCookie = (cookieName: string) => parseCookies()[cookieName];
export const getCookie = (cookieName: string): string | undefined => parseCookies()[cookieName];