koekiemonster v2.2.1
koekiemonster
A node.js compatible version of cookie-monster, which is a clone of
cookie-cutter. We must fork deeper yessss?
Installation
The package is released in the public npm registry as koekiemonster which is
the dutch name for cookie monster and can be installed by running:
npm install --save koekiemonsterAPI
The module returns a single function that requires a reference to document. If you are in a Node.js environment you can pass in a object instead and it should still function as intended.
var cookie = require('koekiemonster')(document, { /* advanced options */ });
var times = parseInt(cookie.getItem('times'), 10) || 0;
cookie.setItem('times', times + 1);The first argument is a reference to the document so it can access document.cookie
the second argument is an object for advanced options. This allows you to specify
a custom read and write method for cookies.
readCalled when it needs to read all cookies and expects an array to be returned withkey=cookiestrings for each cookie.writeCalled when a cookie needs to be stored, withcookie, andmetaas arguments. Assumes it returns the cookie string once it's stored. Themetais an object that contains the following properties:removeBoolean indicating if this is a removal request.valueCookie value.keyKey of the cookie.optsOriginal supplied options.
It's worth noting that if you do not supply document as first argument we
will attempt to feature detect the existance of document and document.cookie
automatically and default to that. In the case where it's missing, we will
default to an empty object so the following will work fine in a browser based
environment:
var cookie = require('koekiemonster')();
console.log(cookie.getItem('items')); // should output the same as above.getItem(key)
Return the contents of a cookie for the given key name.
setItem(key, value, opts)
Set a new cookie with the given key as name and value as contents. You can use
the opts object to configure the cookie string.
expiresSets the expiree of the cookie.pathPath of the cookie.domainDomain of the cookie.secureShould the cookie be secure only.
removeItem(key, opts)
Remove a cookie with the name of the key. You can use the same opts as the
setItem method.
clear
Remove all cookies.
License
MIT/X11