-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix ClientOnly * Remove console.log in StackLayerPriorities * Force locale & timzone to avoid react hydration problems
- Loading branch information
Showing
4 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export type SetCookieOptions = { | ||
expires?: string | number | Date; | ||
path?: string; | ||
[key: string]: any; | ||
}; | ||
|
||
export function setCookie( | ||
name: string, | ||
value: any, | ||
options: SetCookieOptions = {} | ||
) { | ||
options = { | ||
path: "/", | ||
// add other defaults here if necessary | ||
...options, | ||
}; | ||
|
||
if (options.expires instanceof Date) { | ||
options.expires = options.expires.toUTCString(); | ||
} | ||
|
||
let updatedCookie = | ||
encodeURIComponent(name) + "=" + encodeURIComponent(value); | ||
|
||
for (let optionKey in options) { | ||
updatedCookie += "; " + optionKey; | ||
let optionValue = options[optionKey]; | ||
updatedCookie += "=" + optionValue; | ||
} | ||
|
||
document.cookie = updatedCookie; | ||
} | ||
|
||
export function deleteCookie(name: string) { | ||
setCookie(name, "", { | ||
"max-age": -1, | ||
}); | ||
} | ||
|
||
export function getCookie(name: string, cookie?: string) { | ||
cookie = cookie ?? document.cookie; | ||
let matches = cookie.match( | ||
new RegExp( | ||
"(?:^|; )" + | ||
name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, "\\$1") + | ||
"=([^;]*)" | ||
) | ||
); | ||
return matches ? decodeURIComponent(matches[1]) : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters