A lightweight, slightly opinionated cookie manager
A lightweight cookie manager for both the browser and nodejs.
light as a feather
1.66kb minified, 450 bytes gzipped
oatmealcookie"raisin" "yumyum" seconds: 50oatmealcookie"chewy" "yumyum" minutes: 10oatmealcookie"thick" "yumyum" hours: 12oatmealcookie"soft" "yumyum" days: 15oatmealcookie"Specialty's" "yum!" months: 3oatmealcookie"thin" "meh" years: 1oatmealcookie"crunchy" "meh!" expires:
flexible might be an understatement
oatmealcookie"raisin" "yummy" months: 3 days: 10oatmealcookie"raisin" "yummy" months: 3 days: 10 seconds: 10oatmealcookie"raisin" "yummy" expires: myDate days: 10
works with your objects, not against
var penelope =age: 26height: "6'1"beautiful: "yes"oatmealcookie"person" penelope
Some of the methods take an optional
options configuration object
secureto the cookie string.
A couple of notes. Without
expires, all of the timing is relative to the current time. With
expires, the other timing options are added to the date specified.
Timing options can be combined together, e.g., you can specify
months: 1, days: 3 to get an expiration date of one month and three days from now.
Sets a cookie named
value. Note that
value can be a string, boolean, number or object. The value will always be encoded and JSONized.
Gets the value for a cookie called
oatmeal.cookie(name, value) except that it avoids setting the actual cookie and returns the properly formatted cookie string instead, e.g.,
name=key; path=/; secure. This is mainly useful on the node side.
Deletes the cookie with the specified name.
Deletes all cookies.
Forces a refresh of the known cookies. Normally you won't need to call this externally. An instance where you might need to is if you respecify the source. The previously parsed cookies would be cached and unless you add a new one it won't get updated. You can force that update instead by calling this method.
Specifies a string to parse for cookies. This is mainly useful on the node side.
You can use oatmeal in nodejs as well, albeit in a limited fashion.
Generates a properly formatted cookie string for the given parameters. It's up to you to actually set the response header, i.e.,
Specifies the string to parse for cookies. You can grab this from the request headers.
This library works with Ender!
ender build oatmeal
When used with ender, the method names are changed up a bit because we're on a global namespace object ($).
Othewise, everything else should work the same. You can also
require the oatmeal library.
var oatmeal = require'oatmeal'
This library depends on
JSON.stringify. This is natively supported in browsers Internet Explorer 8+, Firefox 3.1+, Safari 4+, Chrome 3+. If you are unfortunate enough to have to care about older browsers, it's up to you to polyfill the behavior.