1.0.1 • Published 6 years ago

cookie-handler-object v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

cookie-handler-object:

Background: I wanted an object that would ease the access to the document.cookie object. As the current document.cookie object isn't exactly user friendly, i wanted to create my own.

It only handles the document.cookie object, so the only cookies you'll be interfacing with are the ones for the current page.

Usage: for example: document.cookie => "optionOne=true; OptionTwo=false;"

var ch = new CookieHandler(); Upon creation, it defines every cookie in document.cookie as a property of itself.

So now, it has the properties:
optionOne:
  set; get;

OptionTwo:
  set; get;

As you can guess, to set / get a cookie, you would now just:
  var x = ch.optionOne; //Sets x to "true"
  var y = ch.optionOne; //Sets y to "false"

  ch.optionOne = "false"; //Changes optionOne in document.cookie to be "false".

CookieHandler.Update(): Update is the method used to turn document.cookie's cookies into properties of CookieHandler.

If there's a cookie in document.cookie, put there by another piece of code, it won't be added to CookieHandler as
a property until CookieHandler.Update() is called.