Skip to content
✌ Makis Tracend edited this page May 24, 2013 · 7 revisions

A generic cookie parser that offers a simplified REST-like API

Usage

initialize by copying the the

var cookie = c.cookie();

Use the methods on the cookie objects to execute operations...

Methods

set()

Sets a cookie value cookie onto the collection and the document.cookie property. Returns a boolean as a result of the operation.

Parameters

This method accepts a single object that should include all information about the cookie to be set. Properties on this object:

  • name (string) Required. The name of the cookie
  • value (string) Required. The value of this cookie
  • path (string) Optional. The path of this cookie
  • domain (string) Optional. The domain of this cookie
  • expires (Object) Optional. Set the expiration date of this cookie. Accepted keys: minutes, hours, days, weeks, months, years

Example

cookie.set({ 
  name: "cookiename", 
  value: "authenticated", 
  expires: {
    days: 1
  }
});

get()

Returns the string value of a cookie. Returns a string with the passed arguments.

Parameters

  • name (string) Required. The name of the cookie.

Example

cookie.get("cookiename");

has()

Checks for the existence of a cookie on the collection, updating the collection if it's not found. Returns a boolean.

Parameters

  • name (string) Required. The name of the cookie.

Example

cookie.has("cookiename");

remove()

Deletes a cookie from the collection and updates the document object. Returns a boolean.

Parameters

  • name (string) Required. The name of the cookie.

Example

cookie.remove("cookiename");