htmx-router 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cookies.d.ts +1 -0
- package/cookies.js +26 -21
- package/package.json +1 -1
package/cookies.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class Cookies {
|
|
|
23
23
|
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
24
24
|
has(name: string): boolean;
|
|
25
25
|
set(name: string, value: string, options?: CookieOptions): void;
|
|
26
|
+
private string;
|
|
26
27
|
unset(name: string): void;
|
|
27
28
|
/** Creates the response headers required to make the changes done to these cookies */
|
|
28
29
|
export(): string[];
|
package/cookies.js
CHANGED
|
@@ -48,9 +48,13 @@ export class Cookies {
|
|
|
48
48
|
this.config[name] = options;
|
|
49
49
|
this.map[name] = value;
|
|
50
50
|
if (this.source !== null && typeof this.source === "object") {
|
|
51
|
-
document.cookie =
|
|
51
|
+
document.cookie = this.string(name);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
string(name) {
|
|
55
|
+
return encodeURIComponent(name) + "=" + encodeURIComponent(this.map[name]) + ";" + StringifyOptions(this.config[name]);
|
|
56
|
+
;
|
|
57
|
+
}
|
|
54
58
|
unset(name) {
|
|
55
59
|
this.parse();
|
|
56
60
|
return this.set(name, "", { maxAge: 0 });
|
|
@@ -58,26 +62,27 @@ export class Cookies {
|
|
|
58
62
|
/** Creates the response headers required to make the changes done to these cookies */
|
|
59
63
|
export() {
|
|
60
64
|
const headers = new Array();
|
|
61
|
-
for (const name in this.config)
|
|
62
|
-
|
|
63
|
-
for (const opt in this.config[name]) {
|
|
64
|
-
const prop = opt === "maxAge"
|
|
65
|
-
? "Max-Age"
|
|
66
|
-
: opt[0].toUpperCase() + opt.slice(1);
|
|
67
|
-
const raw = this.config[name][opt];
|
|
68
|
-
if (raw === true) {
|
|
69
|
-
config += `; ${prop}`;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (raw === false)
|
|
73
|
-
continue;
|
|
74
|
-
let value = String(raw);
|
|
75
|
-
value = value[0].toUpperCase() + value.slice(1);
|
|
76
|
-
config += `; ${prop}=${value}`;
|
|
77
|
-
}
|
|
78
|
-
const cookie = encodeURIComponent(name) + "=" + encodeURIComponent(this.map[name]) + config + ";";
|
|
79
|
-
headers.push(cookie);
|
|
80
|
-
}
|
|
65
|
+
for (const name in this.config)
|
|
66
|
+
headers.push(this.string(name));
|
|
81
67
|
return headers;
|
|
82
68
|
}
|
|
83
69
|
}
|
|
70
|
+
function StringifyOptions(options) {
|
|
71
|
+
let config = "";
|
|
72
|
+
for (const opt in options) {
|
|
73
|
+
const prop = opt === "maxAge"
|
|
74
|
+
? "Max-Age"
|
|
75
|
+
: opt[0].toUpperCase() + opt.slice(1);
|
|
76
|
+
const raw = options[opt];
|
|
77
|
+
if (raw === true) {
|
|
78
|
+
config += `; ${prop}`;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (raw === false)
|
|
82
|
+
continue;
|
|
83
|
+
let value = String(raw);
|
|
84
|
+
value = value[0].toUpperCase() + value.slice(1);
|
|
85
|
+
config += `${prop}=${value};`;
|
|
86
|
+
}
|
|
87
|
+
return config;
|
|
88
|
+
}
|