cookies SymbolThe cookies symbol gives you a clean API for working with browser cookies, making them behave more like window.localStorage instead of the awkward document.cookie string API.
| name | description | example |
|---|---|---|
| cookies. |
returns (or sets) the value of the cookie with the given name | set cookies.foo to 'bar' |
| cookies[ |
returns (or sets) the value of the cookie with the given name | set cookies['foo'] to 'bar' |
| cookies.length | returns the total number of cookies | log cookies.length |
| cookies[ |
returns the nth cookie | log cookies[0] |
| cookies.clear( |
clears a given cookie | cookies.clear('foo') |
| cookies.clearAll() | clears all cookies | cookies.clearAll() |
The cookies symbol can be iterated over:
for c in cookies
log c.name, c.value
end
You can assign a simple javascript object to a given cookie name in order to pass values for
specialized attributes like expires:
set cookies['My-Cookie'] to {value: "true", maxAge: 600}
The attributes of the javascript object will be interpreted as follows:
value will be the value of the cookie<button _="on click set cookies.hello to 'world'">
Set the cookie 'hello' to 'world'!
</button>
cookies