mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-28 18:46:09 +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._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 })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue