Skip to content

Commit 0cf8491

Browse files
David Biereggeratk
authored andcommitted
Fix a few things from code review
1 parent b3a9d9e commit 0cf8491

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

packages/storage/src/cookies.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type CookieProperties = {
1919
sameSite?: "None" | "Lax" | "Strict";
2020
}
2121

22-
const cookiePropertyKeys: (keyof CookieProperties)[] = ["domain", "expires", "path", "secure", "httpOnly", "maxAge", "sameSite"];
22+
const cookiePropertyKeys = ["domain", "expires", "path", "secure", "httpOnly", "maxAge", "sameSite"] as const;
2323

2424

2525
function serializeCookieOptions(options?: CookieOptions) {
@@ -28,9 +28,8 @@ function serializeCookieOptions(options?: CookieOptions) {
2828
}
2929
let memo = "";
3030
for (const key in options) {
31-
if (!options.hasOwnProperty(key) || !cookiePropertyKeys.includes(key as keyof CookieProperties)) {
31+
if (!cookiePropertyKeys.includes(key as keyof CookieProperties))
3232
continue;
33-
}
3433

3534
const value = options[key as keyof CookieProperties];
3635
memo +=
@@ -88,7 +87,7 @@ export const cookieStorage: StorageWithOptions<CookieOptions> = addClearMethod({
8887
if (eventOrRequest.responseHeaders) // Check if we really got a pageEvent
8988
{
9089
const responseHeaders = eventOrRequest.responseHeaders as Headers;
91-
result += responseHeaders.get("Set-Cookie")?.split(",").map(cookie => !cookie.match(`\\w*\\s*=\\s*[^;]+`)).join(";") ?? "";
90+
result += responseHeaders.get("Set-Cookie")?.split(",").map(cookie => !cookie.match(/\\w*\\s*=\\s*[^;]+/)).join(";") ?? "";
9291
}
9392
return `${result};${request?.headers?.get("Cookie") ?? ""}`; // because first cookie will be preferred we don't have to worry about duplicates
9493
}
@@ -111,9 +110,8 @@ export const cookieStorage: StorageWithOptions<CookieOptions> = addClearMethod({
111110
: (key: string, value: string, options?: CookieOptions) => {
112111
document.cookie = `${key}=${value}${serializeCookieOptions(options)}`;
113112
},
114-
getItem: (key: string, options?: CookieOptions) => {
115-
return deserializeCookieOptions(cookieStorage._read(options), key)
116-
},
113+
getItem: (key: string, options?: CookieOptions) =>
114+
deserializeCookieOptions(cookieStorage._read(options), key),
117115
setItem: (key: string, value: string, options?: CookieOptions) => {
118116
const oldValue = isServer ? cookieStorage.getItem(key, options) : null;
119117
cookieStorage._write(key, value, options);

packages/storage/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type StorageWithOptions<O> = {
55
setItem: (key: string, value: string, options?: O) => void;
66
removeItem: (key: string, options?: O) => void;
77
key: (index: number, options?: O) => string | null;
8-
getLength: (options?: O) => number | undefined;
8+
getLength?: (options?: O) => number | undefined;
99
readonly length: number | undefined;
1010
[name: string]: any;
1111
};

0 commit comments

Comments
 (0)