Library to manipulate cookie in JavaScript
JavaScript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
README.md
index.js
logo.png
logo.svg
package.json

README.md

Cookie

browser support

Nom nom nom! The easy way to cook and eat cookies (yummy!) in #JavaScript.

Install via npm

$ npm install putainde-cookie (--save-dev)

Usage

cookie

var cookie = require("putainde-cookie")

cookie.set(name, value[, opts])

cookie.set("my-own-cookie", "nom nom nom", {
  domain: ".wonderland.com",
  path: "/foo",
  expires: +new Date() + (cookie.DAY * 4)
});

var expires = new Date();
expires.setTime(expires.getTime() + 8 * cookie.DAY);
cookie.set("my-own-cookie", "nom nom nom", expires);
cookie.set("my-own-cookie", "nom nom nom");

cookie.get(name)

cookie.get("my-own-cookie"); // 'nom nom nom'

cookie.remove(name[, opts])

// bye-bye!
cookie.remove("my-own-cookie");
cookie.remove("my-own-cookie", {
  domain: ".wonderland.com",
  path: "/foo"
});

Sugar!

Cookie fits well with the excellent lib moment.js.

First of all, install moment:

$ bower install moment

Now, you can use something like this:

// Cookie should be eaten before the end of the day
cookie.set("gingerbread", "excellent", {
  expires: moment().endOf('day')
});

Attribution

Cookie designed by Caroline Lancaster from The Noun Project.