api/cookie: formatting

This commit is contained in:
jj 2024-11-01 14:05:18 +00:00
parent 48883486fa
commit 2351cf74f4
No known key found for this signature in database

View file

@ -6,14 +6,17 @@ export default class Cookie {
this._values = {};
this.set(input)
}
set(values) {
Object.entries(values).forEach(
([ key, value ]) => this._values[key] = value
)
}
unset(keys) {
for (const key of keys) delete this._values[key]
}
static fromString(str) {
const obj = {};
@ -25,12 +28,15 @@ export default class Cookie {
return new Cookie(obj)
}
toString() {
return Object.entries(this._values).map(([ name, value ]) => `${name}=${value}`).join('; ')
}
toJSON() {
return this.toString()
}
values() {
return Object.freeze({ ...this._values })
}