diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-03-22 11:37:34 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-03-22 11:37:34 +0300 |
| commit | 254bc97e737a568cb23fbbcb773f0dfb8894b9ff (patch) | |
| tree | 850c6dceda07214248c3bfa2bf3bf0e15fa3e329 /src/cookie.ts | |
| parent | 6c991424547b149b3cac70a94a4e14f3661908a6 (diff) | |
| download | the-epube-typescript-native.tar.gz the-epube-typescript-native.tar.xz | |
wip typescript stuff typescript-native
Diffstat (limited to 'src/cookie.ts')
| -rw-r--r-- | src/cookie.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/cookie.ts b/src/cookie.ts new file mode 100644 index 0000000..e37146c --- /dev/null +++ b/src/cookie.ts @@ -0,0 +1,28 @@ +// @ts-check + +'use strict'; + +export class Cookie { + static set(name, value, lifetime) { + const d = new Date(); + d.setTime(d.getTime() + lifetime * 1000); + const expires = "expires=" + d.toUTCString(); + document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires; + } + + static get(name) { + name = name + "="; + const ca = document.cookie.split(';'); + for (let i=0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1); + if (c.indexOf(name) == 0) return decodeURIComponent(c.substring(name.length, c.length)); + } + return ""; + } + + static delete(name) { + const expires = "expires=Thu, 01-Jan-1970 00:00:01 GMT"; + document.cookie = name + "=; " + expires; + } +} |
