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