blob: 5005b726faeccbb2c4198c9845d569824973560f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { isNothing } from "@jet/environment/types/optional";
/**
* Iterate the cookies contained in a string.
*
* @param cookie A string containing zero or more cookies.
*/
export function* cookiesOf(cookie) {
if (isNothing(cookie)) {
return;
}
const rawEntries = cookie.split(";");
for (const rawEntry of rawEntries) {
const keyEndIndex = rawEntry.indexOf("=");
if (keyEndIndex === -1) {
// If there's no splitter, treat the whole raw
// entry as the key and provide an empty value.
const key = decodeURIComponent(rawEntry).trim();
yield { key, value: "" };
}
else {
const key = decodeURIComponent(rawEntry.substring(0, keyEndIndex)).trim();
const value = decodeURIComponent(rawEntry.substring(keyEndIndex + 1)).trim();
yield { key, value };
}
}
}
//# sourceMappingURL=cookies.js.map
|