Skip to content

Commit 0218ec9

Browse files
author
Luca Forstner
committed
Map instead of obj
1 parent ce50a60 commit 0218ec9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/utils/src/cookie.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
/**
3232
* Parses a cookie string
3333
*/
34-
export function parseCookie(str: string): Record<string, string> {
35-
const obj: Record<string, string> = {};
34+
export function parseCookie(str: string): Map<string, string> {
35+
const cookieMap = new Map<string, string>();
3636
let index = 0;
3737

3838
while (index < str.length) {
@@ -56,7 +56,7 @@ export function parseCookie(str: string): Record<string, string> {
5656
const key = str.slice(index, eqIdx).trim();
5757

5858
// only assign once
59-
if (undefined === obj[key]) {
59+
if (undefined === cookieMap.get(key)) {
6060
let val = str.slice(eqIdx + 1, endIdx).trim();
6161

6262
// quoted values
@@ -65,14 +65,14 @@ export function parseCookie(str: string): Record<string, string> {
6565
}
6666

6767
try {
68-
obj[key] = val.indexOf('%') !== -1 ? decodeURIComponent(val) : val;
68+
cookieMap.set(key, val.indexOf('%') !== -1 ? decodeURIComponent(val) : val);
6969
} catch (e) {
70-
obj[key] = val;
70+
cookieMap.set(key, val);
7171
}
7272
}
7373

7474
index = endIdx + 1;
7575
}
7676

77-
return obj;
77+
return cookieMap;
7878
}

0 commit comments

Comments
 (0)