caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

36 lines
1.1 KiB
TypeScript

type CookieOptions = string[][]
const encodeCookie = (name: string, val: string) => {
return `${name}=${encodeURIComponent(val)}`
}
const decodeCookie = (cookie: string) => {
const parts = cookie.trim().split('=')
const rest = parts.slice(1).join('') // there may be more = in the value
return [parts[0], decodeURIComponent(rest)] as const
}
export const setCookie = (name: string, val: string, opts?: CookieOptions) => {
const parts = [encodeCookie(name, val)]
if (opts != null) {
parts.push(...opts.map((opt) => opt.join('=')))
}
const cookie = parts.join('; ')
document.cookie = cookie
}
// Note that this intentionally ignores the case where multiple cookies have
// the same name but different paths. Hopefully we never need to think about it.
export const getCookiesFromString = (cookiesStr: string) => {
const data = cookiesStr.trim()
if (!data) {
return {}
} else {
return Object.fromEntries(data.split(';').map(decodeCookie))
}
}
export const getCookie = (cookie: string) => {
return getCookiesFromString(document.cookie)[cookie]
}