The cookies Symbol

Syntax

  cookies

Description

The cookies symbol is not a proper expression, but rather a value assigned, by default, to the cookies symbol. This value presents a better API than the standard document.cookie API, making cookies work more like window.localStorage

The API of the cookies symbol is as follows:

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()

In addition to this, the cookies symbol can be iterated over:

    for c in cookies
      log c.name, c.value
    end

You can also 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 the javascript object will be interpreted as follows:

Examples

<button _="on click set cookies.hello to 'world'">
    Set the cookie 'hello' to 'world'!
</button>