mirror of
https://github.com/braver/programmingfonts.git
synced 2024-09-08 12:41:32 +02:00
20 lines
411 B
JavaScript
20 lines
411 B
JavaScript
export class Cookies {
|
|
static get (key) {
|
|
return document.cookie
|
|
.split('; ')
|
|
.find((row) => row.startsWith(`${key}=`))
|
|
?.split('=')[1]
|
|
}
|
|
|
|
convert (value) {
|
|
if (value[0] === '"') {
|
|
value = value.slice(1, -1)
|
|
}
|
|
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
|
|
}
|
|
|
|
static set (key, value) {
|
|
document.cookie = `${key}=${value};max-age=172800`
|
|
}
|
|
}
|