@solid-primitives/storage
Advanced tools
Comparing version 3.7.0 to 3.7.1
@@ -103,3 +103,3 @@ import { S as StringStorageProps, a as StorageWithOptions, b as StorageObject, c as StorageSetter, d as StorageActions, A as AnyStorageProps, e as AsyncStorage, f as AsyncStorageWithOptions, g as AsyncStorageObject, h as AsyncStorageSetter, i as AsyncStorageActions, j as StorageSignalProps, k as StorageProps } from '../types-C92rHTXK.js'; | ||
}; | ||
type CookieProperties = { | ||
type CookiePropertyTypes = { | ||
domain?: string; | ||
@@ -113,2 +113,5 @@ expires?: Date | number | String; | ||
}; | ||
type CookieProperties = { | ||
[key in keyof CookiePropertyTypes]: CookiePropertyTypes[key]; | ||
}; | ||
/** | ||
@@ -115,0 +118,0 @@ * handle cookies exactly like you would handle localStorage |
@@ -444,11 +444,25 @@ import { createHydratableSignal } from '@solid-primitives/utils'; | ||
// src/cookies.ts | ||
var cookiePropertyMap = { | ||
domain: "Domain", | ||
expires: "Expires", | ||
path: "Path", | ||
secure: "Secure", | ||
httpOnly: "HttpOnly", | ||
maxAge: "Max-Age", | ||
sameSite: "SameSite" | ||
}; | ||
function serializeCookieOptions(options) { | ||
if (!options) | ||
return ""; | ||
return Object.entries(options).map(([key, value]) => { | ||
if (key === "maxAge") { | ||
key = "max-age"; | ||
} | ||
return value instanceof Date ? `; ${key}=${value.toUTCString()}` : typeof value === "boolean" ? `; ${key}` : `; ${key}=${value}`; | ||
}).join(""); | ||
const result = Object.entries(options).map(([key, value]) => { | ||
const serializedKey = cookiePropertyMap[key]; | ||
if (!serializedKey) | ||
return void 0; | ||
if (value instanceof Date) | ||
return `${serializedKey}=${value.toUTCString()}`; | ||
if (typeof value === "boolean") | ||
return value ? `${serializedKey}` : void 0; | ||
return `${serializedKey}=${value}`; | ||
}).filter((v) => !!v); | ||
return result.length != 0 ? `; ${result.join("; ")}` : ""; | ||
} | ||
@@ -477,10 +491,7 @@ function deserializeCookieOptions(cookie, key) { | ||
const responseHeaders = getResponseHeaders(); | ||
const currentCookies = responseHeaders?.get("Set-Cookie")?.split(", ")?.filter((cookie) => cookie && !cookie.startsWith(`${key}=`)) ?? []; | ||
responseHeaders.set( | ||
"Set-Cookie", | ||
(responseHeaders.get("Set-Cookie") || "").replace( | ||
new RegExp(`(?:^|, )${key}=[^,]+`, "g"), | ||
"" | ||
) | ||
[...currentCookies, `${key}=${value}${serializeCookieOptions(options)}`].join(", ") | ||
); | ||
responseHeaders.append("Set-Cookie", `${key}=${value}${serializeCookieOptions(options)}`); | ||
} : (key, value, options) => { | ||
@@ -487,0 +498,0 @@ document.cookie = `${key}=${value}${serializeCookieOptions(options)}`; |
{ | ||
"name": "@solid-primitives/storage", | ||
"version": "3.7.0", | ||
"version": "3.7.1", | ||
"description": "Primitive that provides reactive wrappers for storage access", | ||
@@ -5,0 +5,0 @@ "author": "Alex Lohr <alex.lohr@logmein.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92777
1625