htmx-router
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -26,2 +26,3 @@ export interface CookieOptions { | ||
set(name: string, value: string, options?: CookieOptions): void; | ||
private string; | ||
unset(name: string): void; | ||
@@ -28,0 +29,0 @@ /** Creates the response headers required to make the changes done to these cookies */ |
@@ -51,5 +51,9 @@ /** | ||
if (this.source !== null && typeof this.source === "object") { | ||
document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`; | ||
document.cookie = this.string(name); | ||
} | ||
} | ||
string(name) { | ||
return encodeURIComponent(name) + "=" + encodeURIComponent(this.map[name]) + ";" + StringifyOptions(this.config[name]); | ||
; | ||
} | ||
unset(name) { | ||
@@ -62,24 +66,25 @@ this.parse(); | ||
const headers = new Array(); | ||
for (const name in this.config) { | ||
let config = ""; | ||
for (const opt in this.config[name]) { | ||
const prop = opt === "maxAge" | ||
? "Max-Age" | ||
: opt[0].toUpperCase() + opt.slice(1); | ||
const raw = this.config[name][opt]; | ||
if (raw === true) { | ||
config += `; ${prop}`; | ||
continue; | ||
} | ||
if (raw === false) | ||
continue; | ||
let value = String(raw); | ||
value = value[0].toUpperCase() + value.slice(1); | ||
config += `; ${prop}=${value}`; | ||
} | ||
const cookie = encodeURIComponent(name) + "=" + encodeURIComponent(this.map[name]) + config + ";"; | ||
headers.push(cookie); | ||
} | ||
for (const name in this.config) | ||
headers.push(this.string(name)); | ||
return headers; | ||
} | ||
} | ||
function StringifyOptions(options) { | ||
let config = ""; | ||
for (const opt in options) { | ||
const prop = opt === "maxAge" | ||
? "Max-Age" | ||
: opt[0].toUpperCase() + opt.slice(1); | ||
const raw = options[opt]; | ||
if (raw === true) { | ||
config += `; ${prop}`; | ||
continue; | ||
} | ||
if (raw === false) | ||
continue; | ||
let value = String(raw); | ||
value = value[0].toUpperCase() + value.slice(1); | ||
config += `${prop}=${value};`; | ||
} | ||
return config; | ||
} |
{ | ||
"name": "htmx-router", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "A lightweight SSR framework with server+client islands", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
2372
81953