mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-28 02:26:10 +00:00
api/cookie: formatting
This commit is contained in:
parent
48883486fa
commit
2351cf74f4
|
@ -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 })
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue