Class atropa.CookieMonster
Version
20130223.
This represents a cookie handler
Defined in: <node_modules/atropa-CookieMonster/src/atropa-CookieMonster.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
This is a cookie handler.
|
| Method Attributes | Method Name and Description |
|---|---|
|
bakeCookie(cookieObj)
Converts a cookie object to a cookie string.
|
|
|
cookie2obj(cookie)
Converts a cookie string into an object.
|
|
|
deleteCookie(whichKey)
Removes a specified cookie by user submitted string.
|
|
|
deleteCookieObj(cookieObj)
Removes a specified cookie by user submitted cookieObj.
|
|
|
getCookie(whichKey)
Gets a user requested cookie.
|
|
|
Get all cookies.
|
|
|
inspectCookies(callback, args)
Filter cookies based on user specified callback.
|
|
|
setCookie(whichKey, setTo)
Sets a cookie per user specifications as strings.
|
|
|
setCookieObj(cookieObj)
Sets a cookie per user specifications as an object.
|
Class Detail
atropa.CookieMonster()
// cookie object
var cookieObj = {"key" : "cookieName", "val" : "cookieVal"}
// cookie string
var cookieString = cookieName=cookieVal;
- Returns:
- {CookieMonster} A cookie handler.
- Requires:
- atropa.data
Method Detail
{String}
bakeCookie(cookieObj)
Converts a cookie object to a cookie string.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
var cookieMonster = new atropa.CookieMonster();
// creating a cookie
cookieMonster.setCookie('atropa', 'hial atropa!!');
console.log(document.cookie);
// getting a cookie object
var cookieObj = cookieMonster.getCookie('atropa');
console.log(cookieObj);
// convert the cookie object to a string
console.log(cookieMonster.bakeCookie(cookieObj));
- Parameters:
- {Object} cookieObj
- A cookie object
- Returns:
- {String} Returns a cookie string.
{cookieObj}
cookie2obj(cookie)
Converts a cookie string into an object.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
var cookieMonster = new atropa.CookieMonster();
var cookieObj = cookieMonster.cookie2obj('atropa=hial atropa!!;');
console.log(cookieObj);
- Parameters:
- {String} cookie
- A cookie represented as a string
cookieName=cookieVal;
- Returns:
- {cookieObj} Returns a cookie object.
deleteCookie(whichKey)
Removes a specified cookie by user submitted string.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
var cookieMonster = new atropa.CookieMonster();
// creating the cookie to delete
cookieMonster.setCookie('atropa', 'hial atropa!!');
console.log(document.cookie);
// delete a cookie
cookieMonster.deleteCookie('atropa');
console.log(document.cookie);
- Parameters:
- {String} whichKey
- The cookies key (name) that will be deleted.
deleteCookieObj(cookieObj)
Removes a specified cookie by user submitted cookieObj.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
var cookieMonster = new atropa.CookieMonster();
// creating the cookie to delete
cookieMonster.setCookie('atropa', 'hial atropa!!');
console.log(document.cookie);
// delete a cookie
cookieMonster.deleteCookieObj(
{key : 'atropa', val : 'does not matter'});
console.log(document.cookie);
- Parameters:
- {cookieObj} cookieObj
- A cookie object.
{cookieObj|false}
getCookie(whichKey)
var cookieMonster = new atropa.CookieMonster();
// creating a cookie
cookieMonster.setCookie('atropa', 'hial atropa!!');
console.log(document.cookie);
// get a specific cookie
var cookieObj = cookieMonster.getCookie('atropa');
console.log(cookieObj.key);
console.log(cookieObj.val);
- Parameters:
- {String} whichKey
- The cookies key (name)
- Returns:
- {cookieObj|false} Returns a cookie object if a cookie with the specified key is found or false if it is not found.
{Array}
getCookies()
var cookieMonster = new atropa.CookieMonster();
// creating a cookie
cookieMonster.setCookie('atropa', 'hial atropa!!');
// get all cookie objects in an array
console.log(cookieMonster.getCookies());
- Returns:
- {Array} An array whose elements are cookie objects.
{Array}
inspectCookies(callback, args)
Filter cookies based on user specified callback.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
var cookieMonster = new atropa.CookieMonster();
// creating a few cookies
cookieMonster.setCookie('atropa', 'hial atropa!!');
cookieMonster.setCookie('katjii', 'munching');
console.log(document.cookie);
// filter cookies
function cookieFilter(cookieObj, cookieValue) {
if(cookieObj.val === cookieValue) {
return true;
} else {
return false;
}
}
var cookieObjArray = cookieMonster.inspectCookies(
cookieFilter, 'munching');
console.log(cookieObjArray);
- Parameters:
- {function} callback
- The callback function will be passed
two arguments. The first is a cookie object from the current
document. The second argument is the value supplied for
argsif the callback function returnstruethen the cookie object will be included in the return results. - {Array} args
- Arguments to pass to the callback function.
- Returns:
- {Array} An array of cookie objects.
setCookie(whichKey, setTo)
Sets a cookie per user specifications as strings. The cookie
will expire when the browser is closed.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
var cookieMonster = new atropa.CookieMonster();
// set a cookie
cookieMonster.setCookie('atropa', 'hial');
console.log(document.cookie);
- Parameters:
- {String} whichKey
- The key (name) of the new cookie
- {String} setTo
- The value of the new cookie.
setCookieObj(cookieObj)
Sets a cookie per user specifications as an object.
The cookie will expire when the browser is closed.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
Author: Matthew Christopher Kastor-Inare III
☭ Hial Atropa!! ☭.
var cookieMonster = new atropa.CookieMonster();
// set a cookie
cookieMonster.setCookieObj({key : 'atropa', val : 'hial atropa!!'});
console.log(document.cookie);
- Parameters:
- {cookieObj} cookieObj
- A cookie object.