mirror of
https://github.com/wukko/cobalt.git
synced 2025-06-13 13:47:38 +02:00
api/cookie: formatting
This commit is contained in:
@ -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 })
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user